/* Guildford Borough Council - Building Safety Levy
   Visual design. Dependency-free, accessible, print-friendly. */

:root {
  --teal-900: #06302f;
  --teal-700: #0a4f4c;
  --teal-600: #00625f;
  --teal-100: #e2f0ef;
  --teal-50: #f2f8f8;

  --ink: #16262b;
  --ink-2: #44606a;
  --ink-3: #6d858c;

  --line: #dbe4e6;
  --line-2: #b9c9cd;
  --bg: #f4f7f8;
  --card: #ffffff;

  --amber-700: #8a5000;
  --amber-bg: #fff4e0;
  --amber-line: #f0d29b;

  --red-700: #9c2118;
  --red-bg: #fdecea;
  --red-line: #f0bcb7;

  --green-700: #176034;
  --green-bg: #e8f5ec;
  --green-line: #b6ddc4;

  --blue-700: #1a5480;
  --blue-bg: #e9f1f9;
  --blue-line: #bcd6ec;

  --radius: 8px;
  --radius-sm: 5px;
  --shadow-1: 0 1px 2px rgba(18, 38, 43, .07);
  --shadow-2: 0 2px 10px rgba(18, 38, 43, .09);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.55 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal-600); text-underline-offset: 2px; }
a:hover { color: var(--teal-900); }
h1, h2, h3 { margin: 0 0 .35rem; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .7rem; }
p:last-child { margin-bottom: 0; }

.muted { color: var(--ink-2); }
.small { font-size: .86rem; }
.xs { font-size: .79rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none !important; }

/* ---------------- login ---------------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% 0%, #0d6b67, var(--teal-900));
}
.login-card {
  width: 100%; max-width: 430px; background: #fff; border-radius: 12px;
  padding: 32px; box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}
.login-card h1 { margin-top: 16px; font-size: 1.5rem; }
.crest {
  display: inline-block; background: var(--teal-600); color: #fff; font-weight: 700;
  letter-spacing: .05em; padding: 6px 10px; border-radius: 4px;
  font-size: .72rem; text-transform: uppercase;
}

/* ---------------- shell ---------------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: var(--teal-900); color: #fff; padding: 0 18px;
  display: flex; align-items: center; gap: 14px; min-height: 56px; flex-wrap: wrap;
}
.topbar .brand { font-weight: 650; font-size: 1rem; }
.topbar .brand span { opacity: .75; font-weight: 400; }
.topbar .spacer { flex: 1 1 auto; }
.topbar .who { font-size: .85rem; opacity: .92; }
.topbar form { display: flex; gap: 6px; align-items: center; }
.topbar input[type=search] { width: 240px; margin: 0; }
.topbar button.ghost { color: #fff; border-color: rgba(255,255,255,.5); }
.topbar button.ghost:hover { background: rgba(255,255,255,.12); }

.layout { display: flex; flex: 1 1 auto; align-items: stretch; min-height: 0; }
.sidenav {
  width: 224px; flex: 0 0 224px; background: #fff; border-right: 1px solid var(--line);
  padding: 12px 10px; position: sticky; top: 0; align-self: flex-start; max-height: 100vh; overflow-y: auto;
}
.sidenav a {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--ink); text-decoration: none; font-weight: 550; margin-bottom: 2px; font-size: .93rem;
}
.sidenav a:hover { background: var(--teal-50); }
.sidenav a.active { background: var(--teal-600); color: #fff; }
.sidenav .ico { width: 18px; text-align: center; opacity: .85; }
.sidenav .group {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-3); margin: 14px 12px 6px; font-weight: 700;
}
.content { flex: 1 1 auto; padding: 22px 24px 60px; min-width: 0; max-width: 1180px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1 1 auto; }
.page-head h1 { margin-bottom: 2px; }
.crumbs { font-size: .85rem; color: var(--ink-2); margin-bottom: 6px; }
.crumbs a { text-decoration: none; }

/* ---------------- cards / panels ---------------- */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow-1);
}
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-head .spacer { flex: 1 1 auto; }
.panel.flat { box-shadow: none; background: var(--teal-50); border-color: #cfe2e1; }
.panel.danger { border-color: var(--red-line); background: #fffafa; }

.grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ---------------- stats ---------------- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; box-shadow: var(--shadow-1);
}
.stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; color: var(--teal-700); }
.stat .l { font-size: .82rem; color: var(--ink-2); margin-top: 2px; }
.stat.alert .n { color: var(--red-700); }
.stat.warn .n { color: var(--amber-700); }
.stat.link { cursor: pointer; }
.stat.link:hover { border-color: var(--teal-600); }

/* ---------------- forms ---------------- */
.field { margin-bottom: 14px; }
.field > label, .field > .lab {
  display: block; font-weight: 600; font-size: .89rem; margin-bottom: 4px; color: var(--ink);
}
.field .req { color: var(--red-700); font-weight: 700; margin-left: 5px; font-size: .78rem; }
.field .help { font-size: .82rem; color: var(--ink-2); margin: 4px 0 0; }
.field .field-error {
  font-size: .83rem; color: var(--red-700); margin-top: 4px; font-weight: 600;
  display: flex; gap: 5px; align-items: flex-start;
}
.field .field-error::before { content: "!"; display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; background: var(--red-700); color: #fff; font-size: .7rem; flex: 0 0 auto; margin-top: 2px; }

input, select, textarea, button { font: inherit; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password],
input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; color: var(--ink); background: #fff;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); margin: 0;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid #f0b429; outline-offset: 1px;
}
input:disabled, select:disabled, textarea:disabled { background: #f1f4f5; color: var(--ink-2); }
.invalid, input.invalid, select.invalid, textarea.invalid {
  border-color: var(--red-700) !important; background: var(--red-bg) !important; box-shadow: 0 0 0 2px rgba(156,33,24,.12);
}
.checkline { display: flex; align-items: flex-start; gap: 8px; font-size: .9rem; margin-bottom: 12px; }
.checkline input { width: auto; margin-top: 3px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 14px; }
legend { font-weight: 650; padding: 0 6px; font-size: .95rem; }

/* ---------------- buttons ---------------- */
button, .btn {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line-2); background: #fff; color: var(--teal-700);
  border-radius: var(--radius-sm); padding: 8px 14px; text-decoration: none; line-height: 1.2;
}
button:hover, .btn:hover { background: var(--teal-50); border-color: var(--teal-600); color: var(--teal-900); }
button.primary, .btn.primary { background: var(--teal-600); border-color: var(--teal-600); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--teal-700); border-color: var(--teal-700); color: #fff; }
button.ghost, .btn.ghost { border-color: transparent; background: transparent; }
button.danger { border-color: var(--red-line); color: var(--red-700); }
button.danger:hover { background: var(--red-bg); border-color: var(--red-700); }
button.small, .btn.small { padding: 5px 10px; font-size: .85rem; }
button.tiny { padding: 2px 8px; font-size: .8rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; }
.actions.sticky {
  position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line);
  padding: 10px 0 0; margin-top: 4px;
}

/* ---------------- tabs ---------------- */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 2px solid var(--line); margin-bottom: 18px; }
.tabs button {
  border: 0; background: transparent; border-bottom: 3px solid transparent; border-radius: 0;
  padding: 9px 13px; color: var(--ink-2); font-weight: 600;
}
.tabs button:hover { background: var(--teal-50); color: var(--teal-700); }
.tabs button[aria-selected=true] { color: var(--teal-600); border-bottom-color: var(--teal-600); }
.tabs .count { background: #e6edee; color: var(--ink-2); border-radius: 999px; padding: 0 7px; font-size: .78rem; margin-left: 6px; }

/* ---------------- next action banner ---------------- */
.next-action {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--blue-bg); border: 1px solid var(--blue-line); margin-bottom: 16px;
}
.next-action .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--blue-700); }
.next-action .v { font-weight: 650; }
.next-action.attention { background: var(--amber-bg); border-color: var(--amber-line); }
.next-action.attention .k { color: var(--amber-700); }
.next-action.done { background: var(--green-bg); border-color: var(--green-line); }
.next-action.done .k { color: var(--green-700); }

/* ---------------- step cards ---------------- */
.step { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 12px; box-shadow: var(--shadow-1); }
.step > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; display: flex; align-items: center; gap: 12px; font-weight: 650;
}
.step > summary::-webkit-details-marker { display: none; }
.step > summary::after { content: "▾"; margin-left: auto; color: var(--ink-3); transition: transform .15s; }
.step[open] > summary::after { transform: rotate(180deg); }
.step .num {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--teal-100); color: var(--teal-700); font-weight: 700; font-size: .86rem;
}
.step.complete .num { background: var(--green-bg); color: var(--green-700); }
.step.blocked .num { background: var(--amber-bg); color: var(--amber-700); }
.step .body { padding: 4px 16px 18px; border-top: 1px solid var(--line); }
.step.complete > summary { background: #fbfdfb; }

/* ---------------- readiness checklist ---------------- */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.checklist li:last-child { border-bottom: 0; }
.checklist .tick { flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 700; }
.checklist .ok .tick { background: var(--green-bg); color: var(--green-700); }
.checklist .todo .tick { background: var(--red-bg); color: var(--red-700); }
.checklist .txt { flex: 1 1 auto; }
.checklist .txt b { display: block; }
.checklist .txt span { color: var(--ink-2); font-size: .86rem; }
.checklist .fix { flex: 0 0 auto; }

/* ---------------- tables ---------------- */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f6f9f9; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); font-weight: 700; }
tbody tr:hover { background: #fafcfc; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
table.rows td { padding: 6px 8px; }
table.rows input, table.rows select { padding: 6px 8px; min-width: 90px; }
.empty { padding: 26px 18px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------------- badges ---------------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem;
  font-weight: 650; border: 1px solid transparent; white-space: nowrap;
}
.badge.grey { background: #eef1f2; color: #46595f; border-color: #dde4e6; }
.badge.green { background: var(--green-bg); color: var(--green-700); border-color: var(--green-line); }
.badge.amber { background: var(--amber-bg); color: var(--amber-700); border-color: var(--amber-line); }
.badge.red { background: var(--red-bg); color: var(--red-700); border-color: var(--red-line); }
.badge.blue { background: var(--blue-bg); color: var(--blue-700); border-color: var(--blue-line); }
.badge.teal { background: var(--teal-100); color: var(--teal-700); border-color: #bfdedd; }

/* ---------------- messages ---------------- */
.msg { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border-left: 4px solid; font-size: .92rem; }
.msg:empty { display: none; }
.msg.error { background: var(--red-bg); border-color: var(--red-700); color: #6f1610; }
.msg.ok { background: var(--green-bg); border-color: var(--green-700); color: #11401f; }
.msg.warn { background: var(--amber-bg); border-color: var(--amber-700); color: #5c3600; }
.msg.info { background: var(--blue-bg); border-color: var(--blue-700); color: #123c5c; }
.msg ul { margin: 6px 0 0; padding-left: 20px; }
.msg h4 { margin: 0 0 4px; font-size: .95rem; }

#toast { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: 400px; }
#toast .msg { margin: 0; box-shadow: var(--shadow-2); background-color: #fff; animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateY(6px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------------- modal ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(12, 30, 34, .55); display: grid; place-items: center; padding: 18px; z-index: 70; overflow: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; box-shadow: 0 24px 70px rgba(0, 0, 0, .35); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; position: sticky; top: 0; background: #fff; z-index: 2; }
.modal header h2 { margin: 0; font-size: 1.08rem; }
.modal header .spacer { flex: 1 1 auto; }
.modal .body { padding: 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; position: sticky; bottom: 0; background: #fff; }

/* ---------------- calculation result ---------------- */
.calc { border: 1px solid var(--green-line); background: linear-gradient(180deg, #f4fbf6, #fff); border-radius: var(--radius); padding: 18px; }
.calc .amount { font-size: 2.1rem; font-weight: 750; color: var(--green-700); line-height: 1; }
.calc .lines { margin-top: 12px; font-size: .92rem; }
.calc .line { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.calc .line:last-child { border-bottom: 0; }
.calc .line.total { font-weight: 700; border-top: 2px solid var(--green-line); border-bottom: 0; margin-top: 4px; padding-top: 9px; }
input[type=file] { padding: 7px; background: #fff; }

/* ---------------- misc ---------------- */
.kv { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 7px 16px; font-size: .9rem; margin: 0; }
.kv dt { color: var(--ink-2); font-weight: 600; }
.kv dd { margin: 0; }
.event { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .89rem; }
.event:last-child { border-bottom: 0; }
.event .when { color: var(--ink-3); font-size: .8rem; }
details.raw > summary { cursor: pointer; color: var(--teal-600); font-size: .87rem; }
pre.doc { white-space: pre-wrap; overflow-wrap: anywhere; background: #f7fafb; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px; font: 13px/1.6 ui-monospace, Menlo, Consolas, monospace; }
.card-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: #fff; }
.card-row .card-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.card-row .card-head .spacer { flex: 1 1 auto; }
.hint-inline { font-size: .84rem; color: var(--ink-2); }
.qlist { margin: 6px 0 0; padding-left: 18px; }

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidenav {
    width: auto; flex: 0 0 auto; border-right: 0; border-bottom: 1px solid var(--line);
    display: flex; gap: 4px; overflow-x: auto; padding: 8px; position: static; max-height: none;
  }
  .sidenav a { margin: 0; white-space: nowrap; }
  .sidenav .group { display: none; }
  .content { padding: 16px 14px 60px; }
}
@media (max-width: 620px) {
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .topbar input[type=search] { width: 100%; }
}

@media print {
  .topbar, .sidenav, .tabs, .actions, #toast, button, .next-action { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .panel, .step { box-shadow: none; border: 0; padding: 0; margin-bottom: 12px; }
  .step > summary::after { display: none; }
  .step .body { border: 0; padding: 0; }
  details:not([open]) .body { display: block !important; }
}
