/* Design tokens + app shell styles. */
:root {
  color-scheme: dark;

  /* Surfaces — a slightly blue-black ramp, each step ~1 elevation level. */
  --bg: #0a0d13;
  --bg-2: #121722;
  --bg-3: #1b2230;
  --bg-4: #232c3d;

  /* Text */
  --fg: #e8edf5;
  --fg-dim: #98a3b5;
  --fg-faint: #6b7688;

  /* Brand + status */
  --accent: #5b8cff;
  --accent-2: #a374ff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --ok: #46c76a;
  --warn: #e0a336;
  --err: #ff6058;

  /* Lines */
  --border: #262f3f;
  --border-strong: #334054;

  /* Radii */
  --radius-sm: 7px;
  --radius: 11px;
  --radius-lg: 16px;

  /* Elevation — layered, low-opacity, never a single hard drop. */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.32), 0 20px 48px rgba(0, 0, 0, 0.4);

  --ring: 0 0 0 3px var(--accent-soft);
  --ease: cubic-bezier(0.2, 0.6, 0.3, 1);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  /* Ambient wash — keeps the page from reading as a flat slab. */
  background-image:
    radial-gradient(60rem 32rem at 12% -8%, rgba(91, 140, 255, 0.09), transparent 60%),
    radial-gradient(48rem 28rem at 92% 0%, rgba(163, 116, 255, 0.07), transparent 62%);
  background-attachment: fixed;
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { letter-spacing: -0.015em; line-height: 1.25; }
h1 { font-size: 1.65rem; margin: 0 0 6px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: rgba(91, 140, 255, 0.32); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- topbar ---------- */

#topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: rgba(10, 13, 19, 0.78);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

#topbar .brand {
  font-weight: 650;
  color: var(--fg);
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  padding: 5px 8px;
  margin-right: 2px;
}
#topbar .brand:hover { text-decoration: none; opacity: 0.85; }

#topbar nav { display: flex; gap: 2px; flex-wrap: wrap; }

#topbar nav a,
#topbar .topbar-right a {
  color: var(--fg-dim);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
}

#topbar a:hover {
  color: var(--fg);
  background: var(--bg-3);
  text-decoration: none;
}

#topbar a.active {
  color: var(--fg);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(91, 140, 255, 0.28);
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ---------- layout ---------- */

.container { max-width: 1120px; margin: 0 auto; padding: 28px 20px 64px; }

.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.card h2 { margin-top: 0; font-size: 1.05rem; }
.card > :last-child { margin-bottom: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.grid .card { margin: 0; }

/* Hero — the home page masthead. */
.hero {
  background:
    linear-gradient(135deg, rgba(91, 140, 255, 0.12), rgba(163, 116, 255, 0.08) 55%, transparent),
    var(--bg-2);
  border-color: var(--border-strong);
  padding: 30px 24px;
}
.hero p { max-width: 60ch; margin-bottom: 0; }
.hero .muted { font-size: 1rem; }

.hero-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* Module tile — whole card is the link. */
a.module-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  transition: transform 0.18s var(--ease), border-color 0.18s var(--ease),
    box-shadow 0.18s var(--ease), background-color 0.18s var(--ease);
}

a.module-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  background: var(--bg-3);
  box-shadow: var(--shadow);
  text-decoration: none;
}

a.module-card:active { transform: translateY(0); }

.module-card .icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--bg-4);
  border: 1px solid var(--border);
  font-size: 1.2rem;
  line-height: 1;
}

.module-card h2 { margin: 2px 0 0; font-size: 1rem; }
.module-card p { margin: 0; color: var(--fg-dim); font-size: 0.89rem; }

.module-card .go {
  margin-top: auto;
  padding-top: 10px;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 550;
}
.module-card .go span {
  display: inline-block;
  transition: transform 0.18s var(--ease);
}
a.module-card:hover .go span { transform: translateX(3px); }

/* ---------- controls ---------- */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 16px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: filter 0.15s var(--ease), transform 0.1s var(--ease),
    background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

button:hover, .btn:hover { filter: brightness(1.12); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { box-shadow: var(--ring); }

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
  transform: none;
  box-shadow: none;
}

button.ghost {
  background: transparent;
  color: var(--fg-dim);
  border-color: var(--border-strong);
  box-shadow: none;
}
button.ghost:hover { background: var(--bg-3); color: var(--fg); filter: none; }

input, select, textarea {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 9px 11px;
  font: inherit;
  width: 100%;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

input::placeholder, textarea::placeholder { color: var(--fg-faint); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

input[type="checkbox"] { width: auto; accent-color: var(--accent); }

textarea { resize: vertical; font-family: var(--font); }

label {
  display: block;
  margin: 12px 0 5px;
  color: var(--fg-dim);
  font-size: 0.86rem;
  font-weight: 550;
}

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 140px; }
.row > button { flex: 0 0 auto; min-width: auto; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 0.79rem;
  font-weight: 550;
  border: 1px solid var(--border-strong);
  color: var(--fg-dim);
  background: var(--bg-2);
  white-space: nowrap;
}
/* Status dot — reads at a glance without relying on color alone for shape. */
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}
.badge.ok { color: var(--ok); border-color: rgba(70, 199, 106, 0.4); background: rgba(70, 199, 106, 0.1); }
.badge.warn { color: var(--warn); border-color: rgba(224, 163, 54, 0.4); background: rgba(224, 163, 54, 0.1); }
.badge.plain::before { display: none; }

/* ---------- data ---------- */

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th {
  color: var(--fg-faint);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

.muted { color: var(--fg-dim); font-size: 0.92rem; }
.error { color: var(--err); }
.ok-text { color: var(--ok); }

/* ---------- chat shell ---------- */

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 4px 2px;
  margin-bottom: 14px;
}

.msg {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
  max-width: 85%;
  box-shadow: var(--shadow-sm);
  animation: msg-in 0.2s var(--ease);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: var(--radius-sm);
}
.msg.assistant {
  background: var(--bg-3);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: var(--radius-sm);
}
.msg.error { background: rgba(255, 96, 88, 0.12); border-color: rgba(255, 96, 88, 0.4); }

.chat-form { display: flex; gap: 10px; align-items: end; }
.chat-form textarea { flex: 1; }

canvas {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 100%;
}

/* ---------- scrollbars ---------- */

* { scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bg-4);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: content-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  a.module-card:hover { transform: none; }
}

/* The nav wraps to 2–3 rows on narrow screens; sticking it there would eat a
   fifth of the viewport, so it scrolls away instead. */
@media (max-width: 700px) {
  #topbar { position: static; gap: 8px; padding: 10px 14px; }
}

@media (max-width: 560px) {
  .container { padding: 20px 14px 48px; }
  .card { padding: 16px; }
  .hero { padding: 22px 18px; }
  h1 { font-size: 1.4rem; }
  .msg { max-width: 92%; }
  .row > * { min-width: 100%; }
  .row > button { min-width: 100%; }
}
