/* Praetorian CRM — one stylesheet, no inline styles (the page CSP forbids them). */
:root {
  --bg: #f5f3ee; --surface: #ffffff; --surface-2: #faf8f4; --ink: #111a2b; --muted: #556072; --line: #e2ddd2; --line-strong: #cfc7b6;
  --navy: #0c1626; --navy-2: #15233a; --gold: #cdbb8e; --accent: #7a6235; --accent-ink: #ffffff; --focus: #2c6bed;
  --ok: #1d7044; --ok-bg: #e6f3ec; --warn: #8a5a00; --warn-bg: #fdf3dc; --danger: #b42318; --danger-bg: #fdecea; --info-bg: #eaf0fb;
  --radius: 10px; --shadow: 0 1px 2px rgba(12,22,38,.06), 0 4px 16px rgba(12,22,38,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a111d; --surface: #111b2c; --surface-2: #0e1726; --ink: #e9e5db; --muted: #9ea7b5; --line: #24324b; --line-strong: #344563;
    --accent: #cdbb8e; --accent-ink: #0c1626; --focus: #7fa7ff;
    --ok: #6fcf97; --ok-bg: #11291d; --warn: #f2c45a; --warn-bg: #2b2210; --danger: #ff8a7a; --danger-bg: #331512; --info-bg: #132341;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a111d; --surface: #111b2c; --surface-2: #0e1726; --ink: #e9e5db; --muted: #9ea7b5; --line: #24324b; --line-strong: #344563;
  --accent: #cdbb8e; --accent-ink: #0c1626; --focus: #7fa7ff;
  --ok: #6fcf97; --ok-bg: #11291d; --warn: #f2c45a; --warn-bg: #2b2210; --danger: #ff8a7a; --danger-bg: #331512; --info-bg: #132341;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font: 400 26px/1.2 var(--serif); }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 .8em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---------------------------------------------------------------- buttons and inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
:root[data-theme="dark"] .btn.primary { background: var(--gold); border-color: var(--gold); color: var(--navy); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { background: var(--gold); border-color: var(--gold); color: var(--navy); } }
.btn.danger { color: var(--danger); border-color: currentColor; background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; min-height: 24px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
textarea { min-height: 84px; resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--navy); }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 3px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; min-height: 32px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-msg { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }
.form-msg.ok { color: var(--ok); }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #d8dde6; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 18px 12px; display: flex; flex-direction: column; }
.brand { font: 400 15px var(--serif); letter-spacing: .22em; color: var(--gold); padding: 4px 10px 18px; text-transform: uppercase; }
.brand small { display: block; letter-spacing: .08em; font: 12px var(--font); color: #9aa6b8; text-transform: none; margin-top: 2px; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #d8dde6; text-decoration: none; font-weight: 500; min-height: 40px; }
.nav a:hover { background: var(--navy-2); }
.nav a[aria-current="page"] { background: var(--navy-2); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav .count { margin-left: auto; background: var(--gold); color: var(--navy); border-radius: 999px; font-size: 12px; font-weight: 700; padding: 0 7px; min-width: 20px; text-align: center; }
.nav-sep { height: 1px; background: #233149; margin: 10px 4px; }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; padding: 12px 10px 0; font-size: 13px; color: #9aa6b8; border-top: 1px solid #233149; }
.side-foot b { color: #fff; font-weight: 600; display: block; }
.side-foot .linkbtn { color: var(--gold); }

.main-wrap { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  display: flex; gap: 10px; align-items: center; padding: 10px 24px; }
.search { position: relative; flex: 1 1 auto; max-width: 520px; }
.search input { padding-left: 36px; }
.search .ico { position: absolute; left: 10px; top: 11px; color: var(--muted); }
.search-results { position: absolute; top: 46px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 60vh; overflow: auto; z-index: 30; }
.search-results a { display: block; padding: 9px 12px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); }
.search-results a:hover, .search-results a:focus { background: var(--surface-2); }
.search-results .grp { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 12px 4px; }
main:focus { outline: none; }
main { padding: 22px 24px 40px; max-width: 1280px; width: 100%; }
.page-head { display: flex; gap: 12px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin: 4px 0 0; }

.bottom-nav { display: none; }

/* ---------------------------------------------------------------- cards, tables, badges */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card > h2 { display: flex; align-items: center; gap: 8px; }
.card > h2 .btn { margin-left: auto; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.side-main { grid-template-columns: minmax(0, 1fr) 340px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
.kpi .n { font: 400 26px/1.1 var(--serif); }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi.alert .n { color: var(--danger); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.list > li:last-child { border-bottom: 0; }
.list .meta { color: var(--muted); font-size: 13px; }
.list a { color: var(--ink); font-weight: 600; text-decoration: none; }
.list a:hover { text-decoration: underline; }
.empty { color: var(--muted); padding: 14px 0; }
.empty-big { text-align: center; padding: 40px 16px; color: var(--muted); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--ink); border-color: transparent; }
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td a { color: var(--ink); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs a, .tabs button { padding: 8px 12px; text-decoration: none; color: var(--muted); font-weight: 600; border: 0; background: none; font: inherit; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; min-height: 40px; }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"] { max-width: 280px; }
.toolbar select, .toolbar input[type="date"] { width: auto; }
.toolbar label { margin: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 18px; margin: 0; }
.facts dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.facts dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--info-bg); margin-bottom: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.danger { background: var(--danger-bg); color: var(--danger); }
.focus-list li .why { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.why.danger { color: var(--danger); } .why.warn { color: var(--warn); } .why.info { color: var(--accent); }
.notes-block { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- pipeline */
.board { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 140px; scroll-snap-align: start; }
.col.drop { outline: 2px dashed var(--accent); }
.col h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; margin-bottom: 8px; }
.col .total { font-size: 12px; color: var(--muted); margin: -4px 0 8px; }
.deal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: grab; }
.deal-card a { color: var(--ink); text-decoration: none; font-weight: 600; display: block; }
.deal-card .meta { font-size: 12px; color: var(--muted); }
.deal-card select { margin-top: 8px; min-height: 32px; padding: 4px 8px; font-size: 13px; }
.deal-card.overdue { border-left: 3px solid var(--danger); }

/* ---------------------------------------------------------------- timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0 10px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-strong); }
.timeline li.k-call::before, .timeline li.k-meeting::before { border-color: var(--accent); }
.timeline li.k-status::before { background: var(--accent); border-color: var(--accent); }
.timeline .meta { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- chat */
.chat { display: grid; grid-template-columns: 260px minmax(0, 1fr); height: calc(100vh - 150px); min-height: 420px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.chat-list { border-right: 1px solid var(--line); overflow-y: auto; padding: 10px; background: var(--surface-2); }
.chat-list a { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; min-height: 40px; }
.chat-list a[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.chat-list .count { margin-left: auto; background: var(--navy); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; }
.chat-list h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 10px 6px; }
.chat-main { display: flex; flex-direction: column; min-height: 0; }
.chat-head { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.msgs { position: relative; flex: 1; overflow-y: auto; padding: 14px; }
.msg { margin-bottom: 12px; max-width: 760px; }
.msg .who { font-weight: 700; font-size: 13px; }
.msg .when { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 6px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .acts { display: inline-flex; gap: 8px; margin-left: 8px; }
.msg .acts button { font-size: 12px; }
.msg.deleted .body { color: var(--muted); font-style: italic; }
.attach { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-top: 4px; text-decoration: none; color: var(--ink); background: var(--surface-2); }
.composer { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; }
.day-sep { text-align: center; color: var(--muted); font-size: 12px; margin: 12px 0; }
.meet-frame { width: 100%; height: calc(100vh - 170px); min-height: 420px; border: 0; border-radius: var(--radius); background: #000; }

/* ---------------------------------------------------------------- calendar */
.agenda-day { margin-bottom: 14px; }
.agenda-day h2 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 6px; }
.agenda-day.today h2 { color: var(--accent); }
.ev { display: grid; grid-template-columns: 90px 1fr; gap: 10px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; margin-bottom: 6px; }
.ev.booking { border-left-color: var(--navy); }
.ev .t { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.ev a { color: var(--ink); font-weight: 600; text-decoration: none; }

/* ---------------------------------------------------------------- reports */
.bars { list-style: none; padding: 0; margin: 0; }
.bars li { display: grid; grid-template-columns: minmax(90px, 150px) 1fr auto; gap: 10px; align-items: center; padding: 4px 0; font-size: 14px; }
.bars .track { display: block; height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.bars .fill { display: block; height: 100%; background: var(--accent); width: 0; }
.bars .v { text-align: right; font-variant-numeric: tabular-nums; }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 90px; border-bottom: 1px solid var(--line); }
.spark span { flex: 1; max-width: 28px; background: var(--accent); min-height: 1px; border-radius: 2px 2px 0 0; }

/* ---------------------------------------------------------------- dialog, toast */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(8,14,24,.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { margin: 0; font: 400 20px var(--serif); }
.dlg-body { padding: 16px 18px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); flex-wrap: wrap; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--danger); }

/* ---------------------------------------------------------------- sign in */
.auth-body { min-height: 100vh; display: grid; place-items: center; background: var(--navy); padding: 16px; }
.auth-card { background: var(--surface); color: var(--ink); width: min(420px, 100%); padding: 28px; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.brand-mark { font: 400 14px var(--serif); letter-spacing: .25em; text-transform: uppercase; color: var(--accent); margin-bottom: 18px; }
.auth-card .btn { width: 100%; margin-top: 8px; }
.devlink { margin-top: 14px; padding: 10px; background: var(--warn-bg); color: var(--warn); border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .grid.side-main { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .side.open { display: flex; position: fixed; inset: 0 30% 0 0; min-width: 260px; z-index: 60; height: 100%; }
  .scrim { position: fixed; inset: 0; background: rgba(8,14,24,.5); z-index: 55; }
  .topbar { padding: 8px 16px; }
  main { padding: 16px 16px 96px; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--navy);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; color: #c9d1dd; text-decoration: none; font: 600 11px var(--font); min-height: 52px; justify-content: center; background: none; border: 0; position: relative; cursor: pointer; }
  .bottom-nav [aria-current="page"] { color: var(--gold); }
  .bottom-nav .dot { position: absolute; top: 6px; right: calc(50% - 16px); background: var(--gold); color: var(--navy); font-size: 10px; border-radius: 999px; padding: 0 5px; }
  .chat { grid-template-columns: 1fr; height: calc(100vh - 210px); }
  .chat.has-channel .chat-list { display: none; }
  .chat:not(.has-channel) .chat-main { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .list > li.stackable { flex-direction: column; align-items: stretch; }
  .list > li.stackable .row select { width: auto; flex: 1; }
  .bars li { grid-template-columns: 96px 1fr auto; }
  h1 { font-size: 22px; }
  /* tables become cards */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.stack td { border: 0; padding: 3px 8px; display: flex; gap: 10px; justify-content: space-between; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; text-align: left; flex: none; }
  table.stack td:first-child { font-size: 16px; text-align: left; }
  table.stack td:first-child::before { content: none; }
  table.stack td.num { text-align: right; }
  .toolbar input[type="search"] { max-width: none; flex: 1 1 100%; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
}
@media (min-width: 901px) { .only-mobile { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
@media print { .side, .topbar, .bottom-nav, .btn { display: none !important; } .shell { display: block; } }
