:root {
  color-scheme: light dark;
  --border: #d0d0d0;
  --muted: #666;
  --accent: #2b6cb0;
  --radius-sm: 4px;
  --radius-pill: 999px;
  --color-critical: #c53030;
  --color-warning: #b7791f;
  --color-success: #2f855a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", sans-serif;
  color: #1a1a1a;
  background: #fff;
}

@media (prefers-color-scheme: dark) {
  body { color: #eee; background: #111; }
  :root {
    --border: #3a3a3a;
    --muted: #999;
    /* Brighter/more saturated than the light-mode values - the originals
       were never checked against a #111 background and read as muddy. */
    --color-critical: #f56565;
    --color-warning: #ecc94b;
    --color-success: #48bb78;
  }
}

header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 1.1rem; margin: 0; }
#status { color: var(--muted); font-size: 0.85rem; }

main {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  height: calc(100vh - 3rem);
}

#tree {
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 0.5rem;
}

#tree details { margin-bottom: 0.25rem; }
#tree summary { cursor: pointer; font-weight: 600; padding: 0.15rem 0; }
#tree ul { list-style: none; margin: 0.15rem 0 0.5rem 0.75rem; padding: 0; }
#tree li { padding: 0.1rem 0; }
#tree button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.1rem 0.25rem;
  text-align: left;
  width: 100%;
  border-radius: 3px;
}
#tree button:hover { background: rgba(43, 108, 176, 0.12); }
/* app.js's hisLink() - the per-equipment "chart everything" jump into
   his.html, sitting inside each equipment <summary>. */
#tree summary .his-link { text-decoration: none; font-size: 0.8rem; opacity: 0.55; }
#tree summary .his-link:hover { opacity: 1; }
#detail .his-link { color: var(--accent); }
#tree button.selected { background: var(--accent); color: #fff; }

#detail { padding: 1rem; overflow-y: auto; }
.hint { color: var(--muted); }

.tag-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag-list li {
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
}

canvas { border: 1px solid var(--border); border-radius: var(--radius-sm); max-width: 100%; }

.login-gate { display: flex; justify-content: center; padding: 3rem 1rem; }
.login-gate form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  max-width: 280px;
}
.login-gate h2 { margin: 0 0 0.25rem 0; font-size: 1rem; }
.login-gate label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; }
.login-gate input {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: inherit;
  color: inherit;
}
.login-gate button {
  font: inherit;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.login-gate #login-error { color: #c0392b; }

.top-nav { margin-left: auto; font-size: 0.85rem; display: flex; gap: 0.75rem; }
.top-nav a { color: var(--accent); }
/* Set by auth.js's highlightCurrentNavLink() on whichever link matches the
   current page - shown as inert location text instead of a link, so
   "where am I" doesn't rely on inferring it from the *absence* of a link. */
.top-nav a[aria-current="page"] {
  color: var(--muted);
  font-weight: 600;
  pointer-events: none;
}

/* Long cell values (point URIs, ids, JSON blobs) - full value stays
   reachable via the title="" attribute set alongside this class. */
.truncate {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* Shared by devices.html/derivations.html/alarms.html - anything with a
   data table, status/severity badges, or a <dialog>-based form. */
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

/* Base shape only - every badge is a tinted-fill chip (background = its
   semantic color at 15% opacity via color-mix, text = the full color, no
   border) rather than plain outlined text, so a critical/open row is
   something you notice scanning the table, not something you have to
   read to find. Each page's own CSS sets --badge-color per variant
   class (e.g. console.css's .severity-critical); a badge with no
   variant class falls back to the neutral --muted outline below. */
.badge {
  display: inline-block;
  border-radius: var(--radius-pill);
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid transparent;
  color: var(--badge-color, var(--muted));
  background: color-mix(in srgb, var(--badge-color, var(--muted)) 15%, transparent);
}

dialog {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  color: inherit;
  background: canvas;
  max-width: 480px;
}
dialog label { display: block; margin-bottom: 0.5rem; font-size: 0.85rem; }
dialog input, dialog textarea, dialog select {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  font: inherit;
  padding: 0.3rem;
}
dialog textarea { min-height: 4rem; font-family: monospace; font-size: 0.8rem; }
dialog menu { display: flex; gap: 0.5rem; padding: 0; margin: 0.75rem 0 0; }
