/* ───────────── Font: Vazirmatn (variable, OFL) ───────────── */
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ───────────── Design tokens ───────────── */
:root {
  --font: "Vazirmatn", ui-sans-serif, system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --surface-3: #e8ebf0;
  --border: #dde1e8; --border-strong: #c6ccd6;
  --text: #171b22; --text-2: #424a57; --muted: #6a7382;
  --accent: #3b5bdb; --accent-hover: #2f49b5; --accent-soft: #e7ecfd; --on-accent: #ffffff;
  --ok: #1a7f4b; --ok-soft: #e3f4ea;
  --fail: #c92a2a; --fail-soft: #fde8e8;
  --warn: #b35c00; --warn-soft: #fff0dc;
  --info: #3a6ea5; --info-soft: #e5eef8;
  --crit: #a1123a; --crit-soft: #fbe3ea;
  --bar-ok: #7b93e8; --bar-fail: #e5484d; --bar-unk: #b9c0cc;
  --diff-old: #fde8e8; --diff-new: #e3f4ea;
  --shadow: 0 8px 28px rgba(15, 23, 42, .16); --radius: 8px; --row-h: 44px;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}
[data-theme="dark"] {
  --bg: #0f1218; --surface: #171b23; --surface-2: #1d222c; --surface-3: #262c38;
  --border: #2a303c; --border-strong: #3a4252;
  --text: #e8ebf1; --text-2: #bcc3cf; --muted: #8d97a8;
  --accent: #7c93f5; --accent-hover: #9aabf8; --accent-soft: #232d57; --on-accent: #0f1218;
  --ok: #4cc38a; --ok-soft: #14301f; --fail: #ff7a7a; --fail-soft: #3a1b1d;
  --warn: #f0a24b; --warn-soft: #3a2a12; --info: #7fb2e6; --info-soft: #172a3d;
  --crit: #ff7a9c; --crit-soft: #3d1827;
  --bar-ok: #5a73d6; --bar-fail: #ef6a6f; --bar-unk: #566074;
  --diff-old: #3a1b1d; --diff-new: #14301f; --shadow: 0 8px 28px rgba(0, 0, 0, .55);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --surface: #171b23; --surface-2: #1d222c; --surface-3: #262c38;
    --border: #2a303c; --border-strong: #3a4252;
    --text: #e8ebf1; --text-2: #bcc3cf; --muted: #8d97a8;
    --accent: #7c93f5; --accent-hover: #9aabf8; --accent-soft: #232d57; --on-accent: #0f1218;
    --ok: #4cc38a; --ok-soft: #14301f; --fail: #ff7a7a; --fail-soft: #3a1b1d;
    --warn: #f0a24b; --warn-soft: #3a2a12; --info: #7fb2e6; --info-soft: #172a3d;
    --crit: #ff7a9c; --crit-soft: #3d1827;
    --bar-ok: #5a73d6; --bar-fail: #ef6a6f; --bar-unk: #566074;
    --diff-old: #3a1b1d; --diff-new: #14301f; --shadow: 0 8px 28px rgba(0, 0, 0, .55);
  }
}
[data-density="compact"] { --row-h: 32px; }

/* ───────────── Base ───────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ───────────── Shell ───────────── */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); height: 100vh; }
.sidebar { background: var(--surface); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; gap: 4px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 14px; font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text-2); background: none; border: 0; width: 100%; text-align: start; }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-title { margin: 16px 10px 4px; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.nav-item .count { margin-inline-start: auto; font-size: 12px; color: var(--muted); }
.sidebar-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 700; font-size: 12px; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar h1 { font-size: 17px; margin: 0; margin-inline-end: auto; font-weight: 650; }
.view { flex: 1; overflow-y: auto; padding: 16px 20px 40px; }

/* ───────────── Controls ───────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 6px; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { padding: 6px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 10px; border-inline-end: 1px solid var(--border); }
.seg button:last-child { border-inline-end: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg button:hover { background: var(--surface-2); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
[aria-pressed="true"] > .live-dot { background: var(--ok); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(26,127,75,.5)} 70%{box-shadow:0 0 0 7px rgba(26,127,75,0)} 100%{box-shadow:0 0 0 0 rgba(26,127,75,0)} }
.menu { position: relative; display: inline-block; }
.menu-list { position: absolute; inset-inline-end: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 170px; padding: 4px; z-index: 30; }
.menu-list button { display: flex; width: 100%; gap: 8px; padding: 7px 10px; border: 0; background: none; border-radius: 5px; text-align: start; }
.menu-list button:hover { background: var(--surface-2); }

.search { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 260px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 0 10px; height: 38px; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { flex: 1; border: 0; outline: 0; background: none; height: 100%; min-width: 0; }
kbd { font: 11px var(--mono); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface-2); color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; min-height: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border: 1px solid transparent; border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12.5px; }
[dir="rtl"] .chip { padding: 2px 10px 2px 4px; }
.chip b { font-weight: 600; }
.chip button { border: 0; background: none; color: inherit; border-radius: 50%; width: 20px; height: 20px; display: grid; place-items: center; }
.chip button:hover { background: rgba(0,0,0,.12); }

/* ───────────── Layout of the log view ───────────── */
.log-layout { display: grid; grid-template-columns: 224px minmax(0, 1fr); gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.facets { padding: 6px 0; position: sticky; top: 0; max-height: calc(100vh - 180px); overflow-y: auto; }
.facet { padding: 8px 12px 10px; border-bottom: 1px solid var(--border); }
.facet:last-child { border-bottom: 0; }
.facet h3 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 650; }
.facet label { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.facet label span.n { margin-inline-start: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.facet input { accent-color: var(--accent); }

.hist-card { padding: 12px 14px 10px; margin-bottom: 12px; }
.hist-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.hist-head .total { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 12px; margin-inline-start: auto; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-inline-end: 5px; }
.hist { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; height: 84px; align-items: end; }
.hist .col { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; cursor: pointer; border-radius: 3px; }
.hist .col:hover { background: var(--surface-2); }
.hist .seg-ok, .hist .seg-fail, .hist .seg-unk { width: 100%; }
.hist .seg-ok { background: var(--bar-ok); border-radius: 2px 2px 0 0; }
.hist .seg-unk { background: var(--bar-unk); }
.hist .seg-fail { background: var(--bar-fail); border-radius: 2px 2px 0 0; }
.hist .col > :first-child { border-radius: 2px 2px 0 0; }
.hist-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 11.5px; color: var(--muted); }

.results-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.results-bar .spacer { margin-inline-start: auto; }
.table-wrap { overflow-x: auto; }
table.events { width: 100%; border-collapse: collapse; }
.events th { text-align: start; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 650; padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); position: sticky; top: 0; white-space: nowrap; }
.events td { padding: 0 10px; height: var(--row-h); border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 380px; overflow: hidden; text-overflow: ellipsis; }
.events tbody tr { cursor: pointer; }
.events tbody tr:hover { background: var(--surface-2); }
.events tbody tr[aria-selected="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
[dir="rtl"] .events tbody tr[aria-selected="true"] { box-shadow: inset -3px 0 0 var(--accent); }
.events tbody tr:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 0; }
td.t-msg { max-width: 420px; color: var(--text-2); }
td.t-time { font-variant-numeric: tabular-nums; color: var(--text-2); }
.link { color: var(--text); border-bottom: 1px dotted var(--border-strong); }
.link:hover { color: var(--accent); text-decoration: none; border-bottom-color: var(--accent); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.failure { background: var(--fail-soft); color: var(--fail); }
.badge.unknown { background: var(--surface-3); color: var(--muted); }
.sev { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.sev i { width: 8px; height: 8px; border-radius: 50%; }
.sev.info i { background: var(--muted); } .sev.low i { background: var(--info); } .sev.medium i { background: #e0a100; }
.sev.high i { background: #e8590c; } .sev.critical i { background: var(--crit); box-shadow: 0 0 0 3px var(--crit-soft); }
.tag { display: inline-block; padding: 0 7px; border-radius: 4px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-family: var(--mono); }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty h3 { margin: 8px 0 4px; color: var(--text); }
.skel td > div { height: 12px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.1s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.more { display: flex; justify-content: center; padding: 12px; }

/* ───────────── Drawer ───────────── */
.drawer { position: fixed; inset-block: 0; inset-inline-end: 0; width: min(580px, 100%); background: var(--surface); border-inline-start: 1px solid var(--border); box-shadow: var(--shadow); z-index: 40; display: flex; flex-direction: column; transform: translateX(0); transition: transform .18s ease; }
[dir="rtl"] .drawer { transform: translateX(0); }
.drawer[hidden] { display: flex !important; transform: translateX(105%); visibility: hidden; }
[dir="rtl"] .drawer[hidden] { transform: translateX(-105%); }
.drawer-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.drawer-top { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.drawer-top .spacer { margin-inline-start: auto; }
.drawer-title { font-size: 16px; font-weight: 650; margin: 0 0 4px; }
.drawer-sub { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 12.5px; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; background: none; padding: 9px 10px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs button:hover { color: var(--text); }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 16px 30px; }
.group { margin-bottom: 18px; }
.group h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 5px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.diff { width: 100%; border-collapse: collapse; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.diff th { text-align: start; font-size: 11.5px; padding: 6px 10px; background: var(--surface-2); color: var(--muted); }
.diff td { padding: 6px 10px; border-top: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.diff td.old { background: var(--diff-old); } .diff td.new { background: var(--diff-new); }
.diff td.old::before { content: "− "; color: var(--fail); } .diff td.new::before { content: "+ "; color: var(--ok); }
.masked { font-size: 11px; color: var(--warn); background: var(--warn-soft); padding: 0 6px; border-radius: 4px; margin-inline-start: 6px; }
.related { display: flex; flex-direction: column; gap: 6px; }
.related button { text-align: start; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 7px 10px; display: flex; gap: 10px; align-items: center; }
.related button:hover { background: var(--surface-2); }
pre.json { margin: 0; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; overflow: auto; font: 12.5px/1.55 var(--mono); direction: ltr; text-align: left; }
.jk { color: var(--accent); } .js { color: var(--ok); } .jn { color: var(--warn); } .jb { color: var(--crit); }
.callout { padding: 9px 12px; border-radius: 6px; background: var(--fail-soft); color: var(--fail); margin-bottom: 14px; }

/* ───────────── Overview / entity ───────────── */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--fail); } .delta.down { color: var(--ok); } .delta.flat { color: var(--muted); }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.panel { padding: 14px 16px; }
.panel h2 { margin: 0 0 10px; font-size: 14px; }
.barlist { display: flex; flex-direction: column; gap: 8px; }
.barrow { display: grid; grid-template-columns: minmax(80px, 150px) 1fr 44px; align-items: center; gap: 10px; }
.barrow .track { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.barrow .fill { height: 100%; background: var(--bar-ok); border-radius: 4px; }
.barrow .num { text-align: end; color: var(--muted); font-variant-numeric: tabular-nums; }
.barrow button { border: 0; background: none; text-align: start; padding: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barrow button:hover { color: var(--accent); }
.crumb { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; color: var(--muted); }
.entity-head { padding: 16px 18px; margin-bottom: 14px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.entity-head h2 { margin: 0; font-size: 18px; }
.timeline { position: relative; margin: 0; padding: 0; list-style: none; }
.timeline::before { content: ""; position: absolute; inset-block: 6px; inset-inline-start: 7px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-inline-start: 30px; padding-bottom: 16px; }
.tl-dot { position: absolute; inset-inline-start: 0; top: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); }
.tl-item.failure .tl-dot { border-color: var(--fail); }
.tl-card { padding: 10px 12px; cursor: pointer; }
.tl-card:hover { background: var(--surface-2); }
.tl-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.mini-change { margin-top: 6px; font-size: 12.5px; }
.mini-change .o { background: var(--diff-old); padding: 0 5px; border-radius: 3px; text-decoration: line-through; text-decoration-color: var(--fail); }
.mini-change .n { background: var(--diff-new); padding: 0 5px; border-radius: 3px; }

/* ───────────── Misc ───────────── */
.tooltip { position: fixed; z-index: 70; pointer-events: none; background: #11151c; color: #fff; padding: 6px 9px; border-radius: 6px; font-size: 12px; box-shadow: var(--shadow); }
.toast { position: fixed; inset-inline-start: 50%; bottom: 22px; transform: translateX(-50%); background: #11151c; color: #fff; padding: 9px 14px; border-radius: 8px; z-index: 80; box-shadow: var(--shadow); }
.modal-back { position: fixed; inset: 0; background: rgba(8, 12, 20, .5); z-index: 60; display: grid; place-items: center; }
.modal { width: min(480px, 92vw); padding: 18px 20px; }
.modal h2 { margin: 0 0 12px; font-size: 16px; }
.modal table td { padding: 4px 8px 4px 0; }
.note { font-size: 12px; color: var(--muted); padding: 6px 2px 0; }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, 1fr); } .two { grid-template-columns: 1fr; } }
@media (min-width: 901px) { #btn-filters { display: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ───────────── App-specific additions ───────────── */
a.nav-item { text-decoration: none; }
.nav-item.is-active, a.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot form { margin-inline-start: auto; }
.sidebar-foot .btn { padding: 4px 8px; font-size: 12.5px; }
.sidebar-user { min-width: 0; }
.sidebar-user div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.load-error { padding: 28px 20px; text-align: center; color: var(--fail); }
.facet .empty-note { color: var(--muted); }
#page-title { margin-inline-end: auto; }

/* ───────────── Sign-in layout ───────────── */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-card { width: min(400px, 100%); padding: 28px 28px 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.auth-card h1 { font-size: 18px; margin: 0 0 4px; }
.auth-card .sub { color: var(--muted); margin: 0 0 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 13px; }
.field input[type="text"], .field input[type="password"] { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field .field-error { color: var(--fail); font-size: 12.5px; margin-top: 3px; display: block; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.check input { accent-color: var(--accent); }
.btn.block { width: 100%; justify-content: center; height: 40px; }
.form-error { background: var(--fail-soft); color: var(--fail); padding: 9px 12px; border-radius: 6px; margin-bottom: 14px; }
.form-error ul { margin: 0; padding-inline-start: 18px; }
.auth-tools { display: flex; justify-content: flex-end; gap: 6px; margin-top: 14px; }

/* ───────────── Responsive / mobile ───────────── */
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.menu-btn, .nav-backdrop { display: none; }
.facets-head, .facets-foot { display: none; }
.topbar { padding-top: max(10px, env(safe-area-inset-top)); padding-inline: max(20px, env(safe-area-inset-left)) max(20px, env(safe-area-inset-right)); }
.view { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }

/* Larger touch targets on touch screens. */
@media (pointer: coarse) {
  .btn, .seg button { min-height: 40px; }
  .btn.icon { min-width: 40px; justify-content: center; }
  .nav-item { padding: 11px 10px; }
  .facet label { padding: 8px 0; }
  .chip button { width: 28px; height: 28px; }
  .menu-list button { padding: 11px 12px; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }

  /* Sidebar becomes an off-canvas menu opened from the hamburger button. */
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(290px, 86vw); z-index: 55; transform: translateX(-105%);
    transition: transform .2s ease; box-shadow: var(--shadow); padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  body.nav-open .sidebar { transform: none; }
  .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 12, 20, .5); z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open, body.has-sheet, body.has-drawer { overflow: hidden; }
  .menu-btn { display: inline-flex; }

  .topbar { padding: 8px 12px; gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right)); }
  .topbar h1 { font-size: 16px; min-width: 0; }

  .view { padding: 12px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .log-layout { grid-template-columns: 1fr; }

  /* Filters open as a full-screen sheet. */
  #btn-filters { display: inline-flex; }
  .facets { display: none; position: fixed; inset: 0; z-index: 56; max-height: none; border: 0; border-radius: 0; padding: 0; overflow-y: auto; }
  .facets.open { display: flex; flex-direction: column; }
  .facets-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1; background: var(--surface);
    padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border); }
  .facets-foot { display: block; margin-top: auto; position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .toolbar .search { min-width: 0; flex-basis: 0; }
  .toolbar .lbl { display: none; }
}

@media (min-width: 901px) { #btn-filters { display: none; } }

/* Event list becomes a list of cards. */
@media (max-width: 760px) {
  .table-wrap { overflow-x: visible; }
  table.events, .events tbody { display: block; }
  .events thead { display: none; }
  .events tbody tr { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .events td { display: block; height: auto; padding: 0; border: 0; max-width: none; white-space: normal; overflow: visible; }
  .events td.t-time { grid-column: 1; grid-row: 1; font-size: 12.5px; }
  .events td.col-severity { display: block; grid-column: 2; grid-row: 1; }
  .events td.c-outcome { grid-column: 3; grid-row: 1; justify-self: end; }
  .events td.t-msg { grid-column: 1 / -1; grid-row: 2; color: var(--text); font-weight: 500; max-width: none; }
  .events td.c-actor { grid-column: 1 / 3; grid-row: 3; font-size: 12.5px; color: var(--muted); }
  .events td.c-target { grid-column: 3; grid-row: 3; justify-self: end; font-size: 12.5px; }
  .events td.c-action, .events td.col-source { display: none; }
  .events tbody tr[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--accent); }
  [dir="rtl"] .events tbody tr[aria-selected="true"] { box-shadow: inset -3px 0 0 var(--accent); }
  .hist { height: 68px; }
  .results-bar { flex-wrap: wrap; }
}

/* Event details: full-screen sheet. */
@media (max-width: 700px) {
  .drawer { width: 100%; border: 0; }
  .drawer-head { padding: 10px 14px 8px; padding-top: max(10px, env(safe-area-inset-top)); }
  .drawer-top .lbl { display: none; }
  .tabs { overflow-x: auto; scrollbar-width: none; padding-inline: 8px; }
  .tabs button { white-space: nowrap; }
  .drawer-body { padding: 12px 14px calc(30px + env(safe-area-inset-bottom)); }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 8px; font-size: 12px; }
  .diff th, .diff td { padding: 6px; }
  .entity-head { gap: 12px; }
  .barrow { grid-template-columns: minmax(70px, 110px) 1fr 36px; }
}

@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .value { font-size: 22px; }
  .hist-head { flex-wrap: wrap; gap: 6px 12px; }
  .legend { margin-inline-start: 0; }
  .auth-card { padding: 22px 18px 18px; }
}

/* Installed app (standalone window): no browser chrome, so respect the safe areas everywhere. */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
}

/* ───────────── Brand lock-up (name + tagline) ───────────── */
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text small { font-size: 11px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.auth-brand .brand-text small { font-size: 12px; }

/* ───────────── Small screens: header controls move into a bottom sheet opened by a floating action button ───────────── */
.fab, .actions-backdrop, .actions-head { display: none; }

@media (max-width: 900px) {
  .topbar { flex-wrap: nowrap; }

  .fab {
    display: grid; place-items: center; position: fixed; z-index: 45;
    inset-inline-end: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
    width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%;
    background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 20px rgba(15, 23, 42, .35);
  }
  .fab:active { transform: scale(.95); }
  .fab svg { width: 24px; height: 24px; }

  .topbar-actions {
    position: fixed; z-index: 60; inset-inline: 0; bottom: 0; width: auto; max-height: 85vh; overflow-y: auto;
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: stretch;
    padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--surface);
    border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; box-shadow: var(--shadow);
    transform: translateY(105%); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s;
  }
  body.actions-open .topbar-actions { transform: none; visibility: visible; transition: transform .2s ease; }

  .actions-head { display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; margin-bottom: 2px; }
  .actions-head strong { font-size: 15px; }
  .actions-backdrop { display: block; position: fixed; inset: 0; z-index: 58; background: rgba(8, 12, 20, .5); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.actions-open .actions-backdrop { opacity: 1; pointer-events: auto; }
  body.actions-open { overflow: hidden; }
  body.actions-open .fab, body.has-drawer .fab, body.has-sheet .fab, body.nav-open .fab { display: none; }

  .topbar-actions #range-seg { grid-column: 1 / -1; }
  .topbar-actions .seg { width: 100%; }
  .topbar-actions .seg button { flex: 1; min-height: 40px; }
  .topbar-actions > .btn { width: 100%; justify-content: center; min-height: 40px; }
  .topbar-actions #btn-help { display: none; }   /* keyboard shortcuts are pointless on phones */

  /* keep the last rows clear of the floating button */
  .view { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
}

/* Text next to icon-only buttons: only shown inside the small-screen sheet. */
.lbl-m { display: none; }
@media (max-width: 900px) {
  .topbar-actions .lbl-m { display: inline; margin-inline-start: 8px; }
}

/* Set for two frames while the text direction flips (see applyPrefs). */
.no-anim *, .no-anim *::before, .no-anim *::after { transition: none !important; animation: none !important; }
