/* FR-33 operations dashboard — mobile-first, dark, no framework.
   Polish pass: gradient depth, glow status dots, skeleton shimmer,
   fade-in tile updates, SVG sparkline. Honors prefers-reduced-motion. */

:root {
  --bg: #0b0e14;
  --card: rgba(22, 27, 36, 0.88);
  --card-border: #232b38;
  --card-border-top: rgba(241, 196, 106, 0.16);
  --text: #dde3ee;
  --muted: #7b8494;
  --accent: #e3b25c;
  --accent-2: #b87f2e;
  --ok: #43d18b;
  --warn: #e0b341;
  --err: #ef7a67;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* Soft ambient glow behind the content — the single biggest "not flat"
   signal, costs nothing. */
.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60vw 40vh at 75% -10%, rgba(227, 178, 92, 0.07), transparent 60%),
    radial-gradient(50vw 35vh at 10% 110%, rgba(76, 124, 175, 0.06), transparent 60%);
  pointer-events: none;
}

/* ── Header ─────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  background: rgba(11, 14, 20, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
}

.brand { display: flex; align-items: baseline; gap: 0.55rem; }
.brand .mark { height: 22px; width: auto; align-self: center; filter: drop-shadow(0 0 6px rgba(227, 178, 92, 0.35)); }
.brand h1 { margin: 0; font-size: 1.12rem; letter-spacing: 0.02em; }
.brand-sub {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--accent);
  opacity: 0.8;
}

.header-right { display: flex; align-items: center; gap: 0.5rem; }

button {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 9px;
  padding: 0.4rem 0.8rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
button:hover { border-color: var(--accent-2); }
button:active { transform: scale(0.96); }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #1a1408;
  font-weight: 600;
}

/* ── Layout ─────────────────────────────────────────────────────── */

main, #auth {
  padding: 0.9rem;
  max-width: 1100px;
  margin: 0 auto;
}

main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}
@media (min-width: 720px) {
  main { grid-template-columns: 1fr 1fr; }
  #tile-cron { grid-column: span 2; }
}

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 30%), var(--card);
  border: 1px solid var(--card-border);
  border-top-color: var(--card-border-top);
  border-radius: 14px;
  padding: 0.95rem 1.05rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
@media (hover: hover) {
  .card:hover {
    transform: translateY(-2px);
    border-color: rgba(227, 178, 92, 0.28);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.36);
  }
}

.card h2 {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.card h2::after {
  content: "";
  display: block;
  width: 28px;
  height: 2px;
  margin-top: 0.35rem;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0.7;
}

/* Tile content fades in on every refresh swap. */
.tile-body { animation: tile-in 0.35s ease both; }
@keyframes tile-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error {
  color: var(--err);
  background: rgba(239, 122, 103, 0.08);
  border: 1px solid rgba(239, 122, 103, 0.35);
  border-radius: 9px;
  padding: 0.5rem 0.8rem;
}
#load-error { grid-column: 1 / -1; }

/* ── Skeleton shimmer (initial load) ───────────────────────────── */

.skeleton {
  height: 0.95rem;
  border-radius: 6px;
  margin: 0.55rem 0;
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.045) 25%,
    rgba(255, 255, 255, 0.10) 45%,
    rgba(255, 255, 255, 0.045) 65%);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton.w60 { width: 60%; }
.skeleton.w80 { width: 80%; }
.skeleton.tall { height: 3.2rem; }
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -20% 0; }
}

/* ── Auth ───────────────────────────────────────────────────────── */

.auth-card { max-width: 420px; margin: 10vh auto 0; }
.auth-card form { display: flex; gap: 0.5rem; margin: 0.6rem 0; }
.auth-card input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 9px;
  padding: 0.5rem 0.7rem;
  font-size: 1rem;
  min-width: 0;
  transition: border-color 0.15s ease;
}
.auth-card input:focus { outline: none; border-color: var(--accent-2); }

/* ── Key/value rows (status tile) ──────────────────────────────── */

.kv .row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.24rem 0;
  border-bottom: 1px solid rgba(35, 43, 56, 0.6);
}
.kv .row:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); font-size: 0.88rem; text-align: right; word-break: break-all; }

/* ── Status dots (with glow) + chips ───────────────────────────── */

.dot {
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  margin-right: 0.45em;
  background: var(--muted);
}
.dot.ok { background: var(--ok); box-shadow: 0 0 7px rgba(67, 209, 139, 0.65); }
.dot.warn { background: var(--warn); box-shadow: 0 0 7px rgba(224, 179, 65, 0.6); }
.dot.err { background: var(--err); box-shadow: 0 0 7px rgba(239, 122, 103, 0.65); }

.chip {
  display: inline-block;
  font-size: 0.78rem;
  font-family: var(--mono);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  margin: 0.12rem 0.2rem 0.12rem 0;
  color: var(--muted);
}
.chip.on {
  border-color: rgba(67, 209, 139, 0.55);
  color: var(--ok);
  background: rgba(67, 209, 139, 0.07);
}

/* ── Cost tile ──────────────────────────────────────────────────── */

.cost-big { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.cost-big .num {
  font-size: 1.65rem;
  font-weight: 650;
  font-family: var(--mono);
  background: linear-gradient(120deg, #f3e9d4 30%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.cost-big .lbl { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }

/* SVG area sparkline */
.spark { width: 100%; height: 64px; display: block; margin: 0.45rem 0 0.1rem; }
.spark .area { fill: url(#spark-fill); }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark .pt { fill: var(--accent); }
.spark .pt.today { filter: drop-shadow(0 0 4px rgba(227, 178, 92, 0.9)); }
.trend-labels { display: flex; }
.trend-labels span {
  flex: 1;
  text-align: center;
  font-size: 0.65rem;
  color: var(--muted);
  font-family: var(--mono);
}

/* ── Tables (cron, sessions, models) ───────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { text-align: left; padding: 0.32rem 0.4rem; border-bottom: 1px solid rgba(35, 43, 56, 0.6); }
th { color: var(--muted); font-weight: 500; font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.06em; }
td.mono, .mono { font-family: var(--mono); font-size: 0.82rem; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-family: var(--mono); }
tbody tr { transition: background 0.12s ease; }
@media (hover: hover) {
  tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
}

/* Horizontal scroll for tables on narrow screens */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Accessibility: respect reduced motion ─────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .tile-body { animation: none; }
  .skeleton { animation: none; }
  .card, button, tbody tr { transition: none; }
}

/* ── Settings view (FR-97 Stufe 2) ─────────────────────────────── */

main.settings {
  display: block;
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem;
}

main.settings .card { margin-bottom: 1rem; }

.settings-toolbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  padding: 0.7rem 1rem;
}

.settings-toolbar .readonly-note { margin-left: auto; font-size: 0.8rem; }

.seg { display: flex; border: 1px solid var(--card-border); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: transparent; padding: 0.35rem 0.9rem; }
.seg button.active {
  background: linear-gradient(180deg, rgba(227, 178, 92, 0.22), rgba(227, 178, 92, 0.10));
  color: var(--accent);
}

#settings-btn.active { border-color: var(--accent-2); color: var(--accent); }

.search {
  background: rgba(11, 14, 20, 0.6);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.4rem 0.7rem;
  min-width: 200px;
  flex: 1;
}
.search:focus { outline: none; border-color: var(--accent-2); }

.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 0.15rem 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(35, 43, 56, 0.6);
}
.setting-row:last-child { border-bottom: none; }

.setting-row .skey { display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; }
.setting-row .skey .mono { font-family: var(--mono); font-size: 0.86rem; word-break: break-all; }
.setting-row .stype {
  color: var(--muted);
  font-size: 0.72rem;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 0 0.35rem;
  white-space: nowrap;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.setting-row .v {
  font-family: var(--mono);
  font-size: 0.86rem;
  text-align: right;
  word-break: break-all;
  align-self: baseline;
}
.setting-row .sdoc { grid-column: 1 / -1; font-size: 0.8rem; }

.center { text-align: center; }

/* Approve page (approve.html) — externalized from style attributes so
   the strict FR-135 CSP (style-src 'self') keeps working layout. */
.approve-main { max-width: 26rem; margin: 8vh auto; padding: 0 1rem; }
.approve-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
#approve-status { margin-top: 0.8rem; }
.approve-hint { margin-top: 1rem; }

@media (max-width: 560px) {
  .setting-row { grid-template-columns: 1fr; }
  .setting-row .v { text-align: left; }
  .settings-toolbar .readonly-note { display: none; }
}

/* ── Staged config writes (FR-97 Stufe 3) ──────────────────────── */

/* The edit pencil is the row's primary action — golden pill instead of
   a muted glyph so it reads as tappable at a glance. */
.setting-row .row-edit {
  border: 1px solid rgba(227, 178, 92, 0.35);
  border-radius: 999px;
  background: rgba(227, 178, 92, 0.08);
  color: var(--accent);
  padding: 0.1rem 0.45rem;
  font-size: 0.95rem;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.setting-row .row-edit:hover,
.setting-row .row-edit:focus-visible {
  background: rgba(227, 178, 92, 0.18);
  box-shadow: 0 0 10px rgba(227, 178, 92, 0.35);
  transform: scale(1.06);
}
.setting-row .row-edit:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
@media (prefers-reduced-motion: reduce) {
  .setting-row .row-edit { transition: none; }
  .setting-row .row-edit:hover,
  .setting-row .row-edit:focus-visible { transform: none; }
}
.setting-row.staged .skey .mono { color: var(--accent); }
.setting-row .edit-control {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent-2);
  border-radius: 7px;
  padding: 0.3rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.86rem;
  width: 100%;
}
.setting-row .edit-control:focus { outline: none; border-color: var(--accent); }

.staged-bar {
  position: sticky;
  bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 1rem;
  padding: 0.6rem 1rem;
  background: rgba(11, 14, 20, 0.92);
  border: 1px solid var(--accent-2);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.staged-bar #staged-count { flex: 1; }

.plan-diff .setting-row { grid-template-columns: 1fr; }
.plan-diff .delta { font-family: var(--mono); font-size: 0.86rem; word-break: break-all; }
.plan-diff .delta .old { color: var(--err); text-decoration: line-through; opacity: 0.8; }
.plan-diff .delta .new { color: var(--ok); }
.chip.crit {
  border-color: rgba(239, 122, 103, 0.55);
  color: var(--err);
  background: rgba(239, 122, 103, 0.07);
}
.chip.secret {
  border-color: rgba(227, 178, 92, 0.55);
  color: var(--accent);
  background: rgba(227, 178, 92, 0.07);
}
.confirm-critical { display: flex; align-items: center; gap: 0.5rem; margin: 0.7rem 0; }
.confirm-critical input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }

/* ── Budget bars (FR-93) ───────────────────────────────────────── */

.budget { margin: 0.5rem 0 0.3rem; }
.budget-row {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.18rem 0;
}
.budget-row .k { color: var(--muted); font-size: 0.8rem; }
.budget-row .v { font-family: var(--mono); font-size: 0.8rem; }
.budget-bar {
  height: 7px;
  border-radius: 4px;
  background: rgba(35, 43, 56, 0.8);
  overflow: hidden;
}
.budget-bar .fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.budget-bar .fill.ok { background: linear-gradient(90deg, rgba(67, 209, 139, 0.55), var(--ok)); }
.budget-bar .fill.warn { background: linear-gradient(90deg, rgba(224, 179, 65, 0.55), var(--warn)); }
.budget-bar .fill.err { background: linear-gradient(90deg, rgba(239, 122, 103, 0.55), var(--err)); }
.budget-mode { font-size: 0.74rem; margin-top: 0.15rem; }

/* ── Brain Explorer (FR-19) ────────────────────────────────────── */

/* Header anchors styled like the header buttons. */
a.icon-link {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 9px;
  padding: 0.4rem 0.8rem;
  font-size: 0.95rem;
  text-decoration: none;
  line-height: 1;
  transition: border-color 0.15s ease;
}
a.icon-link:hover { border-color: var(--accent-2); }

main.explorer {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
  max-width: 1400px;
}
main.explorer .toolbar-card,
main.explorer #load-error { grid-column: 1 / -1; }
@media (min-width: 960px) {
  main.explorer.has-detail { grid-template-columns: minmax(0, 1fr) 340px; }
  main.explorer.has-detail .detail {
    position: sticky;
    top: 4rem;
    align-self: start;
    max-height: calc(100vh - 5rem);
    overflow-y: auto;
  }
}

.toolbar-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.7rem 1rem;
}
.toolbar-card label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.toolbar-card select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 0.32rem 0.5rem;
  font-size: 0.88rem;
  font-family: var(--mono);
}
.toolbar-card select:focus { outline: none; border-color: var(--accent-2); }
#stats-line { margin-left: auto; }
#stats-line .trunc { color: var(--warn); }

#graph {
  width: 100%;
  height: 68vh;
  min-height: 380px;
  display: block;
  border-radius: 10px;
  background: radial-gradient(60% 60% at 50% 40%, rgba(76, 124, 175, 0.05), transparent 70%);
  touch-action: none;
}
#graph circle.node:hover { stroke: var(--accent-2); stroke-width: 2px; }
#graph circle.selected { stroke: var(--accent); stroke-width: 2.5px; }
.node-label {
  font: 10px var(--mono);
  fill: var(--muted);
  pointer-events: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.9rem;
  margin-top: 0.55rem;
}
.legend .li {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--muted);
  cursor: pointer;
}
.legend .li:hover, .legend .li.active { color: var(--text); }
.legend .sw { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .hint { margin-left: auto; font-size: 0.72rem; color: var(--muted); }

/* FR-19 export controls + Live toggle */
.export-group { display: inline-flex; gap: 0.35rem; }
.export-group button {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
  font-family: var(--mono);
}
#live-btn.active {
  border-color: var(--ok);
  color: var(--ok);
  box-shadow: 0 0 8px rgba(67, 209, 139, 0.35);
}

/* FR-19 new-node flash on a live update */
@keyframes node-pulse {
  0% { stroke: var(--ok); stroke-width: 4px; }
  100% { stroke: #0b0e14; stroke-width: 1.2px; }
}
#graph circle.pulse { animation: node-pulse 1.6s ease-out; }
@media (prefers-reduced-motion: reduce) {
  #graph circle.pulse { animation: none; }
}

/* FR-19 timeline card */
.timeline-card { padding: 0.55rem 0.9rem 0.35rem; }
.timeline-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.15rem;
}
.timeline-title {
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
#timeline-info { font-size: 0.78rem; font-family: var(--mono); }
#timeline-clear {
  margin-left: auto;
  padding: 0.12rem 0.5rem;
  font-size: 0.72rem;
}
#timeline {
  width: 100%;
  height: 96px;
  display: block;
  touch-action: none;
}
#timeline .tl-bar { fill: var(--accent); fill-opacity: 0.55; }
#timeline .tl-axis path,
#timeline .tl-axis line { stroke: var(--card-border); }
#timeline .tl-axis text { fill: var(--muted); font-size: 0.66rem; font-family: var(--mono); }
#timeline .tl-brush .selection {
  fill: rgba(227, 178, 92, 0.14);
  stroke: var(--accent-2);
  stroke-opacity: 0.7;
}

.detail { position: relative; }
.detail-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.85rem;
}
.detail-preview { white-space: pre-wrap; word-break: break-word; }
.detail-full {
  font-family: var(--mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 9px;
  padding: 0.6rem 0.75rem;
  max-height: 42vh;
  overflow-y: auto;
}

/* Inline CLI snippets on the auth cards (paircode hint). */
.auth-card code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
  white-space: nowrap;
}
