:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c2230;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --hover: #f0f3fa;
  --danger: #c4372f;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --shadow: 0 10px 30px rgba(20, 30, 50, 0.12);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --panel: #1b1f27;
    --text: #e6e8ec;
    --muted: #98a2b3;
    --line: #2c323d;
    --accent: #5b82f0;
    --hover: #232937;
    --danger: #ef6b62;
    --ok: #4cc283;
    --warn: #e3a948;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 18px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 8px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* ------------------------------------------------ forms */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; min-width: 0;
}
textarea { width: 100%; min-height: 60px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); font-size: 14px; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 7px 12px; cursor: pointer;
}
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--danger); }
button.big { padding: 10px 18px; font-weight: 600; }
button.case { background: var(--ok); border-color: var(--ok); color: #fff; }
button.nocase { background: var(--danger); border-color: var(--danger); color: #fff; }
button.case:hover:not(:disabled), button.nocase:hover:not(:disabled) { filter: brightness(1.08); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.form-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-top: 10px; background: var(--bg); }

/* ------------------------------------------------ layout */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: none; background: none; padding: 8px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; }
.tabs button.active { background: var(--hover); color: var(--text); }
.user { margin-left: auto; display: flex; gap: 10px; align-items: center; }
main { padding: 18px 20px 40px; max-width: 1500px; margin: 0 auto; }
.filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* ------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; background: var(--panel); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-top: 1px solid var(--line); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ------------------------------------------------ badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--hover); color: var(--muted); border: 1px solid transparent; }
.b-new { background: var(--hover); color: var(--muted); }
.b-proposed, .b-to_lawyer, .b-negotiating { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.b-case, .b-paid, .b-settled { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.b-no_case, .b-court, .b-rejected { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.b-confirmed, .b-letter_sent { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.b-closed, .b-withdrawn { background: var(--hover); color: var(--muted); }
.b-role { background: var(--hover); color: var(--muted); font-weight: 500; }

/* ------------------------------------------------ drawer */
.overlay { position: fixed; inset: 0; background: rgba(10, 15, 25, .35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(820px, 100vw); background: var(--panel); z-index: 21;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.drawer-body { padding: 4px 20px 30px; overflow-y: auto; flex: 1; }
.close { margin-left: auto; font-size: 20px; line-height: 1; padding: 4px 10px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 16px; margin-top: 14px; }
.fact .k { font-size: 12px; color: var(--muted); }
.fact .v { font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.tile { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.tile .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile.hl { border-color: var(--accent); }
.bio { white-space: pre-wrap; color: var(--muted); margin-top: 10px; }
.decision-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.notes { white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 10px; font-size: 13px; }

/* ------------------------------------------------ log */
.log { list-style: none; padding: 0; margin: 0; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 130px 1fr; gap: 10px; }
.log li:last-child { border-bottom: none; }
.log .when { color: var(--muted); font-size: 12px; }
.log .who { color: var(--muted); font-size: 12px; }

/* ------------------------------------------------ login, toasts */
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); padding: 26px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 20px; }
.toast-area { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 700px) {
  main { padding: 12px; }
  .topbar { padding: 10px 12px; }
  .log li { grid-template-columns: 1fr; gap: 2px; }
}

/* ------------------------------------------------ lawyers page */
.split { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.section-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.section-head h2 { font-size: 16px; }
.hint { font-size: 12px; color: var(--muted); padding: 10px 14px; }
.inline-select { padding: 4px 6px; font-size: 13px; max-width: 220px; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }
