/* Jhome Site Studio — app shell.
   Tokens and rules are governed by DESIGN.md at the repo root. */

:root {
  --ground: #0a0d0f;
  --surface: #11161a;
  --surface-2: #181f24;
  --line: #232c33;
  --line-strong: #313d46;

  --text: #e6edf1;
  --text-muted: #94a5b0;
  /* 4.57:1 on --surface-2, the darkest ground it sits on. The previous
     #64757f was 3.49 there, and it is used for help text and placeholders
     that people actually have to read. */
  --text-faint: #7a8891;

  --accent: #2dd4bf;
  --accent-light: #7ff0e2;
  --accent-ink: #062a26;

  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;

  --shadow-float: 0 16px 48px -12px rgba(0, 0, 0, .7);
  --ease: cubic-bezier(.32, .72, 0, 1);

  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* The shell: header, content that grows, brand footer pinned last.
   The content pane grows with flex, so the footer always stays at the bottom. */
.shell { display: flex; flex-direction: column; min-height: 100%; }
.shell > main { flex: 1; }

h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); letter-spacing: -.02em; }
h2 { font-size: 1.35rem; letter-spacing: -.01em; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-light); }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); font-size: .9375rem; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .85rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand {
  display: inline-flex; align-items: center; gap: .55rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1.02rem;
  color: var(--text); letter-spacing: -.01em;
}
.brand .mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: .72rem; font-weight: 700;
}
.topbar nav { margin-left: auto; display: flex; align-items: center; gap: .35rem; }
.topbar nav a {
  color: var(--text-muted); font-size: .8125rem; font-weight: 600;
  padding: .45rem .7rem; border-radius: var(--r-sm);
  transition: background .14s var(--ease), color .14s var(--ease);
}
.topbar nav a:hover { color: var(--text); background: var(--surface-2); }
.topbar nav a[aria-current="page"] { color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-size: .9375rem; font-weight: 600;
  padding: .6rem 1.05rem; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text);
  cursor: pointer; text-decoration: none;
  transition: background .14s var(--ease), border-color .14s var(--ease),
              transform .14s var(--ease);
}
.btn:hover { background: #1f282e; border-color: #3d4a54; color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent-light); border-color: var(--accent-light);
  color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn-sm { padding: .38rem .7rem; font-size: .8125rem; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------- forms ---------- */
label { display: block; font-size: .8125rem; font-weight: 600; color: var(--text-muted);
  margin-bottom: .35rem; }
input[type=text], input[type=email], input[type=password], input[type=url],
input[type=number], select, textarea {
  width: 100%; font: inherit; font-size: .9375rem;
  padding: .62rem .75rem; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  transition: border-color .14s var(--ease);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
.field { margin-bottom: 1rem; }

.alert {
  padding: .7rem .9rem; border-radius: var(--r-sm); font-size: .9375rem;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: #fca5a5; margin-bottom: 1rem;
}
.alert-ok {
  background: color-mix(in srgb, var(--ok) 12%, transparent);
  border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: #86efac;
}

/* ---------- auth ---------- */
.auth-wrap { display: grid; place-items: center; padding: 3.5rem 1.25rem; }
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 2rem;
}
.auth-card h1 { font-size: 1.6rem; margin-bottom: .35rem; }
.auth-card .sub { color: var(--text-muted); font-size: .9375rem; margin-bottom: 1.5rem; }
.auth-card .btn { width: 100%; }
.auth-alt { margin-top: 1.25rem; font-size: .9375rem; color: var(--text-muted);
  text-align: center; }

/* ---------- brand footer (house rule 1) ---------- */
.brand-footer {
  padding: 1.1rem 1rem calc(1.1rem + env(safe-area-inset-bottom));
  text-align: center; font-size: .8125rem; color: var(--text-faint);
  border-top: 1px solid var(--line);
}
.brand-footer a { color: var(--text-faint); }
.brand-footer a:hover { color: var(--text-muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- dashboard ---------- */
.page { max-width: 1080px; margin-inline: auto; padding: 2.5rem 1.5rem 3rem; }
.page-head { display: flex; align-items: flex-start; gap: 1.5rem; margin-bottom: 2rem; }
.page-head > div { flex: 1; }
.page-head p { margin: 0; max-width: 60ch; }

.site-list { list-style: none; margin: 0 0 3rem; padding: 0; display: grid; gap: .75rem; }
.site-card {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 1rem;
  padding: 1.05rem 1.25rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md);
  transition: border-color .14s var(--ease);
}
.site-card:hover { border-color: var(--line-strong); }
.site-card-main { display: flex; flex-direction: column; gap: .15rem; color: var(--text); }
.site-card-name { font-family: var(--font-display); font-weight: 600; font-size: 1.08rem; }
.site-card-url { font-family: var(--font-mono); font-size: .8125rem; color: var(--text-faint); }
.site-card-meta { display: flex; gap: .4rem; flex-wrap: wrap; }
.site-card-actions { display: flex; gap: .4rem; align-items: center; }
.site-card-actions form { display: inline; }

.chip {
  display: inline-flex; align-items: center; padding: .22rem .6rem; border-radius: 999px;
  font-size: .6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-muted);
}
.chip--live, .chip--ok {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent);
}
.chip--warn {
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn);
}

.empty {
  text-align: center; padding: 3.5rem 1.5rem; margin-bottom: 3rem;
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--r-lg);
}
.empty h2 { margin-bottom: .35rem; }
.empty p { margin-bottom: 1.25rem; }

.templates { border-top: 1px solid var(--line); padding-top: 2.25rem; }
.templates h2 { margin-bottom: 1.25rem; }
.template-form { max-width: 900px; }
.template-grid {
  border: 0; padding: 0; margin: 0 0 1.5rem;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem;
}
.template-grid legend { font-size: .8125rem; font-weight: 600; color: var(--text-muted);
  margin-bottom: .5rem; padding: 0; }
.template-card { display: block; cursor: pointer; margin: 0; }
.template-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.template-card-body {
  display: flex; flex-direction: column; gap: .3rem;
  padding: 1.1rem; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.template-card:hover .template-card-body { border-color: var(--line-strong); }
.template-card input:checked + .template-card-body {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.template-card input:focus-visible + .template-card-body {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.template-card-cat { font-size: .6875rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--accent); }
.template-card-name { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.template-card-blurb { font-size: .9375rem; color: var(--text-muted); line-height: 1.5; }

/* ---------- mobile nav (house rule: starts at iPad-retina width) ---------- */
.mobile-nav { display: none; }
@media (max-width: 1024px) {
  .topbar nav a[href="/dashboard"] { display: none; }
  .site-card { grid-template-columns: 1fr; }
  .site-card-actions { justify-content: flex-start; }
  .page { padding-bottom: calc(5rem + env(safe-area-inset-bottom)); }
  .brand-footer { padding-bottom: calc(5.2rem + env(safe-area-inset-bottom)); }
  .mobile-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; display: flex;
    background: #0a0c14; border-top: 1px solid #1e2535;
    height: calc(60px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; color: #718096; font-size: .58rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .05em; text-decoration: none;
  }
  .mobile-nav a:hover { color: var(--accent-light); }
  .mobile-nav a[aria-current="page"] { color: var(--accent); }
  .mobile-nav-ico { font-size: 1.15rem; line-height: 1; }
}

/* ---------- token badge (fleet standard) ----------
   Accent derivations use color-mix off the single --accent, so a brand change moves
   the badge with everything else. Contrast measured: --accent #2dd4bf on the badge
   ground (accent at 12% over --ground) is 8.9:1, comfortably over the 7:1 bar, so the
   text colour stays var(--accent) rather than stepping up to --accent-light. */
.tok-badge {
  position: fixed; top: 4.2rem; right: 1rem; z-index: 150;
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.85rem; border-radius: 999px;
  font-size: 0.85rem; font-weight: 700; white-space: nowrap;
  text-decoration: none; cursor: pointer; transition: transform .15s ease;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent);
}
.tok-badge:hover { color: var(--accent); }
.tok-badge .tok-badge-icon { font-size: 0.95rem; }
.tok-badge[data-state="low"] {
  background: rgba(245, 158, 11, 0.14); border-color: rgba(245, 158, 11, 0.4); color: #fbbf24;
}
.tok-badge[data-state="zero"] {
  background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.4); color: #f87171;
}
.tok-badge.tok-badge-pulse { transform: scale(1.06); }

/* ---------- tokens page ---------- */
.balance-card {
  display: flex; flex-direction: column; gap: .3rem;
  padding: 1.5rem; margin-bottom: 2.5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
}
.balance-label { font-size: .6875rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-faint); }
.balance-value { font-family: var(--font-display); font-size: 2.6rem; color: var(--accent);
  line-height: 1.1; }
.balance-card p { margin: .35rem 0 0; }
.pack-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: .75rem; margin-bottom: 2.5rem; }
.pack { display: flex; flex-direction: column; gap: .4rem; padding: 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.pack-amount { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; }
.pack-price { color: var(--text-muted); font-size: .9375rem; }
.pack .btn { margin-top: .4rem; }
.pack p { margin: 0; }
.cost-table { width: 100%; border-collapse: collapse; font-size: .9375rem; }
.cost-table th, .cost-table td { text-align: left; padding: .6rem .5rem;
  border-bottom: 1px solid var(--line); }
.cost-table th { font-size: .6875rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-faint); }
