/*
 * Samsara Hub base styles. ACC brand palette (acc-color-palette.md): Lato; teal #00A7B5,
 * gold #EBB700, coral #D4603A; text #1E1E1E / #53565A; semantic success #2D8659,
 * warning #C48800, error #C4342D. Modules add their own files (hub.css, admin.css, ...)
 * through the view's `styles` list and reuse these tokens; they never redefine them.
 *
 * Floating elements (menus, popovers, dropdowns): use the native `popover` attribute or
 * <dialog> (top layer, clipped by nothing). If one must be position:absolute, lift overflow on
 * every clipping ancestor while it is open: give it class "float" and the rule below lifts
 *   .card:has(details.float[open]), .tablewrap:has(details.float[open]) { overflow: visible; }
 * Plain <details> that expand in flow must NOT lift it: an open one inside a table would stop the
 * table scrolling in its wrapper, and body's overflow-x: hidden would cut the right side off.
 * Test it on a table with one row and with no rows, narrow and wide.
 */
:root {
  --teal: #00a7b5;
  --teal-dark: #008a96; /* accessible teal text on white */
  --teal-fill: #00707a; /* white text on this passes AA; on brand teal it does not */
  --teal-light: #e5f4f7;
  --gold: #ebb700;
  --gold-dark: #8b6d00;
  --gold-light: #fff8e1;
  --coral: #d4603a;
  --coral-dark: #a3432a;
  --coral-light: #fdf0eb;
  --ink: #1e1e1e;
  --body: #53565a;
  --muted: #6b6e72;
  --border: #7c7f82;
  --line: #e1e4e6;
  --bg: #f4f7f8;
  --card: #ffffff;
  --success: #2d8659;
  --success-light: #eaf5ef;
  --warning: #c48800;
  --warning-text: #8b6d00;
  --warning-light: #fff5d6;
  --error: #c4342d;
  --error-light: #fdeceb;
  --info: #008a96;
  --radius: 8px;
  --gutter: 16px;
  --page: 1180px;
  --font: Lato, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--body);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--teal-dark); }
a:hover { color: var(--ink); }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
h1, h2, h3 { color: var(--ink); line-height: 1.25; }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip { position: absolute; left: -9999px; }
.skip:focus { left: var(--gutter); top: 8px; z-index: 10; background: #fff; padding: 8px 12px; }

/* ---- header ---- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-height: 56px;
  padding: 8px max(var(--gutter), calc((100vw - var(--page)) / 2 + var(--gutter)));
  background: #fff;
  border-bottom: 3px solid var(--teal);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: 18px; color: var(--ink); text-decoration: none; }
.brand .logo { width: 28px; height: 28px; display: block; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  text-decoration: none; padding: 8px 12px; border-radius: 6px;
  font-weight: 700; font-size: 14px; color: var(--body);
}
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.on { background: var(--teal-light); color: var(--teal-fill); }
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.who-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28ch; }
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 900;
  letter-spacing: 0.5px; background: var(--gold-light); color: var(--gold-dark);
}
@media (max-width: 720px) {
  .nav { order: 3; width: 100%; }
  .who-email { max-width: 18ch; }
}

/* ---- page layout ---- */
.wrap {
  max-width: var(--page);
  margin: 0 auto;
  padding: 24px var(--gutter) 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.wrap.narrow { max-width: 520px; }
.h1 { font-size: 26px; font-weight: 900; margin: 0; }
.h2 { font-size: 18px; font-weight: 900; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.titlebar { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; }
.titlebar .right { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---- cards and stat tiles ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.stat .label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.stat .value { font-size: 30px; font-weight: 900; color: var(--ink); line-height: 1.1; margin-top: 4px; }
.stat .note { font-size: 13px; margin-top: 4px; }

/* ---- tables ----
 * .tablewrap scrolls sideways on its own so the page never does. It clips: never put a
 * popover inside it unless the :has() rule from the header comment is in place. */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.tablewrap:has(details.float[open]), .card:has(details.float[open]) { overflow: visible; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); background: #fafbfb; white-space: nowrap; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover { background: #fafcfc; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list tr.dim td { opacity: 0.6; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* ---- pills (status, severity, tags) ---- */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--bg); color: var(--body); border: 1px solid var(--line); white-space: nowrap;
}
.pill.ok, .pill.valid, .pill.pass { background: var(--success-light); color: var(--success); border-color: transparent; }
.pill.warn, .pill.partial, .pill.medium, .pill.unconfigured { background: var(--warning-light); color: var(--warning-text); border-color: transparent; }
.pill.error, .pill.failed, .pill.invalid, .pill.high, .pill.gap { background: var(--error-light); color: var(--error); border-color: transparent; }
.pill.info, .pill.running, .pill.low { background: var(--teal-light); color: var(--teal-fill); border-color: transparent; }

/* ---- alerts ---- */
.alert { padding: 12px 14px; border-radius: var(--radius); border-left: 4px solid var(--info); background: var(--teal-light); color: var(--ink); }
.alert.ok { border-color: var(--success); background: var(--success-light); }
.alert.warn { border-color: var(--warning); background: var(--warning-light); }
.alert.error { border-color: var(--error); background: var(--error-light); }

/* ---- forms and buttons ---- */
.lbl { font-weight: 700; color: var(--ink); font-size: 14px; }
input[type="text"], input[type="email"], input[type="search"], input:not([type]), select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px; min-height: 40px; max-width: 100%;
}
input.code { font-size: 24px; letter-spacing: 4px; text-align: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; font-size: 14px; text-decoration: none; cursor: pointer;
  padding: 9px 16px; min-height: 40px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--teal-fill); border-color: var(--teal-fill); color: #fff; }
.btn.primary:hover { background: var(--ink); border-color: var(--ink); }
.btn.danger { color: var(--error); border-color: var(--error); }
.btn.big { min-height: 48px; font-size: 16px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--teal-dark); text-decoration: underline; cursor: pointer; }
form.inline { display: inline; margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }

/* ---- code blocks (webhook payloads, raw JSON) ---- */
pre.json {
  margin: 0; padding: 14px; background: #1e1e1e; color: #f4f7f8; border-radius: var(--radius);
  overflow-x: auto; white-space: pre; max-height: 70vh;
}

/* ---- auth + admin (auth module) ---- */
.nowrap { white-space: nowrap; }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.subnav { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.subnav a {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; padding: 6px 12px;
  border-radius: 6px; font-weight: 700; font-size: 14px; color: var(--body);
}
.subnav a:hover { background: var(--card); color: var(--ink); }
.subnav a.on { background: var(--teal-light); color: var(--teal-fill); }
.subnav .n { font-size: 12px; font-weight: 700; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; color: var(--muted); }
a.cardlink { text-decoration: none; color: inherit; display: block; }
a.cardlink:hover { border-color: var(--teal); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.grow { flex: 1 1 240px; }
.addform { display: flex; flex-direction: column; gap: 10px; }
.addform .filters input, .addform .filters select { width: 100%; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
td.emailcell { overflow-wrap: anywhere; min-width: 16ch; }
td.ua { max-width: 36ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager { justify-content: flex-end; }
@media (max-width: 560px) {
  .row-actions { justify-content: flex-start; }
}
