/* Kailora Admin — internal operations UI.
   Modern, fast, accessible: bold system-stack typography, a vibrant indigo
   accent over clean white space, layered depth (soft shadows + gradient
   sheens) for a subtle 3D feel, and smooth scroll-driven reveals that are
   fully disabled under prefers-reduced-motion. No external assets — the CSP
   only allows same-origin, so everything here is self-contained. */

:root {
  color-scheme: light;

  /* neutrals */
  --page: #f4f6fb;
  --surface: #ffffff;
  --ink: #0f1222;
  --ink-2: #454a63;
  --muted: #7d829c;
  --grid: #e8eaf3;
  --baseline: #d3d7e6;
  --border: rgba(15, 18, 34, 0.08);

  /* brand — the Kailora logo palette: vivid blue into cyan-teal, over the
     wordmark's deep navy */
  --accent: #1b6cf5;
  --accent-strong: #1257d6;
  --accent-soft: #e9f2ff;
  --accent-glow: rgba(27, 108, 245, 0.28);
  --teal: #23d8ce;
  --navy: #131b2e;
  --brand-grad: linear-gradient(135deg, #1d4dff 0%, #1e9bf0 55%, #23d8ce 130%);

  /* dataviz series-1 stays the established chart blue */
  --series-1: #2a78d6;

  /* status colors are reserved for state, never decoration */
  --status-good: #0ca30c;
  --status-good-text: #006300;
  --status-warn: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  /* depth: layered, soft, directional (the "subtle 3D") */
  --shadow-1: 0 1px 2px rgba(15, 18, 34, 0.05), 0 1px 1px rgba(15, 18, 34, 0.03);
  --shadow-2: 0 2px 6px rgba(15, 18, 34, 0.06), 0 8px 24px rgba(15, 18, 34, 0.07);
  --shadow-3: 0 4px 12px rgba(15, 18, 34, 0.10), 0 24px 60px rgba(15, 18, 34, 0.16);
  --sheen: inset 0 1px 0 rgba(255, 255, 255, 0.85);

  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-size: 12px; background: var(--accent-soft); color: var(--accent-strong);
  padding: 1px 5px; border-radius: 5px;
}

/* bold display typography */
h1 { font-size: 26px; margin: 0; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0; font-weight: 700; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

/* accessible focus everywhere, without outlining mouse clicks */
:focus-visible {
  outline: 3px solid var(--accent-glow);
  outline-offset: 1px;
  border-radius: 6px;
}

::selection { background: var(--accent-soft); }

/* ------------------------------------------------ layout shell */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex-shrink: 0;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(27, 108, 245, 0.30) 0%, rgba(27, 108, 245, 0) 55%),
    linear-gradient(180deg, #14203c 0%, #0d1426 100%);
  color: #d7def0;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px; font-weight: 800; font-size: 16px; color: #fff;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0; padding: 5px;
  border-radius: 9px; background: #fff;
  box-shadow: 0 4px 14px rgba(13, 20, 38, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.brand-mark img { width: 100%; height: 100%; display: block; }
.brand-text em { font-style: normal; color: #7fb2ff; font-weight: 700; }
.sidebar-brand span { color: #7fb2ff; } /* legacy: brand without a mark */

.nav-section {
  margin: 14px 0 4px; padding: 0 18px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px;
  color: #61729c; font-weight: 700;
}
.nav-link {
  display: block; margin: 1px 8px; padding: 7px 12px;
  color: #b4c2df; font-size: 13px; font-weight: 500;
  border-radius: 8px; border-left: 3px solid transparent;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.07); color: #fff; text-decoration: none; }
.nav-link.active {
  background: linear-gradient(90deg, rgba(27, 108, 245, 0.4), rgba(27, 108, 245, 0.12));
  color: #fff; font-weight: 650; border-left-color: #23d8ce;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px) saturate(1.5);
  -webkit-backdrop-filter: blur(12px) saturate(1.5);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
  transition: box-shadow 0.2s ease;
}
.topbar.is-scrolled { box-shadow: var(--shadow-2); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-user .roles { font-size: 11.5px; color: var(--muted); }
.avatar {
  width: 34px; height: 34px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--brand-grad); color: #fff;
  font-size: 13px; font-weight: 700; letter-spacing: 0.02em;
  box-shadow: 0 3px 10px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.content { padding: 24px 28px 56px; max-width: 1280px; width: 100%; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header-actions { display: flex; gap: 8px; align-items: center; }

/* ------------------------------------------------ cards & panels */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px;
  overflow-x: auto; min-width: 0;
  box-shadow: var(--shadow-1), var(--sheen);
}
.card h2 { display: flex; justify-content: space-between; align-items: baseline; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }

/* ------------------------------------------------ KPI tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  position: relative;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: block; color: inherit;
  box-shadow: var(--shadow-1), var(--sheen);
  overflow: hidden;
}
.kpi::before {
  /* gradient hairline across the top — depth without decoration overload */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--brand-grad); opacity: 0;
  transition: opacity 0.2s ease;
}
.kpi-link { transition: transform 0.18s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.18s ease, border-color 0.18s ease; }
.kpi-link:hover {
  border-color: rgba(79, 70, 229, 0.4); text-decoration: none;
  transform: translateY(-2px);
  box-shadow: var(--shadow-2), var(--sheen);
}
.kpi-link:hover::before { opacity: 1; }
.kpi-label { font-size: 11.5px; color: var(--ink-2); font-weight: 600; letter-spacing: 0.01em; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.kpi-good { color: var(--status-good-text); }
.kpi-warn { color: #8a5a00; }
.kpi-critical { color: var(--status-critical); }

/* ------------------------------------------------ alerts */
.alert-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid; border-left-width: 4px;
  background: var(--surface); font-size: 13px;
  box-shadow: var(--shadow-1);
}
.alert-high { border-color: var(--status-critical); background: linear-gradient(90deg, rgba(208, 59, 59, 0.05), var(--surface) 30%); }
.alert-medium { border-color: var(--status-warn); background: linear-gradient(90deg, rgba(250, 178, 25, 0.07), var(--surface) 30%); }
.alert .alert-icon { font-weight: 700; }
.alert-high .alert-icon { color: var(--status-critical); }
.alert-medium .alert-icon { color: #8a5a00; }
.alert a { margin-left: auto; white-space: nowrap; font-weight: 600; }

/* ------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
  background: var(--surface);
}
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--muted); font-weight: 700; padding: 9px 10px;
  border-bottom: 1px solid var(--baseline); white-space: nowrap;
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
table.data tr:hover td { background: var(--accent-soft); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.row-link { cursor: pointer; }

/* ------------------------------------------------ badges */
.badge {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-good { background: #e5f7e5; color: #045904; border-color: #b8e4b8; }
.badge-warn { background: #fdf3da; color: #6d4a00; border-color: #f1dca4; }
.badge-serious { background: #fdeae2; color: #87360f; border-color: #f6cdbb; }
.badge-critical { background: #fbe4e4; color: #8f1f1f; border-color: #f2bfbf; }
.badge-neutral { background: #eef0f7; color: var(--ink-2); border-color: var(--grid); }

/* ------------------------------------------------ forms & buttons */
.btn {
  font: inherit; font-size: 13px; font-weight: 650;
  padding: 7px 15px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--baseline); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-1);
  transition: transform 0.15s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.15s ease,
              border-color 0.15s ease, background-color 0.15s ease;
}
.btn:hover { border-color: var(--ink-2); transform: translateY(-1px); box-shadow: var(--shadow-2); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary {
  background: var(--brand-grad); background-size: 130% 130%;
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:hover { box-shadow: 0 8px 22px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25); border-color: transparent; }
.btn-danger {
  background: linear-gradient(180deg, #dc4646, #c73434);
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 12px rgba(208, 59, 59, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.btn-danger:hover { box-shadow: 0 7px 18px rgba(208, 59, 59, 0.35); border-color: transparent; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn-ghost:hover { border-color: var(--grid); background: var(--surface); }

input, select, textarea {
  font: inherit; font-size: 13px; color: var(--ink);
  padding: 7px 11px; border: 1px solid var(--baseline); border-radius: 8px;
  background: var(--surface);
  box-shadow: inset 0 1px 2px rgba(15, 18, 34, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), inset 0 1px 2px rgba(15, 18, 34, 0.04);
}
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 650; }
label.field > input, label.field > select, label.field > textarea { font-weight: 400; }

.filter-bar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar label.field { min-width: 130px; }

.pagination { display: flex; align-items: center; gap: 12px; justify-content: flex-end; padding: 10px 0; }

/* ------------------------------------------------ modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 15, 38, 0.5);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px;
  z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 480px; max-width: 100%;
  max-height: 84vh; overflow-y: auto;
  box-shadow: var(--shadow-3), var(--sheen);
}
.modal-wide { width: 680px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px 10px; border-bottom: 1px solid var(--grid);
}
.modal-body { padding: 14px 20px 20px; display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.consequences { margin: 0; border: 1px solid var(--status-warn); border-radius: var(--radius-sm); overflow: hidden; background: linear-gradient(180deg, rgba(250, 178, 25, 0.05), transparent 40%); }
.consequence-row { display: flex; padding: 8px 12px; gap: 12px; border-bottom: 1px solid var(--grid); }
.consequence-row:last-child { border-bottom: none; }
.consequence-row dt { width: 140px; flex-shrink: 0; color: var(--ink-2); font-weight: 650; font-size: 12px; }
.consequence-row dd { margin: 0; font-size: 13px; }

.desc-list { margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 20px; }
.desc-row dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); font-weight: 700; }
.desc-row dd { margin: 1px 0 0; font-size: 13.5px; }

/* ------------------------------------------------ states */
.skeleton-block { display: flex; flex-direction: column; gap: 10px; padding: 12px 0; }
.skeleton-row {
  height: 14px; border-radius: 5px;
  background: linear-gradient(90deg, var(--grid) 25%, #f2f4fa 50%, var(--grid) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.state-card {
  border: 1px dashed var(--baseline); border-radius: var(--radius);
  padding: 26px; text-align: center; color: var(--ink-2);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  background: var(--surface);
}
.state-error { border-color: var(--status-critical); border-style: solid; }
.state-card p { margin: 0; }

/* ------------------------------------------------ global search */
.search-box { position: relative; width: 400px; max-width: 40vw; }
.search-box input { width: 100%; border-radius: 999px; padding-left: 14px; }
.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-3); max-height: 65vh; overflow-y: auto; z-index: 50;
}
.search-group { padding: 6px 0; border-bottom: 1px solid var(--grid); }
.search-group:last-child { border-bottom: none; }
.search-group-title { padding: 4px 14px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); font-weight: 700; }
.search-item { display: flex; gap: 8px; align-items: baseline; padding: 6px 14px; color: inherit; }
.search-item:hover { background: var(--accent-soft); text-decoration: none; }
.search-item .muted { font-size: 12px; }

/* ------------------------------------------------ timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.timeline li:last-child { border-bottom: none; }
.timeline .t-at { width: 150px; flex-shrink: 0; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.timeline .t-kind { width: 84px; flex-shrink: 0; }

/* ------------------------------------------------ tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--baseline); margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 8px 14px; font-size: 13px; font-weight: 650; color: var(--ink-2);
  border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }

/* ------------------------------------------------ login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden; padding: 24px;
  background:
    radial-gradient(90% 80% at 15% 0%, rgba(29, 77, 255, 0.5) 0%, rgba(29, 77, 255, 0) 55%),
    radial-gradient(70% 70% at 95% 100%, rgba(35, 216, 206, 0.3) 0%, rgba(35, 216, 206, 0) 55%),
    linear-gradient(160deg, #0d1426 0%, #16264d 100%);
}
.login-wrap::before, .login-wrap::after {
  /* slow aurora drift behind the card — pure CSS, killed under reduced motion */
  content: ""; position: absolute; border-radius: 50%; filter: blur(70px); z-index: 0;
  pointer-events: none;
}
.login-wrap::before {
  width: 460px; height: 460px; top: -140px; left: -110px;
  background: rgba(30, 116, 255, 0.4);
  animation: drift 18s ease-in-out infinite alternate;
}
.login-wrap::after {
  width: 380px; height: 380px; bottom: -120px; right: -90px;
  background: rgba(35, 216, 206, 0.28);
  animation: drift 22s ease-in-out infinite alternate-reverse;
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(60px, 40px, 0) scale(1.15); }
}

.login-card {
  position: relative; z-index: 1;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 18px; padding: 36px; width: 400px; max-width: 100%;
  display: flex; flex-direction: column; gap: 15px;
  box-shadow: var(--shadow-3), var(--sheen);
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
.login-card h1 { font-size: 26px; }
.login-card h1 span {
  background: var(--brand-grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--accent-strong);
}
.login-brand-mark {
  width: 48px; height: 48px; border-radius: 13px; padding: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--grid);
  box-shadow: 0 8px 24px var(--accent-glow);
}
.login-brand-mark img { width: 100%; height: 100%; display: block; }
.login-error { color: var(--status-critical); font-size: 13px; }

/* ------------------------------------------------ chart */
.chart-wrap { overflow-x: auto; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.chart-legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ------------------------------------------------ scroll-driven reveals
   site.js adds .reveal only when JS runs, IntersectionObserver exists AND the
   user allows motion — so content is never hidden without JS or for
   reduced-motion users. */
@media (prefers-reduced-motion: no-preference) {
  .reveal {
    opacity: 0; transform: translateY(14px);
    transition: opacity 0.5s ease, transform 0.55s cubic-bezier(0.2, 0.7, 0.2, 1);
    will-change: opacity, transform;
  }
  .reveal.reveal-in { opacity: 1; transform: none; }
}

/* motion is an enhancement: switch every animation off on request */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 900px) {
  .sidebar { width: 64px; }
  .sidebar .nav-label, .sidebar .nav-section, .sidebar-brand span, .sidebar .brand-text { display: none; }
  .content { padding: 16px 12px 40px; }
}

/* ------------------------------------------------ MVC additions */
.flash {
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px;
  border: 1px solid; border-left-width: 4px; font-size: 13px;
  background: var(--surface); box-shadow: var(--shadow-1);
}
.flash-ok { border-color: var(--status-good); color: var(--status-good-text); background: linear-gradient(90deg, rgba(12, 163, 12, 0.06), var(--surface) 30%); }
.flash-error { border-color: var(--status-critical); color: var(--status-critical); background: linear-gradient(90deg, rgba(208, 59, 59, 0.06), var(--surface) 30%); }

.json-block {
  white-space: pre-wrap; word-break: break-word; font-size: 12px;
  background: var(--page); border: 1px solid var(--grid); border-radius: 8px;
  padding: 8px 10px; margin: 4px 0 0;
}
.device-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs a.tab { text-decoration: none; display: inline-block; }
.topbar form { margin: 0; }
