/* Required Notice: Copyright (c) 2026 Carsten Isert AI Labs (https://carsten-isert-ai-labs.de). All rights reserved.
   Dual-licensed under the Carsten Isert AI Labs Research License (based on PolyForm Noncommercial 1.0.0, + Industrial Research Grant) and the Carsten Isert AI Labs Commercial License. See LICENSE. */

/* The web app's look: "maps and robots" (docs/DEPLOYMENT_DESIGN.md §5.4). Colours come from the
   shared tokens (/inspector/tokens.css). */

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 14px/1.5 var(--font-sans);
  color: var(--ink);
  background:
    url("../img/contours.svg") right -120px top -80px / 900px auto no-repeat,
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 32px 32px,
    var(--paper);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: var(--sea); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: 0.005em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
p { margin: 0 0 var(--space-2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- top bar ------------------------------------------------------------------------------ */
.topbar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-4); height: 52px; flex: none;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1000; backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: var(--space-2); color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.brand svg { width: 28px; height: 28px; --mark-bg: var(--panel); }
.brand small { font: 500 10px var(--font-mono); color: var(--ink-muted); letter-spacing: 0.1em; text-transform: uppercase; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.nav a {
  color: var(--ink-muted); text-decoration: none; padding: 6px 10px; border-radius: var(--radius);
  font-size: 13px; font-weight: 550; white-space: nowrap;
}
.nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.nav a.active { color: var(--ink); background: var(--paper-raised); box-shadow: var(--shadow); }
.nav a.active::before { content: "▸ "; color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.who { font-size: 12px; color: var(--ink-muted); text-align: right; line-height: 1.2; }
.who strong { color: var(--ink); display: block; font-size: 13px; }

/* --- main --------------------------------------------------------------------------------- */
main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: var(--space-4); }
main.wide { max-width: none; padding: 0; display: flex; flex-direction: column; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.page-head p { color: var(--ink-muted); margin: 2px 0 0; }
.eyebrow { font: 600 10px var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }

.grid { display: grid; gap: var(--space-3); }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

.card {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3);
  position: relative;
}
.card > header { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); flex-wrap: wrap; }
.card > header h2::before { content: "§ "; color: var(--line-strong); font-family: var(--font-mono); }
/* Corner ticks like a map frame. */
.card::after {
  content: ""; position: absolute; inset: 4px; pointer-events: none; border-radius: 2px;
  background:
    linear-gradient(var(--line-strong), var(--line-strong)) top left / 8px 1px no-repeat,
    linear-gradient(var(--line-strong), var(--line-strong)) top left / 1px 8px no-repeat,
    linear-gradient(var(--line-strong), var(--line-strong)) bottom right / 8px 1px no-repeat,
    linear-gradient(var(--line-strong), var(--line-strong)) bottom right / 1px 8px no-repeat;
  opacity: 0.6;
}

.tile { padding: var(--space-3); }
.tile .value { font: 650 26px/1.1 var(--font-mono); letter-spacing: -0.02em; }
.tile .label { font-size: 12px; color: var(--ink-muted); }
.tile .sub { font: 11px var(--font-mono); color: var(--ink-muted); }

.muted { color: var(--ink-muted); }
.small { font-size: 12px; }
.mono { font-family: var(--font-mono); }
.error-text { color: var(--crit); font-weight: 600; }
.row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack { display: grid; gap: var(--space-2); }

/* --- forms -------------------------------------------------------------------------------- */
label.field { display: grid; gap: 3px; font-size: 12px; color: var(--ink-muted); font-weight: 550; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 9px; min-width: 0; color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
button, .button {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line-strong); background: var(--paper-raised); color: var(--ink);
  border-radius: var(--radius); padding: 5px 12px; font-weight: 550; font-size: 13px;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); color: var(--ink); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); color: var(--accent-ink); }
button.danger { color: var(--crit); }
button.danger:hover:not(:disabled) { border-color: var(--crit); color: var(--crit); }
button.ghost { border-color: transparent; background: transparent; }
button.small, .button.small { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: default; }
form.inline { display: flex; gap: var(--space-2); align-items: flex-end; flex-wrap: wrap; }
form.stack { display: grid; gap: var(--space-3); }
fieldset { border: 1px dashed var(--line); border-radius: var(--radius); padding: var(--space-2) var(--space-3); }

/* --- tables ------------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  text-align: left; font: 600 10px var(--font-mono); text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--ink-muted); padding: 6px 8px; border-bottom: 1px solid var(--line-strong);
}
td { padding: 7px 8px; border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent); vertical-align: top; }
tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
td.num, th.num { text-align: right; font-family: var(--font-mono); }
tr.selected td { background: color-mix(in srgb, var(--sea) 12%, transparent); }

/* --- chips, lights, glyphs ---------------------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 999px;
  font: 600 11px var(--font-mono); border: 1px solid currentColor; white-space: nowrap; line-height: 1.6;
}
.chip.ok { color: var(--ok); } .chip.warn { color: var(--warn); } .chip.crit { color: var(--crit); }
.chip.info { color: var(--info); } .chip.idle { color: var(--idle); } .chip.accent { color: var(--accent); }
.chip.sea { color: var(--sea); }
.light { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--idle); flex: none; }
.light.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.light.warn { background: var(--warn); } .light.crit { background: var(--crit); }
.robot { display: inline-flex; align-items: center; gap: 8px; }
.robot img { width: 22px; height: 22px; }
.edition { font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
.edition b { color: var(--accent); font-weight: 650; }
.secret {
  font: 600 14px var(--font-mono); background: var(--paper); border: 1px dashed var(--accent);
  padding: 8px 10px; border-radius: var(--radius); word-break: break-all; user-select: all;
}
.notice { border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--paper-raised)); padding: 8px 12px; border-radius: var(--radius); margin: var(--space-2) 0; }
.notice.crit { border-left-color: var(--crit); background: color-mix(in srgb, var(--crit) 7%, var(--paper-raised)); }

/* --- alerts ------------------------------------------------------------------------------- */
.alerts { display: grid; gap: var(--space-2); margin-bottom: var(--space-3); }
.alert {
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3); align-items: center;
  background: var(--paper-raised); border: 1px solid var(--line); border-left: 4px solid var(--info);
  border-radius: var(--radius); padding: 8px 12px; box-shadow: var(--shadow);
}
.alert.warning { border-left-color: var(--warn); } .alert.critical { border-left-color: var(--crit); }
.alert.acknowledged { opacity: 0.7; }
.alert .meta { font: 11px var(--font-mono); color: var(--ink-muted); }

/* --- charts ------------------------------------------------------------------------------- */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .gridline { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .tick { fill: var(--ink-muted); font: 10px var(--font-mono); }
.chart .series-0 { stroke: var(--sea); fill: none; stroke-width: 1.6; }
.chart .series-1 { stroke: var(--accent); fill: none; stroke-width: 1.2; stroke-dasharray: 3 2; }
.chart .series-2 { stroke: var(--warn); fill: none; stroke-width: 1.4; }
.chart .series-3 { stroke: var(--info); fill: none; stroke-width: 1.4; }
.chart .area-0 { fill: color-mix(in srgb, var(--sea) 16%, transparent); stroke: none; }
.chart .bar-0 { fill: var(--sea); } .chart .bar-1 { fill: var(--crit); }
.chart .limit { stroke: var(--crit); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .heat-0 { fill: var(--heat-0); } .chart .heat-1 { fill: var(--heat-1); } .chart .heat-2 { fill: var(--heat-2); }
.chart .heat-3 { fill: var(--heat-3); } .chart .heat-4 { fill: var(--heat-4); } .chart .heat-5 { fill: var(--heat-5); }
.legend-line { display: flex; gap: var(--space-3); font: 11px var(--font-mono); color: var(--ink-muted); flex-wrap: wrap; }
.legend-line i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; }
.legend-line i.s0 { background: var(--sea); } .legend-line i.s1 { background: var(--accent); }
.legend-line i.s2 { background: var(--warn); } .legend-line i.s3 { background: var(--info); }
.meter { height: 8px; background: var(--heat-0); border-radius: 4px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--sea); }
.meter.warn > span { background: var(--warn); } .meter.crit > span { background: var(--crit); }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.segmented button { border: 0; border-radius: 0; padding: 3px 10px; }
.segmented button.active { background: var(--ink); color: var(--paper); }

/* --- maps page ---------------------------------------------------------------------------- */
#site-map { height: 420px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); }
#anchor-map { height: 300px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); margin: var(--space-2) 0; }
label.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
progress { width: 220px; height: 8px; accent-color: var(--accent); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.leaflet-container { font: 12px var(--font-sans); }
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9) saturate(0.6); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9) saturate(0.6); }
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--paper-raised); color: var(--ink); }
.site-marker { background: var(--accent); border: 2px solid var(--paper-raised); border-radius: 50%; box-shadow: 0 0 0 2px var(--accent); }
.site-marker.public { background: var(--sea); box-shadow: 0 0 0 2px var(--sea); }

/* --- inspector page ----------------------------------------------------------------------- */
.inspector-frame { flex: 1; width: 100%; border: 0; min-height: calc(100vh - 52px - 30px); display: block; background: var(--paper); }

/* --- versions ----------------------------------------------------------------------------- */
details.day { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: var(--space-2); background: var(--paper); }
details.day > summary { cursor: pointer; padding: 6px 10px; font: 600 12px var(--font-mono); display: flex; gap: var(--space-3); align-items: center; }
details.day > summary .counts { font-weight: 400; color: var(--ink-muted); }
details.day table { margin: 0 0 6px; }
.diff-kind.added { color: var(--ok); } .diff-kind.changed { color: var(--warn); } .diff-kind.removed { color: var(--crit); }

/* --- empty states ------------------------------------------------------------------------- */
.empty { display: grid; justify-items: center; gap: var(--space-2); padding: var(--space-4); color: var(--ink-muted); text-align: center; }
.empty img { width: 96px; height: 96px; opacity: 0.9; }

/* --- status bar ----------------------------------------------------------------------------- */
.statusbar {
  display: flex; gap: var(--space-4); justify-content: space-between; align-items: center;
  height: 30px; padding: 0 var(--space-4); flex: none;
  font: 11px var(--font-mono); color: var(--ink-muted);
  border-top: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 92%, transparent);
}
.statusbar .coords::before { content: "⌖ "; color: var(--accent); }

/* --- sign-in pages ------------------------------------------------------------------------ */
.gate { flex: 1; display: grid; place-items: center; padding: var(--space-4); }
.gate .card { width: min(420px, 100%); padding: var(--space-4) var(--space-5); }
.gate .brand { margin-bottom: var(--space-3); font-size: 18px; }
.gate .brand svg { --mark-bg: var(--paper-raised); }
.gate h1 { font-size: 18px; margin-bottom: var(--space-3); }

/* --- toast ---------------------------------------------------------------------------------- */
#toast {
  position: fixed; bottom: 44px; left: 50%; transform: translateX(-50%); z-index: 2000;
  background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: var(--radius);
  font-size: 13px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25); max-width: min(90vw, 640px);
}
#toast.crit { background: var(--crit); color: #fff; }

@media (max-width: 760px) {
  .topbar { gap: var(--space-2); padding: 0 var(--space-2); }
  .brand span { display: none; }
  .who { display: none; }
  main { padding: var(--space-2); }
  .grid.two { grid-template-columns: 1fr; }
}
::placeholder { color: var(--ink-muted); opacity: 0.55; }
#org-switch { max-width: 170px; }
@media (max-width: 1000px) {
  .brand span { display: none; }
  .who { display: none; }
  .nav a { padding: 6px 7px; font-size: 12.5px; }
  .nav a.active::before { content: none; }
}
/* Too narrow for one line: the navigation gets a row of its own under the brand. */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; height: auto; padding-top: 6px; padding-bottom: 6px; row-gap: 4px; }
  .topbar-right { margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; }
}
td .row { flex-wrap: nowrap; }
