/* ═══════════════════════════════════════════════════════════════════
   ink-ls · Core
   Design tokens, resets, typography, and shared UI primitives
   (buttons, fields, badges, ghost skeletons, layout helpers).
   Loaded on every page via Shell.html.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Design tokens ────────────────────────────────────────────────── */
:root {
  /* Backgrounds — #020409 base */
  --bg: #020409;
  --bg-surface: #0a0d14;
  --bg-raised: #10141c;
  --bg-hover: #161b24;
  --bg-inset: #010307;

  /* Ink blue */
  --accent: #0051ff;
  --accent-light: #2a6fff;
  --accent-dim: rgba(0, 81, 255, 0.12);
  --accent-line: rgba(0, 81, 255, 0.25);
  --accent-glow: rgba(0, 81, 255, 0.08);

  /* Text — white titles, white body, gray captions */
  --fg: #ffffff;
  --fg-soft: #d0d7de;
  --fg-muted: #8b949e;
  --fg-subtle: #6e7681;

  /* Borders */
  --border: #1a1f2b;
  --border-muted: #12161e;

  /* Elevated surface — half-step brighter than bg-raised, for sidebars
     and active tiles where a less-flat secondary surface reads better. */
  --bg-elev: #141925;
  --bg-elev-hover: #181e2c;
  --border-strong: #252b3a;

  /* Status */
  --green: #3fb950;
  --green-dim: rgba(63, 185, 80, 0.15);
  --red: #f85149;
  --red-dim: rgba(248, 81, 73, 0.15);
  --yellow: #d29922;
  --yellow-dim: rgba(210, 153, 34, 0.15);

  --topbar-height: 46px;
  --sidebar-width: 290px;
  --page-max: 960px;
  --radius: 6px;
}

/* ── Reset ────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* No page should ever scroll sideways. */
html { overflow-x: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  color: var(--fg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  padding-top: var(--topbar-height);
  overflow: hidden;
}

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

.page-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Animations ───────────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ghostShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes btnPulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.98); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn,
.btn-primary,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  transition:
    transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    filter 0.15s ease,
    opacity 0.15s ease;
}

.btn {
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--border);
}
.btn:hover {
  background: var(--bg-hover);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.btn:active {
  transform: translateY(1px);
  box-shadow: none;
  filter: brightness(0.85);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none !important;
  box-shadow: none !important;
}

.btn-primary {
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
}
.btn-primary:hover {
  background: var(--accent-light);
  border-color: var(--accent-light);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 12px rgba(0, 81, 255, 0.35);
}
.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 0 0 rgba(0, 81, 255, 0);
  filter: brightness(0.85);
}
.btn-primary:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none !important;
  box-shadow: none !important;
}

.btn-danger {
  color: var(--red);
  background: transparent;
  border: 1px solid var(--border);
}
.btn-danger:hover {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 12px rgba(248, 81, 73, 0.3);
}
.btn-danger:active {
  transform: translateY(1px);
  box-shadow: none;
  filter: brightness(0.85);
}

.btn-sm {
  font-size: 12px;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-sm:hover { background: var(--accent-dim); text-decoration: none; }
.btn-sm:active { filter: brightness(0.8); }
.btn-sm:disabled { opacity: 0.4; }

.btn:focus-visible,
.btn-primary:focus-visible,
.btn-danger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Applied by BtnLoading() in Core.js */
.btn-loading-state {
  pointer-events: none !important;
  opacity: 0.7 !important;
  animation: btnPulse 1s infinite ease-in-out;
}

/* Legacy spinner — kept for pages that still rely on it. */
.btn-loading,
.btn-primary-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after,
.btn-primary-loading::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--fg-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.5s linear infinite;
}

/* ── Fields ───────────────────────────────────────────────────────── */
.field-group { margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: #ffffff; margin-bottom: 6px; }
.field-hint  { font-size: 12px; color: var(--fg-subtle); margin-bottom: 6px; }

.field {
  width: 100%;
  padding: 5px 12px;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-family: inherit;
  transition: border-color 0.12s;
}
.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.field::placeholder { color: var(--fg-subtle); }
.field:-webkit-autofill,
.field:-webkit-autofill:hover,
.field:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 30px var(--bg-inset) inset !important;
  -webkit-text-fill-color: var(--fg) !important;
}

.field-code {
  width: 140px;
  padding: 5px 12px;
  font-size: 18px;
  letter-spacing: 6px;
  text-align: center;
  font-family: monospace;
  font-weight: 600;
  color: var(--fg);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.12s;
}
.field-code:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.field-code::placeholder {
  color: var(--fg-subtle);
  letter-spacing: 3px;
  font-weight: 400;
}

/* ── Messages ─────────────────────────────────────────────────────── */
.msg { font-size: 12px; padding: 6px 0; display: none; }
.msg.err  { color: var(--red); }
.msg.ok   { color: var(--green); }
.msg.info { color: var(--fg-muted); }
.msg.visible { display: block; }

/* ── Badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 2em;
}
.badge.on     { color: var(--green); background: var(--green-dim); }
.badge.off    { color: var(--fg-muted); background: var(--bg-raised); }
.badge.accent { color: var(--accent); background: var(--accent-dim); }

/* ── Toggle ───────────────────────────────────────────────────────── */
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.15s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background: var(--fg-muted);
  border-radius: 50%;
  transition: all 0.15s;
}
.toggle input:checked + .toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle input:checked + .toggle-slider::before {
  transform: translateX(16px);
  background: #fff;
}

/* ── Ghost / skeleton ──────────────────────────────────────────────
   Shimmer uses bg-elev → border-strong so skeletons sit naturally on
   the darker ink-ls surface. Sizes are weighty on purpose — suggests
   real content is coming, not a tiny progress indicator. */
.ghost {
  background: linear-gradient(
    90deg,
    var(--bg-elev) 25%,
    var(--bg-hover) 50%,
    var(--bg-elev) 75%
  );
  background-size: 200% 100%;
  animation: ghostShimmer 1.6s ease-in-out infinite;
  border-radius: 5px;
}
.ghost-line     { height: 14px; margin-bottom: 10px; }
.ghost-line.sm  { height: 11px; }
.ghost-line.lg  { height: 18px; }
.ghost-block    { height: 54px; width: 100%; margin-bottom: 10px; }
.ghost-card {
  border: 1px solid var(--border-muted);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 10px;
  background: var(--bg-surface);
}
.ghost-card .ghost-line:last-child { margin-bottom: 0; }

/* Preset compositions — full-row skeletons pages can drop in instead
   of hand-rolling a 3-line stub each time. */
.ghost-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-muted);
}
.ghost-row:first-child { border-top: none; }
.ghost-circle { width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0; }
.ghost-stack  { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.ghost-spark  { width: 120px; height: 36px; flex-shrink: 0; border-radius: 5px; }
.ghost-frame {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-surface);
  overflow: hidden;
}
.ghost-pill { height: 22px; width: 70px; border-radius: 2em; display: inline-block; }

.w40 { width: 40%; }
.w60 { width: 60%; }
.w80 { width: 80%; }

/* ── Layout helpers ───────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 16px;
}
.row         { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.flex-1      { flex: 1; min-width: 0; }
.mt-1 { margin-top: 8px; }    .mt-2 { margin-top: 16px; }    .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.center { text-align: center; }

.divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
  color: var(--fg-subtle);
  font-size: 12px;
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.ink-footer {
  text-align: center;
  padding: 16px;
  color: var(--fg-subtle);
  font-size: 12px;
  border-top: 1px solid var(--border-muted);
}

/* ── Scrollbar ────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-subtle); }
