/* Components. Tones: critical, high, upcoming, ok (on track), neutral. */

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card--pad { padding: 20px 22px; }
.card--flush { overflow: hidden; }
.card--rail { border-left-width: 3px; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.rail-critical { border-left-color: var(--critical); }
.rail-high { border-left-color: var(--high); }
.rail-upcoming { border-left-color: var(--upcoming); }
.rail-on_track, .rail-ok { border-left-color: var(--ok); }
.rail-neutral { border-left-color: var(--neutral); }

.notecard { background: var(--surface-2); border: 1px dashed var(--line); border-radius: 11px; padding: 12px 15px; font-size: 12.5px; color: var(--muted); }
.notecard strong { color: var(--ink-2); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); font-size: 13.5px; }
.empty__mark { font-size: 22px; color: var(--ok); margin-bottom: 6px; }
.divider { height: 1px; background: var(--line-2); margin: 14px 0; }

/* ---------- Badges, tags, chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
  padding: 2px 9px; border-radius: 99px; border: 1px solid; white-space: nowrap;
}
.badge--critical { color: var(--critical); background: var(--critical-bg); border-color: var(--critical-line); }
.badge--high { color: var(--high); background: var(--high-bg); border-color: var(--high-line); }
.badge--upcoming { color: var(--upcoming); background: var(--upcoming-bg); border-color: var(--upcoming-line); }
.badge--on_track, .badge--ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.badge--neutral { color: var(--neutral); background: var(--neutral-bg); border-color: var(--neutral-line); }
.badge--outline { background: var(--surface); color: var(--muted); border-color: var(--line); }
.badge--brand { color: var(--brand-ink); background: var(--brand-soft); border-color: #CFE3D9; }
.badge--dot { width: 8px; height: 8px; padding: 0; border-radius: 50%; }
.badge.badge--dot { background: currentColor; }

.due { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.due--critical { background: var(--critical-bg); color: var(--critical); }
.due--high { background: var(--high-bg); color: var(--high); }
.due--upcoming { background: var(--upcoming-bg); color: var(--upcoming); }
.due--neutral { background: var(--neutral-bg); color: var(--neutral); }
.due--done { background: var(--ok-bg); color: var(--ok); }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--ink-2); background: var(--neutral-bg); border-radius: 7px; padding: 2px 8px; }
.chip svg { width: 13px; height: 13px; color: var(--muted); }
.chip--due { background: var(--high-bg); color: var(--high); font-weight: 600; }
.chip--due svg { color: var(--high); }

.pill { font-size: 11.5px; font-weight: 600; background: var(--neutral-bg); color: var(--ink-2); border-radius: 6px; padding: 2px 8px; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; font-family: var(--font-display);
  background: var(--brand-softer); color: var(--brand-ink); border: 1px solid #D6E5DD;
}
.avatar:hover { text-decoration: none; }
.avatar--lg { width: 52px; height: 52px; font-size: 17px; border-radius: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-weight: 600; font-size: 13px; line-height: 1.3;
  border-radius: 10px; padding: 8px 14px; border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 15px; height: 15px; }
.btn--primary { background: var(--brand); color: #FFF; }
.btn--primary:hover { background: var(--brand-ink); }
.btn--secondary { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.btn--secondary:hover { border-color: #C9D2CC; background: var(--surface-2); }
.btn--ghost { color: var(--brand-ink); }
.btn--ghost:hover { background: var(--brand-softer); }
.btn--danger { background: var(--surface); border-color: var(--critical-line); color: var(--critical); }
.btn--danger:hover { background: var(--critical-bg); }
.btn--sm { font-size: 12.5px; padding: 5px 11px; border-radius: 8px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.link-button { color: var(--brand-ink); font-weight: 600; font-size: 12.5px; }
.link-button:hover { text-decoration: underline; }

/* A plain dropdown for secondary actions. */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu__list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30;
  min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.menu--left .menu__list { left: 0; right: auto; }
.menu__item { display: block; width: 100%; text-align: left; padding: 7px 11px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.menu__item:hover { background: var(--surface-2); text-decoration: none; }
.menu__item--on { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.menu__list form { display: block; }

/* ---------- Metrics ---------- */
.metric {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 15px 18px; color: var(--ink);
}
a.metric:hover { border-color: #C9D5CE; text-decoration: none; }
.metric__num { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric__num small { font-size: 16px; color: var(--faint); font-weight: 600; }
.metric__label { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.metric__hint { font-size: 11.5px; color: var(--faint); }
.metric--critical .metric__num { color: var(--critical); }
.metric--high .metric__num { color: var(--high); }
.metric--upcoming .metric__num { color: var(--upcoming); }
.metric--ok .metric__num { color: var(--ok); }

/* A one-line status strip, e.g. the workload check on Home. */
.strip { display: flex; align-items: center; gap: 12px; padding: 14px 18px; }
.strip__icon { width: 18px; height: 18px; }
.strip__icon--critical { color: var(--critical); }
.strip__icon--high { color: var(--high); }
.strip__icon--ok { color: var(--ok); }
.strip__body { flex: 1; min-width: 0; font-size: 13.5px; color: var(--ink-2); }
.strip__body p + p { margin-top: 4px; }

/* ---------- Action cards ---------- */
.action-list { display: flex; flex-direction: column; gap: 10px; }
.action-card {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line); border-left-width: 3px; border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 18px;
}
.action-card__body { flex: 1; min-width: 0; }
.action-card__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.action-card__who { font-weight: 600; font-size: 14px; color: var(--ink); }
.action-card__title { font-size: 13.5px; color: var(--ink-2); margin-top: 3px; }
.action-card__next { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.action-card__next strong { color: var(--ink-2); font-weight: 600; }
.action-card__buttons { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.action-card__side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; text-align: right; }
.action-card__date { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- Compact rows ---------- */
.rows { display: flex; flex-direction: column; }
.rows__item { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.rows__item:last-child { border-bottom: none; }
.rows__grow { flex: 1; min-width: 0; }
.rows__label { width: 200px; flex-shrink: 0; font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; font-size: 13.5px; }
.table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--faint); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.person { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.person:hover { text-decoration: none; }
.person:hover span:last-child { text-decoration: underline; }

/* ---------- Filters ---------- */
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter {
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 5px 13px;
}
.filter:hover { border-color: #C9D2CC; text-decoration: none; }
.filter--on { background: var(--ink); border-color: var(--ink); color: #FFF; }
.filter__count { font-weight: 500; opacity: 0.7; margin-left: 3px; }

/* ---------- Key/value grid ---------- */
.facts { display: grid; grid-template-columns: 170px 1fr; gap: 6px 18px; font-size: 13px; }
.facts dt { color: var(--muted); font-weight: 500; }
.facts dd { color: var(--ink); font-weight: 500; }
.basis { display: block; }
.basis + .basis { margin-top: 4px; }
.basis strong { font-weight: 600; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label, .field .label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; font-size: 13.5px; background: var(--surface);
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field__hint { font-size: 11.5px; color: var(--faint); margin-top: 4px; }
.field--inline { display: flex; align-items: center; gap: 8px; }
.field--inline label { margin: 0; font-weight: 500; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.optional { font-weight: 400; color: var(--faint); }
.form-errors { background: var(--critical-bg); border: 1px solid var(--critical-line); color: var(--critical); border-radius: 9px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 14px; }
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented label { display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; font-size: 13px; font-weight: 500; cursor: pointer; margin: 0; }
.segmented label:has(input:checked) { border-color: var(--brand); background: var(--brand-softer); color: var(--brand-ink); font-weight: 600; }

/* ---------- Dialogs (modals and the Why drawer) ---------- */
.dialog {
  border: none; padding: 0; margin: auto; color: var(--ink);
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: calc(100% - 32px); max-width: 480px; max-height: 90vh; overflow-y: auto;
  animation: rise 0.18s ease;
}
.dialog::backdrop { background: rgb(20 29 25 / 42%); animation: fade 0.15s ease; }
.dialog__head { padding: 20px 24px 0; display: flex; align-items: flex-start; gap: 10px; }
.dialog__head h2 { font-size: 20px; }
.dialog__body { padding: 16px 24px 20px; }
.dialog__foot { padding: 14px 24px 18px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line-2); }
.dialog__head form { margin-left: auto; }
.dialog form:has(input[value="deferred"]:checked) .waiting-only { display: none; }
.dialog__close { color: var(--faint); border-radius: 8px; padding: 2px 8px; font-size: 18px; line-height: 1; }
.dialog__close:hover { background: var(--surface-2); color: var(--ink); }

.dialog--drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: 460px; max-width: 94vw;
  border-radius: 0; animation: slide 0.2s ease;
}
.dialog--drawer .dialog__head { border-bottom: 1px solid var(--line-2); padding-bottom: 14px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Why panel ---------- */
.why { counter-reset: why; display: flex; flex-direction: column; gap: 14px; }
.why__step { counter-increment: why; display: flex; gap: 11px; }
.why__step::before {
  content: counter(why); flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-ink); font-size: 11.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-family: var(--font-display);
}
.why__step h3 { font-size: 13px; margin-bottom: 2px; }
.why__step p { font-size: 13.5px; color: var(--ink-2); }

/* ---------- History (audit trail) ---------- */
.trail { position: relative; padding-left: 20px; }
.trail::before { content: ""; position: absolute; left: 5px; top: 8px; bottom: 8px; width: 2px; background: var(--line-2); }
.trail__item { position: relative; padding: 5px 0 5px 6px; font-size: 12.5px; color: var(--ink-2); }
.trail__item::before { content: ""; position: absolute; left: -19px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
.trail__item--system::before { border-color: var(--upcoming); }
.trail__meta { color: var(--faint); font-size: 11.5px; }
.trail__actor { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--neutral-bg); border-radius: 5px; padding: 0 6px; margin-left: 4px; }

.history-action + .history-action { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-2); }
.history-action__head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }

/* ---------- Planner ---------- */
.plan-table { width: 100%; font-size: 12.5px; border-collapse: separate; border-spacing: 0; }
.plan-table th { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); font-weight: 600; text-align: center; padding: 8px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.plan-table th:first-child, .plan-table td:first-child { text-align: left; padding-left: 2px; min-width: 190px; }
.plan-table td { padding: 7px 4px; text-align: center; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.plan-table th.is-current { color: var(--brand-ink); }
.plan-table .name { font-weight: 600; font-size: 13px; color: var(--ink); }
.plan-table .meta { font-size: 11px; color: var(--faint); }
.plan-table .meta--warn { color: var(--high); font-weight: 600; }
.plan-table tr.summary td { color: var(--faint); font-size: 12px; }
.plan-table tr.free td { font-weight: 700; border-bottom: none; padding-top: 9px; }
.cell { display: inline-flex; flex-direction: column; align-items: center; gap: 1px; }
.cell__stepper { display: inline-flex; align-items: center; gap: 3px; }
.cell__value { min-width: 20px; font-variant-numeric: tabular-nums; font-weight: 600; }
.cell__value--zero { color: #C5CDC7; font-weight: 400; }
.cell__booked { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.step {
  width: 18px; height: 18px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 12px; line-height: 1; padding: 0; display: inline-flex; align-items: center; justify-content: center;
}
.step:hover { border-color: var(--brand); color: var(--brand); }
.step:disabled { opacity: 0.25; cursor: default; }
.step-form { display: inline; }
.free--negative { color: var(--critical); background: var(--critical-bg); border-radius: 7px; padding: 2px 7px; }
.free--positive { color: var(--ok); }
.estimate { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Funding bar ---------- */
.bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--line-2); }
.bar__used { background: var(--brand); }
.bar__committed { background: #8FBFA9; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend__swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Rules ---------- */
.rule { scroll-margin-top: 20px; }
.rule:target { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Flash ---------- */
.flash {
  position: fixed; bottom: 22px; right: 22px; z-index: 200; max-width: 380px;
  background: var(--ink); color: #FFF; border-radius: 11px; padding: 11px 16px; font-size: 13px; box-shadow: var(--shadow-lg);
  display: flex; gap: 10px; align-items: flex-start;
  animation: rise 0.2s ease, fade-away 0.5s ease 5s forwards;
}
.flash__tick { color: #7ED4A9; }
.flash--alert .flash__tick { color: #F3A79D; }
.auth .flash { position: static; margin-bottom: 14px; animation: none; }
@keyframes fade-away { to { opacity: 0; visibility: hidden; } }

/* ---------- Setup codes ---------- */
.qr { display: flex; justify-content: center; padding: 8px; }
.qr svg { width: 180px; height: 180px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; }
.secret { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; letter-spacing: 0.08em; word-break: break-all; }

@media (max-width: 700px) {
  .action-card { flex-direction: column; gap: 8px; }
  .action-card__side { align-items: flex-start; flex-direction: row; gap: 10px; }
  .action-card > .avatar { display: none; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
  .fields-2 { grid-template-columns: 1fr; }
  .rows__label { width: auto; }
}

/* ---------- Email preview ---------- */
.email-preview__head { padding: 14px 18px; border-bottom: 1px solid var(--line); grid-template-columns: 70px 1fr; }
.email-preview__frame { display: block; width: 100%; height: 720px; border: 0; background: var(--bg); }

/* ---------- Tour (Driver.js popover) ---------- */
.driver-popover.tour {
  font-family: var(--font-body); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 16px 18px 14px; max-width: 340px;
}
.tour .driver-popover-title { font-family: var(--font-display); font-size: 16px; font-weight: 700; color: var(--ink); padding-right: 20px; }
.tour .driver-popover-description { font-size: 13.5px; line-height: 1.55; }
.tour .driver-popover-progress-text { font-size: 12px; color: var(--faint); }
.tour .driver-popover-footer-btn { font-size: 12.5px; font-weight: 600; border-radius: 8px; padding: 5px 11px; border: 1px solid var(--line); color: var(--ink-2); }
.tour .driver-popover-next-btn { background: var(--brand); border-color: var(--brand); color: #FFF; }
.tour .driver-popover-next-btn:hover, .tour .driver-popover-next-btn:focus { background: var(--brand-ink); }
.tour .driver-popover-close-btn { color: var(--faint); }

/* ---------- File audit ---------- */
.audit-item { border-top: 1px solid var(--line-2); padding: 10px 0; }
.audit-item .between { flex-wrap: wrap; }
.audit-item__fix, .audit-item__rating { margin-top: 10px; }
.audit-item__evidence { margin: 8px 0 0; }
.audit-item:not(:has(input[value="gap"]:checked, input[value="unavailable"]:checked)) .audit-item__fix { display: none; }
.audit-item:not(:has(input[value="gap"]:checked)) .audit-item__rating { display: none; }
.audit-item:has(input[value="not_applicable"]:checked, input[value="nil_return"]:checked) .audit-item__evidence { display: none; }
.escalation { border: 0; padding: 0; margin: 0; }
.escalation legend { font-weight: 600; margin-bottom: 6px; }
.escalation:not(:has(input[value="true"]:checked)) .escalation__details { display: none; }
.fields-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .fields-3 { grid-template-columns: 1fr; } }
.facts--compact { grid-template-columns: 1fr auto; gap: 4px 14px; }
.status-help { padding-left: 16px; display: grid; gap: 3px; }

/* ---------- Incidents, billing ---------- */
.incident > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.incident > summary::-webkit-details-marker { display: none; }
.incident { display: block; }
.incident__body { padding: 8px 0 2px; display: grid; gap: 4px; }
.action-card__issues { margin: 6px 0 0 18px; color: var(--ink-2); }
.status-link { color: var(--ink-2); font-weight: 500; border-bottom: 1px dashed var(--line); }
.status-link:hover { text-decoration: none; color: var(--brand-ink); }
.checklist { margin-top: 4px; }
.checklist > summary { list-style: none; cursor: pointer; }
.checklist > summary::-webkit-details-marker { display: none; }
@media (max-width: 560px) { .incident__head .rows__grow { flex-basis: 100%; } }
.btn--disabled { opacity: .45; pointer-events: none; }
.rows__item--nested { padding-left: 34px; border-top: 0; padding-top: 0; }
.section-row:has(+ .rows__item--nested) { border-bottom: 0; }
.triage { border: 0; padding: 0; margin: 0; display: none; }
form:has(select[name="incident[kind]"] option[value="incident"]:checked):has(select[name="incident[severity]"] option:not([value="low"]):checked) .triage { display: block; }
.pathway .field { margin-bottom: 8px; }
.pathways { margin: 2px 0 8px 18px; padding: 0; }
.register-row { align-items: flex-start; flex-wrap: wrap; }
.register-row .button-row { margin: 0; }
.form-errors ul { margin: 6px 0 0 18px; padding: 0; }
.register-row .rows__grow { flex: 1 1 260px; min-width: 0; }
