/* styles.css */

:root {
  --bg: #1b1d1f;
  --bg-elevated: #222629;
  --surface: #2a2f34;
  --surface-2: #31373d;
  --surface-3: #383f46;

  --border: #46505a;
  --border-strong: #5a6673;

  --text: #f3f6f8;
  --text-soft: #c8d0d8;
  --text-dim: #9aa6b2;

  --cyan: #39d5ff;
  --cyan-soft: rgba(57, 213, 255, 0.14);

  --orange: #f59e0b;
  --orange-soft: rgba(245, 158, 11, 0.16);

  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);

  --success: #22c55e;

  --shadow: 0 14px 32px rgba(0, 0, 0, 0.24);
  --radius: 14px;
  --radius-sm: 10px;

  --status-bar-h: 78px;
  --footer-h: 82px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background:
    radial-gradient(circle at top, rgba(57, 213, 255, 0.04), transparent 24%),
    linear-gradient(180deg, #1b1d1f 0%, #181a1c 100%);
  color: var(--text);
  line-height: 1.42;
}

button,
input,
textarea,
select {
  font: inherit;
}

input[type="number"] {
  font-size: 16px !important;
  -webkit-text-size-adjust: 100%;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  max-width: 1180px;
  margin: 0 auto;
  padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px) + 10px);
}

.app-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 10px 12px 12px;
}

/* =========================
   STATUS BAR
========================= */

.status-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding:
    calc(8px + env(safe-area-inset-top, 0px))
    12px
    8px;
  background: rgba(27, 29, 31, 0.94);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(90, 102, 115, 0.34);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.status-row + .status-row {
  margin-top: 6px;
}

.status-row-primary {
  justify-content: space-between;
}

.status-brand {
  color: var(--cyan);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.01em;
  line-height: 1;
}

.status-pill,
.status-meta {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(90, 102, 115, 0.48);
  background: rgba(42, 47, 52, 0.9);
  color: var(--text);
  line-height: 1;
}

.status-pill {
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill-warning {
  border-color: rgba(245, 158, 11, 0.52);
  color: #ffd58a;
  background: rgba(245, 158, 11, 0.12);
}

.status-meta {
  padding: 0 10px;
  border-radius: 999px;
  color: var(--text-soft);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

/* =========================
   GENERIC CARDS
========================= */

.card,
.report-card {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.02), transparent 100%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.report-card {
  padding: 14px;
}

.control-stack,
.preview-stack {
  display: grid;
  gap: 12px;
}

/* =========================
   MODE TOGGLE
========================= */

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
}

.mode-btn {
  width: 100%;
  min-height: 52px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #2a3036;
  color: var(--text-soft);
  font-weight: 800;
  font-size: 1rem;
  transition: 0.18s ease;
}

.mode-btn.active {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #081318;
  box-shadow: 0 0 0 3px rgba(57, 213, 255, 0.16);
}

/* =========================
   FORM + ACCORDION
========================= */

.layout-form {
  display: grid;
  gap: 12px;
}

.accordion-card {
  overflow: hidden;
}

.accordion-toggle {
  width: 100%;
  min-height: 54px;
  padding: 14px 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: center;
  text-align: left;
}

.accordion-title {
  font-weight: 800;
  font-size: 0.98rem;
  white-space: nowrap;
}

.accordion-summary {
  color: var(--text-dim);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.accordion-chevron {
  color: var(--text-dim);
  font-size: 1rem;
  transition: transform 0.18s ease;
}

.accordion-card.is-open .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-panel {
  padding: 0 16px 14px;
  border-top: 1px solid rgba(90, 102, 115, 0.28);
}

.field-grid {
  display: grid;
  gap: 6px;
}

label {
  display: block;
  margin-top: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-dim);
}

input {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  background: #23282d;
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  outline: none;
  transition: 0.18s ease;
}

input::placeholder {
  color: #7f8b97;
}

input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(57, 213, 255, 0.15);
}

.inline-note {
  padding: 13px 14px;
  border: 1px solid rgba(57, 213, 255, 0.2);
  border-radius: 12px;
  background: rgba(57, 213, 255, 0.07);
  color: var(--text-soft);
  font-size: 0.92rem;
}

/* =========================
   OPENINGS
========================= */

.openings-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.opening-entry-grid {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.opening-item {
  background: #252b31;
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  font-family: "Fira Code", monospace;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.opening-item span {
  display: block;
  line-height: 1.45;
  word-break: break-word;
}

.delete-btn {
  width: auto;
  min-width: 40px;
  padding: 7px 10px;
  border: 1px solid rgba(239, 68, 68, 0.42);
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
  font-weight: 800;
  flex-shrink: 0;
}

.secondary-action {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  background: #31373d;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: var(--cyan);
  font-weight: 800;
}

/* =========================
   PREVIEW
========================= */

.preview-card {
  padding: 14px;
  border-radius: 20px;
}

.preview-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.preview-header-copy h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--text);
}

.preview-subtitle {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 0.86rem;
  font-weight: 600;
}

.ghost-action {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  color: var(--text-soft);
  font-weight: 800;
}

.preview-toolbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.tool-btn {
  min-height: 42px;
  padding: 10px 12px;
  background: #2b3137;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  color: var(--cyan);
  font-weight: 800;
}

.svg-frame {
  position: relative;
  padding: 10px;
  border: 1px solid rgba(90, 102, 115, 0.58);
  border-radius: 18px;
  background:
    linear-gradient(rgba(57, 213, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 213, 255, 0.07) 1px, transparent 1px),
    #20252a;
  background-size: 20px 20px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}

.svg-frame::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  border: 1px solid rgba(90, 102, 115, 0.28);
  pointer-events: none;
}

#wallSvg {
  width: 100%;
  height: 320px;
  display: block;
  position: relative;
  z-index: 1;
  background: rgba(32, 37, 42, 0.72);
  border: 1px solid rgba(90, 102, 115, 0.52);
  border-radius: 12px;
}

/* =========================
   RESULTS
========================= */

.results-card {
  overflow: hidden;
  border-radius: 18px;
}

.results-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid rgba(90, 102, 115, 0.36);
}

.results-tab {
  min-height: 50px;
  padding: 10px 6px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-soft);
  font-weight: 800;
  font-size: 0.96rem;
}

.results-tab.active {
  color: var(--cyan);
  border-bottom-color: var(--orange);
  background: rgba(255,255,255,0.02);
}

.results-panels {
  padding: 14px;
  min-height: 120px;
}

.results-panel {
  display: none;
}

.results-panel.active {
  display: block;
}

.report-card-inline {
  margin: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.empty-state {
  color: var(--text-dim);
  font-size: 0.92rem;
  font-weight: 600;
}

/* =========================
   MOBILE FOOTER
========================= */

.mobile-action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: 1fr 110px 1.08fr;
  gap: 10px;
  padding:
    10px 12px
    calc(10px + env(safe-area-inset-bottom, 0px));
  background: rgba(27, 29, 31, 0.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid rgba(90, 102, 115, 0.34);
}

.footer-btn {
  min-height: 56px;
  padding: 12px 14px;
  border-radius: 16px;
  font-weight: 800;
  font-size: 1rem;
}

.footer-btn-primary {
  background: #2a3036;
  color: var(--cyan);
  border: 1px solid var(--border-strong);
}

.footer-btn-icon {
  min-width: 64px;
  background: #2a3036;
  color: var(--text-soft);
  border: 1px solid var(--border-strong);
  font-size: 1.25rem;
  letter-spacing: 0.08em;
}

.footer-btn-accent {
  background: var(--cyan);
  color: #081318;
  border: 1px solid #7be6ff;
}

/* =========================
   REPORT CONTENT STYLES
========================= */

#openingReport {
  margin-top: 0;
}

.opening-report-block {
  border-top: 1px solid rgba(90, 102, 115, 0.42);
  padding-top: 12px;
  margin-top: 12px;
  font-size: 0.86rem;
  color: var(--text-soft);
}

.panel-cut-list ul,
.warning-box ul {
  margin: 6px 0 0 18px;
  padding: 0;
}

.warning-box {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  background: var(--orange-soft);
  border-radius: 12px;
  color: #ffd58a;
}

.good-status {
  color: #9ae6b4;
}

/* =========================
   SUMMARY STYLES
========================= */

.summary-block h3 {
  margin: 0 0 14px;
  color: var(--text);
  font-size: 1rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-stat {
  padding: 12px;
  border: 1px solid rgba(90, 102, 115, 0.36);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.summary-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 600;
}

.summary-value {
  color: var(--text);
  font-family: "Fira Code", monospace;
  font-size: 0.96rem;
}

.summary-detail-list {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.summary-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #252b31;
  border: 1px solid rgba(90, 102, 115, 0.3);
  color: var(--text-soft);
}

.summary-detail-row strong {
  color: var(--text);
  font-family: "Fira Code", monospace;
}

.summary-cut-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.summary-cut-item {
  padding: 12px;
  border-radius: 12px;
  background: #252b31;
  border: 1px solid rgba(90, 102, 115, 0.3);
}

.summary-cut-head {
  margin-bottom: 8px;
  color: var(--text);
}

.summary-cut-values {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-soft);
  font-family: "Fira Code", monospace;
}

/* compact gable cut schedule */
.gable-cut-schedule {
  border: 1px solid rgba(90, 102, 115, 0.3);
  border-radius: 12px;
  overflow: hidden;
  background: #252b31;
}

.gable-cut-schedule-head,
.gable-cut-row {
  display: grid;
  grid-template-columns: 72px 1fr 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  font-family: "Fira Code", monospace;
}

.gable-cut-schedule-head {
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(90, 102, 115, 0.28);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gable-cut-row {
  color: var(--text-soft);
  font-size: 0.84rem;
}

.gable-cut-row + .gable-cut-row {
  border-top: 1px solid rgba(90, 102, 115, 0.18);
}

.gable-cut-row strong {
  color: var(--text);
}

/* =========================
   REPORT CARD STYLES
========================= */

.report-block h3 {
  margin: 0 0 14px;
  color: var(--text);
  font-size: 1rem;
}

.report-stack {
  display: grid;
  gap: 12px;
}

.opening-report-card {
  padding: 14px;
  border-radius: 12px;
  background: #252b31;
  border: 1px solid rgba(90, 102, 115, 0.3);
}

.opening-report-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.opening-report-head h4 {
  margin: 0;
  color: var(--text);
  font-size: 0.96rem;
}

.report-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.report-badge-good {
  color: #b7f7c5;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.report-badge-warn {
  color: #ffd58a;
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.32);
}

.report-metric-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.report-metric-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(90, 102, 115, 0.24);
  color: var(--text-soft);
}

.report-metric-row strong {
  color: var(--text);
  font-family: "Fira Code", monospace;
  text-align: right;
}

.report-subsection {
  margin-top: 12px;
}

.report-subtext {
  color: var(--text-dim);
  font-size: 0.84rem;
}

.report-clear {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.22);
}

/* =========================
   SVG ELEMENT STYLES
========================= */

.wall-outline {
  fill: #23282d;
  stroke: #ecf2f6;
  stroke-width: 1.2;
}

.panel-full {
  fill: rgba(57, 213, 255, 0.06);
  stroke: rgba(57, 213, 255, 0.5);
  stroke-width: 1;
}

.panel-cut {
  fill: rgba(245, 158, 11, 0.08);
  stroke: #f59e0b;
  stroke-width: 2;
}

.opening-box {
  fill: rgba(245, 158, 11, 0.14);
  stroke: #f59e0b;
  stroke-width: 2;
}

.panel-seam {
  stroke: #d9edf7;
  stroke-width: 1.45;
}

.rib-line {
  stroke: var(--cyan);
  stroke-width: 1;
  stroke-dasharray: 2 5;
  opacity: 0.4;
}

.dimension-line {
  stroke: #8aa0b2;
  stroke-width: 1;
}

.tick {
  stroke: #ffffff;
  stroke-width: 2;
}

.dimension-text,
.total-text,
.panel-label {
  font-family: "Fira Code", monospace;
}

.dimension-text {
  fill: #f3f8fd;
  font-size: 11px;
}

.total-text {
  fill: #f3f8fd;
  font-size: 12px;
}

.panel-label {
  fill: #dff4ff;
  font-size: 11px;
}

.wall-line,
.roof-line,
.panel-line {
  stroke: #d8edf7;
  stroke-width: 2;
}

.grid-line {
  stroke: rgba(57, 213, 255, 0.12);
  stroke-width: 1;
}

/* Optional preview toggles */
#wallSvg.grid-hidden .grid-line,
#wallSvg.grid-hidden .rib-line {
  opacity: 0;
}

#wallSvg.labels-hidden .dimension-text,
#wallSvg.labels-hidden .panel-label,
#wallSvg.labels-hidden .total-text {
  opacity: 0;
}

/* =========================
   HELPERS
========================= */

.hidden {
  display: none !important;
}

/* =========================
   TABLET / DESKTOP
========================= */

@media (min-width: 780px) {
  .app-main {
    grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
    align-items: start;
    padding: 14px 16px 16px;
  }

  .preview-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .ghost-action {
    width: auto;
  }

  #wallSvg {
    height: 420px;
  }

  .report-metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .opening-entry-grid {
    grid-template-columns: 1fr 1fr;
    column-gap: 12px;
    row-gap: 6px;
  }

  .opening-entry-grid label[for="openingLabel"],
  .opening-entry-grid input#openingLabel {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1040px) {
  .status-bar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .app-main {
    padding-left: 16px;
    padding-right: 16px;
  }

  #wallSvg {
    height: 480px;
  }
}

/* =========================
   SMALLER PHONES
========================= */

@media (max-width: 420px) {
  .accordion-toggle {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .accordion-summary {
    grid-column: 1 / -1;
    white-space: normal;
    margin-top: -2px;
    text-align: left;
  }

  .results-tab {
    font-size: 0.9rem;
    padding-left: 4px;
    padding-right: 4px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .summary-cut-values {
    flex-direction: column;
    gap: 4px;
  }

  .gable-cut-schedule-head,
  .gable-cut-row {
    grid-template-columns: 58px 1fr 1fr;
    gap: 8px;
    padding: 9px 10px;
    font-size: 0.78rem;
  }

  .opening-report-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .report-metric-row {
    flex-direction: column;
  }

  .report-metric-row strong {
    text-align: left;
  }

  .mobile-action-bar {
    grid-template-columns: 1fr 88px 1.06fr;
    gap: 8px;
  }

  .footer-btn {
    min-height: 54px;
  }

  #wallSvg {
    height: 280px;
  }
}