:root {
  --bg: #F6F5F2;
  --card: #FFFFFF;
  --soft: #FAF9F6;
  --line: #E3E1DB;
  --line-soft: #EFEDE8;
  --ink: #1A1A18;
  --ink-2: #33332E;
  --muted: #5F5E58;
  --muted-2: #46463F;
  --chip: #ECEAE4;
  --accent: #1B4A82;
  --blue: #1B4A82;   --blue-bg: #E2EBF7;
  --red: #8C1C13;    --red-bg: #F7E1DE;
  --amber: #6B4100;  --amber-bg: #FBEBD0;
  --green: #1E6B3A;  --green-bg: #E3F1E6;
  --grey: #46463F;   --grey-bg: #ECEAE4;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

/* ---------- layout ---------- */
.wrap { max-width: 1320px; margin: 0 auto; padding: 24px 24px 48px; display: flex; flex-direction: column; gap: 20px; }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.col-main { flex: 999 1 600px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.col-side { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.card-head > div { display: flex; flex-direction: column; gap: 4px; }
.card.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.card.dark .muted { color: #C9C7C0; }
.empty { color: var(--muted); font-size: 14px; padding: 4px 0; }

/* ---------- header ---------- */
header.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.wordmark { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; color: var(--accent); }
.divider { width: 1px; height: 28px; background: #D6D3CB; }
.brand-sub { display: flex; flex-direction: column; gap: 2px; }
.brand-sub strong { font-size: 17px; font-weight: 600; }
.brand-sub span { font-size: 13px; color: var(--muted); }
.who { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sync { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sync.bad { color: var(--red); font-weight: 600; }
.avatar { width: 36px; height: 36px; border-radius: 999px; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex: none; }
.who-text { display: flex; flex-direction: column; font-size: 13px; }
.who-text strong { font-size: 14px; font-weight: 600; }
select.client-pick { min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); padding: 0 10px; font-weight: 600; }

/* ---------- banners ---------- */
.banner { border-radius: 10px; padding: 12px 16px; font-size: 14px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.banner.shadow { background: #FFF6E0; border: 1px solid #F0D9A0; color: #6B4100; }
.banner.stop { background: var(--red-bg); border: 1px solid #EBC3BD; color: var(--red); font-weight: 500; }
.banner.error { background: var(--red-bg); border: 1px solid #EBC3BD; color: var(--red); }

/* ---------- nav ---------- */
nav.tabs { display: flex; flex-wrap: wrap; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
nav.tabs a { min-height: 44px; padding: 0 16px; border-radius: 8px; display: inline-flex; align-items: center; gap: 8px; color: var(--muted-2); text-decoration: none; font-size: 14px; font-weight: 500; }
nav.tabs a:hover { background: var(--chip); }
nav.tabs a[aria-current="page"] { background: var(--ink); color: #fff; font-weight: 600; }
.count { font-size: 12px; font-weight: 700; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
nav.tabs a[aria-current="page"] .count { background: #fff; color: var(--ink); }

/* ---------- KPIs ---------- */
.kpis { display: flex; flex-wrap: wrap; gap: 16px; }
.kpi { flex: 1 1 220px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; overflow-wrap: anywhere; }
.kpi .sub { font-size: 13px; color: var(--muted); }

/* ---------- pills, buttons, forms ---------- */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.blue { background: var(--blue-bg); color: var(--blue); }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.grey { background: var(--grey-bg); color: var(--grey); }
.btn { min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid #CFCCC3; background: var(--card); color: var(--ink); font-size: 14px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted-2); padding: 0 10px; }
.btn.quiet:hover { background: var(--chip); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted-2); }
label.field .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=date], input[type=search], select, textarea {
  min-height: 44px; border: 1px solid #CFCCC3; border-radius: 8px; background: var(--card); padding: 8px 12px; font-size: 15px; font-weight: 400; color: var(--ink); width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
label.check { display: flex; gap: 10px; align-items: center; font-size: 14px; min-height: 44px; }
label.check input { width: 20px; height: 20px; }
.form { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; color: var(--muted-2); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.toolbar input[type=search] { max-width: 340px; }

/* ---------- lists and tables ---------- */
.item { border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.item-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.item-head > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-title { font-size: 15px; font-weight: 600; }
.letter { background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; color: #26261F; }
.quote { font-style: italic; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.rows { display: flex; flex-direction: column; }
.row-line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.row-line:last-child { border-bottom: 0; }
.row-line > :last-child { text-align: right; font-weight: 600; }

.table { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.thead, .trow { display: grid; grid-template-columns: 2.1fr 1fr 1fr 0.9fr 0.9fr 1.3fr 1.8fr; gap: 12px; padding: 12px 16px; align-items: center; }
.thead { background: var(--soft); border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.trow { border: 0; border-bottom: 1px solid var(--line-soft); width: 100%; background: var(--card); text-align: left; font-size: 14px; cursor: pointer; }
.trow:last-child { border-bottom: 0; }
.trow:hover { background: var(--soft); }
.trow .cell-client { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.trow .cell-client small { font-size: 12px; color: var(--muted); }
.overdue { font-weight: 600; color: var(--red); }
.notdue { color: var(--muted); }
.label-sm { display: none; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bars + .bars { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.bars-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bar { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 10px; background: var(--chip); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: grid; grid-template-columns: 12px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.timeline li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 999px; background: var(--muted); margin-top: 6px; }
.dot.sent { background: var(--blue); } .dot.failed { background: var(--red); } .dot.reply { background: var(--amber); }
.dot.approval, .dot.decision { background: var(--accent); } .dot.closed { background: var(--green); } .dot.change { background: var(--muted-2); }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(26, 26, 24, .35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); z-index: 21; overflow-y: auto; box-shadow: -8px 0 32px rgba(0,0,0,.12); display: flex; flex-direction: column; }
.drawer-head { position: sticky; top: 0; background: var(--bg); border-bottom: 1px solid var(--line); padding: 16px 20px; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; z-index: 1; }
.drawer-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.fact .fact-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.fact strong { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- sign in ---------- */
.signin { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.signin .card { width: min(420px, 100%); gap: 18px; padding: 28px; }
.signin h1 { font-size: 22px; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: min(560px, calc(100vw - 32px)); pointer-events: auto; }
.toast.bad { background: var(--red); }

footer.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 16px; }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .wrap { padding: 16px 16px 40px; gap: 16px; }
  .card { padding: 16px; }
  .kpi .value { font-size: 24px; }
  .thead { display: none; }
  .trow { grid-template-columns: 1fr auto; grid-template-areas: "client amount" "inv status" "next next"; gap: 6px 12px; padding: 14px 16px; }
  .trow .c-client { grid-area: client; } .trow .c-amount { grid-area: amount; text-align: right; }
  .trow .c-inv { grid-area: inv; font-size: 13px; color: var(--muted); }
  .trow .c-status { grid-area: status; text-align: right; }
  .trow .c-next { grid-area: next; font-size: 13px; color: var(--muted-2); }
  .trow .c-due, .trow .c-overdue { display: none; }
  .label-sm { display: inline; }
  nav.tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 10px; }
  nav.tabs a { flex: none; }
  .bar { grid-template-columns: 90px 1fr auto; }
  .avatar { display: none; }
  .who { width: 100%; justify-content: space-between; gap: 8px 12px; }
  .sync { width: 100%; }
}
