/* ApplicaFlow styles. Light by default, dark from the system or the toggle. No inline styles
   anywhere (CSP style-src 'self'). */

:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #17202b;
  --muted: #5b6776;
  --border: #dde3ea;
  --accent: #0b5cad;
  --accent-soft: #e6f0fa;
  --accent-text: #ffffff;
  --focus: #f2a900;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --ok: #1a7f37;
  --ok-soft: #e7f6ec;
  --radius: 12px;
  --radius-sm: 8px;
  --space: 1rem;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar: 15.5rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1216;
    --surface: #161b21;
    --surface-2: #1b2129;
    --text: #e6e9ed;
    --muted: #9aa5b1;
    --border: #2a323c;
    --accent: #6cb0f6;
    --accent-soft: #15283d;
    --accent-text: #0e1216;
    --danger: #f97066;
    --danger-soft: #3a1714;
    --warn: #f5c451;
    --warn-soft: #352a0d;
    --ok: #4ac26b;
    --ok-soft: #12301c;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1216;
  --surface: #161b21;
  --surface-2: #1b2129;
  --text: #e6e9ed;
  --muted: #9aa5b1;
  --border: #2a323c;
  --accent: #6cb0f6;
  --accent-soft: #15283d;
  --accent-text: #0e1216;
  --danger: #f97066;
  --danger-soft: #3a1714;
  --warn: #f5c451;
  --warn-soft: #352a0d;
  --ok: #4ac26b;
  --ok-soft: #12301c;
  --shadow: none;
}

:root[data-theme="light"] { color-scheme: light; }

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

body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }

a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1 { font-size: clamp(1.45rem, 3.5vw, 1.9rem); line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip-link:focus { left: var(--space); }

.icon {
  width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --- Top bar --------------------------------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-row { display: flex; align-items: center; gap: .75rem; min-height: 3.5rem; padding-inline: var(--space); max-width: 90rem; margin-inline: auto; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-weight: 800;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; justify-content: flex-end; }
.topbar-actions a:not(.button) { text-decoration: none; }

/* --- Shell ------------------------------------------------------------------------------------ */
.shell { max-width: 90rem; margin-inline: auto; display: flex; align-items: flex-start; }
.content { flex: 1; min-width: 0; padding: calc(var(--space) * 1.5) var(--space) var(--space); display: flex; flex-direction: column; min-height: calc(100vh - 3.5rem); }
.signed-out .content { max-width: 64rem; margin-inline: auto; }

.sidebar {
  width: var(--sidebar); flex: none; position: sticky; top: 3.5rem; align-self: flex-start;
  height: calc(100vh - 3.5rem); overflow-y: auto; padding: 1rem .75rem;
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; justify-content: space-between; gap: 1rem;
}
.nav-list, .nav-sub { list-style: none; margin: 0; padding: 0; display: grid; gap: .15rem; }
.nav-sub { margin: .2rem 0 .4rem .9rem; padding-left: .5rem; border-left: 1px solid var(--border); }
.nav-sub a { font-size: .9rem; min-height: 36px; }
.nav-list a, .nav-button {
  display: flex; align-items: center; gap: .65rem; width: 100%; min-height: 42px; padding: .4rem .7rem;
  border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font: inherit;
  background: none; border: 0; cursor: pointer; text-align: left;
}
.nav-button { justify-content: flex-start; }
.nav-list a:hover, .nav-button:hover { background: var(--surface-2); }
.nav-list a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-list form { margin: 0; display: block; }
.nav-secondary { border-top: 1px solid var(--border); padding-top: .75rem; }
.menu-toggle { display: none; }

@media (max-width: 899px) {
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: 3.5rem; left: 0; bottom: 0; height: auto; z-index: 4;
    transform: translateX(-105%); transition: transform .18s ease; box-shadow: var(--shadow);
  }
  .menu-open .sidebar { transform: none; }
  .theme-toggle { display: none; }
  .menu-open .theme-toggle { display: inline-flex; }
}

/* --- Buttons ------------------------------------------------------------------------------------ */
button, .button {
  font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 44px; padding: .5rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; line-height: 1.2;
}
button:hover, .button:hover { background: var(--surface-2); }
.button-primary, button.button-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.button-primary:hover { filter: brightness(1.07); background: var(--accent); }
.button-danger { color: var(--danger); border-color: var(--danger); }
.button-small { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.icon-button { min-height: 40px; width: 40px; padding: 0; }
.link-button { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
.inline-form { display: inline; margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.button-facebook { background: #1877f2; color: #fff; border-color: #1877f2; }

/* --- Cards and page headers -------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: calc(var(--space) * 1.25); box-shadow: var(--shadow); }
.card + .card { margin-top: var(--space); }
.narrow { max-width: 34rem; margin-inline: auto; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head p { margin: .25rem 0 0; }
.crumbs { font-size: .9rem; margin-bottom: .35rem; }
.crumbs a { text-decoration: none; }

.grid { display: grid; gap: var(--space); grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.tile {
  display: grid; gap: .35rem; padding: 1rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.tile:hover { border-color: var(--accent); }
.tile-head { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.tile-head .icon { width: 1.35rem; height: 1.35rem; color: var(--accent); }
.tile-count { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.tile-locked { opacity: .75; }

.badge { display: inline-flex; align-items: center; gap: .25rem; font-size: .78rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }

/* --- Record lists -------------------------------------------------------------------------------- */
.records { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.record {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .85rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.record-main { min-width: 0; display: grid; gap: .2rem; }
.record-title { font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.record-detail { color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.record-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.secret-row { display: flex; align-items: center; gap: .5rem; font-size: .92rem; flex-wrap: wrap; }
.secret-value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .03em; }
.empty { text-align: center; padding: 2rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.empty .icon { width: 2rem; height: 2rem; color: var(--accent); }

/* --- Forms ----------------------------------------------------------------------------------------- */
form { display: grid; gap: .9rem; margin-block: 1rem; }
.form-grid { display: grid; gap: .9rem 1rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.form-grid .field-wide { grid-column: 1 / -1; }
.field { display: grid; gap: .3rem; align-content: start; }
.field label { font-weight: 600; }
.field .help { color: var(--muted); font-size: .85rem; margin: 0; }
.field-check { display: flex; align-items: flex-start; gap: .6rem; }
.field-check label { font-weight: 400; }
.field-check input { width: 1.2rem; height: 1.2rem; margin-top: .15rem; flex: none; }
.lead-choices { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.lead-choices .field-check { font-weight: 400; }
input[type="email"], input[type="text"], input[type="date"], input[type="number"], input[type="tel"],
input[type="datetime-local"], input[type="password"], select, textarea {
  font: inherit; width: 100%; min-height: 44px; padding: .5rem .75rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text);
}
textarea { min-height: 6rem; resize: vertical; }
select[multiple] { min-height: 9rem; }
input[type="file"] { font: inherit; max-width: 100%; }
input[autocomplete="one-time-code"] { font-size: 1.4rem; letter-spacing: .3em; max-width: 12rem; }
.error, .form-errors { color: var(--danger); }
.form-errors { background: var(--danger-soft); border-radius: var(--radius-sm); padding: .6rem .8rem; }
.form-errors p { margin: 0; }
.field-error input, .field-error select, .field-error textarea { border-color: var(--danger); }
.steps { color: var(--muted); font-size: .9rem; margin: 0 0 .25rem; }
.choices { border: 0; padding: 0; margin: 0; display: grid; gap: .6rem; }
.choices legend { font-weight: 600; margin-bottom: .4rem; }
.choice { display: flex; gap: .75rem; align-items: flex-start; border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; cursor: pointer; }
.choice span { display: grid; gap: .15rem; }
.choice-disabled { opacity: .6; cursor: not-allowed; }
.choice input { margin-top: .3rem; width: 1.1rem; height: 1.1rem; }
ul.checkbox-list, .field ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .3rem; }

/* --- Messages, notices, details ------------------------------------------------------------------- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .5rem; }
.message { display: flex; gap: .6rem; align-items: flex-start; padding: .7rem 1rem; border-radius: var(--radius-sm); background: var(--ok-soft); color: var(--text); }
.message .icon { color: var(--ok); margin-top: .15rem; }
.message-error { background: var(--danger-soft); }
.message-error .icon { color: var(--danger); }
.message-info { background: var(--accent-soft); }
.message-info .icon { color: var(--accent); }
.notice { border-left: 4px solid var(--accent); padding: .6rem .85rem; background: var(--accent-soft); border-radius: var(--radius-sm); }
.draft { border-left: 4px solid var(--danger); padding: .5rem .75rem; background: var(--danger-soft); border-radius: var(--radius-sm); }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.secret { overflow-wrap: anywhere; }
.qr svg, .qr img { display: block; width: 220px; height: 220px; background: #fff; border-radius: var(--radius); }
.or { display: flex; align-items: center; gap: .75rem; color: var(--muted); margin: 1.25rem 0 .75rem; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* --- Tables, sessions, pager ------------------------------------------------------------------------ */
.session-list { list-style: none; padding: 0; display: grid; gap: .75rem; }
.session { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
.session form { margin: 0; }
.session p { margin: .25rem 0 0; font-size: .9rem; }
.filters { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); align-items: end; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.pager { display: flex; gap: 1rem; justify-content: center; margin-top: 1rem; }

/* --- Footer ------------------------------------------------------------------------------------------- */
.site-footer { margin-top: auto; padding-top: 2rem; color: var(--muted); font-size: .88rem; }
.site-footer p { margin: .25rem 0; }
.footer-links a { color: var(--muted); }
.prose p { max-width: 65ch; }

/* htmx request feedback */
.htmx-request { opacity: .7; transition: opacity .15s; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
.sr-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* --- Applications (M8) ----------------------------------------------------------------------- */
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; display: grid; gap: .15rem; }
.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.kpi-label { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-block { margin: .5rem 0 1.25rem; display: grid; gap: .35rem; }
progress { width: 100%; height: .7rem; border: 0; border-radius: 999px; background: var(--border); overflow: hidden; appearance: none; }
progress::-webkit-progress-bar { background: var(--border); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
.split { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; margin-bottom: 1.25rem; }
@media (max-width: 1099px) { .split { grid-template-columns: minmax(0, 1fr); } }
.side { display: grid; gap: 1rem; }
.side .card + .card { margin-top: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.section-head h2 { margin: 0; }
.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.stage details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stage summary { display: flex; align-items: center; gap: .65rem; padding: .75rem 1rem; cursor: pointer; list-style: none; }
.stage summary::-webkit-details-marker { display: none; }
.stage-num { display: grid; place-items: center; width: 1.8rem; height: 1.8rem; flex: none; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 700; font-size: .9rem; }
.stage-done .stage-num { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.stage-in_progress .stage-num { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.stage-name { font-weight: 600; flex: 1; min-width: 0; }
.stage-count { flex: none; }
.stage-body { padding: 0 1rem 1rem; display: grid; gap: .6rem; }
.stage-body p { margin: 0; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.check-item { display: flex; align-items: center; gap: .6rem; padding: .2rem 0; }
.check-item.is-done .check-text { color: var(--muted); text-decoration: line-through; }
.check-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.check-box { width: 30px; height: 30px; min-height: 30px; padding: 0; border-radius: 8px; border: 2px solid var(--border); background: var(--surface); color: transparent; }
.check-box[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.check-box .icon { width: 1rem; height: 1rem; }
.icon-link { color: var(--muted); display: inline-flex; padding: .25rem; }
.add-item { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0; }
.add-item input[type="text"] { flex: 1 1 12rem; }
.add-item input[type="date"] { flex: 0 1 10rem; }
.mini-list { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .45rem; }
.mini-list li { display: grid; gap: .1rem; padding-left: .6rem; border-left: 3px solid var(--border); }
.mini-list .sev-critical { border-left-color: var(--danger); }
.mini-list .sev-warning { border-left-color: var(--warn); }
.mini-list .sev-info { border-left-color: var(--accent); }
.timeline { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .5rem; }
.timeline li { display: grid; grid-template-columns: 7rem 1fr; gap: .75rem; }
.timeline-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline-auto span:last-child { color: var(--muted); }
@media (max-width: 599px) { .timeline li { grid-template-columns: 1fr; gap: 0; } }
.card > h2:first-child, .card > .section-head:first-child h2 { margin-top: 0; }

/* --- 190 tools (M9) -------------------------------------------------------------------------- */
.points-total { display: flex; align-items: baseline; gap: .6rem; margin-bottom: .75rem; }
.points-total .kpi-value { font-size: 2.4rem; }
.points-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.points-lines li { display: grid; gap: .15rem; padding: .5rem .7rem; border-radius: var(--radius-sm); border-left: 4px solid var(--border); background: var(--surface-2); }
.points-line-head { display: flex; justify-content: space-between; gap: .5rem; }
.points-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.flag-green { border-left-color: var(--ok) !important; }
.flag-amber { border-left-color: var(--warn) !important; }
.flag-red { border-left-color: var(--danger) !important; }
.flag-blue { border-left-color: var(--accent) !important; }
.flag-dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; border-left: 0 !important; vertical-align: middle; }
.flag-dot.flag-green { background: var(--ok); } .flag-dot.flag-amber { background: var(--warn); }
.flag-dot.flag-red { background: var(--danger); } .flag-dot.flag-blue { background: var(--accent); }
.flag-line { margin: .2rem 0 0; padding-left: .5rem; border-left: 3px solid var(--border); color: var(--muted); }
.tabs { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1rem; }
.tabs a { padding: .35rem .7rem; border-radius: 999px; border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: .9rem; background: var(--surface); }
.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.eoi-form .field { margin-bottom: .4rem; }
.eoi-heading { margin: 1rem 0 .25rem; font-size: 1rem; }
.yesno, .multi { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
.yesno label, .multi label { font-weight: 400; display: inline-flex; gap: .35rem; align-items: center; }
.upper { text-transform: uppercase; }
.eoi-group { border: 1px dashed var(--border); border-radius: var(--radius); padding: .75rem; margin: .5rem 0; display: grid; gap: .75rem; }
.eoi-row { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; background: var(--surface-2); }
.eoi-row-title { display: flex; justify-content: space-between; gap: .5rem; margin: 0 0 .5rem; }
.field .label { font-weight: 600; }
.sheet table td:first-child { white-space: normal; width: 55%; color: var(--muted); }
.sheet table td { white-space: normal; }
.sheet-heading { background: var(--surface-2); }
@media print {
  .topbar, .sidebar, .site-footer, .no-print, .messages { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; color: #000; }
  .sheet-page { break-inside: avoid; }
}
.eoi-form > h2 { margin-top: 0; }
