/* Rhodos Console — frame and components. Colours come only from tokens.css. */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs)/1.4 var(--font);
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
}

button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-size: 0.95em; letter-spacing: 0; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.selectable { user-select: text; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* ------------------------------------------------------------------ frame */

.app {
  display: grid;
  height: 100vh;
  grid-template-rows: var(--h-menubar) var(--h-toolbar) 1fr var(--h-statusbar);
  grid-template-columns: var(--w-nav) 1fr;
  grid-template-areas:
    "menu menu"
    "nav  tool"
    "nav  main"
    "stat stat";
}

.menubar {
  grid-area: menu;
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 6px;
  gap: 2px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 6px;
  margin-right: 6px;
  border-right: 1px solid var(--line);
  font: 600 var(--fs) var(--font-display);
  letter-spacing: 0.01em;
}
.brand-mark {
  width: 18px; height: 18px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  display: grid; place-items: center;
}
.brand-mark svg { width: 12px; height: 12px; color: var(--ink-inverse); }

.menu { position: relative; display: flex; }
.menu > button {
  border: 0;
  background: none;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  margin: 3px 0;
  cursor: default;
}
.menu > button:hover, .menu.open > button { background: var(--hover); }
.menu-pop {
  position: absolute;
  top: calc(100% + 1px);
  left: 0;
  min-width: 232px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  z-index: 1000;
  display: none;
}
.menu.open .menu-pop { display: block; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  background: none;
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: default;
}
.menu-item:hover:not(:disabled) { background: var(--accent); color: var(--ink-inverse); }
.menu-item:disabled { color: var(--ink-3); }
.menu-item .kbd { margin-left: auto; color: inherit; opacity: 0.6; font-size: var(--fs-cap); }
.menu-item .check { width: 14px; text-align: center; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 2px; }

.menubar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; padding-right: 6px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 10px 2px 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.avatar {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700;
}
.role-tag {
  font-size: var(--fs-cap);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-2);
}

/* nav */
.nav {
  grid-area: nav;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 8px 8px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.nav-group { margin-bottom: 10px; }
.nav-group-label {
  font-size: var(--fs-cap);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  padding: 8px 10px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  position: relative;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 7px; bottom: 7px;
  width: 3px; border-radius: 2px; background: var(--accent);
}
.nav-item svg { width: 16px; height: 16px; flex: none; }
.nav-item .count {
  margin-left: auto;
  min-width: 20px; height: 18px; padding: 0 6px;
  border-radius: 9px;
  background: var(--crit); color: #fff;
  font-size: var(--fs-cap); font-weight: 700;
  display: grid; place-items: center;
}
.nav-spacer { flex: 1; }
.nav-footer { border-top: 1px solid var(--line); padding-top: 8px; }

/* toolbar */
.toolbar {
  grid-area: tool;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px 0 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.toolbar-title {
  font: 600 var(--fs-md) var(--font-display);
  margin-right: 14px;
  white-space: nowrap;
}
.toolbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--ink);
  white-space: nowrap;
  cursor: default;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover:not(:disabled) { background: var(--hover); border-color: var(--line); }
.btn:active:not(:disabled) { background: var(--surface-3); }
.btn:disabled { color: var(--ink-3); }
.btn.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--ink-inverse); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--ink-inverse); }
.btn-outline { border-color: var(--line-strong); background: var(--surface); }
.btn-danger { color: var(--crit); }
.btn-icon { width: 28px; padding: 0; justify-content: center; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.segmented button {
  border: 0; background: none;
  height: 24px; padding: 0 10px;
  font-size: var(--fs-sm);
  border-right: 1px solid var(--line);
  color: var(--ink-2);
}
.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: var(--hover); }
.segmented button.on { background: var(--accent); color: var(--ink-inverse); }

.search {
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-3);
}
.search:focus-within { border-color: var(--focus); box-shadow: inset 0 -1px 0 var(--focus); }
.search svg { width: 14px; height: 14px; flex: none; }
.search input { border: 0; outline: 0; background: none; width: 100%; color: var(--ink); user-select: text; }
.search input::placeholder { color: var(--ink-3); }

/* main + status bar */
.main { grid-area: main; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.view { position: absolute; inset: 0; display: flex; min-height: 0; }

.statusbar {
  grid-area: stat;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  font-size: var(--fs-sm);
  color: var(--ink-2);
  white-space: nowrap;
}
.statusbar .right { margin-left: auto; display: flex; gap: 18px; }
.conn { display: flex; align-items: center; gap: 6px; }
.conn .dot { width: 8px; height: 8px; }

/* ------------------------------------------------------------ primitives */

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--idle); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.crit { background: var(--crit); box-shadow: 0 0 0 3px var(--crit-soft); }
.dot.idle { background: transparent; border: 1.5px solid var(--idle); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  height: 18px; padding: 0 7px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-cap); font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  background: var(--idle-soft); color: var(--ink-2);
}
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.crit { background: var(--crit-soft); color: var(--crit); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

.bars { display: inline-flex; align-items: flex-end; gap: 1.5px; height: 11px; vertical-align: -1px; }
.bars i { width: 3px; background: var(--line-strong); border-radius: 1px; }
.bars i:nth-child(1) { height: 3px; } .bars i:nth-child(2) { height: 5px; }
.bars i:nth-child(3) { height: 8px; } .bars i:nth-child(4) { height: 11px; }
.bars[data-n="1"] i:nth-child(-n+1), .bars[data-n="2"] i:nth-child(-n+2),
.bars[data-n="3"] i:nth-child(-n+3), .bars[data-n="4"] i:nth-child(-n+4) { background: var(--ink-2); }
.bars[data-n="1"] i:nth-child(1) { background: var(--crit); }

.panel { background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.panel-head {
  display: flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 12px;
  border-bottom: 1px solid var(--line);
}
.panel-title { font-weight: 600; }
.panel-body { flex: 1; overflow: auto; min-height: 0; }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 32px 24px; text-align: center; color: var(--ink-2);
}
.empty svg { width: 28px; height: 28px; color: var(--ink-3); margin-bottom: 4px; }
.empty strong { color: var(--ink); font-weight: 600; }

/* --------------------------------------------------------- live: fleet list */

.fleet-pane { width: var(--w-list); flex: none; border-right: 1px solid var(--line); }
.fleet-pane .panel-head { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px; }
.fleet-pane .search { width: 100%; }

.unit {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  column-gap: 10px;
  row-gap: 2px;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  cursor: default;
}
.unit:hover { background: var(--hover); }
.unit.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.unit-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit-age { font-size: var(--fs-sm); color: var(--ink-2); text-align: right; }
.unit-sub {
  grid-column: 2 / 4;
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-sm); color: var(--ink-2);
  overflow: hidden; white-space: nowrap;
}
.unit-sub .sep { color: var(--line-strong); }

/* ----------------------------------------------------------------- map */

.map-pane { flex: 1; position: relative; min-width: 0; background: var(--map-bg); }
.map { position: absolute; inset: 0; background: var(--map-bg); }
.leaflet-container { font: inherit; background: var(--map-bg); }
.leaflet-control-attribution { font-size: 10px; background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--ink-3); }
.leaflet-control-attribution a { color: var(--ink-2); }
:root[data-theme="dark"] .leaflet-control-zoom a { background: var(--surface); color: var(--ink); border-color: var(--line); }

.map-tools {
  position: absolute; top: 10px; right: 10px; z-index: 500;
  display: flex; flex-direction: column; gap: 6px;
}
.map-tools .group {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  overflow: hidden;
}
.map-tools .btn { border-radius: 0; height: 32px; width: 32px; padding: 0; justify-content: center; }
.map-tools .btn + .btn { border-top: 1px solid var(--line); }

/* While the emergency strip is up, the map tools and note move below it. */
.map-pane.has-strip .map-tools { top: 58px; }
.map-pane.has-strip .map-note { top: 60px; }

.map-legend {
  position: absolute; left: 10px; bottom: 22px; z-index: 500;
  display: flex; gap: 14px; align-items: center;
  padding: 6px 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: var(--fs-sm); color: var(--ink-2);
}
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }

.map-note {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 500;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  font-size: var(--fs-sm); color: var(--ink-2);
}

.pin { position: relative; }
.pin-dot {
  position: absolute; left: 50%; top: 50%;
  width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent), 0 1px 3px rgba(0,0,0,0.3);
}
.pin.stale .pin-dot { background: var(--surface); box-shadow: 0 0 0 2px var(--idle); }
.pin.cell .pin-dot { background: var(--surface); box-shadow: 0 0 0 2px var(--accent); }
.pin.crit .pin-dot { background: var(--crit); box-shadow: 0 0 0 1px var(--crit), 0 1px 3px rgba(0,0,0,0.3); }
.pin.crit::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%;
  border: 2px solid var(--crit); opacity: 0;
  animation: ring 1.6s ease-out infinite;
}
.pin.sel .pin-dot { width: 18px; height: 18px; margin: -9px 0 0 -9px; box-shadow: 0 0 0 2px var(--accent), 0 0 0 6px color-mix(in srgb, var(--accent) 22%, transparent); }
.pin-label {
  position: absolute; left: 50%; top: 13px; transform: translateX(-50%);
  padding: 1px 6px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line-strong);
  font-size: var(--fs-cap); font-weight: 600; white-space: nowrap; color: var(--ink);
}
@keyframes ring { 0% { transform: scale(0.4); opacity: 0.9; } 100% { transform: scale(1.2); opacity: 0; } }

/* ------------------------------------------------------------ inspector */

.inspector { width: var(--w-inspector); flex: none; border-left: 1px solid var(--line); }
.insp-head { padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
.insp-title { display: flex; align-items: center; gap: 8px; }
.insp-title h2 { margin: 0; font: 600 var(--fs-lg) var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.insp-meta { margin-top: 4px; font-size: var(--fs-sm); color: var(--ink-2); display: flex; gap: 10px; }
.insp-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

.group-box { padding: 12px 16px 6px; border-bottom: 1px solid var(--line); }
.group-label {
  font-size: var(--fs-cap); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-3); margin-bottom: 6px;
}
.props { display: grid; grid-template-columns: 112px 1fr; column-gap: 12px; }
.props dt, .props dd { margin: 0; padding: 4px 0; font-size: var(--fs); }
.props dt { color: var(--ink-2); }
.props dd { color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: text; }
.props dd.warn { color: var(--warn); }
.props dd.crit { color: var(--crit); font-weight: 600; }

.callout {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 12px 16px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-3);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: var(--fs-sm); color: var(--ink-2);
}
.callout strong { display: block; color: var(--ink); font-size: var(--fs); margin-bottom: 2px; }
.callout.warn { border-left-color: var(--warn); }
.callout.crit { border-left-color: var(--crit); background: var(--crit-soft); }
.callout svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; gap: 8px; align-items: baseline; padding: 5px 0; font-size: var(--fs-sm); border-top: 1px solid var(--line); }
.mini-list li:first-child { border-top: 0; }
.mini-list .when { margin-left: auto; color: var(--ink-3); white-space: nowrap; }

.spark { width: 100%; height: 44px; display: block; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.spark path.area { fill: var(--accent-soft); stroke: none; }
.spark line.ref { stroke: var(--line-strong); stroke-dasharray: 2 3; }

/* --------------------------------------------------------------- tables */

.table-wrap { flex: 1; overflow: auto; background: var(--surface); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--fs-sm); }
table.grid th {
  position: sticky; top: 0; z-index: 1;
  height: 32px; padding: 0 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-strong);
  text-align: left; font-weight: 600; color: var(--ink-2);
  white-space: nowrap;
}
table.grid th.sortable:hover { color: var(--ink); background: var(--surface-3); }
table.grid th .arrow { opacity: 0.7; margin-left: 4px; }
table.grid td {
  height: var(--row); padding: 0 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  user-select: text;
}
table.grid td.num, table.grid th.num { text-align: right; }
table.grid tbody tr:hover td { background: var(--hover); }
table.grid tbody tr.sel td { background: var(--accent-soft); }

/* --------------------------------------------------------------- alerts */

.alert-strip {
  position: absolute; left: 0; right: 0; top: 0; z-index: 700;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: var(--crit); color: #fff;
  font-weight: 600;
}
.alert-strip > svg { width: 18px; height: 18px; flex: none; }
.alert-strip .btn { color: #fff; border-color: rgba(255,255,255,0.5); background: transparent; }
.alert-strip .btn:hover { background: rgba(255,255,255,0.15); border-color: #fff; }
.alert-strip .spacer { flex: 1; }

.sev { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.sev svg { width: 14px; height: 14px; flex: none; }
table.grid td .btn svg { width: 16px; height: 16px; }
table.grid td .btn { height: 24px; }
.sev.critical, .sev.error { color: var(--crit); }
.sev.warn { color: var(--warn); }
.sev.info { color: var(--ink-2); }

/* --------------------------------------------------------------- dialog */

.scrim { position: fixed; inset: 0; background: rgba(15, 20, 26, 0.35); z-index: 2000; display: grid; place-items: center; }
.dialog {
  width: 440px; max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: var(--shadow-pop);
}
.dialog-head { padding: 16px 20px 4px; font: 600 var(--fs-lg) var(--font-display); }
.dialog-body { padding: 8px 20px 16px; color: var(--ink-2); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; background: var(--surface-2); border-top: 1px solid var(--line); border-radius: 0 0 6px 6px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.field input, .field select {
  height: 32px; padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  user-select: text;
}
.field input:focus, .field select:focus { outline: 0; border-color: var(--focus); box-shadow: inset 0 -2px 0 var(--focus); }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 5px; border: 2px solid var(--surface); }
::-webkit-scrollbar-track { background: transparent; }
