:root {
  --bg: #f4f5f7; --card: #fff; --text: #14181f; --muted: #6a7382; --line: #e4e7ec;
  --accent: #2563eb; --accent-text: #fff; --ok: #16a34a; --err: #dc2626; --err-bg: #fee2e2;
  --radius: 14px; --tab-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --card: #171b22; --text: #e8ebf0; --muted: #8b95a5; --line: #262c36;
    --accent: #5b8def; --accent-text: #0b1020; --ok: #34d399; --err: #f87171; --err-bg: #3b1d1f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --card: #171b22; --text: #e8ebf0; --muted: #8b95a5; --line: #262c36;
  --accent: #5b8def; --accent-text: #0b1020; --ok: #34d399; --err: #f87171; --err-bg: #3b1d1f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin-bottom: .6rem; display: flex; align-items: center; gap: .5rem; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(.7rem + env(safe-area-inset-top)) 1rem .7rem; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.25rem; }
.tools { display: flex; gap: .4rem; }
.tools form { margin: 0; }
.icon {
  min-width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font-size: 1.15rem; cursor: pointer;
}
main { max-width: 760px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
main.narrow { min-height: 100dvh; align-content: center; padding-bottom: 3rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.login { text-align: center; }
.login h1 { font-size: 1.6rem; margin-bottom: .8rem; }
.btn {
  display: inline-block; width: 100%; min-height: 48px; padding: .75rem 1.2rem; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.note { margin: 0 0 1rem; padding: .7rem .9rem; border-radius: 10px; text-align: left; }
.err { background: var(--err-bg); color: var(--err); }
.muted { color: var(--muted); font-size: .92rem; }
.badge {
  display: inline-block; min-width: 1.6rem; padding: 0 .5rem; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-size: .85rem; text-align: center;
}
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .7rem 0; border-top: 1px solid var(--line);
}
.list li:first-child { border-top: 0; }
.list .muted { margin-left: auto; }
.list.links a { font-weight: 600; }
.dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 .5rem transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .dot.live { animation: none; } }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem;
  color: var(--muted); font-size: .72rem;
}
.tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tabs .ico { font-size: 1.3rem; line-height: 1; }
@media (min-width: 900px) { main { padding: 1.5rem; } }

/* sections with data */
.stack { display: grid; gap: 1rem; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.seg a { min-height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: .95rem; }
.seg a[aria-current] { background: var(--accent); color: var(--accent-text); }
.stats { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .6rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; text-align: center; }
.stat b { display: block; font-size: 1.35rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .8rem; }
.chart { position: relative; height: 220px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
select { width: 100%; min-height: 44px; padding: 0 .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); font: inherit; }
.btn.small { width: auto; min-height: 44px; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .82rem; font-weight: 600; }
.pill.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.err { background: color-mix(in srgb, var(--err) 18%, transparent); color: var(--err); }
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: .8rem; }
.pager a { min-height: 44px; display: inline-flex; align-items: center; padding: 0 .4rem; font-weight: 600; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .4rem; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .8rem; font-weight: 600; border-top: 0; }
@media (max-width: 600px) {
  table.cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { padding: .55rem 0; border-top: 1px solid var(--line); }
  table.cards tr:first-child { border-top: 0; }
  table.cards td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem 0; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex: none; }
}
@media (max-width: 600px) {
  /* journal: one compact card per entry — who and what on top, when and where below */
  table.feed tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "user event" "when chat" "by by"; column-gap: .8rem; row-gap: .1rem; align-items: center; }
  table.feed td { display: block; padding: 0; text-align: left; }
  table.feed td::before { display: none; }
  table.feed .c-user { grid-area: user; }
  table.feed .c-event { grid-area: event; text-align: right; }
  table.feed .c-when { grid-area: when; color: var(--muted); font-size: .88rem; }
  table.feed .c-chat { grid-area: chat; color: var(--muted); font-size: .88rem; text-align: right; }
  table.feed .c-by { grid-area: by; color: var(--muted); font-size: .88rem; }
  table.feed .c-by:not(:has(.muted))::before { display: inline; content: "Кем: "; }
  table.feed .c-by:has(.muted) { display: none; }
}

/* orders */
.orders { display: grid; gap: .6rem; }
a.order { display: block; padding: .8rem .9rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); }
.card .orders a.order { border-radius: 12px; }
.order-top { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.route { margin: .25rem 0; line-height: 1.35; }
.order-meta { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .88rem; }
.mark { color: var(--muted); }
.mark.warn { color: var(--warn); font-weight: 600; }
.pill.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill.info { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.filters3 { grid-template-columns: 1fr 1fr; }
.filters3 input[type=search] { grid-column: 1 / -1; min-height: 44px; padding: 0 .8rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); font: inherit; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--line); display: grid; gap: .8rem; }
.timeline li { display: flex; flex-direction: column; gap: .1rem; position: relative; }
.timeline li::before { content: ""; position: absolute; left: calc(-1rem - 6px); top: .45rem; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
:root { --warn: #b45309; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --warn: #fbbf24; } }
:root[data-theme="dark"] { --warn: #fbbf24; }
