/* VIAGE · KSC Reporting — shadcn-flavored tokens, light + dark, responsive.
   Single CSS, no framework. Variable names kept stable so existing page markup
   (.card, .btn, .info-bar, etc.) still works; legacy --bg / --text aliases sit
   on top of the shadcn HSL palette so a theme flip only swaps the base layer. */

:root {
  /* shadcn — light */
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card-bg: 0 0% 100%;
  --card-fg: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-fg: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-fg: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-fg: 240 3.8% 46.1%;
  --border-h: 240 5.9% 90%;
  --input-h: 240 5.9% 86%;
  --ring: 240 5.9% 10%;

  /* Status pairs (bg / fg / border) — H S L triplets */
  --info-bg-h:   213 87% 94%;  --info-fg-h:   213 70% 28%;  --info-border-h: 213 70% 55%;
  --ok-bg-h:     91  55% 90%;  --ok-fg-h:     95  78% 18%;  --ok-border-h:   95  60% 38%;
  --warn-bg-h:   34  85% 92%;  --warn-fg-h:   28  85% 28%;  --warn-border-h: 30  80% 41%;
  --err-bg-h:    0   78% 95%;  --err-fg-h:    0   60% 30%;  --err-border-h:  0   75% 58%;

  --radius: 8px;
  --radius-input: 6px;
  --shadow: 0 4px 18px hsl(0 0% 0% / 0.06);
  --shadow-lg: 0 16px 48px hsl(0 0% 0% / 0.10);
  --mono: ui-monospace, "Cascadia Code", "Consolas", "SF Mono", monospace;
  --sans: "Segoe UI Variable Display", "Segoe UI", -apple-system, "Inter", system-ui, sans-serif;

  /* Legacy aliases used across pages — resolved from the shadcn tokens above */
  --bg:            hsl(var(--background));
  --surface:       hsl(var(--card-bg));
  --surface-2:     hsl(var(--secondary));
  --nav-rail-bg:   hsl(var(--secondary));
  --border:        hsl(var(--border-h));
  --border-strong: hsl(var(--input-h));
  --text:          hsl(var(--foreground));
  --text-2:        hsl(var(--muted-fg));
  --text-3:        hsl(var(--muted-fg) / 0.7);
  --accent:        hsl(var(--primary));

  --info-bg:   hsl(var(--info-bg-h));   --info-text: hsl(var(--info-fg-h));   --info-border: hsl(var(--info-border-h));
  --ok-bg:     hsl(var(--ok-bg-h));     --ok-text:   hsl(var(--ok-fg-h));     --ok-border:   hsl(var(--ok-border-h));
  --warn-bg:   hsl(var(--warn-bg-h));   --warn-text: hsl(var(--warn-fg-h));   --warn-border: hsl(var(--warn-border-h));
  --err-bg:    hsl(var(--err-bg-h));    --err-text:  hsl(var(--err-fg-h));    --err-border:  hsl(var(--err-border-h));
}

[data-theme="dark"] {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card-bg: 240 10% 5.5%;
  --card-fg: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-fg: 240 5.9% 10%;
  --secondary: 240 3.7% 12%;
  --secondary-fg: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-fg: 240 5% 64.9%;
  --border-h: 240 3.7% 17%;
  --input-h: 240 3.7% 22%;
  --ring: 240 4.9% 83.9%;

  --info-bg-h:   213 70% 14%;  --info-fg-h:   213 90% 80%;  --info-border-h: 213 70% 45%;
  --ok-bg-h:     95  40% 12%;  --ok-fg-h:     91  60% 70%;  --ok-border-h:   95  55% 40%;
  --warn-bg-h:   34  60% 15%;  --warn-fg-h:   34  90% 75%;  --warn-border-h: 30  70% 45%;
  --err-bg-h:    0   60% 17%;  --err-fg-h:    0   85% 80%;  --err-border-h:  0   72% 50%;

  --shadow: 0 4px 18px hsl(0 0% 0% / 0.40);
  --shadow-lg: 0 16px 48px hsl(0 0% 0% / 0.55);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
html { color-scheme: light; }
[data-theme="dark"] html, html[data-theme="dark"] { color-scheme: dark; }

a { color: inherit; text-decoration: none; }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
h3 { font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
small { color: var(--text-2); }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
pre.mono, pre.xml-preview {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.7;
  background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius-input);
  white-space: pre-wrap; word-break: break-word; max-height: 480px; overflow: auto;
  margin: 8px 0 0;
  border: 1px solid var(--border);
}

/* ---------- Shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  height: 100dvh;
}

.nav-rail {
  background: var(--nav-rail-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px 8px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand img { width: 30px; height: 30px; }
.brand-title { font-weight: 600; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--text-2); }

.nav-menu { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  height: 40px;
  border-radius: 6px;
  color: var(--text-2);
  font-size: 13px;
  position: relative;
  cursor: pointer;
}
.nav-item:hover { background: hsl(var(--foreground) / 0.06); color: var(--text); }
.nav-item.active {
  background: hsl(var(--foreground) / 0.09);
  color: var(--text);
  font-weight: 600;
}
.nav-item.active::before {
  content: ""; position: absolute; left: -4px; top: 11px; bottom: 11px;
  width: 3px; border-radius: 2px; background: var(--accent);
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.env-pill { font-size: 11px; padding: 3px 10px; border-radius: 4px; font-weight: 500; white-space: nowrap; }
.env-pill--accept { background: var(--warn-bg); color: var(--warn-text); }
.env-pill--prod { background: var(--err-bg); color: var(--err-text); }
.content { padding: 22px; overflow-y: auto; flex: 1; }

/* ---------- Mobile drawer / hamburger ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  color: var(--text);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.icon-btn--hamburger { display: none; }
.scrim {
  display: none;
  position: fixed; inset: 0;
  background: hsl(0 0% 0% / 0.45);
  z-index: 40;
}
.scrim.open { display: block; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0 0 14px;
  box-shadow: var(--shadow);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; gap: 8px; }
.card-header h2 { margin: 0; }
.card-sub { color: var(--text-2); font-family: var(--mono); font-size: 11.5px; }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-actions .btn { margin-left: 0; }
.muted { color: var(--text-2); }
.warn { color: var(--warn-text); }

/* ---------- Inputs ---------- */
input[type=text], input[type=email], input[type=number], input[type=password],
input[type=date], input[type=time], select, textarea {
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-input);
  padding: 0 10px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
  width: 100%;
}
textarea { height: auto; padding: 8px 10px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.18);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }

label { display: block; margin: 0 0 12px; }

/* Safety net: adjacent inputs/selects/textareas / labels never touch.
   This protects ad-hoc forms (e.g. KSC credentials) where elements are
   dropped one after another without a wrapper. */
input + input, input + select, input + textarea,
select + input, select + select, select + textarea,
textarea + input, textarea + select, textarea + textarea,
h2 + input, h2 + select, h2 + textarea,
h3 + input, h3 + select, h3 + textarea,
label + label, .form-stack > * + * { margin-top: 10px; }

/* Vertical stack utility — wrap groups of bare inputs to guarantee spacing. */
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack--sm { gap: 6px; }
.stack--lg { gap: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 0; min-width: 0; }
.row > .row-fixed { flex: 0 0 auto; }
.field-label { display: block; font-size: 11px; color: var(--text-2); margin: 0 0 4px; text-transform: none; }
.checkbox-line { display: flex; align-items: center; gap: 6px; height: 36px; }
input[type=checkbox] { width: 16px; height: 16px; margin: 0; accent-color: hsl(var(--primary)); }
.file-input { padding: 6px 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px;
  padding: 0 16px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-input);
  cursor: pointer;
  margin: 0;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
/* Safety net: never let two buttons touch, regardless of layout context. */
.btn + .btn, .btn + a.btn, a.btn + .btn { margin-left: 8px; }
.btn:hover { background: var(--surface-2); border-color: var(--accent); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px hsl(var(--ring) / 0.20); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: hsl(var(--primary)); color: hsl(var(--primary-fg)); border-color: hsl(var(--primary)); }
.btn--primary:hover { background: hsl(var(--primary) / 0.88); border-color: hsl(var(--primary)); }
.btn--danger { color: var(--err-text); border-color: var(--err-border); }
.btn--danger:hover { background: var(--err-bg); }
.btn--small { height: 28px; padding: 0 10px; font-size: 11px; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; row-gap: 8px; }
.btn-row .btn { margin-left: 0; } /* flex gap takes over */

/* ---------- Layout helpers ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.row-input { display: flex; gap: 8px; flex-wrap: wrap; }
.row-input input { flex: 1; min-width: 140px; }

/* ---------- Metrics ---------- */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0 0 14px; }
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.metric-label { font-size: 11px; color: var(--text-2); margin-bottom: 4px; }
.metric-value { font-size: 24px; font-weight: 500; }
.metric-value-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot--ok { background: var(--ok-border); }
.dot--err { background: var(--err-border); }

/* ---------- Feed (Ingestion) ---------- */
.feed { font-family: var(--mono); font-size: 12px; max-height: 480px; overflow: auto; }
.feed-empty { color: var(--text-2); padding: 20px 0; text-align: center; }
.feed-row { display: flex; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); align-items: center; flex-wrap: wrap; }
.feed-row:last-child { border-bottom: none; }
.feed-row--err { color: var(--err-text); }
.feed-ts { color: var(--text-3); width: 100px; }
.feed-cmd { width: 130px; }
.feed-betid { width: 130px; color: var(--text-2); }
.feed-amount { width: 80px; color: var(--text-2); }
.feed-ip { margin-left: auto; color: var(--text-3); }

.badge { font-size: 11px; padding: 2px 6px; border-radius: 4px; }
.badge--err { background: var(--err-bg); color: var(--err-text); }
.badge--ok { background: var(--ok-bg); color: var(--ok-text); }

/* ---------- Logs ---------- */
.log-stream { font-family: var(--mono); font-size: 11.5px; max-height: 560px; overflow: auto; }
.log-row { display: grid; grid-template-columns: 150px 80px 220px 1fr; gap: 8px; padding: 2px 0; }
.log-ts { color: var(--text-3); }
.log-src { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-level { font-weight: 500; }
.log-level--error, .log-level--fatal { color: var(--err-text); }
.log-level--warning { color: var(--warn-text); }
.log-level--information { color: var(--info-text); }
.filter { display: inline-flex; align-items: center; gap: 6px; margin-right: 6px; font-size: 12px; color: var(--text-2); }
.filter select { width: auto; height: 28px; }

/* ---------- Status banners ---------- */
.status { padding: 10px 12px; border-radius: var(--radius-input); margin: 12px 0; font-size: 13px; }
.status--info { background: var(--info-bg); color: var(--info-text); }
.status--ok { background: var(--ok-bg); color: var(--ok-text); }
.status--err { background: var(--err-bg); color: var(--err-text); }

.info-bar {
  display: block;
  padding: 12px 14px;
  border-radius: var(--radius-input);
  margin: 0 0 14px;
  font-size: 13px;
  border-left: 4px solid;
}
.info-bar--info { background: var(--info-bg); color: var(--info-text); border-left-color: var(--info-border); }
.info-bar--ok { background: var(--ok-bg); color: var(--ok-text); border-left-color: var(--ok-border); }
.info-bar--warn { background: var(--warn-bg); color: var(--warn-text); border-left-color: var(--warn-border); }
.info-bar--err { background: var(--err-bg); color: var(--err-text); border-left-color: var(--err-border); }
.info-bar-title { font-weight: 600; margin-bottom: 4px; }

/* ---------- Schedule row (Configuration) ---------- */
.schedule-row { display: grid; grid-template-columns: 50px 1fr 110px; gap: 8px; align-items: center; margin-bottom: 8px; }
.schedule-row select, .schedule-row input { height: 32px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
.table th, .table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 500; color: var(--text-2); }

.kv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv-table th, .kv-table td { padding: 4px 8px; text-align: left; vertical-align: top; }
.kv-table th { color: var(--text-2); font-weight: 500; width: 220px; }

.list { list-style: none; padding: 0; margin: 0 0 12px; }
.list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }

/* Horizontal scroll wrapper for wide tables on small screens */
.table-scroll { overflow-x: auto; }

/* ---------- Blazor error UI ---------- */
#blazor-error-ui {
  background: var(--err-bg);
  color: var(--err-text);
  bottom: 0;
  box-shadow: 0 -1px 2px hsl(0 0% 0% / 0.2);
  display: none;
  left: 0; right: 0;
  padding: 0.6rem 1.25rem 0.7rem;
  position: fixed;
  z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* ---------- Login page ---------- */
.login-body { display: flex; min-height: 100vh; min-height: 100dvh; align-items: center; justify-content: center; background: var(--bg); }
.login-shell { width: 100%; max-width: 420px; padding: 32px 24px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand img { width: 36px; height: 36px; }
.login-title { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
.login-sub { margin: 0 0 22px; font-size: 13px; }
.login-submit { width: 100%; margin-top: 16px; margin-right: 0; }
.login-footnote { text-align: center; margin-top: 24px; font-size: 11.5px; }

/* ---------- Topbar user chip ---------- */
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); font-size: 12px; }
.user-name { color: var(--text-2); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-link { color: var(--text); font-size: 14px; text-decoration: none; padding: 0 2px; cursor: pointer; display: inline-flex; align-items: center; }
.user-link:hover { color: var(--accent); }

/* ---------- HugeIcons component ---------- */
svg.hgi { display: inline-block; vertical-align: middle; flex-shrink: 0; stroke-width: 1.5; }
.icon-danger { color: var(--err-text); }
.icon-warn { color: var(--warn-text); }
.icon-ok { color: var(--ok-text); }
.icon-muted { color: var(--text-3); }

.nav-glyph { width: 18px; height: 18px; color: inherit; }
.btn .hgi { margin-right: 6px; vertical-align: -3px; }
.feed-row .hgi, .log-row .hgi { vertical-align: -3px; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .log-row { grid-template-columns: 130px 70px 1fr; }
  .log-row .log-src { display: none; }
}

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .nav-rail {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .nav-rail.open { transform: translateX(0); }
  .icon-btn--hamburger { display: inline-flex; }
  .topbar { padding: 10px 14px; }
  .content { padding: 14px; }
  .row3 { grid-template-columns: 1fr; }
  .schedule-row { grid-template-columns: 44px 1fr; }
  .schedule-row > :last-child { grid-column: 1 / -1; }
  .topbar-title { font-size: 13px; }
  .user-name { display: none; }
  .feed-betid, .feed-amount, .feed-ip { width: auto; }
  .login-shell { padding: 16px; }
  .login-card { padding: 22px 18px; }
  h1 { font-size: 18px; }
}

@media (max-width: 480px) {
  .env-pill { display: none; }
  .card { padding: 14px; }
  .btn { padding: 0 12px; }
}

/* Reduce-motion respect */
@media (prefers-reduced-motion: reduce) {
  .nav-rail, .btn { transition: none; }
}
