:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1b1f27; --muted: #6a7282; --line: #e3e6ec;
  --accent: #1f5eff; --accent-ink: #ffffff; --accent-soft: #e8efff;
  --ok: #138a4b; --ok-soft: #e1f5ea; --warn: #a85f00; --warn-soft: #fff1d6;
  --orange: #c2410c; --orange-soft: #ffe8dc; --danger: #b42318; --danger-soft: #fde4e1;
  --radius: 10px; --shadow: 0 8px 30px rgba(20, 28, 45, .16);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --panel: #1a1e26; --ink: #e8ebf1; --muted: #98a1b3; --line: #2b313d;
    --accent: #5b8bff; --accent-ink: #0c1220; --accent-soft: #1f2a47;
    --ok: #4cc88a; --ok-soft: #14301f; --warn: #f0b24d; --warn-soft: #3a2c10;
    --orange: #ff9a63; --orange-soft: #3d2212; --danger: #ff7b6e; --danger-soft: #3d1a17;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; word-break: break-all; }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 70px; resize: vertical; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; font-weight: 600; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.err { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; }
.okmsg { color: var(--ok); background: var(--ok-soft); border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; }

/* ---------- каркас ---------- */
.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: 20; }
.brand { font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.brand small { font-weight: 500; color: var(--muted); margin-left: 8px; }
.spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: 10px; }
.role-tag { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.demo-banner { background: var(--warn-soft); color: var(--warn); padding: 6px 20px; font-weight: 600; text-align: center; }
.page { padding: 18px 20px 40px; max-width: 1500px; margin: 0 auto; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.alert .v { color: var(--danger); }
.kpi.good .v { color: var(--ok); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tab { background: none; border: none; padding: 10px 14px; border-bottom: 3px solid transparent; font-weight: 700;
  color: var(--muted); display: flex; gap: 8px; align-items: center; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.count { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--bg); color: var(--ink); font-variant-numeric: tabular-nums; }
.tab.active .count { background: var(--accent-soft); color: var(--accent); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { width: auto; min-width: 150px; }
.filters input[type=search] { min-width: 230px; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 12px; }
.bulk { display: flex; gap: 8px; align-items: center; background: var(--accent-soft); padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; }

/* ---------- таблица ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel); position: sticky; top: 0; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg); }
tbody tr:last-child td { border-bottom: none; }
td.nowrap { white-space: nowrap; }
.who { font-weight: 700; }
.sub { color: var(--muted); font-size: 12px; }
.clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 4px; color: var(--muted); }

.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip.gray { background: var(--bg); color: var(--muted); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.orange { background: var(--orange-soft); color: var(--orange); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.blue { background: var(--accent-soft); color: var(--accent); }

/* ---------- панель кейса ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel);
  z-index: 41; box-shadow: var(--shadow); overflow-y: auto; display: flex; flex-direction: column; }
.drawer-head { padding: 18px 20px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h2 { margin: 0; font-size: 19px; }
.drawer-body { padding: 16px 20px 30px; display: grid; gap: 18px; }
.x { background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); padding: 4px 8px; }
.section h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; }
a { color: var(--accent); }

.journey { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.step { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg); }
.step .t { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.step .d { font-weight: 800; font-size: 17px; margin-top: 4px; }
.step.done { background: var(--ok-soft); border-color: transparent; } .step.done .d { color: var(--ok); }
.step.now { background: var(--warn-soft); border-color: transparent; } .step.now .d { color: var(--warn); }

.spark { width: 100%; height: 56px; display: block; }
.spark .bar { fill: var(--accent); } .spark .zero { fill: var(--line); }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 2px; }

.timeline { display: grid; gap: 0; }
.ev { display: grid; grid-template-columns: 14px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.ev::before { content: ""; position: absolute; left: 6px; top: 14px; bottom: 0; width: 2px; background: var(--line); }
.ev:last-child::before { display: none; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--line); margin-top: 3px; }
.dot.opened { background: var(--warn); } .dot.touch { background: var(--accent); } .dot.comment { background: var(--muted); }
.dot.returned { background: var(--ok); } .dot.assigned { background: #8b5cf6; } .dot.closed { background: var(--danger); }
.ev .head { font-weight: 700; } .ev .meta { color: var(--muted); font-size: 12px; }
.ev .txt { margin-top: 2px; white-space: pre-wrap; word-break: break-word; }

.form-row { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--bg); }

/* ---------- модальные окна ---------- */
.modal { position: fixed; z-index: 60; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(960px, 96vw);
  max-height: 90vh; overflow: auto; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); }
.modal.narrow { width: min(460px, 96vw); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 12px; }
.modal-head h2 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 16px 18px 22px; }
.mini-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.mini-tabs .btn.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; z-index: 90; font-weight: 600; }

@media (max-width: 760px) {
  .page { padding: 12px; } .journey { grid-template-columns: 1fr; } .kv { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}

/* номер водителя: без выделения и копирования */
.phone-mask { user-select: none; -webkit-user-select: none; }
.phone-shown { font-weight: 700; font-size: 15px; letter-spacing: .02em; }
