/* ── AIRTABLE-INSPIRED DESIGN SYSTEM ── */
/*
 * Primary font: Haas (Neue Haas Grotesk) as per DESIGN.md.
 * Fallback chain: Inter (loaded via Google Fonts) → system fonts → Sarabun for Thai.
 */
/* @import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;900&family=Sarabun:wght@400;500;600;700&display=swap"); */
@import url('https://fonts.googleapis.com/css2?family=Anuphan:wght@100..700&display=swap');

:root {
  /* ── Brand ── */
  --blue: #1b61c9;
  /* Airtable Blue — primary CTA */
  --blue-dark: #254fad;
  /* Mid Blue — accent variant */
  --blue-lt: #eef4ff;
  /* Blue tint surface */

  /* ── Text ── */
  --text: #181d26;
  /* Deep Navy — primary text */
  --text-weak: rgba(4, 14, 32, 0.55);
  --text-muted: rgba(4, 14, 32, 0.38);

  /* ── Semantic ── */
  --green: #006400;
  /* Success text */
  --green-lt: #ecf8ec;
  --emerald: #10b981;
  /* Net Profit highlight */
  --orange: #b45309;
  --orange-lt: #fffbeb;
  --red: #c62828;
  --red-lt: #fff0f0;
  --teal: #0e7490;
  --teal-lt: #ecfeff;

  /* ── Neutral ── */
  --slate: #94a3b8;
  /* Slate — cost node fill */
  --slate-dark: #64748b;
  /* Slate Dark — depreciation node */
  --gray: #4b5563;
  --gray-lt: #f1f3f5;

  /* ── Surface ── */
  --surface: #ffffff;
  --surface-sub: #f8fafc;
  --border: #e0e2e6;
  --border-dark: #c8cbd1;

  /* ── Shadows ── */
  --shadow-card: rgba(0, 0, 0, 0.32) 0px 0px 1px,
    rgba(0, 0, 0, 0.08) 0px 0px 2px,
    rgba(45, 127, 249, 0.18) 0px 1px 3px,
    rgba(0, 0, 0, 0.06) 0px 0px 0px 0.5px inset;
  --shadow-soft: rgba(15, 48, 106, 0.05) 0px 0px 20px;

  /* ── Chart color tokens (used by buildCostDistributionBars) ── */
  --chart-materials: #1b61c9;
  /* Emerald */
  --chart-labor: #f59e0b;
  /* Amber */
  --chart-overhead: #ef4444;
  /* Red */
  --chart-admin: #8b5cf6;
  /* Purple */
  --chart-depreciation: #64748b;
  /* Slate */
  --chart-tax: #f97316;
  /* Orange */
  --chart-net-profit: #10b981;
  /* Airtable Blue */
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Anuphan", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
}

body {
  font-family: "Anuphan", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--surface-sub);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0.08px;
  -webkit-font-smoothing: antialiased;
}

/* ── TOP BANNER ── */
header {
  background: transparent;
  color: var(--text);
  padding: 24px 36px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  position: relative;
}

header .logo {
  font-size: 34px;
  font-weight: 900;
  background: var(--blue);
  color: #fff;
  border-radius: 12px;
  padding: 6px 16px;
  line-height: 1;
  letter-spacing: -1px;
  margin-bottom: 4px;
}

header .title h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.1px;
}

header .title p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  letter-spacing: 0.1px;
}

/* ── HEADER ACTIONS (preset label + reset button) ── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.header-cost-type-label {
  font-weight: 600;
  color: var(--blue);
  letter-spacing: 0.08px;
  display: none;
}

.header-cost-type-label.visible {
  display: inline;
}

/* ── HEADER RESET BUTTON ── */
.btn-reset-header {
  position: static;
  transform: none;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  letter-spacing: 0.08px;
  font-family: inherit;
  white-space: nowrap;
  box-shadow: none;
}

.btn-reset-header:hover {
  background: var(--red-lt);
  color: var(--red);
  border-color: rgba(198, 40, 40, 0.3);
  opacity: 1;
  transform: translateY(-1px);
}

/* ── TYPE SELECTOR CARD GRID ── */
.type-selector-hint {
  font-size: 13px;
  color: var(--text-weak);
  margin-bottom: 16px;
  letter-spacing: 0.08px;
}

.type-card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

@media (max-width: 640px) {
  .type-card-grid {
    grid-template-columns: 1fr;
  }
}

/* ── TYPE CARD ── */
.type-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px 20px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s, transform 0.18s;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.type-card:hover {
  border-color: var(--blue);
  background: var(--blue-lt);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.type-card--active {
  border-color: var(--blue);
  background: var(--blue-lt);
  box-shadow: 0 0 0 3px rgba(27, 97, 201, 0.15), var(--shadow-card);
}

.type-card-icon {
  font-size: 28px;
  line-height: 1;
  margin-bottom: 2px;
}

.type-card-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.1px;
  line-height: 1.2;
}

.type-card-name-en {
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.type-card-desc {
  font-size: 12px;
  color: var(--text-weak);
  letter-spacing: 0.08px;
  line-height: 1.5;
  margin-top: 2px;
}

/* ── NAV STEPS (dot progress bar) ── */
.steps-nav {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: transparent;
  padding: 20px 24px 0;
  overflow-x: auto;
  gap: 0;
}

.step-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 180px;
  min-width: 100px;
  padding: 0 0 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-weak);
  transition: color 0.18s;
  position: relative;
}

/* connector lines on left and right of each dot */
.step-btn::before,
.step-btn::after {
  content: '';
  position: absolute;
  top: 6px;
  height: 2px;
  width: calc(50% - 9px);
  background: var(--border);
  transition: background 0.2s;
}

.step-btn::before {
  left: 0;
}

.step-btn::after {
  right: 0;
}

/* hide outer half-connectors on first and last */
.step-btn:first-child::before,
.step-btn:last-child::after {
  display: none;
}

/* fill connectors for visited/active steps */
.step-btn.visited::before,
.step-btn.visited::after,
.step-btn.active::before {
  background: var(--blue);
}

.step-btn .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  transition: all 0.2s;
}

.step-btn.visited .dot {
  background: var(--blue);
  border-color: var(--blue);
}

.step-btn.active .dot {
  width: 16px;
  height: 16px;
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(27, 97, 201, 0.15);
}

.step-btn.active {
  color: var(--blue);
  font-weight: 700;
}

.step-btn.visited {
  color: var(--blue);
}

.step-btn:hover:not(.active) {
  color: var(--text);
}

/* ── CONTENT WRAPPER ── */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ── SECTION PANELS ── */
.section {
  display: none;
  animation: fadeIn 0.25s ease;
}

.section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.section-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 1px solid var(--border);
}

.section-header h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.1px;
  color: var(--text);
}

.section-header p {
  font-size: 13px;
  color: var(--text-weak);
  margin-top: 3px;
  letter-spacing: 0.1px;
}

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 26px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-soft);
}

.card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  letter-spacing: 0.1px;
}

h3.card-title-row {
  justify-content: space-between;
}

.prod-badge {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  background: var(--surface-sub, #f3f4f6);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 12px;
  white-space: nowrap;
}

.prod-badge strong {
  font-weight: 700;
  color: var(--text);
}

/* ── INFO GRID ── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.info-item label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-weak);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}

#productName {
  font-weight: 600;
}

.info-item input,
.info-item select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border 0.18s, box-shadow 0.18s;
  letter-spacing: 0.08px;
  font-family: inherit;
}

.info-item input:focus,
.info-item select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(27, 97, 201, 0.12);
  background: var(--surface);
}

.info-item input[readonly] {
  background: var(--surface-sub);
  color: var(--text-weak);
  cursor: not-allowed;
}

/* ── PRICE ROW ── */
.price-row {
  display: grid;
  grid-template-columns: 180px 1fr 1fr 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 10px;
}

.price-row .ph {
  background: var(--surface-sub);
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-weak);
  text-align: center;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.price-row .row-data {
  display: contents;
}

.price-row .cell {
  background: var(--surface);
  padding: 10px 12px;
  font-size: 13px;
  text-align: right;
  color: var(--text);
}

.price-row .cell.label {
  text-align: left;
  font-weight: 500;
  color: var(--text-weak);
}

.price-row .cell.highlight {
  background: #fffbeb;
  font-weight: 600;
  color: var(--orange);
}

.price-row .cell.green-bg {
  background: var(--green-lt);
  font-weight: 700;
  color: var(--green);
}

/* ── Pricing Structure <table> ── */
.price-table {
  border: 1px solid #f0f0f0;
  border-radius: 8px;
  overflow: hidden;
}

.price-table th.ph {
  background: #fafafa;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.88);
  text-align: right;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.price-table td.cell {
  background: var(--surface);
  padding: 10px 16px;
  text-align: right;
  color: rgba(0, 0, 0, 0.88);
  font-variant-numeric: tabular-nums;
  transition: background 0.15s;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.price-table td.cell.label {
  text-align: left;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.65);
  font-variant-numeric: normal;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.price-table th.ph:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fafafa;
  border-right: 1px solid var(--border);
}

.price-table td.cell.highlight {
  background: #fffbeb;
  font-weight: 600;
  color: var(--orange);
}

.price-table td.cell.green-bg {
  background: var(--green-lt);
  font-weight: 700;
  color: var(--green);
}

/* ── TABLE (Ant Design style) ── */
.cost-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid #f0f0f0;
  border-radius: 8px;
  border-collapse: separate;
  border-spacing: 0 0px;
  overflow: hidden;
}

.cost-table thead tr {
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}

.cost-table th {
  background: #fafafa;
  color: rgba(0, 0, 0, 0.88);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

.cost-table th:not(:first-child) {
  text-align: right;
}

.cost-table td {
  padding: 10px 16px;
  border-bottom: 1px solid #f0f0f0;
  text-align: right;
  color: rgba(0, 0, 0, 0.88);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  transition: background 0.15s;
}

.cost-table td:first-child {
  text-align: left;
  color: rgba(0, 0, 0, 0.88);
  font-weight: 600;
  font-variant-numeric: normal;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.cost-table td:first-child input[type="text"] {
  font-weight: 600;
}

.cost-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fafafa;
  border-right: 1px solid var(--border);
}

.cost-table tbody tr:hover td:first-child {
  background: #fafafa;
}

.cost-table tr:nth-child(even) td {
  background: #fafafa;
}

.cost-table tbody tr:hover td {
  background: #fafafa;
}

.cost-table input[type="number"] {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  text-align: right;
  background: var(--surface);
  font-family: inherit;
  color: var(--text);
  transition: border 0.18s, box-shadow 0.18s;
}

.cost-table input[type="number"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(27, 97, 201, 0.10);
  background: var(--surface);
}

/* Separator row between pct and div groups */
#adminBody tr.adm-group-separator td {
  padding: 0;
  border-bottom: none;
  background: transparent;
}

#adminBody tr.adm-group-separator span {
  display: block;
  padding: 10px 16px;
  background: #fafafa;
  border-bottom: 1px solid #f0f0f0;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: rgba(0, 0, 0, 0.88);
}

.cost-table tfoot tr {
  border-top: 1px solid var(--border-dark);
}

.cost-table tfoot td {
  font-weight: 600;
  font-size: 13px;
  background: #fafafa;
  border-top: 1px solid #f0f0f0;
  border-bottom: none;
  color: rgba(0, 0, 0, 0.88);
  padding: 12px 16px;
}

.cost-table tfoot td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fafafa;
  border-right: 1px solid var(--border);
}

.cost-table .pct {
  color: var(--text-muted);
}

/* ── TOTALS BAR ── */
.totals-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.total-box {
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
  border: 1px solid var(--border);
}

.total-box .tb-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-weak);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.total-box .tb-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 5px;
  color: var(--text);
}

.total-box .tb-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── SUMMARY TABLE (Ant Design style) ── */
/* ── ANT DESIGN STYLE TABLE ── */
.summary-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid #f0f0f0;
  border-radius: 8px;
  border-collapse: separate;
  border-spacing: 0 0px;
  overflow: hidden;
}

.summary-table thead tr {
  background: #fafafa;
}

.summary-table th {
  background: #fafafa;
  color: rgba(0, 0, 0, 0.88);
  padding: 12px 16px;
  text-align: right;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  border-bottom: 1px solid #f0f0f0;
}

.summary-table th:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fafafa;
  border-right: 1px solid var(--border);
}

.summary-table td {
  padding: 10px 16px;
  border-bottom: 1px solid #f0f0f0;
  color: rgba(0, 0, 0, 0.88);
  background: var(--surface);
  transition: background 0.15s;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.summary-table td:first-child {
  font-weight: 600;
  text-align: left;
  font-variant-numeric: normal;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.summary-table tbody tr:hover td:first-child {
  background: #fafafa;
}

.summary-table tbody tr:hover td {
  background: #fafafa;
}

/* section divider rows */
.summary-table .section-row td {
  background: #fafafa;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.88);
  letter-spacing: 0.3px;
  border-bottom: 1px solid #f0f0f0;
  padding: 10px 16px;
}

.summary-table .section-row td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  border-right: 1px solid var(--border);
}

/* indent levels */
.summary-table .indent-1 td:first-child {
  padding-left: 32px;
}

.summary-table .indent-2 td:first-child {
  padding-left: 48px;
}

/* legacy class kept for back-compat */
.summary-table .indent-row td:first-child {
  padding-left: 32px;
}

/* total / summary rows — same style pattern, just different color tokens */
.summary-table .revenue-row td {
  font-weight: 600;
  color: var(--green);
}

.summary-table .total-cost-row td {
  font-weight: 600;
  color: var(--blue-dark);
}

.summary-table .section-total-row td {
  font-weight: 600;
  color: var(--orange);
}

.summary-table .ebitda-row td {
  font-weight: 600;
  color: var(--orange);
}

.summary-table .profit-row td {
  font-weight: 600;
  color: var(--green);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge-green {
  background: var(--green-lt);
  color: var(--green);
}

.badge-orange {
  background: var(--orange-lt);
  color: var(--orange);
}

.badge-red {
  background: var(--red-lt);
  color: var(--red);
}

/* ── ALL-COST MINI SUMMARY BLOCK ── */
.all-cost-block {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.all-cost-block h4 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.all-cost-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
  font-size: 13px;
}

.all-cost-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
  color: var(--text-weak);
}

.all-cost-line.sub {
  padding-left: 14px;
}

.all-cost-line .acl-val {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.all-cost-total {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding: 8px 12px;
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
}

.all-cost-total .acl-val {
  color: #fff;
  font-size: 15px;
}

/* ── ALL-COST MINI TABLE ── */
.all-cost-tbl {
  width: 100%;
  background: var(--surface);
  border: 1px solid #f0f0f0;
  border-radius: 8px;
  border-collapse: separate;
  border-spacing: 0 0px;
  overflow: hidden;
}

.all-cost-tbl thead tr {
  background: #fafafa;
}

.all-cost-tbl th {
  background: #fafafa;
  color: rgba(0, 0, 0, 0.88);
  padding: 12px 16px;
  text-align: right;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

.all-cost-tbl th:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fafafa;
  border-right: 1px solid var(--border);
}

.all-cost-tbl td {
  padding: 10px 16px;
  border-bottom: 1px solid #f0f0f0;
  text-align: right;
  color: rgba(0, 0, 0, 0.88);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  transition: background 0.15s;
}

.all-cost-tbl td:first-child {
  text-align: left;
  font-weight: 600;
  font-variant-numeric: normal;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.all-cost-tbl tbody tr:hover td:first-child {
  background: #fafafa;
  border-right: 1px solid var(--border);
}

.all-cost-tbl tbody tr:hover td {
  background: #fafafa;
}

.all-cost-tbl tr.ac-total td {
  background: #fff1f0;
  color: var(--red) !important;
  font-weight: 700;
  border-bottom: none;
}

.all-cost-tbl tr.ac-total td:first-child {
  color: var(--red) !important;
  border-right: 1px solid rgba(198, 40, 40, 0.25);
}

/* ── PROFIT KPI CARDS ── */
.profit-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 8px;
}

.profit-kpi-card {
  border-radius: 12px;
  padding: 20px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.profit-kpi-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.kpi-tag {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  opacity: 0.6;
}

.kpi-gp .kpi-tag {
  color: var(--green);
}

.kpi-ebit .kpi-tag {
  color: var(--orange);
}

.kpi-np .kpi-tag {
  color: var(--blue);
}

.kpi-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.kpi-amount {
  font-size: clamp(16px, 2vw, 26px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  line-height: 1.1;
  margin-top: 4px;
}

.kpi-gp .kpi-amount {
  color: var(--green);
}

.kpi-ebit .kpi-amount {
  color: var(--orange);
}

.kpi-np .kpi-amount {
  color: var(--blue);
}

.kpi-unit {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.6;
  margin-left: 3px;
}

.kpi-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed rgba(0, 0, 0, 0.1);
  font-size: 12px;
  color: var(--text-weak);
  gap: 8px;
}

.kpi-meta .kpi-pct {
  font-weight: 700;
  font-size: 13px;
}

.kpi-gp .kpi-meta .kpi-pct {
  color: var(--green);
}

.kpi-ebit .kpi-meta .kpi-pct {
  color: var(--orange);
}

.kpi-np .kpi-meta .kpi-pct {
  color: var(--blue);
}

.kpi-year-val {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.formula-hint {
  background: var(--blue-lt);
  border-left: 3px solid var(--blue);
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--blue-dark);
  letter-spacing: 0.08px;
}

.formula-hint strong {
  font-weight: 600;
}

.formula-hint code {
  background: rgba(27, 97, 201, 0.10);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 12px;
}

/* ── NAVIGATION BUTTONS ── */
.nav-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 28px;
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  letter-spacing: 0.08px;
  font-family: inherit;
  box-shadow: var(--shadow-card);
}

.btn-prev {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn-next {
  background: var(--blue);
  color: #fff;
}

.btn:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── PROFIT PIE VISUAL ── */
.pie-grid {
  display: grid;
  /* grid-template-columns: 1fr 1fr; */
  gap: 16px;
}

.bar-chart {
  margin-top: 12px;
}

.info-item {
  align-content: space-between;
  display: grid;
}

/* ── macOS-style stacked bar ── */
.stack-bar-track {
  display: flex;
  height: 20px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
  gap: 2px;
  margin-bottom: 16px;
}

.stack-segment {
  height: 100%;
  transition: width 0.6s ease;
  min-width: 2px;
}

.stack-legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px 16px;
}

.stack-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-weak);
}

.stack-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stack-legend-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stack-legend-pct {
  font-weight: 700;
  color: var(--text);
  min-width: 40px;
  text-align: right;
}

/* ── RESULT HIGHLIGHT ── */
.result-highlight {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff;
  border-radius: 16px;
  padding: 28px 28px;
  text-align: center;
  margin-top: 20px;
  box-shadow: var(--shadow-card);
}

.result-highlight .big {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.result-highlight .sub {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  margin-top: 5px;
  letter-spacing: 0.1px;
}

@media (max-width: 640px) {
  .price-row {
    grid-template-columns: 1fr 1fr;
  }

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

/* ══════════════════════════════════════
   RESPONSIVE – iPad (≤ 1024px)
══════════════════════════════════════ */
@media (max-width: 1024px) {
  main {
    max-width: 100%;
    padding: 24px 20px 60px;
  }

  .profit-kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .steps-nav {
    padding: 16px 16px 0;
    gap: 0;
  }

  .step-btn {
    font-size: 12px;
    min-width: 80px;
  }
}

/* ══════════════════════════════════════
   RESPONSIVE – Mobile (≤ 768px)
══════════════════════════════════════ */
@media (max-width: 512px) {

  /* Header */
  header {
    padding: 16px 16px 14px;
    gap: 8px;
  }

  .header-actions {
    align-self: center;
  }

  .btn-reset-header:hover {
    transform: translateY(-1px);
  }

  header .title h1 {
    font-size: 20px;
    padding: 12px 0px;
  }

  /* Step nav – allow horizontal scroll, compact buttons */
  .steps-nav {
    padding: 12px 12px 0;
    justify-content: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .steps-nav::-webkit-scrollbar {
    display: none;
  }

  .step-btn {
    font-size: 11px;
    min-width: 72px;
    max-width: 120px;
    padding: 0 0 12px;
    flex-shrink: 0;
  }

  /* Main content */
  main {
    padding: 16px 12px 60px;
  }

  /* Section header */
  .section-header h2 {
    font-size: 16px;
  }

  .section-header p {
    font-size: 12px;
  }

  /* Cards */
  .card {
    padding: 16px 14px;
    border-radius: 12px;
  }

  .card h3 {
    font-size: 15px;
  }

  /* Info grid – single column on mobile */
  .info-grid {
    grid-template-columns: 1fr !important;
  }

  /* Price row */
  .price-row {
    grid-template-columns: 1fr 1fr;
  }

  /* KPI cards – single column on mobile */
  .profit-kpi-grid {
    grid-template-columns: 1fr;
  }

  /* All cost grid – single column */
  .all-cost-grid {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  /* Pie grid – single column */
  .pie-grid {
    grid-template-columns: 1fr;
  }

  /* Totals bar */
  .totals-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Nav buttons */
  .nav-buttons {
    gap: 10px;
  }

  .btn {
    padding: 10px 16px;
    font-size: 13px;
  }

  /* KPI amounts */
  .kpi-amount {
    font-size: 22px;
  }

  /* Result highlight */
  .result-highlight {
    padding: 20px 16px;
  }

  .result-highlight .big {
    font-size: 30px;
  }

  /* Tables – ensure horizontal scrolling */
  .cost-table,
  .price-table,
  .summary-table,
  .all-cost-tbl {
    font-size: 12px;
  }


}

/* ══════════════════════════════════════
   COST TABLE — HIDE CALCULATED COLUMNS (≤ 1199px)
   Base: expand-btn, mob-total, detail-row hidden on desktop.
   Revealed inside the ≤1199px query below.
══════════════════════════════════════ */

/* Hidden by default on desktop */
.expand-btn {
  display: none;
  min-width: 48px;
  padding: 4px 10px !important;
}

/* Keep action buttons (expand + delete) on one line */
.cost-table td:last-child {
  white-space: nowrap;
}

.mob-table-total {
  display: none;
}

.cost-table .detail-row {
  display: none;
}

@media (max-width: 1199px) {

  .cost-table .cpd,
  .cost-table .cpm,
  .cost-table .pct2,
  .cost-table .cu-cell {
    display: none;
  }

  /* Hide corresponding thead th columns */
  #materialTable thead th:nth-child(n+3):nth-child(-n+5) {
    display: none;
  }

  #laborTable thead th:nth-child(n+3):nth-child(-n+6),
  #overheadTable thead th:nth-child(n+3):nth-child(-n+6),
  #adminTable thead th:nth-child(n+3):nth-child(-n+6) {
    display: none;
  }

  /* Show expand button and detail row */
  .expand-btn {
    display: inline-block;
  }

  .cost-table .detail-row {
    display: table-row;
  }

  /* Hide tfoot — mobile total is in .mob-table-total div instead */
  .cost-table tfoot {
    display: none;
  }

  /* Mobile total bar */
  .mob-table-total {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px 12px;
    margin-top: -1px;
    background: #fafafa;
    border: 1px solid #f0f0f0;
    border-top: 2px solid var(--border);
    border-radius: 0 0 8px 8px;
    font-size: 13px;
    color: rgba(0, 0, 0, 0.88);
  }

  .mob-total-label {
    font-weight: 700;
    font-size: 13px;
  }

  .mob-total-chips {
    display: flex;
    gap: 0;
  }

  .mob-chip {
    display: flex;
    flex-direction: column;
    flex: 1;
    align-items: center;
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    min-width: 0;
  }

  .mob-chip+.mob-chip {
    border-left: 1px solid var(--border);
  }

  .mob-chip-label {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
  }

  .mob-chip-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
  }

  /* Give item name column breathing room */
  .cost-table td:first-child,
  .cost-table th:first-child {
    min-width: 140px;
    width: 100vw;
  }

  /* Detail sub-row styles */
  .cost-table .detail-row td {
    background: var(--surface-sub);
    border-top: none;
  }

  .detail-chips {
    display: flex;
    gap: 0;
  }

  .detail-chip {
    display: flex;
    flex-direction: column;
    flex: 1;
    align-items: center;
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    min-width: 0;
  }

  .detail-chip+.detail-chip {
    border-left: 1px solid var(--border);
  }

  .chip-label {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
  }

  .chip-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
  }
}