/* MEA control plane — operator UI.
 *
 * Dense by intent. The reader is looking at a fleet, not a dashboard: what
 * matters is how many rows fit on screen and whether a bad one is visible
 * without scrolling, not how much whitespace surrounds each one.
 */

:root {
  color-scheme: light dark;

  --bg: #fbfbfc;
  --panel: #ffffff;
  --sunken: #f4f4f6;
  --ink: #16181d;
  --dim: #6b7280;
  --faint: #9ca3af;
  --line: #e3e5ea;
  --accent: #2563eb;
  --accent-ink: #ffffff;

  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --busy: #1d4ed8;
  --busy-bg: #dbeafe;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --radius: 6px;
  --sidebar: 232px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --panel: #171a20;
    --sunken: #1d2129;
    --ink: #e6e8ec;
    --dim: #9aa2b1;
    --faint: #6b7280;
    --line: #272c36;
    --accent: #3b82f6;

    --ok: #4ade80;  --ok-bg: #14321f;
    --bad: #f87171; --bad-bg: #3b1616;
    --warn: #fbbf24; --warn-bg: #3a2c0a;
    --busy: #93c5fd; --busy-bg: #16243f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.mono { font-family: var(--mono); font-size: .86em; }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ----------------------------------------------------------------- login */

#login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.75rem;
}

.card h1 { font-size: 1.15rem; margin: 0 0 .3rem; }
.card p.lede { color: var(--dim); margin: 0 0 1.5rem; font-size: .9rem; }

label.field { display: block; font-size: .8rem; color: var(--dim); margin-bottom: .4rem; }

input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%;
  font: inherit;
  padding: .5rem .65rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------------------------------------------------------------- buttons */

button {
  font: inherit;
  padding: .4rem .8rem;
  cursor: pointer;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
button:hover:not(:disabled) { border-color: var(--dim); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.danger:hover:not(:disabled) { border-color: var(--bad); }
button.wide { width: 100%; padding: .55rem; }
button.small { padding: .22rem .55rem; font-size: .85em; }

/* ------------------------------------------------------------------ shell */

#shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { padding: 1rem 1.1rem .85rem; border-bottom: 1px solid var(--line); }
.brand strong { display: block; font-size: .95rem; }
.brand span { font-size: .75rem; color: var(--faint); }

nav { padding: .6rem; flex: 1; overflow-y: auto; }

nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .65rem;
  margin-bottom: 2px;
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  font-size: .9rem;
}
nav a:hover { background: var(--sunken); }
nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
nav a[aria-current="page"] .count { background: #fff3; color: inherit; }

.count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: .75rem;
  padding: .05rem .4rem;
  border-radius: 999px;
  background: var(--sunken);
  color: var(--dim);
}
.count.attention { background: var(--warn-bg); color: var(--warn); }

.side-foot {
  border-top: 1px solid var(--line);
  padding: .7rem .8rem;
  font-size: .78rem;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-content: space-between;
}

#main { min-width: 0; padding: 1.4rem 1.6rem 3rem; }

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.page-head h2 { font-size: 1.15rem; margin: 0 0 .15rem; }
.page-head p { margin: 0; color: var(--dim); font-size: .87rem; max-width: 62ch; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; align-items: center; }

/* ------------------------------------------------------------------ panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 1.1rem;
  overflow: hidden;
}
.panel > h3 {
  margin: 0;
  padding: .6rem .9rem;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.panel > h3 .count { margin-left: auto; }
.panel-body { padding: .9rem; }

/* ------------------------------------------------------------------ tables */

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--faint);
  background: var(--sunken);
}
/* A device label has no spaces, so it breaks on its hyphen and reads as two
 * lines of unrelated hex. There is room in this table; use it. */
td .mono { white-space: nowrap; }

tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: var(--sunken); }

.empty { padding: 1.6rem .9rem; text-align: center; color: var(--faint); font-style: italic; }

/* ------------------------------------------------------------------- chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .1rem .45rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--sunken);
  color: var(--dim);
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.busy { background: var(--busy-bg); color: var(--busy); }

.dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; flex: none; }

/* -------------------------------------------------------------- key/values */

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.1rem; font-size: .88rem; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.1rem; align-items: start; }

pre {
  background: var(--sunken);
  padding: .7rem .8rem;
  margin: 0;
  overflow-x: auto;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.5;
  max-height: 460px;
}

details summary { cursor: pointer; color: var(--dim); font-size: .85rem; padding: .2rem 0; }
details[open] summary { margin-bottom: .5rem; }

/* ------------------------------------------------------------------ toasts */

#toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 50;
  max-width: min(440px, 90vw);
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--dim);
  border-radius: var(--radius);
  padding: .6rem .8rem;
  font-size: .86rem;
  box-shadow: 0 6px 20px #0002;
  overflow-wrap: anywhere;
}
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }

/* ------------------------------------------------------------------ misc */

.bar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.bar.tight { gap: .4rem; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

a.back { color: var(--dim); text-decoration: none; font-size: .85rem; }
a.back:hover { color: var(--ink); }

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; flex-wrap: wrap; }
.tabs button {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--dim);
  padding: .5rem .8rem;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

@media (max-width: 760px) {
  #shell { grid-template-columns: 1fr; }
  #sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  nav { display: flex; gap: .3rem; overflow-x: auto; }
  nav a { margin: 0; white-space: nowrap; }
  #main { padding: 1rem; }
}

/* The live tail: a fixed window that scrolls, so a chatty service does not
   push the rest of the page out of reach. */
pre.live-log {
  margin-top: .7rem;
  min-height: 6rem;
  max-height: 28rem;
  overflow: auto;
}
