/* ==========================================================================
   ADLAS Cost Calculator — styles
   Brand tokens live in :root so official colours can be swapped in one place.
   ========================================================================== */

:root {
  /* Brand */
  --brand-ink: #0b1f3a;          /* primary navy */
  --brand-accent: #1f4fd1;       /* single accent */
  --brand-accent-hover: #183fa8;
  --brand-accent-soft: #eaf0fd;

  /* Neutrals */
  --ink: #111827;
  --ink-soft: #374151;
  --muted: #5b6472;
  --border: #e3e6eb;
  --border-strong: #c9ced6;
  --surface: #ffffff;
  --surface-alt: #f6f7f9;
  --bg: #ffffff;

  /* Status (always paired with text, never colour alone) */
  --positive: #0f7a4d;
  --positive-soft: #e7f5ee;
  --negative: #b42318;
  --negative-soft: #fdecea;

  /* Type & spacing */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 6px;
  --gutter: 16px;
  --focus: 0 0 0 3px rgba(31, 79, 209, 0.35);
}

*,
*::before,
*::after { box-sizing: border-box; }

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

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: "tnum" 1, "cv11" 1;
}

h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--brand-ink); }
p { margin: 0; }

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

@media (min-width: 768px) {
  :root { --gutter: 32px; }
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -48px;
  background: var(--brand-ink); color: #fff;
  padding: 8px 12px; border-radius: var(--radius);
  z-index: 100; text-decoration: none;
}
.skip-link:focus { top: 8px; }

:focus-visible { outline: none; box-shadow: var(--focus); }

.muted { color: var(--muted); }
.print-only { display: none; }

/* ---------- Header ---------- */

.app-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 20px;
  padding-bottom: 20px;
}

.brand { display: flex; align-items: center; gap: 16px; min-width: 0; }

.brand-mark {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.18em;
  color: var(--brand-ink);
}

.brand-divider { width: 1px; height: 32px; background: var(--border-strong); }

.brand-text h1 { font-size: 18px; font-weight: 600; }
.brand-sub { font-size: 13px; color: var(--muted); }

.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn-primary { background: var(--brand-accent); color: #fff; }
.btn-primary:hover { background: var(--brand-accent-hover); }

.btn-secondary { background: var(--surface); color: var(--brand-ink); border-color: var(--border-strong); }
.btn-secondary:hover { border-color: var(--brand-ink); }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-alt); }

.btn-danger { background: var(--negative); color: #fff; }
.btn-danger:hover { background: #8f1c13; }

.btn-ghost-danger { background: transparent; color: var(--negative); border-color: transparent; }
.btn-ghost-danger:hover { background: var(--negative-soft); }

.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; font-weight: 500; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 8px;
  border: 0; border-radius: var(--radius);
  background: transparent; color: var(--muted);
  font: inherit; font-size: 20px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--ink); }

/* ---------- Sections ---------- */

.section { padding: 40px 0; border-bottom: 1px solid var(--border); }
.section:last-of-type { border-bottom: 0; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--brand-accent);
  margin-bottom: 4px;
}

.section h2 { font-size: 22px; font-weight: 700; }
.section-desc { color: var(--muted); margin-top: 4px; max-width: 640px; }
.section-meta { color: var(--muted); font-size: 14px; }

.subsection { margin-top: 32px; }
.subsection-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }

.note { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ---------- Empty states ---------- */

.empty-state {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}
.empty-state .empty-title { font-size: 17px; font-weight: 600; color: var(--brand-ink); margin-bottom: 4px; }
.empty-state .btn { margin-top: 16px; }

.placeholder {
  color: var(--muted);
  padding: 16px;
  background: var(--surface-alt);
  border-radius: var(--radius);
}

/* ---------- Tables ---------- */

.table-scroll {
  position: relative; /* keeps visually-hidden labels inside the scroll area */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.data-table th,
.data-table td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table thead th {
  background: var(--surface-alt);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  vertical-align: bottom;
}

.data-table tbody tr:last-child > * { border-bottom: 0; }
.data-table tbody tr:hover > * { background: #fafbfc; }
.data-table tbody th { font-weight: 600; color: var(--ink); }

.data-table tfoot th,
.data-table tfoot td {
  border-top: 1px solid var(--border-strong);
  border-bottom: 0;
  font-weight: 700;
  color: var(--brand-ink);
  background: var(--surface-alt);
}

.data-table .num { text-align: right; }
.data-table .strong { font-weight: 600; }
.data-table.compact th, .data-table.compact td { padding: 9px 12px; }

.cell-sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.cell-name { max-width: 260px; white-space: normal; }

.price-line { display: block; }
.price-line.is-used { font-weight: 600; }
.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 3px;
  background: var(--brand-accent-soft);
  color: var(--brand-accent);
  vertical-align: 1px;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

.amount-positive { color: var(--positive); }
.amount-negative { color: var(--negative); }

.sort-btn {
  border: 0; background: none; padding: 0; margin: 0;
  font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit;
  cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.sort-btn::after { content: "↕"; font-size: 11px; opacity: 0.35; }
th[aria-sort="ascending"] .sort-btn::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"] .sort-btn::after { content: "↓"; opacity: 1; }
th[aria-sort] .sort-btn { color: var(--brand-ink); }

.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.row-actions .btn { color: var(--ink-soft); }
.row-actions .btn:hover { color: var(--brand-ink); }
.row-actions .btn-delete { color: var(--negative); }
.row-actions .btn-delete:hover { background: var(--negative-soft); color: var(--negative); }

/* ---------- Summary ---------- */

.summary-grid { display: grid; gap: 24px; }

.combined {
  margin-top: 16px;
  padding: 14px 16px;
  border-left: 3px solid var(--brand-accent);
  background: var(--brand-accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.combined strong { color: var(--brand-ink); }

.rates-panel { margin-top: 20px; border: 1px solid var(--border); border-radius: var(--radius); }
.rates-panel > summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  color: var(--brand-ink);
  font-size: 14px;
}
.rates-body { padding: 0 16px 16px; }
.rates-grid { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; align-items: flex-start; }
.rates-inputs { display: flex; flex-wrap: wrap; gap: 16px; }
.rate-field input { width: 160px; }

/* ---------- Breakdown ---------- */

.breakdown-grid { display: grid; gap: 24px; }
.breakdown-grid > * { min-width: 0; }
@media (min-width: 1024px) {
  .breakdown-grid.multi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.breakdown-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.breakdown-title span { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }

/* ---------- Scenarios ---------- */

.scenario-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  margin-bottom: 24px;
}
.scenario-grid:empty { display: none; }

.scenario-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scenario-card-head { display: flex; gap: 8px; align-items: center; }
.scenario-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 15px;
  color: var(--brand-ink);
}

.scenario-services { border: 0; margin: 0; padding: 0; min-width: 0; }
.scenario-services legend { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; padding: 0; }
.check-row { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; font-size: 14px; cursor: pointer; }
.check-row input { margin-top: 3px; accent-color: var(--brand-accent); }
.check-row .cell-sub { display: inline; margin-left: 4px; }

.scenario-card-total { font-size: 13px; color: var(--ink-soft); border-top: 1px solid var(--border); padding-top: 10px; }
.scenario-card-actions { display: flex; gap: 4px; }

.compare-controls { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.compare-controls select { min-width: 200px; }
.compare-vs { padding-bottom: 10px; color: var(--muted); font-weight: 600; }

.compare-heading { font-weight: 600; margin-bottom: 8px; display: none; }

/* ---------- Analysis ---------- */

.analysis-lead { font-weight: 600; margin-bottom: 10px; color: var(--brand-ink); }
.analysis-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; max-width: 860px; }
.analysis-list li::marker { color: var(--brand-accent); }

/* ---------- Toolbar ---------- */

.toolbar { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.toolbar-group { display: flex; gap: 8px; flex-wrap: wrap; }
.save-status { margin-top: 12px; font-size: 13px; color: var(--muted); }

.app-footer { border-top: 1px solid var(--border); padding: 20px 0; font-size: 13px; color: var(--muted); }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .field legend { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field > legend { padding: 0; margin-bottom: 6px; }

.req { color: var(--negative); }
.opt { font-weight: 400; color: var(--muted); }

input[type="text"],
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
input[type="text"]:hover, select:hover { border-color: #9aa2ae; }
input[type="text"]:focus-visible, select:focus-visible { border-color: var(--brand-accent); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--negative); }

.field-hint { font-size: 12px; color: var(--muted); }
.field-hint:empty { display: none; }
.field-error { font-size: 13px; color: var(--negative); font-weight: 500; }
.field-error:empty { display: none; }
.field-error::before { content: "⚠ "; }

.form-grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 560px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: span 2; }
}
.form-grid.inner { margin-top: 8px; }
.price-group { padding: 14px !important; border: 1px solid var(--border) !important; border-radius: var(--radius); }
.price-group > legend { padding: 0 6px !important; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; align-self: flex-start; }
.segmented label { display: flex; align-items: center; gap: 6px; padding: 8px 14px; cursor: pointer; font-weight: 500; font-size: 14px; }
.segmented label + label { border-left: 1px solid var(--border-strong); }
.segmented input { accent-color: var(--brand-accent); }
.segmented label:has(input:checked) { background: var(--brand-accent-soft); color: var(--brand-ink); }

.form-error-summary {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-left: 3px solid var(--negative);
  background: var(--negative-soft);
  color: var(--negative);
  font-size: 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.preview {
  margin-top: 20px;
  padding: 12px 14px;
  background: var(--surface-alt);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--ink-soft);
}
.preview:empty { display: none; }
.preview dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px 16px; margin: 0; }
.preview dt { font-size: 12px; color: var(--muted); }
.preview dd { margin: 0; font-weight: 600; color: var(--brand-ink); }

/* ---------- Dialogs ---------- */

.dialog {
  width: min(640px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 24px 48px rgba(11, 31, 58, 0.18);
}
.dialog-sm { width: min(460px, calc(100vw - 2 * var(--gutter))); }
.dialog::backdrop { background: rgba(11, 31, 58, 0.45); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }

.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.dialog-head h2 { font-size: 18px; }
.dialog-body { padding: 20px; overflow-y: auto; }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-alt);
}
.confirm-title { font-size: 17px; margin-bottom: 8px; }
.confirm-message { color: var(--ink-soft); white-space: pre-line; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  background: var(--brand-ink);
  color: #fff;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(11, 31, 58, 0.25);
  z-index: 50;
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  .section { padding: 28px 0; }
  .section h2 { font-size: 19px; }
  .brand-mark { font-size: 18px; }
  .brand-divider { height: 26px; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; }
  .toolbar-group .btn { flex: 1 1 auto; }
  .compare-controls select { min-width: 0; }
  .compare-controls .field { flex: 1 1 140px; }
  .compare-vs { display: none; }
}

/* ---------- Print / PDF ---------- */

@page { size: A4 landscape; margin: 14mm; }

@media print {
  :root { --gutter: 0px; }
  body { font-size: 11px; color: #000; }
  .no-print, .skip-link, .toast, dialog, .app-footer { display: none !important; }
  .print-only { display: block; }
  .container { max-width: none; }
  .app-header { border-bottom: 2px solid var(--brand-ink); }
  .header-inner { padding: 0 0 10px; }
  .report-meta { margin-top: 10px; color: var(--muted); font-size: 11px; }
  .section { padding: 16px 0; break-inside: auto; }
  .section-head { margin-bottom: 10px; }
  .section h2 { font-size: 16px; }
  .section-desc { font-size: 10px; }
  .table-scroll { overflow: visible; border: 1px solid var(--border-strong); }
  .data-table { font-size: 10px; }
  .data-table th, .data-table td { padding: 5px 7px; white-space: normal; }
  .data-table tr { break-inside: avoid; }
  .data-table thead { display: table-header-group; }
  .breakdown-grid.multi { grid-template-columns: 1fr 1fr; }
  .compare-heading { display: block; }
  .rates-panel { display: none; }
  .empty-state { padding: 12px; }
  a { color: inherit; text-decoration: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
