/* Fabric Costing Master: v6 design
   Built from the "Fabric Costing" Figma file. One spacing scale, one type scale, Inter throughout.
   Spacing: 4 / 8 / 12 / 16 px.  Radius: 6 / 8 / 10 / 12 / 18 px. */

@font-face { font-family: "Inter"; font-weight: 400; font-style: normal; font-display: swap; src: url("fonts/Inter-Regular.woff") format("woff"); }
@font-face { font-family: "Inter"; font-weight: 600; font-style: normal; font-display: swap; src: url("fonts/Inter-SemiBold.woff") format("woff"); }
@font-face { font-family: "Inter"; font-weight: 700; font-style: normal; font-display: swap; src: url("fonts/Inter-Bold.woff") format("woff"); }

:root {
  color-scheme: light;
  /* colour */
  --paper: #f3f6f4;
  --panel: #ffffff;
  --line: #dde5df;
  --ink: #1e2924;
  --muted: #64716b;
  --brand: #3c5d4d;          /* buttons, step labels */
  --brand-deep: #245b49;     /* brand header, privacy text */
  --brand-pale: #eaf3ed;
  --brand-line: #cfe1d4;
  --input: #efd7df;          /* pink: you type here */
  --input-line: #caa5b3;
  --choice: #eee8f4;         /* lavender: you choose here */
  --choice-line: #bfb1d2;
  --auto: #edf1ee;           /* grey: filled in for you */
  --calc: #f4f7f5;
  --measure: #deebf0;        /* blue: calculated measurements */
  --measure-line: #c9dee6;
  --total: #eff5e3;          /* green: cost totals */
  --total-line: #dce6c7;
  --chip: #e4deef;
  --chip-ink: #514b67;
  --placeholder: #867d80;
  --danger: #973b35;
  /* space and shape */
  --gap: 14px;
  --pad: 16px;
  --field-h: 42px;
  --radius-card: 18px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overscroll-behavior-y: none; scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); font-size: 13px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.bridge-hidden { display: none; }

.shell {
  width: min(560px, 100%); margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 13px calc(48px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--gap);
}

/* ---------- Brand and notes ---------- */
.brand-header { padding: 2px 0 0; }
.eyebrow, .step {
  margin: 0; font-size: 10px; line-height: 1.2; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase;
}
.eyebrow { color: var(--brand-deep); }
.step { color: var(--brand); }
.brand-header h1 { margin: 6px 0 0; font-size: 24px; line-height: 1.15; font-weight: 700; letter-spacing: -0.7px; }

.privacy-note {
  display: flex; align-items: flex-start; gap: 8px; padding: 11px;
  border: 1px solid #cde0d5; background: #e7f2ec; border-radius: 12px; color: var(--brand-deep);
}
.privacy-note p { margin: 0; font-size: 12px; line-height: 1.45; }
.privacy-icon { font-size: 15px; line-height: 1.2; flex: 0 0 auto; }

/* ---------- Cards ---------- */
.panel, .hero-summary {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card);
  padding: calc(var(--pad) - 1px); box-shadow: 0 1px 2px rgba(25, 49, 37, .04);
}
.hero-summary { background: #f8faf7; border-color: var(--brand-line); }
.panel-heading, .summary-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-heading h2, .summary-top h2 { margin: 4px 0 0; font-size: 18px; line-height: 1.25; font-weight: 700; letter-spacing: -0.4px; overflow-wrap: anywhere; }
.small-label { font-size: 11px; line-height: 1.3; color: var(--muted); text-align: right; max-width: 110px; }

.pill {
  flex: 0 0 auto; padding: 5px 10px; border: 1px solid #dfe7e2; border-radius: 100px; background: #f0f4f1;
  color: #68766f; font-size: 10px; line-height: 1.2; font-weight: 600; white-space: nowrap;
}
.pill.good { background: var(--brand-pale); border-color: var(--brand-line); color: var(--brand); font-weight: 700; }
.pill.warn { background: #fff3d8; border-color: #eed8a7; color: #845416; font-weight: 700; }

/* ---------- Workbook panel ---------- */
.bridge-steps { margin: 0 0 12px; padding: 0; list-style: none; counter-reset: bridge; display: grid; gap: 8px; }
.bridge-steps li { counter-increment: bridge; display: grid; grid-template-columns: 24px 1fr; font-size: 13px; line-height: 1.45; }
.bridge-steps li::before { content: counter(bridge) "."; }
.file-name { margin: 0 0 12px; font-size: 11px; line-height: 1.45; color: var(--muted); overflow-wrap: anywhere; }

.status-box {
  margin: 0 0 12px; padding: 11px; border-radius: 10px; border: 1px solid var(--line);
  font-size: 13px; line-height: 1.45; white-space: pre-line; background: var(--calc); color: var(--muted);
}
.status-box.neutral { background: var(--calc); border-color: var(--line); color: var(--muted); }
.status-box.success { background: var(--brand-pale); border-color: var(--brand-line); color: var(--brand); }
.status-box.error { background: #fff0ef; border-color: #f2c9c6; color: var(--danger); }
.actions-panel > .status-box { margin-top: 0; }

.inspection-details { margin: 0 0 12px; }
.inspection-details strong { display: block; margin-bottom: 6px; font-size: 11px; line-height: 1.3; color: var(--muted); }
.inspection-details ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.inspection-details li { position: relative; padding-left: 14px; font-size: 11px; line-height: 1.45; color: var(--muted); }
.inspection-details li::before { content: "•"; position: absolute; left: 3px; }

.draft-banner { margin: 0 0 12px; padding: 11px; border: 1px solid #eed8a7; background: #fff8e6; border-radius: 12px; }
.draft-banner p { margin: 0 0 12px; font-size: 13px; line-height: 1.45; }

/* ---------- Buttons ---------- */
.button {
  appearance: none; -webkit-appearance: none; display: inline-flex; align-items: center; justify-content: center;
  min-height: 43px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  font-family: inherit; font-size: 14px; line-height: 1.3; font-weight: 700; cursor: pointer; text-align: center;
  transition: transform .08s ease, opacity .15s ease, background .15s ease;
}
.button:active:not(:disabled) { transform: scale(.985); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.button.secondary-button { background: var(--auto); border-color: var(--line); color: var(--ink); }
.button.action-button { background: var(--brand-pale); border-color: var(--brand-line); color: var(--brand); }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.full-width { width: 100%; }
.button-row { display: flex; gap: 8px; }
.button-row .button { flex: 1; }

/* ---------- Current costing summary ---------- */
.summary-prices { display: grid; grid-template-columns: 150fr 89fr 89fr; gap: 8px; }
.price-card, .metric-card { min-width: 0; padding: 9px 9px 4px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.price-card > span, .metric-card > span { display: block; margin-bottom: 10px; font-size: 12px; line-height: 14px; font-weight: 700; color: var(--muted); }
.price-card > strong { display: block; font-size: 25px; line-height: 29px; font-weight: 700; letter-spacing: -0.7px; white-space: nowrap; }
.metric-card > strong { display: block; font-size: 21px; line-height: 29px; font-weight: 700; letter-spacing: -0.7px; }
.calculation-note { margin: 10px 0 0; font-size: 11px; line-height: 1.45; color: var(--muted); }

/* ---------- Form sections ---------- */
.form-section { padding: 16px 0; border-top: 1px solid var(--line); }
.form-section.first { padding-top: 0; border-top: 0; }
.form-section:last-child { padding-bottom: 0; }
.section-heading-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.section-number {
  flex: 0 0 29px; width: 29px; height: 29px; display: grid; place-items: center; border-radius: 9px;
  background: var(--chip); color: var(--chip-ink); font-size: 12px; font-weight: 700;
}
.form-section > :last-child { margin-bottom: 0; }
.section-intro { min-width: 0; }
.section-intro h3 { margin: 4px 0 0; font-size: 15px; line-height: 1.3; font-weight: 700; letter-spacing: -0.25px; }
.section-intro p { margin: 2px 0 0; font-size: 11px; line-height: 1.45; color: var(--muted); }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 10px; margin-bottom: 12px; }
.field-grid:last-child, .field:last-child { margin-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 12px; }
.field-grid .field { margin-bottom: 0; }
.field > span { font-size: 11px; line-height: 1.3; font-weight: 700; color: var(--muted); }
.field > span small { font-size: inherit; font-weight: 400; }

.field input, .field select, .input-button-row input {
  display: block; width: 100%; min-width: 0; height: var(--field-h); padding: 0 9px;
  border: 1px solid var(--input-line); border-radius: 8px; background: var(--input); color: var(--ink);
  font-family: inherit; font-size: 16px; line-height: 1.2; outline: none; margin: 0;
  appearance: none; -webkit-appearance: none; -moz-appearance: textfield;
}
.field input::-webkit-outer-spin-button, .field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field input::placeholder, .split-row input::placeholder, .input-button-row input::placeholder { color: var(--placeholder); font-size: 13px; opacity: 1; }
.field select {
  background-color: var(--choice); border-color: var(--choice-line); padding-right: 28px; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364716b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 15 5 5 5-5'/%3E%3Cpath d='m7 9 5-5 5 5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.field input[readonly], .field .readonly-input { background: var(--auto); border-color: var(--line); color: var(--muted); }
.field input:focus, .field select:focus, .input-button-row input:focus, .split-row input:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(60, 93, 77, .15);
}
.input-button-row input { background: #fff; border-color: var(--line); }

/* ---------- Tiles, rows and lines ---------- */
.tile {
  display: flex; flex-wrap: wrap; align-items: baseline; align-content: flex-start; column-gap: 4px; row-gap: 6px;
  min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--calc);
}
.tile > span { flex: 1 0 100%; font-size: 11px; line-height: 16px; color: var(--muted); }
.tile > strong { font-size: 14px; line-height: 16px; font-weight: 700; overflow-wrap: anywhere; }
.tile .date-output, .tile > .date-output { font-size: 12px; }
.tile > small { font-size: inherit; font-weight: 700; line-height: 16px; }
.tile-row, .tile-grid { display: grid; gap: 8px; margin-bottom: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile-row:last-child, .tile-grid:last-child { margin-bottom: 0; }
.tile.wide { grid-column: 1 / -1; }
.tile.solo { margin-bottom: 8px; }
.tile-grid.measure { margin-bottom: 14px; }
.tile-grid.measure .tile { background: var(--measure); border-color: var(--measure-line); }
.tile-grid.measure .tile > strong, .tile-grid.measure .tile > small { font-size: 18px; line-height: 23px; font-weight: 700; }

.cost-line {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 41px; padding: 0 11px;
  margin: 12px 0; border: 1px solid var(--total-line); border-radius: 8px; background: var(--total);
}
.cost-line span { font-size: 13px; line-height: 1.3; }
.cost-line strong { font-size: 15px; font-weight: 700; white-space: nowrap; }

.rate-card { margin-bottom: 12px; padding: 11px; border: 1px solid var(--line); border-radius: 12px; background: #fafcfb; }
.rate-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.rate-card-head strong { font-size: 14px; line-height: 1.3; font-weight: 700; }
.unit-chip { padding: 4px 8px; border-radius: 6px; background: var(--measure); color: #4a6670; font-size: 11px; line-height: 1.2; }
.rate-card .tile-row { margin-bottom: 12px; }
.rate-card .field { margin-bottom: 0; }

.subsection { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.subsection h4 { margin: 0 0 12px; font-size: 14px; line-height: 1.3; font-weight: 700; }
.section-heading-row + .subsection { margin-top: 0; padding-top: 0; border-top: 0; }
#ratesBtn { margin-top: 16px; }

/* ---------- Yarn-dyed split tables ---------- */
.split-table { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.split-head, .split-row { display: grid; grid-template-columns: minmax(56px, 1fr) 98px 98px; gap: 8px; align-items: center; padding: 0 7px; }
.split-head { min-height: 31px; background: var(--chip); font-size: 11px; font-weight: 700; color: var(--chip-ink); }
.split-row { min-height: 51px; border-top: 1px solid var(--line); font-size: 13px; }
.split-row input {
  width: 100%; min-width: 0; height: 35px; padding: 0 7px; border: 1px solid var(--input-line); border-radius: 7px; background: var(--input);
  color: var(--ink); font-family: inherit; font-size: 16px; outline: none; appearance: none; -webkit-appearance: none; margin: 0;
}

/* ---------- Cost breakdown ---------- */
.cost-breakdown { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cost-breakdown > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; padding: 0 11px; background: #fff; font-size: 13px; }
.cost-breakdown > div + div { border-top: 1px solid var(--line); }
.cost-breakdown > div:nth-child(odd) { background: #f7f9f7; }
.cost-breakdown strong { font-size: 15px; font-weight: 700; white-space: nowrap; }
.cost-breakdown .total { background: #e4ebcf; border-top-color: #cedbb4; font-weight: 700; }
.cost-breakdown .total strong { font-size: 18px; }
.validation-line { margin-top: 12px; padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--calc); color: var(--muted); font-size: 13px; line-height: 1.45; }
.validation-line.good { background: var(--brand-pale); border-color: var(--brand-line); color: var(--brand); }
.validation-line.warn { background: #fff3d8; border-color: #eed8a7; color: #845416; }

/* ---------- Actions ---------- */
.action-card { padding: 16px 0; border-top: 1px solid var(--line); }
.action-card:first-of-type { padding-top: 0; border-top: 0; }
.action-title-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.action-icon { flex: 0 0 31px; width: 31px; height: 31px; display: grid; place-items: center; border-radius: 10px; font-size: 18px; font-weight: 700; line-height: 1; }
.save-icon { background: #e7f3e8; color: var(--brand); }
.retrieve-icon { background: #eaedff; color: #6369be; }
.clear-icon { background: #fcf0e7; color: #9c582e; }
.action-title-row h3 { margin: 0; font-size: 14px; line-height: 1.3; font-weight: 700; }
.action-title-row p { margin: 3px 0 0; font-size: 11px; line-height: 1.45; color: var(--muted); }
.input-button-row { display: flex; align-items: flex-end; gap: 10px; }
.input-button-row .field { flex: 1 1 0; margin-bottom: 0; }
.input-button-row .button { flex: 1 1 0; height: var(--field-h); min-height: var(--field-h); }
.actions-panel > .status-box { margin-top: 4px; }
.actions-panel .form-section.converter { margin-top: 4px; padding-bottom: 0; }

/* ---------- Save to iCloud ---------- */
.body-copy { margin: 0 0 12px; font-size: 13px; line-height: 1.45; color: var(--muted); }
body.loaded .export-panel .body-copy { display: none; }
.pending-box { margin: 0 0 12px; padding: 11px; border: 1px solid var(--line); border-radius: 14px; background: var(--calc); font-size: 13px; line-height: 1.45; }
.pending-box ul { margin: 6px 0; padding-left: 18px; }
.pending-box p { margin: 6px 0 0; }
.pending-box p:first-child { margin-top: 0; }

/* ---------- Not-loaded state: show only what is useful ---------- */
body:not(.loaded) .action-card, body:not(.loaded) .form-section.converter { display: none; }
body:not(.loaded) .actions-panel .status-box { margin-bottom: 0; }

/* ---------- Footer ---------- */
footer { padding: 0 2px; color: var(--muted); font-size: 11px; line-height: 1.55; }
footer p { margin: 0 0 10px; }
.footer-links { display: grid; gap: 4px; }
.footer-links a { color: var(--brand); font-weight: 700; text-decoration: none; }

/* ---------- Dialog: bottom sheet ---------- */
.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; width: min(560px, 100%); max-width: 100%; max-height: 90vh;
  padding: 0; border: 0; border-radius: 22px 22px 0 0; background: var(--panel); color: var(--ink);
  box-shadow: 0 -12px 40px rgba(14, 27, 21, .22);
}
.sheet[open] { animation: sheet-up .22s ease-out; }
.sheet::backdrop { background: rgba(14, 27, 21, .45); }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-body { display: flex; flex-direction: column; align-items: stretch; padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet-grabber { width: 36px; height: 4px; margin: 0 auto 16px; border-radius: 4px; background: #cfd8d2; }
.sheet-icon { width: 44px; height: 44px; display: grid; place-items: center; margin-bottom: 12px; border-radius: 50%; background: var(--brand-pale); color: var(--brand); font-size: 20px; font-weight: 700; }
.sheet-body[data-tone="warn"] .sheet-icon { background: #fff3d8; color: #845416; }
.sheet-body[data-tone="danger"] .sheet-icon { background: #fff0ef; color: var(--danger); }
.sheet-body .step { margin-bottom: 4px; }
.sheet-body h2 { margin: 0 0 8px; font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -0.4px; }
.sheet-message { margin: 0; font-size: 14px; line-height: 1.5; color: var(--muted); white-space: pre-line; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.sheet-actions .button { width: 100%; min-height: 48px; font-size: 15px; }

@media (max-width: 340px) {
  .shell { padding-left: 9px; padding-right: 9px; }
  .field-grid { grid-template-columns: 1fr; }
  .tile-row.three { grid-template-columns: 1fr; }
  .split-head, .split-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
  .summary-prices { grid-template-columns: 1fr 1fr; }
  .price-card { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } .button { transition: none; } }
