/* Farmbot portal design system ("Console": dark ops panel, gold accent, mono numbers and labels, crisp edges).
   One stylesheet: tokens first, then components that read only the semantic tokens. The style guide that shows
   every component is portal/design/preview.html. System fonts only: the portal loads nothing from third parties.
   The CSP forbids inline styles, so index.html uses classes only; app.js sets meter widths through CSSOM. */

/* ================================================================== tokens */
:root {
  color-scheme: dark;

  /* Spacing: 4 px base. */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px; --space-16: 64px;

  /* Type scale (1.2 ratio) and weights. */
  --text-xs: 12px; --text-sm: 13px; --text-md: 15px; --text-lg: 18px;
  --text-xl: 22px; --text-2xl: 28px; --text-3xl: 36px;
  --weight-regular: 400; --weight-medium: 500; --weight-bold: 650;
  --leading-tight: 1.2; --leading-body: 1.55;

  /* Layout. */
  --content-max: 1080px;
  --content-narrow: 420px;
  --header-h: 60px;

  /* Motion. */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur-fast: 120ms; --dur: 200ms;

  /* Fonts. */
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;

  /* Surfaces and text. Muted text on --surface is about 6:1, so it stays readable as body copy. */
  --bg: #0b0d10;
  --surface: #12151a;           /* cards, stat tiles */
  --surface-sunken: #0e1014;    /* inputs, table head, character tiles */
  --surface-raised: #181c22;
  --border: #22272f;
  --border-strong: #303743;
  --text: #e6e2d6;
  --text-muted: #8f97a6;
  --text-faint: #5c6370;        /* non-text marks only (offline dot): too dim for copy */
  --text-on-accent: #1a1406;

  --accent: #e2b552;
  --accent-hover: #f0c768;
  --accent-soft: #2a2213;

  --ok: #5fd38d;    --ok-soft: #10261a;
  --warn: #f0a742;  --warn-soft: #2c1f0e;
  --bad: #ff6b5e;   --bad-soft: #2e1412;

  /* Shape. */
  --radius-sm: 3px; --radius: 4px; --radius-pill: 999px;
  --shadow: 0 4px 16px rgb(0 0 0 / .35);
  --label-tracking: .08em;
}

/* ================================================================== base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0; color: var(--text); font: var(--text-md)/var(--leading-body) var(--font-body);
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  background-image: linear-gradient(rgb(255 255 255 / .018) 1px, transparent 1px),
                    linear-gradient(90deg, rgb(255 255 255 / .018) 1px, transparent 1px);
  background-size: 24px 24px;
}

h1, h2, h3 { margin: 0 0 var(--space-3); line-height: var(--leading-tight); letter-spacing: .01em; font-weight: var(--weight-bold); }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
a { color: var(--accent); }
.note, .muted { color: var(--text-muted); font-size: var(--text-sm); }
/* Labels read like instrument captions: small, uppercase, mono. */
.eyebrow, .stat-label, th, label {
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted);
  text-transform: uppercase; letter-spacing: var(--label-tracking); font-weight: var(--weight-medium);
}
code, .mono { font-family: var(--font-mono); font-size: .92em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ================================================================== layout */
main { max-width: var(--content-max); margin: 0 auto; padding: var(--space-8) var(--space-5); }
.stack > * + * { margin-top: var(--space-4); }
.row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-4); }
.page-head { margin-bottom: var(--space-4); gap: var(--space-3); }
.page-head h1 { margin: 0; }
.section-head { display: flex; align-items: baseline; gap: var(--space-3); margin: var(--space-8) 0 var(--space-3); }
.section-head h2 { margin: 0; }

/* ================================================================== app header */
header.bar {
  position: sticky; top: 0; z-index: 5; min-height: var(--header-h);
  display: flex; align-items: center; gap: var(--space-4); padding: 0 var(--space-5);
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-bold); font-size: var(--text-lg); }
.brand-mark { width: 26px; height: 26px; border-radius: var(--radius-sm); background: var(--accent);
  display: grid; place-items: center; color: var(--text-on-accent); font-size: 14px; }
nav.tabs { display: flex; gap: var(--space-1); align-self: stretch; }
.tab {
  background: transparent; color: var(--text-muted); border: 0; border-radius: 0; padding: 0 var(--space-3);
  font: inherit; font-weight: var(--weight-medium); cursor: pointer; white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--text); background: transparent; }
.tab.current { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }

/* ================================================================== card */
/* A thin left stripe marks every panel; it turns gold for the card that wants attention or a PC that is online. */
.card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-5);
}
.card::before { content: ""; position: absolute; inset: -1px auto -1px -1px; width: 2px; background: var(--border-strong); }
.card.feature::before, .card.device.online::before { background: var(--accent); }
.card.narrow { max-width: var(--content-narrow); margin: var(--space-16) auto; padding: var(--space-8); }
.card.narrow .brand { margin-bottom: var(--space-5); }
.card-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card.feature { border-color: var(--accent); }
/* A card that is mostly one table: the table runs edge to edge under a padded heading. */
.card.table-card { padding: 0; overflow: hidden; }
.table-card > h2 { margin: 0; padding: var(--space-5) var(--space-5) var(--space-3); }
.table-card :is(th, td):first-child { padding-left: var(--space-5); }
.table-card :is(th, td):last-child { padding-right: var(--space-5); }

/* ================================================================== stat tile */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); }
.stat-value { font-family: var(--font-mono); font-size: var(--text-2xl); font-weight: var(--weight-bold);
  line-height: 1.15; margin-top: var(--space-1); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ================================================================== buttons */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 10px var(--space-4); border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--text-on-accent); font: inherit; font-weight: var(--weight-medium);
  cursor: pointer; text-decoration: none; transition: background var(--dur-fast) var(--ease);
}
button:hover, .button:hover { background: var(--accent-hover); }
button.ghost, .button.ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
button.ghost:hover, .button.ghost:hover { background: var(--surface-sunken); }
button.quiet { background: transparent; color: var(--accent); padding-inline: var(--space-2); }
button.quiet:hover { background: var(--accent-soft); }
button.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
button.danger:hover { background: var(--bad-soft); }
button.sm { padding: 5px var(--space-3); font-size: var(--text-sm); }
button.wide { width: 100%; }
button:disabled { opacity: .5; pointer-events: none; }

/* ================================================================== forms */
label { display: block; margin-bottom: var(--space-1); }
input, select {
  width: 100%; padding: 10px var(--space-3); margin-bottom: var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-sunken); color: var(--text); font: inherit;
}
input:focus, select:focus { border-color: var(--accent); }
input.code { font-family: var(--font-mono); font-size: var(--text-xl); letter-spacing: .3em; text-align: center; }
.inline-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 var(--space-3); align-items: end; }
.inline-form button { margin-bottom: var(--space-3); }
.copy-field { display: flex; gap: var(--space-2); max-width: 560px; margin-top: var(--space-3); }
.copy-field input { margin: 0; font-family: var(--font-mono); min-width: 0; }

/* ================================================================== status */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: var(--weight-medium); background: var(--surface-sunken); color: var(--text-muted);
  white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); display: inline-block; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.banner { margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  background: var(--ok-soft); color: var(--ok); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.error { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--accent-soft); color: var(--accent); }

/* ================================================================== steps (setup flow) */
.steps { display: grid; gap: var(--space-4); }
.step-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-4); }
.step-card p:last-child { margin-bottom: 0; }
.step {
  width: 32px; height: 32px; border-radius: var(--radius-sm); display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-family: var(--font-mono); font-weight: var(--weight-bold);
  font-size: var(--text-sm);
}
.step.done { background: var(--ok); color: var(--text-on-accent); }

/* ================================================================== XP meter */
.meter { height: 6px; background: var(--border-strong); overflow: hidden; }
.meter > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #a77d2a, var(--accent)); }

/* ================================================================== table */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
th { white-space: nowrap; background: var(--surface-sunken); }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { font-family: var(--font-mono); }

/* ================================================================== device card */
.device .dev-meta { display: flex; gap: var(--space-4); flex-wrap: wrap; color: var(--text-muted); font-size: var(--text-sm); }
.device .chars { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-3); margin-top: var(--space-4); }
.device > h3 { margin: var(--space-5) 0 var(--space-2); }
.device .scroll { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.char { padding: var(--space-3); border-radius: var(--radius-sm); background: var(--surface-sunken); }
.char-name { font-weight: var(--weight-bold); display: flex; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); }
.char .meter + .note { margin-top: var(--space-2); }

/* ================================================================== empty state */
.empty { text-align: center; padding: var(--space-10) var(--space-5); color: var(--text-muted); }
.empty h3 { color: var(--text); }

/* ================================================================== small screens */
@media (max-width: 640px) {
  header.bar { flex-wrap: wrap; gap: 0 var(--space-2); padding: var(--space-2) var(--space-3) 0; }
  nav.tabs { order: 1; width: 100%; min-height: 40px; overflow-x: auto; }
  .hide-sm { display: none; }
  main { padding: var(--space-4) var(--space-3); }
  .card.narrow { margin: var(--space-8) auto; padding: var(--space-5); }
  .page-head h1 { font-size: var(--text-xl); }
}
