/* Business owner and insurer dashboards (/dashboard/). Tokens in /theme.css, shared parts in /ui.css.
   This file holds only the dashboards' own layout and parts. */

/* ---------- page rhythm ---------- */
.dash-head { margin-bottom: var(--s-5); }
.dash-head .proof { margin-top: var(--s-2); color: var(--ink-2); font-weight: var(--w-medium); }
.dash-section { margin-top: var(--s-7); }
.subhead { font: var(--w-bold) var(--t-md)/1.3 var(--sans); margin: var(--s-6) 0 var(--s-3); }
.subhead + .page-sub { margin: calc(-1 * var(--s-2)) 0 var(--s-3); }
.card-foot { margin-top: var(--s-3); }
.table-foot { margin-top: var(--s-3); max-width: 75ch; }
.nowrap { white-space: nowrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
td.actions { white-space: nowrap; }
td.actions .btn + .btn { margin-left: var(--s-1); }
.card > .notice { margin-bottom: var(--s-3); }

/* ---------- loading ---------- */
.skeleton.title { height: 36px; width: min(420px, 70%); margin-bottom: var(--s-3); }
.skeleton.line.note { width: 60%; }
.table-skeleton { padding: var(--s-4) var(--s-5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.table-skeleton .skeleton.line { height: 14px; margin: 14px 0; }
.table-skeleton .skeleton.line:nth-child(3n + 2) { width: 82%; }
.table-skeleton .skeleton.line:nth-child(3n) { width: 64%; }

/* ---------- insurer: quick links to the two tools ---------- */
.quicklinks {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden;
}
.quicklinks a {
  display: flex; align-items: center; gap: var(--s-4); min-width: 0;
  padding: var(--s-4) var(--s-5); color: var(--ink); text-decoration: none;
  transition: background-color var(--dur-fast) ease;
}
.quicklinks a + a { border-left: 1px solid var(--line); }
.quicklinks a > .i:first-child { color: var(--accent); }
.quicklinks a > .i:last-child { margin-left: auto; color: var(--faint); }
.quicklinks a > span { display: grid; gap: 2px; min-width: 0; }
.quicklinks b { font-weight: var(--w-bold); }
.quicklinks a > span > span { font-size: var(--t-sm); color: var(--muted); line-height: 1.4; }
.quicklinks a:focus-visible { outline-offset: -3px; }
@media (hover: hover) and (pointer: fine) {
  .quicklinks a:hover { background: var(--surface-2); }
  .quicklinks a:hover > .i:last-child { color: var(--ink-2); }
}

/* ---------- insurer: tier overview ---------- */
.tool-select { display: inline-flex; align-items: center; gap: var(--s-2); margin: 0; font-size: var(--t-sm); color: var(--muted); font-weight: var(--w-medium); }
.table-tools .segmented { flex-wrap: wrap; }
.tiers-table td { white-space: nowrap; }
table.data.tiers-table th { white-space: normal; vertical-align: bottom; }
table.data.tiers-table td:first-child { min-width: 0; }
.tiers-table th .help, table.data th .help { margin-left: 2px; }
.band-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: currentColor; vertical-align: 1px; }
.band-legend { list-style: none; margin: var(--s-4) 0 0; padding: 0; display: grid; gap: var(--s-2); max-width: 90ch; }
.band-legend li { display: flex; gap: var(--s-3); align-items: baseline; font-size: var(--t-sm); color: var(--ink-2); line-height: 1.5; }
.band-legend .day-chip { flex: none; min-width: 104px; justify-content: center; }

/* ---------- insurer: policies ---------- */
.book-wrap { --table-max-h: 620px; }
.payouts-wrap { --table-max-h: 520px; }
table.data td .biz { overflow-wrap: anywhere; }
table.data td:first-child { min-width: 180px; max-width: 320px; }
table.data tbody tr.clickable:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
table.data tbody tr.clickable:focus-visible td { background: var(--surface-2); }
table.data td .demo-tag { margin-left: var(--s-1); white-space: nowrap; }
#book-table td:nth-child(n+3), table.data td.num { white-space: nowrap; }

/* ---------- insurer: policy drawer ---------- */
dialog.drawer { overscroll-behavior: contain; }
.dash .kpi .v { overflow-wrap: normal; }
.kpi .v .num { white-space: nowrap; }
.drawer-tags { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.band-line { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-3); align-items: center; padding-top: var(--s-3); }
.band-line > .fine { flex-basis: 100%; }
.cap-meter { height: 8px; margin-top: var(--s-3); border-radius: var(--r-pill); background: var(--sunken); overflow: hidden; }
.cap-meter > span { display: block; height: 100%; background: var(--accent-fill); transform-origin: left center; }
.cap-meter + .fine { margin-top: var(--s-2); }
#reject-form label { margin-top: 0; }

/* ---------- insurer: underwriter queue ---------- */
.referrals { padding: 0; }
.referral { padding: var(--s-5); }
.referral + .referral { border-top: 1px solid var(--line); }
.referral-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-1) var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-3); }
.referral-head h3 { font: var(--w-bold) var(--t-md)/1.3 var(--sans); overflow-wrap: anywhere; }
.referral-body { display: grid; gap: var(--s-5); }
.referral-facts .kv .v { overflow-wrap: anywhere; }
.referral-decide .field { margin: var(--s-3) 0; }
.referral-decide .notice { overflow-wrap: anywhere; }
.note-cell { min-width: 220px; max-width: 48ch; white-space: normal; }
@media (min-width: 900px) {
  .referral-body { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
}

/* ---------- insurer: payouts ---------- */
/* Each form is an even grid: fields share the row's width, buttons sit on the fields' baseline. */
.run-form {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--s-3) var(--s-4); align-items: end; margin-bottom: var(--s-4);
}
.run-form label { margin: 0; min-width: 0; }
.run-form label[hidden] { display: none; }
.run-form label > :is(input, select) { width: 100%; margin-top: var(--s-2); }
.run-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); grid-column: 1 / -1; }
.run-form .run-note, .run-form .run-result, .run-form .error, .run-form > h3 { grid-column: 1 / -1; margin: 0; }
.run-form .run-note { max-width: 90ch; }
.run-form .run-result:empty, .run-form .error:empty { display: none; }
.run-form > h3 { font: var(--w-bold) var(--t-lg)/1.25 var(--sans); }

/* ---------- insurer: jump to a section ---------- */
.jumpnav {
  position: sticky; top: calc(var(--nav-h) + var(--s-2)); z-index: 5;
  display: flex; gap: var(--s-1); overflow-x: auto; margin-top: var(--s-5); padding: var(--s-1);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: var(--r-pill); scrollbar-width: none;
}
.jumpnav::-webkit-scrollbar { display: none; }
.jumpnav a {
  flex: none; padding: 6px var(--s-4); border-radius: var(--r-pill); color: var(--ink-2);
  font: var(--w-medium) var(--t-sm)/1.4 var(--sans); text-decoration: none;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
@media (hover: hover) and (pointer: fine) { .jumpnav a:hover { background: var(--sunken); color: var(--ink); } }
.jumpnav a:active { transform: scale(0.97); }
#insurer-dash :is(h2, h3)[id] { scroll-margin-top: calc(var(--nav-h) + 72px); }
td.ref { font-size: var(--t-sm); color: var(--muted); }

/* ---------- insurer: the map ---------- */
.mapframe iframe {
  display: block; width: 100%; height: 560px; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--sunken);
}

/* ---------- business owner ---------- */
/* Side-by-side cards share one height, so their edges line up. */
.sme-grid { display: grid; gap: var(--s-5); align-items: stretch; }
.sme-grid > .card { display: flex; flex-direction: column; }
.sme-grid > .card > .card-foot:last-child, .sme-grid > .card > .cancel-row { margin-top: auto; padding-top: var(--s-4); }
.payout-grid { margin-top: var(--s-5); }

/* Today's readings, each as a bar towards the level that pays */
.readings { display: grid; gap: var(--s-4); }
.reading { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: var(--s-3); align-items: start; }
.reading-icon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-md);
  background: var(--sunken); color: var(--muted);
}
.reading.haze .reading-icon { color: var(--haze); }
.reading.rain .reading-icon { color: var(--rain); }
.reading.heat .reading-icon { color: var(--heat); }
.reading-body { display: grid; gap: 6px; }
.reading-line { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); }
.reading-line > span { color: var(--ink-2); font-size: var(--t-sm); white-space: nowrap; }
.reading-line .num { color: var(--ink); font-weight: var(--w-bold); font-size: var(--t-base); }
.meter { height: 8px; border-radius: var(--r-pill); background: var(--sunken); overflow: hidden; }
.meter > span {
  display: block; height: 100%; border-radius: inherit; background: var(--ink-2);
  transform-origin: left center; transition: transform var(--dur-drawer) var(--ease-out);
}
.reading.haze .meter > span { background: var(--haze); }
.reading.rain .meter > span { background: var(--rain); }
.reading.heat .meter > span { background: var(--heat); }
.reading.hit .reading-line b::after { content: " · pays today"; color: var(--accent); }

/* The right column: today's readings, then what the cover is worth, filling the cover card's height */
.sme-stack { display: flex; flex-direction: column; gap: var(--s-5); min-width: 0; }
.sme-stack > .card { display: flex; flex-direction: column; }
.sme-stack > .card:last-child { flex: 1; }
.sme-stack > .card > .card-foot:last-child { margin-top: auto; padding-top: var(--s-4); }

/* What the cover is worth: four figures, two by two */
.worth { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.worth-fig { display: grid; gap: 2px; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.worth-fig span { font-size: var(--t-sm); color: var(--muted); }
.worth-fig b { font: var(--w-bold) var(--t-lg)/1.2 var(--sans); color: var(--ink); }
.worth-fig:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* An empty list, one line high */
.empty-row { display: flex; align-items: center; gap: var(--s-4); }
.empty-row > .i { flex: none; width: 24px; height: 24px; color: var(--faint); }
.empty-row > div { display: grid; gap: 2px; }

/* A section the owner opens when they need it */
details.disclosure { margin-top: var(--s-5); padding: 0; }
details.disclosure > summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); cursor: pointer; list-style: none;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary > span { display: grid; gap: 2px; }
details.disclosure > summary > .i { flex: none; color: var(--muted); transition: transform var(--dur-base) var(--ease-out); }
details.disclosure[open] > summary > .i { transform: rotate(180deg); }
details.disclosure > summary:focus-visible { outline-offset: -3px; }
details.disclosure > :not(summary) { padding: 0 var(--s-5) var(--s-5); }
.cancel-row { margin-top: var(--s-4); }
.cancel-row .row-actions { margin-top: var(--s-2); }
#cover-card .tiers-row { margin-top: 0; }
#cover-card .tier-card .t { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
/* Prices only: the customer's adviser or association starts the cover, so the cards do not click. */
#cover-card .tier-card { cursor: default; }
#cover-card .tier-card:active { transform: none; }
@media (hover: hover) and (pointer: fine) { #cover-card .tier-card:not(.rec):hover { border-color: var(--line-strong); } }

/* SME map preview: a live thumbnail that opens the atlas in a new tab */
.mappreview {
  position: relative; display: block; height: 280px; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--sunken);
  transition: transform var(--dur-press) var(--ease-out);
}
.mappreview:active { transform: scale(0.99); }
.mappreview iframe { width: 100%; height: 100%; border: 0; pointer-events: none; }
.map-chip {
  position: absolute; display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 6px 12px; border-radius: var(--r-pill); font: var(--w-medium) var(--t-sm)/1.3 var(--sans);
  box-shadow: var(--shadow-1);
}
.map-chip.cap { top: var(--s-3); left: var(--s-3); max-width: calc(100% - 24px); background: var(--surface); color: var(--ink); }
.map-chip.open {
  bottom: var(--s-3); right: var(--s-3); background: var(--accent); color: var(--accent-ink); font-weight: var(--w-bold);
  transition: background-color var(--dur-fast) ease;
}
@media (hover: hover) and (pointer: fine) { .mappreview:hover .map-chip.open { background: var(--accent-hover); } }

/* The ten-year replay */
.burn-takings { display: block; margin: 0 0 var(--s-4); font-size: var(--t-sm); font-weight: var(--w-medium); color: var(--ink-2); }
.burn-takings input { width: 180px; margin-top: var(--s-2); }
.burn-headline { color: var(--ink-2); line-height: 1.6; margin-bottom: var(--s-4); max-width: 70ch; }
.burn-headline b { color: var(--ink); }
.burn-chart { display: flex; gap: var(--s-2); align-items: flex-end; margin: var(--s-3) 0 var(--s-3); }
.burn-year { display: flex; flex-direction: column; align-items: center; gap: var(--s-1); flex: 1; min-width: 0; }
.burn-bars { display: flex; gap: 2px; align-items: flex-end; justify-content: center; width: 100%; height: 120px; }
.burn-bars > span { flex: 1; max-width: 16px; border-radius: 3px 3px 0 0; }
.burn-lost { background: var(--faint); }
.burn-paid { background: var(--info-fill); }
.burn-ghost { height: 60%; max-width: none !important; }
.burn-label { font: var(--t-xs)/1 var(--mono); color: var(--muted); }
.burn-legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin-bottom: var(--s-3); font-size: var(--t-sm); color: var(--ink-2); }
.burn-legend span { display: inline-flex; align-items: center; gap: var(--s-2); }
.burn-legend i { width: 10px; height: 10px; border-radius: 2px; }

/* Every year since 1980, model-filled: one thin bar per year, tap one to see it */
.burn-chart.dense { gap: 2px; overflow-x: auto; padding-bottom: 2px; }
.burn-chart.dense .burn-year { min-width: 7px; cursor: pointer; border-radius: 3px; }
.burn-chart.dense .burn-bars { height: 88px; }
.burn-chart.dense .burn-bars > span { max-width: 9px; }
.burn-chart.dense .burn-year.selected { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.burn-chart.dense .burn-paid.partial { opacity: 0.45; }
.burn-paid.elnino { background: var(--ink); }
.burn-chart.dense .burn-label { min-height: 10px; font-size: 9px; }
.model-controls { margin: var(--s-4) 0 var(--s-3); }
.model-controls input[type="range"] { width: 160px; vertical-align: middle; accent-color: var(--accent); }
.model-controls .range-value { font-size: var(--t-sm); color: var(--ink-2); white-space: nowrap; }
.kv .v .day-chip { margin-left: var(--s-1); }

/* PayNow setup, texts and the owner's payouts */
.payout-form label[hidden] { display: none; }
.payout-form .fine { margin: var(--s-2) 0; }
.verify-row { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: var(--s-3) 0 var(--s-1); }
.verify-row input { width: 9em; min-height: 36px; }
.sms-inbox { display: flex; flex-direction: column; gap: var(--s-2); max-height: 320px; overflow-y: auto; }
.sms {
  align-self: flex-start; max-width: 92%; padding: var(--s-2) var(--s-3);
  background: var(--good-soft); border-radius: var(--r-md) var(--r-md) var(--r-md) var(--r-xs);
}
.sms.payout_failed { background: var(--critical-soft); }
.sms p { margin: 0 0 var(--s-1); font-size: var(--t-sm); line-height: 1.45; color: var(--ink); overflow-wrap: anywhere; }
.sms span { font-size: var(--t-xs); color: var(--muted); }
.payout-list { list-style: none; margin: 0; padding: 0; }
.payout-list li { display: flex; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-4); }
.payout-list li + li { border-top: 1px solid var(--line); }
.payout-list li > div:first-child { display: grid; gap: 2px; min-width: 0; }
.payout-amount { display: grid; justify-items: end; gap: var(--s-1); text-align: right; }
.day-check-form { display: flex; flex-wrap: wrap; align-items: end; gap: var(--s-3); }
.day-check-form label { margin: 0; }
.day-title { font: var(--w-bold) var(--t-md)/1.3 var(--sans); margin: var(--s-4) 0 var(--s-2); }
.day-readings { margin-top: var(--s-3); }
.day-readings .block { display: block; }
.day-readings .trigger { color: var(--muted); }
.day-report { margin-top: var(--s-4); }
.day-report summary { cursor: pointer; color: var(--accent); font-size: var(--t-sm); }
.day-report form { margin-top: var(--s-3); }

/* ---------- small screens ---------- */
@media (min-width: 820px) {
  .sme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sme-grid.wide { grid-template-columns: minmax(0, 1fr); }
  #cover-card .tiers-row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

/* Tablet: the insurer's five figures as 3 + 2 rather than five squeezed cells. */
@media (min-width: 641px) and (max-width: 1100px) {
  #ins-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #ins-kpis .kpi { border-top: 1px solid var(--line); margin-top: -1px; }
}
@media (max-width: 760px) {
  .quicklinks { grid-template-columns: 1fr; }
  .quicklinks a + a { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 640px) {
  .dash .page-title { font-size: var(--t-xl); }
  .dash-section { margin-top: var(--s-6); }
  .kpis .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .dash .kpi { padding: var(--s-3) var(--s-4); }
  .dash .kpi .v { font-size: var(--t-lg); }
  .mappreview { height: 200px; }
  .mapframe iframe { height: 440px; }
  .burn-chart { gap: var(--s-1); }
  .table-tools .input-icon { flex-basis: 100%; max-width: none; }
  .table-tools select { flex: 1 1 140px; }
  .tool-select { flex-wrap: wrap; max-width: 100%; }
  .tool-select :is(select, input[type="range"]) { flex: 1 1 120px; min-width: 0; }
  .table-tools .count { margin-left: 0; flex-basis: 100%; }
  .referral { padding: var(--s-4); }
}

.sms.welcome { background: var(--bg); border: 1px solid var(--line); }

@media (max-width: 1024px) {
  /* Side room so the first and last year labels, wider than their bars, are not clipped. */
  .burn-chart.dense { padding-inline: var(--s-2); }
  .burn-chart.dense .burn-label { min-height: 14px; font-size: var(--t-xs); }
}

/* ---------- support tickets ---------- */
/* Topic and subject side by side, the message and button full width; labels keep no extra margin. */
.support-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s-3) var(--s-4); align-items: end; }
.support-form label { margin: 0; }
.support-form :is(select, input, textarea) { width: 100%; margin-top: var(--s-2); }
.support-form label:has(textarea), .support-form .row-actions, .support-form .error { grid-column: 1 / -1; }
.support-form .error:empty { display: none; }
.tickets { display: grid; gap: var(--s-3); }
.ticket { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); display: grid; gap: var(--s-2); }
.ticket-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.ticket p { margin: 0; }
.ticket-reply { background: var(--surface-2); border-radius: var(--r-sm); padding: var(--s-2) var(--s-3); }
