/* ============================================================================
   Mega Magic — design system (professional, restrained; no AI slop)
   ----------------------------------------------------------------------------
   Tokens, base, buttons, forms, tables, status, layout, nav, dashboard atoms.
   Light theme. One accent. Hairline borders. Tabular numerics.
   ============================================================================ */

/* ---------- Tokens ---------- */
:root {
  /* Semantic Day defaults. redesign.css owns the Day/Night theme boundary;
     these aliases keep standalone/shared primitives safe before it loads. */
  --background: #f7f7f7;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --surface-hover: #f1f5f3;
  --foreground: #1c1c1c;
  --foreground-muted: #68736e;
  --border: #dfe5e2;
  --border-strong: #c8d2cd;
  --primary: #065f46;
  --primary-hover: #064e3b;
  --primary-soft: #dff8ec;
  --focus-ring: #0f766e;
  --success: #16803c;
  --warning: #b45f06;
  --destructive: #c72c41;
  --info: #2563c9;

  --bg: var(--background);
  --bg-subtle: #fafbfa;
  --ink: var(--foreground);
  --ink-soft: #46524d;
  --ink-muted: var(--foreground-muted);
  --line: var(--border);
  --line-soft: #e9eeeb;
  --accent: var(--primary);
  --accent-hover: var(--primary-hover);
  --accent-wash: var(--primary-soft);

  /* status */
  --ok:       var(--success);
  --warn:     var(--warning);
  --bad:      var(--destructive);
  --unknown:  #7e7a72;
  --ok-wash:     #e7f2e7;
  --warn-wash:   #f6ecdc;
  --bad-wash:    #fae9e8;
  --unknown-wash:#f1efe9;

  /* sung: focus ring */
  --focus: var(--focus-ring);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius: var(--radius-sm);
  --shadow-sm: 0 1px 2px rgba(18,49,39,.06);
  --shadow-md: 0 12px 32px rgba(18,49,39,.09);

  --font-ui: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--primary-soft); }

h1, h2, h3, h4 { font-weight: 650; letter-spacing: -0.01em; }

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

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Layout scaffold ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
/* Grid/flex children default to min-width:auto, so one wide child (a data
   table) widens the whole track and pushes the layout past the screen edge.
   This is what made the app overflow horizontally on phones. */
.layout > * { min-width: 0; }

/* Left rail — thin, calm, no cards */
.rail {
  background: var(--bg-subtle);
  border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; gap: 6px;
  padding: 20px 18px;
}
.rail-brand { font-weight: 720; font-size: 16px; letter-spacing: .2px; display:flex; align-items:center; gap:9px; }
.rail-brand .dot { width: 12px; height: 12px; border-radius: var(--radius-xs); background: var(--accent); }
.rail-sub { font-size: 12px; color: var(--ink-muted); margin-top: 3px; }

.rail-section { font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-muted); padding-top: 18px; }

/* Rail head + collapse scaffolding. These wrappers are inert on desktop so the
   rail renders exactly as before; below 900px they become a top bar + menu. */
.rail-head { display: block; }
.rail-menu { display: flex; flex-direction: column; gap: 6px; flex: 1 1 auto; min-height: 0; }
.rail-toggle { display: none; }
.rail-open { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

/* Wide data tables get wrapped at runtime so they can scroll rather than clip */
.tablewrap { max-width: 100%; }

.nav-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 12px; border-radius: var(--radius-xs); background: transparent;
  color: var(--ink-soft); font-size: 14px; font-weight: 550; cursor: pointer;
  border: none;
}
.nav-item:hover { background: var(--accent-wash); color: var(--ink); }
.nav-item[aria-current="page"], .nav-item.active { background: #edeae4; color: var(--ink); font-weight: 650; }

main { padding: 28px 36px; }

.page-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.page-title { font-size: 20px; }
.page-lead { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; display: inline-flex; align-items: center; gap: 7px;
  min-height: 40px; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: transparent; color: var(--ink); cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--surface-hover); }
.btn-primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: transparent; color: var(--bad); border-color: #e6c9c6; }
.btn-danger:hover { background: var(--bad-wash); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 3px 8px; font-size: 12.5px; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-soft); }
.input {
  width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; color: var(--ink); background: var(--surface);
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-wash); }

/* ---------- Tables (dense, real data, mono numerics) ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-soft); padding: 9px 12px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tbody tr:hover { background: var(--surface-hover); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-soft); }

/* ---------- Status ---------- */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.status.ok      { background: var(--ok-wash);      color: var(--ok); }
.status.warn    { background: var(--warn-wash);    color: var(--warn); }
.status.bad     { background: var(--bad-wash);     color: var(--bad); }
.status.unknown { background: var(--unknown-wash); color: var(--unknown); }
.status.ok::before      { background: var(--ok); }
.status.warn::before    { background: var(--warn); }
.status.bad::before     { background: var(--bad); }
.status.unknown::before { background: var(--unknown); }

/* ---------- Dashboard atoms ---------- */
/* Stat cluster: small labels over one big figure, no fake cards */
.stat-cluster { display: grid; grid-auto-flow: column; gap: 34px; margin: 4px 0 0; }
.stat .stat-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.stat .stat-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 650; margin-top: 2px; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 16px; }
.panel-title { font-weight: 640; font-size: 14px; }
.panel-body { padding: 4px 16px 14px; }

/* Device marker (topology): calm, circular, status-colored */
.dev {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; border: 2px solid transparent;
}
.dev.up      { background: var(--ok); }
.dev.stale   { background: var(--warn); }
.dev.offline { background: var(--bad); }
.dev.unknown { background: var(--unknown); color: #fff; }
.dev.node { width: 16px; height: 16px; border-radius: 50%; background: var(--ink-soft); }

/* ---------- Empty state ---------- */
.empty { padding: 34px 20px; text-align: left; color: var(--ink-soft); font-size: 14px; }
.empty .empty-title { font-weight: 650; color: var(--ink); }

/* ---------- Landing (Decide surface: one idea per section) ---------- */
.landing { max-width: 1080px; margin: 0 auto; padding: 0 24px 120px; }
.land-hero { padding: 92px 24px 60px; border-bottom: 1px solid var(--line-soft); }
.land-hero h1 { font-size: 44px; line-height: 1.08; letter-spacing: -0.02em; font-weight: 720; }
.land-hero p  { font-size: 18px; color: var(--ink-soft); max-width: 620px; margin-top: 14px; }
.land-cta { display: flex; gap: 12px; margin-top: 26px; }
.land-section { padding: 64px 24px; }
.land-section h2 { font-size: 26px; font-weight: 680; }
.land-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px; margin-top: 22px; }
.land-grid .cell h3 { font-size: 16px; font-weight: 640; }
.land-grid .cell p { font-size: 14px; color: var(--ink-soft); line-height: 1.55; }
.land-nav { display: flex; align-items: center; justify-content: space-between; padding: 22px 24px; border-bottom: 1px solid var(--line-soft); }
.land-signin { font-weight: 600; }

/* ---------- Sign-in ---------- */
.signin-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 400px; }
.signin-left { background: var(--bg); padding: 80px 72px; display: flex; flex-direction: column; gap: 20px; }
.signin-left h1 { font-size: 32px; font-weight: 720; letter-spacing: -0.015em; }
.signin-left p { color: var(--ink-soft); font-size: 15px; line-height: 1.6; }
.signin-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 34px; align-self: start; width: 360px; box-shadow: var(--shadow-md);
}
.signin-card h2 { font-size: 18px; font-weight: 680; margin-bottom: 18px; }
.alert { padding: 11px 13px; border-radius: var(--radius); font-size: 13.5px; background: var(--bad-wash); color: var(--bad); }

/* ---------- Misc ---------- */
.muted { color: var(--ink-muted); }
.small { font-size: 12px; }
.stack:not(:empty) { display: none; } /* placeholder no-op kept out */
hr.rule { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }

  /* The rail becomes a sticky top bar. Twenty nav items in one endless
     horizontal strip are unreachable on a phone, so they collapse into a
     tap-to-open menu (pure CSS: the .rail-open checkbox + this label). */
  .rail {
    position: sticky; top: 0; z-index: 30;
    padding: 10px 14px; gap: 0;
    border-right: 0; border-bottom: 1px solid var(--line-soft);
  }
  .rail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .rail-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; flex: 0 0 auto;
    cursor: pointer; user-select: none;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    color: var(--ink); font-size: 17px; line-height: 1;
  }
  .rail-toggle:active { background: var(--accent-wash); }
  .rail-open:focus-visible ~ .rail-head .rail-toggle { outline: 2px solid var(--focus); outline-offset: 2px; }
  .rail-menu {
    display: none;
    position: absolute; left: 0; right: 0; top: 100%;
    padding: 10px 14px 16px;
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 26px 52px -26px rgba(0,0,0,.9);
    max-height: min(72vh, 520px); overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .rail-open:checked ~ .rail-menu { display: flex; }
  .rail-menu .rail-section { padding-top: 12px; }

  main { padding: 18px 16px 48px; }
  .page-head { flex-wrap: wrap; gap: 8px; }
  .page-title { font-size: 19px; }

  /* Wide data tables scroll inside their panel instead of running off-screen */
  .tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tablewrap > table { min-width: 560px; }

  /* Stat rows wrap into a 2-up grid instead of clipping the last figure */
  .stat-cluster { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }

  /* Long unbroken strings (paths, messages, ids) must wrap, not overflow */
  .alert, .panel-body, .mono, .page-lead { overflow-wrap: anywhere; }

  .land-grid { grid-template-columns: 1fr; }
  .land-hero { padding: 52px 20px 36px; }
  .land-hero h1 { font-size: 30px; }
  .land-section { padding: 36px 20px; }
  .signin-wrap { grid-template-columns: 1fr; }
  .signin-left { padding: 40px 22px; }
  .signin-card { width: 100%; max-width: 420px; padding: 24px; }

  .input, select, input, textarea { max-width: 100%; }
}

/* Narrow phones: single-column stats and slightly tighter chrome */
@media (max-width: 420px) {
  .stat-cluster { grid-template-columns: 1fr; }
  .rail-toggle { width: 40px; height: 40px; }
  main { padding: 16px 12px 44px; }
}
