/* Stuga Lookout, dark theme with the stuga.it brand colors
   brand blue #5A7CB9, lime #D7DB45, teal #6DA099 / #A1C8CB, font Source Code Pro */

:root {
  color-scheme: dark;
  --bg: #0d121a;
  --surface: #141b26;
  --surface-2: #1a2331;
  --surface-3: #212c3d;
  --line: #263246;
  --line-2: #33415a;
  --text: #e6ebf2;
  --text-2: #b4bfcf;
  --muted: #8593a8;

  --brand: #5A7CB9;
  --brand-hi: #8aa6d8;
  --brand-soft: rgba(90, 124, 185, .16);
  --lime: #D7DB45;
  --lime-ink: #161a05;
  --teal: #6DA099;
  --teal-hi: #A1C8CB;

  --ok: #3fb37f;
  --warn: #e5a33b;
  --bad: #f06368;
  --idle: #6b7890;
  --chart: #5b8fe6;

  --mono: "Source Code Pro", Consolas, "Cascadia Mono", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 8px;
  --sidebar: 290px;
}

* { box-sizing: border-box }
/* min-height, not height: sticky children (topbar) only stick within body's box */
html { height: 100% }
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-hi); text-decoration: none }
a:hover { text-decoration: underline }
code, .mono { font-family: var(--mono) }
h1, h2, h3 { font-family: var(--mono); font-weight: 600; letter-spacing: -.01em; margin: 0 }
h1 { font-size: 22px }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2) }
h3 { font-size: 14px }
::selection { background: var(--brand); color: #fff }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px }

/* ---------- layout */

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: 56px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar::after { /* brand stripe */
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--lime) 0 120px, var(--brand) 120px 60%, var(--teal) 60% 100%);
  opacity: .9;
}
/* Lookout logo: heartbeat line turning into a mountain ridge, beacon above the summit */
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-family: var(--mono); white-space: nowrap }
.brand:hover { text-decoration: none }
.brand .mark { width: 34px; height: 34px; flex: none; display: block }
.brand .wordmark { display: grid; line-height: 1 }
.brand .word { font-weight: 700; font-size: 19px; letter-spacing: -.02em }
.brand .by { font-size: 9px; font-weight: 600; letter-spacing: .3em; text-transform: uppercase; color: var(--muted); margin-top: 3px; padding-left: 1px }
/* the beacon breathes while the live connection is up */
body.live .brand .beacon { animation: beacon 2.4s ease-in-out infinite; transform-origin: 38px 9.5px }
@keyframes beacon { 0%, 100% { opacity: 1; transform: scale(1) } 50% { opacity: .35; transform: scale(.7) } }
body:not(.live) .brand .beacon { fill: var(--bad) }
@media (prefers-reduced-motion: reduce) { body.live .brand .beacon { animation: none } }
.topbar .spacer { flex: 1 }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-family: var(--mono) }
.user { font-size: 13px; color: var(--text-2) }
#logout { display: contents }
#logout[hidden] { display: none }
.menu-btn { display: none }

.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: calc(100vh - 56px); min-height: calc(100dvh - 56px) }
.sidebar {
  position: sticky; top: 56px; height: calc(100vh - 56px); height: calc(100dvh - 56px);
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 12px 8px 24px;
}
main { padding: 24px 28px 64px; min-width: 0 }
.page { max-width: 1400px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr) }
  .sidebar { position: fixed; left: 0; top: 56px; width: min(320px, 88vw); z-index: 15; transform: translateX(-100%); transition: transform .2s; box-shadow: 8px 0 24px rgba(0,0,0,.4) }
  body.nav-open .sidebar { transform: none }
  .menu-btn { display: inline-flex }
  main { padding: 16px 16px 48px }
}
@media (max-width: 520px) {
  .topbar { gap: 8px; padding: 0 10px }
  .user, .conn span:last-child, .hide-sm { display: none }
}

/* ---------- sidebar tree */

.side-search { width: 100%; margin: 0 0 10px }
.tree { list-style: none; margin: 0; padding: 0 }
.tree ul { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 1px solid var(--line); margin-left: 13px }
.tree-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 6px;
  color: var(--text-2); font-size: 13px;
  cursor: pointer; user-select: none; min-width: 0;
}
.tree-row:hover { background: var(--surface-3); color: var(--text); text-decoration: none }
.tree-row.active { background: var(--brand-soft); color: var(--text); box-shadow: inset 2px 0 0 var(--brand-hi) }
.tree-row .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.tree-row .count { font-family: var(--mono); font-size: 11px; color: var(--muted) }
.tree-row.project { color: var(--text); font-family: var(--mono); font-weight: 600; margin-top: 6px }
.tree-row .chev { width: 14px; color: var(--muted); font-size: 10px; text-align: center; flex: none; transition: transform .15s }
.tree-row .chev.open { transform: rotate(90deg) }
.side-section { display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 6px; font: 600 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted) }
.side-links { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px }

/* ---------- status */

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--idle) }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(63,179,127,.15) }
.dot.warn { background: var(--warn) }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px rgba(240,99,104,.18) }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  font: 600 12px var(--mono);
  background: var(--surface-3); color: var(--text-2);
  white-space: nowrap;
}
.pill.ok { color: var(--ok); background: rgba(63,179,127,.12) }
.pill.warn { color: var(--warn); background: rgba(229,163,59,.12) }
.pill.bad { color: var(--bad); background: rgba(240,99,104,.12) }
.pill.brand { color: var(--brand-hi); background: var(--brand-soft) }

/* ---------- controls */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 6px;
  background: var(--surface-2); color: var(--text);
  font: 500 13px var(--sans); cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--brand-hi); background: var(--surface-3); text-decoration: none }
button:disabled { opacity: .45; cursor: not-allowed }
button.primary { background: var(--lime); border-color: var(--lime); color: var(--lime-ink); font-weight: 600 }
button.primary:hover { background: #e3e75c; border-color: #e3e75c }
button.danger { color: var(--bad); border-color: rgba(240,99,104,.4) }
button.danger:hover { background: rgba(240,99,104,.1); border-color: var(--bad) }
button.ghost { background: transparent; border-color: transparent; color: var(--text-2) }
button.ghost:hover { background: var(--surface-3); color: var(--text); border-color: transparent }
button.sm { height: 26px; padding: 0 9px; font-size: 12px }
button.icon { width: 32px; padding: 0 }

input, select, textarea {
  height: 34px; padding: 0 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 6px;
  font: 13px var(--sans);
}
textarea { height: auto; padding: 8px 10px }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-hi); box-shadow: 0 0 0 3px var(--brand-soft) }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted) }
label.check { display: inline-flex; grid-auto-flow: column; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px }
label.check input { height: auto }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden }
.seg button { border: 0; border-radius: 0; height: 28px; background: transparent; color: var(--text-2); font-family: var(--mono); font-size: 12px }
.seg button + button { border-left: 1px solid var(--line-2) }
.seg button.on { background: var(--brand-soft); color: var(--text); box-shadow: inset 0 -2px 0 var(--lime) }

/* ---------- page parts */

.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font: 12px var(--mono); color: var(--muted) }
.crumbs a { color: var(--muted) }
.crumbs a:hover { color: var(--text) }
.crumbs .sep { opacity: .5 }

.head { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between }
.head .title { display: flex; align-items: center; gap: 12px; min-width: 0; flex-wrap: wrap }
.head .actions { display: flex; flex-wrap: wrap; gap: 8px }
.sub-info { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--muted); font-family: var(--mono); margin-top: 6px }
.sub-info b { color: var(--text-2); font-weight: 500 }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
}
.card > .card-h {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.card > .card-b { padding: 16px }
.card.flush > .card-b { padding: 0 }

.grid { display: grid; gap: 16px }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)) }
.grid.charts { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)) }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)) }
@media (max-width: 700px) { .grid.charts, .grid.cards { grid-template-columns: minmax(0, 1fr) } }

.kpi { padding: 14px 16px }
.kpi .k { font-size: 12px; color: var(--muted) }
.kpi .v { font: 600 26px/1.2 var(--mono); margin-top: 4px; font-variant-numeric: tabular-nums }
.kpi .v small { font-size: 14px; color: var(--muted); font-weight: 500 }
.kpi.bad .v { color: var(--bad) }
.kpi.custom { border-color: rgba(215,219,69,.35) }
.kpi.custom .k::before { content: "◆ "; color: var(--lime) }

/* entity cards (project / machine) */
.ecard { display: grid; gap: 12px; padding: 16px; transition: border-color .15s, transform .15s; cursor: pointer; color: inherit }
.ecard:hover { border-color: var(--brand); text-decoration: none }
.ecard .top { display: flex; align-items: center; gap: 10px; justify-content: space-between }
.ecard .name { font: 600 15px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.ecard .meta { font-size: 12px; color: var(--muted); font-family: var(--mono) }
.stats { display: flex; gap: 18px; flex-wrap: wrap }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em }
.stat .v { font: 600 16px var(--mono); font-variant-numeric: tabular-nums }
.stat .v.bad { color: var(--bad) }
.proc-chips { display: flex; flex-wrap: wrap; gap: 6px }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); font: 12px var(--mono); color: var(--text-2); max-width: 100% }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.add-card {
  display: grid; place-items: center; gap: 6px; min-height: 150px;
  border: 1.5px dashed var(--line-2); border-radius: var(--radius);
  color: var(--muted); background: transparent; cursor: pointer; font: 600 13px var(--mono);
  height: auto;
}
.add-card:hover { border-color: var(--lime); color: var(--lime); background: rgba(215,219,69,.04) }
.add-card .plus { font-size: 26px; line-height: 1 }

/* tables */
.tbl-wrap { overflow-x: auto }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle }
th { font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--surface) }
tbody tr:hover { background: var(--surface-2) }
tbody tr:last-child td { border-bottom: 0 }
td.num, th.num { text-align: right; font-family: var(--mono) }
td .pname { font-family: var(--mono); font-weight: 600; color: var(--text) }
td .pid { color: var(--muted); font-family: var(--mono); font-size: 12px }
.custom-val { font-family: var(--mono); font-size: 12px; color: var(--lime) }
.row-actions { display: flex; gap: 6px; justify-content: flex-end }

/* charts */
.chart-card .card-h { padding: 10px 14px }
.chart-card .card-h h3 { display: flex; gap: 8px; align-items: baseline }
.chart-card .now { font: 600 13px var(--mono); color: var(--text) }
.chart-card .now small { color: var(--muted); font-weight: 400 }
.chart-card .card-b { padding: 8px 6px 6px; position: relative }
.chart-card.custom { border-color: rgba(215,219,69,.35) }
.chart-card.custom h3::before { content: "◆"; color: var(--lime); font-size: 11px }
.chart-empty { height: 180px; display: grid; place-items: center; color: var(--muted); font-size: 13px }
.u-legend { display: none }
.uplot { font-family: var(--mono) }
.tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--surface-3); border: 1px solid var(--line-2); border-radius: 6px;
  padding: 6px 9px; font: 12px/1.45 var(--mono); color: var(--text); white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0,0,0,.35); display: none;
}
.tip .t { color: var(--muted) }

/* logs */
.logs {
  height: 360px; overflow: auto;
  padding: 10px 14px;
  font: 12px/1.55 var(--mono);
  background: #0a0e14;
  border-radius: 0 0 var(--radius) var(--radius);
}
.logs .ln { white-space: pre-wrap; word-break: break-word; color: var(--text-2) }
.logs .ln .ts { color: var(--muted) }
.logs .ln .src { color: var(--teal-hi) }
.logs .ln.err { color: var(--bad) }
.logs .empty-hint { color: var(--muted) }
.log-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap }
.log-tools input { height: 28px; width: 180px }

/* events */
.events { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto }
.events li { display: grid; grid-template-columns: 18px 128px minmax(0, 1fr); gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--line); font-size: 13px; align-items: start }
.events li:last-child { border-bottom: 0 }
.events .lv { margin-top: 6px }
.events .when { font: 12px var(--mono); color: var(--muted) }
.events .what { color: var(--text-2); min-width: 0 }
.events .what .mach { color: var(--muted); font-family: var(--mono); font-size: 12px }
.events details { margin-top: 4px }
.events summary { cursor: pointer; color: var(--muted); font-size: 12px }
.events pre { margin: 6px 0 0; padding: 10px; background: #0a0e14; border: 1px solid var(--line); border-radius: 6px; font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; color: var(--text-2); max-height: 300px; overflow: auto }
.events .alert-ev .what { color: var(--text) }
@media (max-width: 600px) { .events li { grid-template-columns: 18px minmax(0, 1fr) } .events .when, .events .what { grid-column: 2 } }

/* info list */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 18px; font-size: 13px; margin: 0 }
.kv dt { color: var(--muted) }
.kv dd { margin: 0; font-family: var(--mono); color: var(--text-2); overflow-wrap: anywhere }

/* modal */
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 12, .7); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(2px) }
.modal { width: min(680px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 24px 60px rgba(0,0,0,.5) }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line) }
.modal-b { padding: 20px; display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) }
/* long commands / URLs must wrap instead of widening the dialog */
.modal-b .grid, .modal-b .steps { grid-template-columns: minmax(0, 1fr) }
.modal-b .steps > li { min-width: 0 }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 10px; color: var(--text-2); font-size: 13px }
.cmd {
  position: relative;
  background: #0a0e14; border: 1px solid var(--line-2); border-left: 3px solid var(--lime);
  border-radius: 6px; padding: 12px 96px 12px 14px;
  font: 13px/1.6 var(--mono); color: var(--text); overflow-wrap: break-word;
}
.cmd .copy { position: absolute; top: 8px; right: 8px }
.cmd .k { color: var(--lime) }
.cmd .s { color: var(--teal-hi) }
.note { font-size: 12px; color: var(--muted); line-height: 1.55 }
.note code { color: var(--text-2) }

/* toast */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px }
.toast { background: var(--surface-3); border: 1px solid var(--line-2); border-left: 3px solid var(--brand-hi); border-radius: 6px; padding: 10px 14px; font-size: 13px; max-width: 380px; box-shadow: 0 8px 24px rgba(0,0,0,.4) }
.toast.error { border-left-color: var(--bad) }
.toast.ok { border-left-color: var(--ok) }

.empty { padding: 32px 16px; text-align: center; color: var(--muted) }
.empty h3 { color: var(--text-2); margin-bottom: 6px }
.muted { color: var(--muted) }
.lime { color: var(--lime) }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; align-items: end }
.err-text { color: var(--bad); font-size: 12px }
.warn-text { color: var(--warn); font-size: 13px }
.hidden { display: none !important }
