:root {
  --bg: #0e1116;
  --bg2: #161b22;
  --bg3: #1f2630;
  --fg: #d9d9d9;
  --fg-dim: #8f8f8f;
  --accent: #4fb3ff;
  --ok: #3ddc84;
  --bad: #ff5c5c;
  --warn: #ffb020;
  --border: #2a313c;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
pre {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 400px;
}

/* nav */
.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand a { color: var(--fg); font-weight: 700; font-size: 16px; }
.brand span { color: var(--accent); }
.nav ul {
  display: flex;
  gap: 14px;
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
}
.nav li a { color: var(--fg-dim); }
.nav li a:hover { color: var(--fg); }
.status { display: flex; align-items: center; gap: 6px; color: var(--fg-dim); }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-dim);
}
.dot.ok  { background: var(--ok); }
.dot.bad { background: var(--bad); }

main { max-width: 1200px; margin: 24px auto; padding: 0 20px; }
h1 { margin: 0 0 16px; font-size: 22px; }
h2 { margin: 28px 0 10px; font-size: 16px; color: var(--fg); }

.hint { color: var(--fg-dim); }

/* cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2 { margin-top: 0; color: var(--fg-dim); font-size: 12px;
           text-transform: uppercase; letter-spacing: 0.8px; }
.card .big { font-size: 28px; font-weight: 600; margin: 4px 0; }
.card .more { font-size: 12px; color: var(--fg-dim); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.err { color: var(--bad); font-size: 12px; margin-top: 6px; }

/* tables */
table.rows {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 24px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table.rows th, table.rows td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
table.rows th {
  background: var(--bg3);
  font-weight: 500;
  color: var(--fg-dim);
}
table.rows tr:last-child td { border-bottom: none; }
table.rows td.topic { font-family: var(--mono); font-size: 11.5px;
                      color: var(--fg-dim); word-break: break-all; }
td.empty { text-align: center; color: var(--fg-dim); padding: 20px; }

/* forms */
form.settings, .actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
form.settings section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
label {
  display: block;
  color: var(--fg-dim);
  font-size: 12px;
  margin-bottom: 6px;
}
label input[type=text], label input[type=password], label input[type=number],
label input:not([type]), label select, label textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 10px;
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-family: var(--mono);
}
label input[type=checkbox] { margin-right: 6px; vertical-align: middle; }
label input[type=range] { margin-top: 4px; width: 80%; }
textarea { font-family: var(--mono); }
button {
  background: var(--accent);
  color: #001b2e;
  border: none;
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
button:hover { filter: brightness(1.08); }
button.danger { background: var(--bad); color: white; }
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0;
}
fieldset legend { color: var(--fg-dim); font-size: 12px; padding: 0 6px; }

/* device id list */
dl { margin: 0; }
dl dt { color: var(--fg-dim); font-size: 11px; text-transform: uppercase;
        letter-spacing: 0.6px; margin-top: 8px; }
dl dd { margin: 0; font-family: var(--mono); }

/* event log */
.log {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  max-height: 360px;
  overflow: auto;
}
.log.big-log { max-height: 70vh; }
.log-entry {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.log-entry:last-child { border-bottom: none; }
.log-entry .t { color: var(--fg-dim); }
.log-entry .k-evt       { color: var(--accent); }
.log-entry .k-cmd_resp  { color: var(--ok); }
.log-entry .k-qry_resp  { color: var(--ok); }
.log-entry .k-lwt       { color: var(--warn); }
.log-entry pre { margin: 4px 0 0; background: none; border: none; padding: 0; }

/* login */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; margin: 0;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 340px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card h1 span { color: var(--accent); }
.login-card .sub { margin: 0 0 18px; color: var(--fg-dim); }
.alert { padding: 8px 12px; border-radius: var(--radius);
         background: rgba(255,92,92,0.15);
         color: var(--bad); margin-bottom: 12px; font-size: 13px; }
.alert.ok { background: rgba(61,220,132,0.12); color: var(--ok); }
.login-card button, form.settings > button { width: 100%; }

/* flash */
.flash {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--bg3); color: var(--fg);
  border: 1px solid var(--accent);
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px;
  animation: in 0.2s ease-out;
}
@keyframes in { from { opacity: 0; transform: translateY(8px); }
                 to  { opacity: 1; transform: translateY(0); } }

.logout a { color: var(--fg-dim); font-size: 13px; }

/* ============================================================================
 * v2.2.f - alert highlighting in the live log.
 *
 * Fault events from the firmware (cat="flt") are styled with a coloured
 * left border + tinted background so the operator notices them while
 * scanning a busy stream. Three classes:
 *
 *   .alert-major     - SM_LVL_MAJOR / CRITICAL (red)
 *   .alert-warn      - SM_LVL_WARN / MINOR (amber)
 *   .alert-resolved  - SM_LVL_RESOLVED (green)
 *
 * The .alert-summary span on the header line shows a one-glance digest
 * (et + level + value/threshold) so the operator does not have to expand
 * the body.
 * ============================================================================ */
.log-entry.alert-major {
  border-left: 4px solid var(--bad);
  background: rgba(255, 92, 92, 0.08);
}
.log-entry.alert-warn {
  border-left: 4px solid #ffb84d;
  background: rgba(255, 184, 77, 0.08);
}
.log-entry.alert-resolved {
  border-left: 4px solid var(--ok);
  background: rgba(61, 220, 132, 0.08);
}
.log-entry .alert-summary {
  color: var(--fg);
  font-weight: 600;
  margin-left: 8px;
}
.log-entry.alert-major .alert-summary    { color: var(--bad); }
.log-entry.alert-warn  .alert-summary    { color: #ffb84d; }
.log-entry.alert-resolved .alert-summary { color: var(--ok); }

/* v2.2.n - version chip glued to .brand, immediately after the
   logo.  Margin-left gives it visual breathing room from the
   logo wordmark; muted opacity so it does not steal attention
   from active nav items. */
.version-badge {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.80em;
    opacity: 0.65;
    margin-left: 0.6em;
    color: inherit;
    white-space: nowrap;
    user-select: all;
}
.version-badge:hover { opacity: 1; }
/* Allow .brand to sit on a baseline with its child badge.       */
.brand { display: inline-flex; align-items: baseline; gap: 0; }

/* v2.2.q - collapsible Actions sections.  Click summary to expand. */
.action-section {
    margin: 6px 0;
    border-radius: 6px;
    background: rgba(255,255,255,0.02);
}
.action-section > summary {
    cursor: pointer;
    padding: 8px 10px;
    font-weight: 600;
    list-style: none;
    user-select: none;
    border-radius: 6px;
}
.action-section > summary::-webkit-details-marker { display: none; }
.action-section > summary::before {
    content: "▸ ";
    display: inline-block;
    transition: transform 0.15s ease;
    opacity: 0.6;
}
.action-section[open] > summary::before {
    transform: rotate(90deg);
}
.action-section > summary:hover {
    background: rgba(255,255,255,0.05);
}
.action-section .action-body {
    border: none;
    margin: 0;
    padding: 8px 12px 12px 12px;
    background: transparent;
}
.action-section .action-body legend { display: none; }

/* v2.2.q - clickable schedule slot rows.  Each row laid out as a wrap-
   friendly flex; long fields collapse on narrow screens. */
.sch-slot {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 6px 8px;
    margin: 4px 0;
    background: rgba(255,255,255,0.03);
    border-radius: 4px;
}
.sch-slot label {
    display: inline-flex;
    flex-direction: column;
    font-size: 0.85em;
    opacity: 0.85;
}
.sch-slot select,
.sch-slot input[type=time],
.sch-slot input[type=number] {
    min-width: 5em;
}
.sch-slot .sch-remove {
    align-self: center;
    margin-left: auto;
    padding: 2px 10px;
    font-weight: bold;
}
