:root {
    --bg: #0f1620;
    --bg2: #16202c;
    --panel: #1b2734;
    --panel2: #223143;
    --line: #2b3b4e;
    --txt: #dce6f0;
    --muted: #7d8ea0;
    --accent: #38b6ff;
    --ok: #35c98a;
    --off: #f0883e;
    --bad: #ef5b6b;
    --word: #b98bff;
    --city: #5fd0e0;
    --geo: #f0b429;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--txt);
    font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
b.on, .on { color: var(--ok); }
b.off, .off { color: var(--off); }
.dim { color: var(--muted); }
.muted { color: var(--muted); }
h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 15px; margin: 22px 0 10px; color: #a9bccf; border-bottom: 1px solid var(--line); padding-bottom: 6px; }

/* Topbar */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 20px; background: var(--bg2); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; color: var(--txt); }
.brand-sub { color: var(--muted); font-weight: 400; font-size: 12px; }
.topbar nav a { margin-left: 18px; }
.topbar .logout { color: var(--muted); }
.wrap { max-width: 1500px; margin: 0 auto; padding: 18px 20px 60px; }

/* Login */
.login-box {
    max-width: 340px; margin: 12vh auto; background: var(--panel);
    padding: 30px; border-radius: 12px; border: 1px solid var(--line); text-align: center;
}
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; text-align: left; }
.login-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
input, select, button {
    font: inherit; color: var(--txt); background: var(--bg2);
    border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px;
}
button { background: var(--accent); color: #05243a; font-weight: 600; cursor: pointer; border: none; }
button:hover { filter: brightness(1.08); }
.alert { background: rgba(239,91,107,.15); border: 1px solid var(--bad); color: #ffb4bd; padding: 9px 12px; border-radius: 8px; margin: 10px 0; }

/* Summary cards */
.summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.summary .card {
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
    padding: 12px 18px; min-width: 96px; display: flex; flex-direction: column;
}
.summary .num { font-size: 22px; font-weight: 700; }
.summary .lbl { color: var(--muted); font-size: 12px; }
.summary .ok .num { color: var(--ok); }
.summary .warn .num { color: var(--bad); }

/* Filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { min-width: 260px; }
.btn-reset { color: var(--muted); padding: 8px 10px; }
.count-line { margin: 6px 0 12px; }

/* Grid table */
.grid { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
.grid th, .grid td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid th { background: var(--panel2); color: #9fb2c6; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
.grid tr:last-child td { border-bottom: none; }
.grid tbody tr:hover { background: #1f2d3d; }
.row-dim td { opacity: .62; }
.row-banned td { background: rgba(239,91,107,.07); }
.uname a { font-weight: 600; }
.noname { color: var(--muted); font-style: italic; }
.uid { color: var(--muted); font-size: 12px; }
.nums span { display: inline-block; margin-right: 10px; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 26px; }
.nowrap { white-space: nowrap; }

/* Chips & badges */
.chip { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; border: 1px solid var(--line); }
.chip-paid { background: rgba(53,201,138,.16); color: var(--ok); border-color: var(--ok); }
.chip-trial { background: rgba(56,182,255,.16); color: var(--accent); border-color: var(--accent); }
.chip-admin { background: rgba(185,139,255,.16); color: var(--word); border-color: var(--word); }
.chip-none { color: var(--muted); }
.badge { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11px; background: var(--panel2); color: #9fb2c6; margin: 1px 2px 1px 0; }
.badge.ok { background: rgba(53,201,138,.18); color: var(--ok); }
.badge.bad { background: rgba(239,91,107,.18); color: var(--bad); }
.badge.dim { color: var(--muted); }

.btn-open { white-space: nowrap; }
.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin: 18px 0; color: var(--muted); }

/* User page */
.crumbs { color: var(--muted); margin-bottom: 10px; font-size: 13px; }
.user-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; }
.user-head h1 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.uh-meta { color: var(--muted); font-size: 13px; }
.uh-state { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.pill { background: var(--bg2); border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px; font-size: 12px; }
.pill-on { border-color: var(--ok); color: var(--ok); }
.pill-off { border-color: var(--off); color: var(--off); }

.interval { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 16px 0; padding: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.interval label { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.presets { display: flex; gap: 6px; }
.presets a { background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; font-size: 12px; }
.tz-note { color: var(--muted); font-size: 12px; margin-left: auto; }

.cols { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.col { flex: 1 1 340px; min-width: 320px; }
.col-wide { flex: 2 1 560px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 16px; }
.panel-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.panel-row:last-child { border-bottom: none; }
.panel-row span { color: var(--muted); }
.geo-block { flex-direction: column; align-items: flex-start; }
.hint { color: var(--muted); font-size: 11px; margin-top: 3px; font-style: italic; }

.tpl-list { margin-top: 10px; }
.tpl-list summary { cursor: pointer; color: var(--accent); padding: 6px 0; }
.tpl { border-left: 3px solid var(--line); padding: 5px 10px; margin: 5px 0; background: var(--panel); border-radius: 0 6px 6px 0; }
.tpl-on { border-left-color: var(--ok); }
.tpl-off { border-left-color: var(--line); opacity: .7; }
.tpl-words { color: var(--muted); font-size: 12px; margin-top: 3px; }
.snap-change { padding: 4px 0; font-size: 13px; border-bottom: 1px dashed var(--line); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.tl-dt { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 150px; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.tl-dot.tl-geo { background: var(--geo); }
.tl-dot.tl-kw { background: var(--word); }
.tl-dot.tl-mon { background: var(--accent); }
.tl-on .tl-label { color: var(--ok); }
.tl-off .tl-label { color: var(--off); }

/* Orders */
h2 .counts { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.tabs { display: flex; gap: 6px; margin: 10px 0; }
.tab { background: var(--bg2); color: var(--muted); border: 1px solid var(--line); padding: 6px 14px; font-size: 13px; border-radius: 7px; }
.tab.active { background: var(--accent); color: #05243a; font-weight: 600; border: none; }
.orders td { font-size: 13px; }
.otext { color: #c2d0de; }
.reason { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11px; margin-left: 4px; }
.reason-word { background: rgba(185,139,255,.16); color: var(--word); }
.reason-city { background: rgba(95,208,224,.16); color: var(--city); }
.reason-geo { background: rgba(240,180,41,.16); color: var(--geo); }
.reason-none { color: var(--muted); }
.order-row.hide { display: none; }

.diag-foot { margin-top: 30px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; text-align: center; }
.warn-text { color: var(--off); }

/* Активные шаблоны за интервал (Feature 1) */
.active-window { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.mini-h { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tchip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 12px; border: 1px solid var(--line); background: var(--bg2); }
.tchip-full { border-color: var(--ok); color: var(--ok); }
.tchip-partial { border-color: var(--geo); color: var(--geo); }
.tchip .uid { color: inherit; opacity: .7; }

/* Поиск + панель вкладок (Feature 3) */
.orders-toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 10px 0; }
.orders-toolbar .tabs { margin: 0; }
.order-search { min-width: 220px; max-width: 360px; }
.orders-toolbar .order-search { flex: 1 1 220px; }
#search-deliv { display: block; width: 100%; max-width: 360px; margin: 8px 0; }
.hide { display: none !important; }

/* Кликабельное слово-причина (Feature 2) */
.reason.clickable { cursor: pointer; text-decoration: underline dotted; }
.reason.clickable:hover { filter: brightness(1.15); text-decoration: underline; }

/* Модалка «машина времени» */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4,9,15,.72); }
.modal-box { position: relative; z-index: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; max-width: 640px; width: 100%; max-height: 84vh; overflow: auto; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-close { position: absolute; top: 10px; right: 12px; background: var(--bg2); color: var(--muted); border: 1px solid var(--line); border-radius: 7px; width: 30px; height: 30px; padding: 0; font-size: 14px; cursor: pointer; }
.modal-close:hover { color: var(--txt); }
.modal-content { margin-top: 6px; }

.verdict { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; line-height: 1.4; }
.verdict-ok { background: rgba(53,201,138,.14); border: 1px solid var(--ok); color: #b9f0d6; }
.verdict-warn { background: rgba(240,136,62,.14); border: 1px solid var(--off); color: #f6cba6; }
.snap-meta { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.snap-tpls { display: flex; flex-direction: column; gap: 6px; }
.snap-tpl { border-left: 3px solid var(--line); padding: 6px 10px; background: var(--bg2); border-radius: 0 7px 7px 0; }
.snap-tpl-on { border-left-color: var(--ok); }
.snap-tpl-off { opacity: .72; }
.snap-tpl-hit { background: rgba(255,210,74,.10); border-left-color: var(--geo); }
.snap-tpl-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.snap-tpl-words { color: var(--muted); font-size: 12px; margin-top: 4px; word-break: break-word; }
.hit-badge { background: var(--geo); color: #241900; padding: 0 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.modal mark, mark { background: #ffd24a; color: #1b1300; padding: 0 2px; border-radius: 3px; }
