:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #17191d;
  --text-2: #4b5260;
  --muted: #7a8291;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --grid: #eceef2;

  /* chart series (validated: info-and-below / warn / error) */
  --s-info: #3b82f6;
  --s-warn: #ca8a04;
  --s-error: #dc2626;

  /* level badges */
  --lv-trace-bg: #f1f3f5; --lv-trace: #6b7280;
  --lv-debug-bg: #eef1f5; --lv-debug: #475569;
  --lv-info-bg: #e8f0ff;  --lv-info: #1d4ed8;
  --lv-warn-bg: #fdf3d8;  --lv-warn: #92600a;
  --lv-error-bg: #fde8e8; --lv-error: #b91c1c;
  --lv-fatal-bg: #f6e5fb; --lv-fatal: #86198f;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111213;
    --surface: #1a1a19;
    --surface-2: #202122;
    --border: #2d2f33;
    --text: #eceef1;
    --text-2: #b5bac3;
    --muted: #8a909b;
    --accent: #6b9cff;
    --accent-soft: #1c2740;
    --grid: #26282b;

    --s-info: #3b82f6;
    --s-warn: #c0860a;
    --s-error: #d93a5a;

    --lv-trace-bg: #24262a; --lv-trace: #9aa1ad;
    --lv-debug-bg: #24282f; --lv-debug: #a8b3c4;
    --lv-info-bg: #1b2a47;  --lv-info: #8db4ff;
    --lv-warn-bg: #3a2d10;  --lv-warn: #f2c35b;
    --lv-error-bg: #43191d; --lv-error: #ff8f8f;
    --lv-fatal-bg: #3a1a42; --lv-fatal: #e7a6f5;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Vazirmatn, "Segoe UI", Tahoma, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}
code, .mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 2px 0; }
.error { color: var(--lv-error); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; direction: ltr; }
.logo { color: var(--accent); letter-spacing: -3px; font-size: 13px; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 6px 14px; border-radius: 8px; color: var(--text-2); font-weight: 500;
}
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.global-filters { display: flex; align-items: end; gap: 12px; margin-inline-start: auto; }

main { padding: 20px 24px 48px; max-width: 1500px; margin: 0 auto; }

/* ---------- controls ---------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.field > span { font-size: 12px; color: var(--muted); }
.field.compact { flex-direction: row; align-items: center; gap: 8px; min-width: 0; }
.field.grow { flex: 1 1 260px; }
input, select, button { font: inherit; color: inherit; }
input, select {
  height: 34px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.btn {
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--lv-error); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 18px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.toggle input { height: auto; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.grid-2 .card { margin-bottom: 0; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi a { color: inherit; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- chart ---------- */
.chart { position: relative; height: 240px; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: "Segoe UI", Tahoma, sans-serif; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: var(--text); fill-opacity: .05; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.15); min-width: 150px;
}
.tooltip .t-title { color: var(--muted); margin-bottom: 4px; direction: ltr; text-align: right; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-table td { padding: 7px 4px; }
.mini-table th { padding: 6px 4px; background: transparent; }
.bar-cell { width: 34%; }
.hbar { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; display: flex; direction: ltr; }
.hbar i { display: block; height: 100%; }

.logs-table { table-layout: fixed; }
.logs-table td { font-size: 13px; }
.logs-table tbody tr { cursor: pointer; }
.logs-table tbody tr:hover { background: var(--surface-2); }
.logs-table tr.fresh { animation: fresh 2s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }
.c-time { width: 170px; } .c-level { width: 72px; } .c-app { width: 130px; } .c-ver { width: 90px; } .c-dev { width: 130px; }
.logs-table .msg { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: left; unicode-bidi: plaintext; }
.logs-table .msg .exc { color: var(--lv-error); margin-inline-end: 6px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ltr { direction: ltr; text-align: left; unicode-bidi: plaintext; }
.time { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; white-space: nowrap; color: var(--text-2); }
.table-foot { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-top: 1px solid var(--border); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .02em; direction: ltr;
}
.lv-0 { background: var(--lv-trace-bg); color: var(--lv-trace); }
.lv-1 { background: var(--lv-debug-bg); color: var(--lv-debug); }
.lv-2 { background: var(--lv-info-bg); color: var(--lv-info); }
.lv-3 { background: var(--lv-warn-bg); color: var(--lv-warn); }
.lv-4 { background: var(--lv-error-bg); color: var(--lv-error); }
.lv-5 { background: var(--lv-fatal-bg); color: var(--lv-fatal); }
.status { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); }
.status.open { border-color: transparent; background: var(--lv-error-bg); color: var(--lv-error); }
.status.resolved { border-color: transparent; background: #e3f6ea; color: #17733f; }
@media (prefers-color-scheme: dark) { .status.resolved { background: #163322; color: #7bd8a0; } }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.filter-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chips { flex-basis: 100%; display: flex; gap: 6px; flex-wrap: wrap; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12.5px; }
.chip button { border: 0; background: transparent; cursor: pointer; color: inherit; padding: 0 6px; }

.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; margin-bottom: 14px; }
.segmented button { border: 0; background: transparent; padding: 5px 14px; border-radius: 7px; cursor: pointer; color: var(--text-2); }
.segmented button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- issues ---------- */
.issue { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.issue:last-child { border-bottom: 0; }
.issue-title { font-family: var(--mono); font-size: 13px; word-break: break-word; direction: ltr; text-align: left; unicode-bidi: plaintext; }
.issue-meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.issue-count { text-align: center; min-width: 80px; }
.issue-count b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.issue-actions { display: flex; gap: 6px; grid-column: 1 / -1; flex-wrap: wrap; }

/* ---------- apps ---------- */
.inline-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.app-card .app-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.app-card h3 { margin: 0; font-size: 16px; }
.keybox { display: flex; gap: 8px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.keybox code { background: var(--surface-2); border: 1px solid var(--border); padding: 6px 10px; border-radius: 8px; direction: ltr; user-select: all; }
details.snippets summary { cursor: pointer; color: var(--accent); margin-top: 4px; }
pre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow: auto; direction: ltr; text-align: left; font-family: var(--mono); font-size: 12.5px; margin: 8px 0;
  white-space: pre;
}
.snippet-tabs { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(760px, 100vw); z-index: 40;
  background: var(--surface); border-right: 1px solid var(--border); box-shadow: 8px 0 30px rgba(0,0,0,.18);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-body { padding: 18px; overflow: auto; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 30; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin-bottom: 16px; }
.kv dt { color: var(--muted); }
.kv dd, .kv dd.ltr { margin: 0; word-break: break-all; text-align: right; }
.kv dd a { cursor: pointer; }
.section-title { font-size: 12.5px; color: var(--muted); margin: 16px 0 4px; }
pre.message { white-space: pre-wrap; word-break: break-word; }
pre.stack { color: var(--lv-error); white-space: pre; max-height: 420px; }

/* ---------- modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(10, 12, 16, .55); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-card { background: var(--surface); border-radius: 14px; padding: 24px; width: min(440px, 100%); display: flex; flex-direction: column; gap: 12px; }
.modal-card h2 { font-size: 18px; }
.modal-card p { margin: 0; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 70;
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

@media (max-width: 760px) {
  .topbar { padding: 10px 12px; gap: 10px; }
  main { padding: 14px 12px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .c-app, .c-ver, .c-dev { display: none; }
  .logs-table td:nth-child(3), .logs-table td:nth-child(5), .logs-table td:nth-child(6) { display: none; }
  .c-time { width: 120px; }
}
