/* Panel styling. Vazirmatn is bundled with the app (wwwroot/fonts) rather than fetched from a CDN:
   this panel is served from an operational host that may have no outbound internet, and a webfont
   that silently fails to load would fall back to a font with poor Persian shaping.

   Only the two weights the panel actually uses are shipped. `font-display: swap` means the console
   is readable immediately even before the font arrives. */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0f1420;
  --surface: #171e2e;
  --surface-2: #1e2638;
  --border: #2a3448;
  --text: #e8edf7;
  --muted: #8d9bb5;
  --accent: #4c8dff;
  --accent-soft: #21345c;
  --danger: #ff5d5d;
  --ok: #35c07f;
  --warn: #ffb45c;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* The single most important rule in this file.
 *
 * The HTML uses the `hidden` attribute to toggle the login screen, the app shell and the toast. The
 * browser's built-in rule for that attribute is `[hidden] { display: none }`, but it lives in the
 * User-Agent origin — and *any* author-origin declaration beats it, regardless of specificity. Since
 * .login-screen and .app below both set `display: flex`, the attribute was silently ignored: the app
 * shell and the login card were rendered on top of each other from the very first paint, which is
 * exactly the "the UI is broken / forms appear behind the page" symptom.
 *
 * Stating it in the author origin with !important is the standard, intention-revealing fix: the
 * attribute now means what every reader assumes it means. */
[hidden] { display: none !important; }

/* Respect the OS "reduce motion" setting: the panel is a status surface, not an animation showcase. */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* Visible keyboard focus everywhere. The default outline is easy to lose against these dark
   surfaces, which matters on a console an operator may be driving from a keyboard. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  transition: filter .15s ease;
  white-space: nowrap;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
button.ghost:hover:not(:disabled) { background: var(--surface-2); filter: none; }
button.danger { background: var(--danger); color: #1a0c0c; font-weight: 600; }
button.small { padding: 4px 10px; font-size: 12px; }

input, select {
  font-family: inherit;
  font-size: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 120px;
  color-scheme: dark;
}
input:disabled, select:disabled { opacity: .6; }
input::placeholder { color: var(--muted); }

/* The date input's calendar icon is invisible on a dark background until the scheme is forced. */
input[type="checkbox"] { min-width: auto; width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.hint {
  background: var(--surface-2);
  border-inline-start: 3px solid var(--warn);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--muted);
}

/* ---- Login ---- */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #1a2436, var(--bg) 70%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: min(380px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card label { margin-top: 8px; color: var(--muted); }
.login-card button { margin-top: 16px; padding: 10px; }
.login-card .brand-mark { font-size: 28px; line-height: 1; }

/* ---- Shell ---- */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand strong { white-space: nowrap; }
.dot {
  width: 10px; height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 8px transparent;
}
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.bad { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.dot.busy { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; min-width: 0; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 6px 12px;
}
.tab:hover:not(.active) { color: var(--text); background: var(--surface-2); filter: none; }
.tab.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.session { display: flex; align-items: center; gap: 10px; }

main { padding: 20px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }
.view { display: none; flex-direction: column; gap: 20px; }
.view.active { display: flex; }

/* A short fade makes a tab switch legible as a change of context instead of a silent repaint. */
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view.active { animation: view-in .18s ease-out; }

/* ---- Cards ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  border-inline-start: 3px solid transparent;
}
.card .value { font-size: 26px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 13px; }
.card.alert { border-inline-start-color: var(--danger); }
.card.alert .value { color: var(--danger); }
.card.good { border-inline-start-color: var(--ok); }
.card.good .value { color: var(--ok); }
.card.warn { border-inline-start-color: var(--warn); }
.card.warn .value { color: var(--warn); }

/* ---- Panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 16px; }
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-head .filters input[type="text"] { min-width: 160px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; max-height: 460px; overflow-y: auto; }
.table-wrap.tall { max-height: 640px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { vertical-align: middle; }
th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  white-space: nowrap;
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* An empty table rendered as one muted row is easy to mistake for a rendering failure. This gives
   "there is genuinely nothing here" a deliberate, centred look. */
td.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px;
  font-size: 13px;
}

code, .mono {
  font-family: "JetBrains Mono", "Consolas", monospace;
  direction: ltr;
  unicode-bidi: embed;
  font-size: 12.5px;
}
td.raw { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: left; }
.reason-cell { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
}
.badge.danger { color: var(--danger); border-color: var(--danger); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }

/* ---- Forms ---- */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input[type="text"] { flex: 1; min-width: 200px; }
.inline-form select { min-width: 140px; }
.settings-form { display: flex; flex-direction: column; gap: 14px; max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field .muted { font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; user-select: none; }
.check input { min-width: auto; }
.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 12px; }

/* ---- Chart ---- */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 10px; }
.bar {
  flex: 1;
  min-width: 2px;
  background: linear-gradient(to top, var(--accent), #7fb0ff);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  position: relative;
  transition: filter .12s ease;
}
.bar:hover { filter: brightness(1.25); }
/* A zero-height bar is invisible, which reads as missing data. Mark hours with no failures
   explicitly so the column still communicates "this hour was quiet". */
.bar.zero { background: var(--border); min-height: 2px; }
.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 160px;
  color: var(--muted);
}
.chart-axis {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

/* ---- Info grid ---- */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.info-item {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 14px;
}
.info-item .k { color: var(--muted); font-size: 12px; }
.info-item .v { font-weight: 600; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  inset-inline-start: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 8px;
  padding: 12px 18px;
  z-index: 50;
  max-width: 420px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .45);
  animation: view-in .18s ease-out;
}
.toast.error { border-inline-start-color: var(--danger); }
.toast.ok { border-inline-start-color: var(--ok); }

/* ---- Loading / skeleton ---- */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row td { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---- Accessibility helpers ---- */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .tabs { justify-content: flex-start; }
  .session { justify-content: space-between; }
  main { padding: 12px; }
  .panel { padding: 14px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .card .value { font-size: 22px; }
  .inline-form input[type="text"] { min-width: 0; }
  .settings-form { max-width: none; }
  .toast { inset-inline: 12px; max-width: none; }
}

/* Tables become horizontally scrollable rather than squashed on small screens. */
@media (max-width: 900px) {
  .table-wrap { max-height: none; }
}
