/*
 * GoldClaw dashboard theme — single source of truth.
 *
 * Include with: <link rel="stylesheet" href="/theme.css">
 *
 * Pages may add their own <style> for page-specific layout, but should
 * use these tokens (var(--bg) etc.) so the whole site stays cohesive.
 */

:root {
  /* Surface */
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f2530;
  --surface-3: #050505;
  --border: #2a313b;
  --border-strong: #3a424d;

  /* Text */
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-muted: #6e7681;

  /* Accents */
  --accent: #58a6ff;          /* links, interactive */
  --accent-soft: rgba(88, 166, 255, 0.14);
  --brand: #f0b429;           /* GoldClaw highlight, active nav */
  --brand-soft: rgba(240, 180, 41, 0.10);

  /* Status */
  --ok: #3fb950;
  --ok-soft: rgba(63, 185, 80, 0.15);
  --warn: #d29922;
  --warn-soft: rgba(210, 153, 34, 0.15);
  --down: #f85149;
  --down-soft: rgba(248, 81, 73, 0.15);
  --info: #58a6ff;
  --info-soft: rgba(88, 166, 255, 0.15);

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, "JetBrains Mono", monospace;
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 24px;

  /* Spacing */
  --gap-xs: 4px;
  --gap-sm: 8px;
  --gap-md: 12px;
  --gap-lg: 16px;
  --gap-xl: 24px;
  --gap-2xl: 32px;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  /* Layout */
  --content-narrow: 760px;
  --content-default: 1100px;
  --content-wide: 1280px;

  /* Touch */
  --touch-min: 40px;
}

/* ──────────────────────────────────────────────────────────────────── */
/* Reset                                                                */
/* ──────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg, canvas { max-width: 100%; }
canvas { display: block; }

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

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}
code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  overflow-x: auto;
  margin: var(--gap-sm) 0;
}

/* ──────────────────────────────────────────────────────────────────── */
/* Headings                                                             */
/* ──────────────────────────────────────────────────────────────────── */

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-md); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); font-weight: 600; }
h3 { font-size: var(--fs-md); }

/* ──────────────────────────────────────────────────────────────────── */
/* Page shell                                                           */
/* ──────────────────────────────────────────────────────────────────── */

.page {
  max-width: var(--content-default);
  margin: 0 auto;
  padding: var(--gap-lg) var(--gap-lg) var(--gap-2xl);
}
.page.narrow { max-width: var(--content-narrow); }
.page.wide { max-width: var(--content-wide); }

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--gap-md);
  margin-bottom: var(--gap-lg);
}
.page-header h1 { font-size: var(--fs-xl); }
.page-header .sub {
  color: var(--text-dim);
  font-size: var(--fs-sm);
}
.page-header .sub a { color: var(--accent); }

/* ──────────────────────────────────────────────────────────────────── */
/* Card                                                                 */
/* ──────────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--gap-lg);
  margin-bottom: var(--gap-lg);
}
.card > h2 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 var(--gap-md);
}
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-md);
  margin-bottom: var(--gap-md);
}

/* ──────────────────────────────────────────────────────────────────── */
/* Tile / Stat                                                          */
/* ──────────────────────────────────────────────────────────────────── */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--gap-md);
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.tile .label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.tile .value {
  font-size: var(--fs-2xl);
  font-weight: 600;
  margin-top: var(--gap-xs);
  font-variant-numeric: tabular-nums;
}
.tile .value.pos { color: var(--ok); }
.tile .value.neg { color: var(--down); }
.tile .value.muted { color: var(--text-dim); font-size: var(--fs-lg); }

/* ──────────────────────────────────────────────────────────────────── */
/* Pill                                                                 */
/* ──────────────────────────────────────────────────────────────────── */

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.pill.pill-ok, .pill.win { background: var(--ok-soft); color: var(--ok); }
.pill.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill.pill-down, .pill.loss { background: var(--down-soft); color: var(--down); }
.pill.pill-info, .pill.open { background: var(--info-soft); color: var(--info); }
.pill.pill-muted, .pill.tie { background: rgba(139, 148, 158, 0.15); color: var(--text-dim); }
.pill.pill-brand { background: var(--brand-soft); color: var(--brand); }

/* ──────────────────────────────────────────────────────────────────── */
/* Table                                                                */
/* ──────────────────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-md);
  min-width: 480px;
}
table.t th, table.t td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.t th {
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  position: sticky;
  top: 0;
}
table.t tr:last-child td { border-bottom: 0; }
table.t td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t td.pos { color: var(--ok); }
table.t td.neg { color: var(--down); }
table.t td.muted { color: var(--text-dim); }

/* ──────────────────────────────────────────────────────────────────── */
/* Button                                                               */
/* ──────────────────────────────────────────────────────────────────── */

button, .btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--fs-md);
  font-weight: 500;
  font-family: inherit;
  line-height: 1.2;
  min-height: var(--touch-min);
  transition: background 80ms ease, border-color 80ms ease, color 80ms ease;
}
button:hover:not(:disabled), .btn:hover:not(:disabled) {
  background: #2a3140;
  border-color: var(--border-strong);
}
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.danger, .btn.danger {
  color: var(--down);
  border-color: rgba(248, 81, 73, 0.35);
}
button.danger:hover:not(:disabled), .btn.danger:hover:not(:disabled) {
  background: var(--down-soft);
}
button.primary, .btn.primary {
  background: var(--accent);
  color: #0a0d12;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover:not(:disabled), .btn.primary:hover:not(:disabled) {
  background: #79b8ff;
  border-color: #79b8ff;
}

/* Tight button row (e.g. key grid) */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-sm);
}
.btn-row button { min-width: 0; }

/* Auto-fit grid for action buttons */
.btn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--gap-sm);
}

/* ──────────────────────────────────────────────────────────────────── */
/* Form input                                                           */
/* ──────────────────────────────────────────────────────────────────── */

input[type="text"], input[type="search"], input[type="number"], textarea, select {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: var(--fs-md);
  min-height: var(--touch-min);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row {
  display: flex;
  gap: var(--gap-sm);
  align-items: stretch;
}
.form-row input { flex: 1; min-width: 0; }

/* ──────────────────────────────────────────────────────────────────── */
/* Definition list                                                      */
/* ──────────────────────────────────────────────────────────────────── */

dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.25rem;
  margin: 0;
  font-size: var(--fs-md);
}
dl.kv dt { color: var(--text-dim); }
dl.kv dd { margin: 0; font-family: var(--font-mono); font-size: var(--fs-sm); word-break: break-all; }

/* ──────────────────────────────────────────────────────────────────── */
/* Status dot                                                           */
/* ──────────────────────────────────────────────────────────────────── */

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  margin-right: 6px;
  vertical-align: middle;
}
.dot.live { background: var(--ok); animation: dot-pulse 2s ease-in-out infinite; }
.dot.warn { background: var(--warn); }
.dot.down { background: var(--down); }
@keyframes dot-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ──────────────────────────────────────────────────────────────────── */
/* Banner / callouts                                                    */
/* ──────────────────────────────────────────────────────────────────── */

.banner {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  margin-bottom: var(--gap-lg);
}
.banner.warn { background: var(--warn-soft); border: 1px solid rgba(210, 153, 34, 0.3); color: var(--warn); }
.banner.error, .banner.down { background: var(--down-soft); border: 1px solid rgba(248, 81, 73, 0.3); color: var(--down); }
.banner.info { background: var(--info-soft); border: 1px solid rgba(88, 166, 255, 0.3); color: var(--info); }
.banner code { background: rgba(255, 255, 255, 0.05); color: inherit; }

/* ──────────────────────────────────────────────────────────────────── */
/* Loading                                                              */
/* ──────────────────────────────────────────────────────────────────── */

.loading { padding: var(--gap-lg); color: var(--text-dim); font-size: var(--fs-sm); }

/* ──────────────────────────────────────────────────────────────────── */
/* Scrollbars (subtle, dark)                                            */
/* ──────────────────────────────────────────────────────────────────── */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ──────────────────────────────────────────────────────────────────── */
/* Mobile (≤640px)                                                      */
/* ──────────────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  body { font-size: 13.5px; }
  h1 { font-size: 18px; }
  h2 { font-size: 12.5px; }

  .page { padding: var(--gap-md) var(--gap-sm) var(--gap-xl); }

  .page-header { gap: var(--gap-sm); }
  .page-header h1 { font-size: 18px; }

  .card { padding: 12px; border-radius: var(--radius-md); }

  .tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--gap-sm); }
  .tile { padding: 10px 12px; }
  .tile .value { font-size: 18px; }

  table.t th, table.t td { padding: 8px 10px; font-size: 12.5px; }

  dl.kv { grid-template-columns: 1fr; gap: 2px 0; }
  dl.kv dt { color: var(--text-muted); font-size: 11.5px; margin-top: 6px; }
  dl.kv dd { font-size: 12.5px; }

  .btn-grid { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

  button, .btn { padding: 0.55rem 0.8rem; font-size: 14px; }

  .page-header { flex-direction: column; align-items: stretch; }
}

/* Very narrow phones */
@media (max-width: 380px) {
  .page { padding: var(--gap-sm) var(--gap-sm) var(--gap-xl); }
  .tiles { grid-template-columns: 1fr 1fr; }
}
