:root {
  --bg: #070b12;
  --panel: #0e1520;
  --panel-2: #131c2a;
  --line: #1f2b3d;
  --text: #dce6f2;
  --muted: #7d8da3;
  --accent: #35d6c4;
  --ok: #3ccf7a;
  --warn: #f2b33d;
  --crit: #ff4d5e;
  --info: #4da3ff;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #0f1c2e 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }

/* ---------- yläpalkki ---------- */
/* Yläpalkki samaan malliin kuin Paalu Kassassa (slate-800, h-12, text-sm). */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; height: 48px; padding: 0 16px;
  background: #1e293b; color: #e2e8f0; font-size: 14px;
}
a.brand { display: flex; align-items: center; gap: 8px; flex: none; color: #fff; text-decoration: none; }
a.brand img { display: block; height: 18px; width: auto; filter: brightness(0) invert(1); }
.brand-app { font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.topbar-context { color: #e2e8f0; white-space: nowrap; }
.topbar-context::before { content: "|"; color: #64748b; margin-right: 16px; }
.tb-btn { background: none; border: 0; border-radius: 4px; padding: 4px 8px; cursor: pointer; color: #e2e8f0; white-space: nowrap; }
.tb-btn:hover { background: #334155; }
.tb-icon { display: grid; place-items: center; }
.tb-icon svg { width: 20px; height: 20px; }
.tb-user { white-space: nowrap; }
.tb-user b { color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .14em; white-space: nowrap; }
.brand-mark { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand-sep { color: var(--line); }
.brand-sub { color: var(--accent); font-weight: 600; }
.brand-lg { font-size: 18px; justify-content: center; margin-bottom: 24px; }
.level-badge {
  padding: 6px 12px; border-radius: 6px; font-weight: 700; letter-spacing: .08em; font-size: 12px;
  border: 1px solid currentColor; white-space: nowrap;
}
.level-normaali { color: var(--ok); background: rgba(60, 207, 122, .08); }
.level-korotettu { color: var(--warn); background: rgba(242, 179, 61, .1); }
.level-kriittinen { color: var(--crit); background: rgba(255, 77, 94, .14); animation: pulse 1.6s infinite; }
.level-unknown { color: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(255, 77, 94, .2); } }
/* Näkymävälilehdet Kassan kategoriapainikkeiden tapaan. */
.view-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 14px 0; }
.view-tabs button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 16px; cursor: pointer;
  color: var(--text); font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap;
}
.view-tabs button:hover { border-color: #475569; }
.view-tabs button.active { background: #e2e8f0; color: #1e293b; border-color: #e2e8f0; }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.clock { font-variant-numeric: tabular-nums; color: #e2e8f0; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.ok { background: var(--ok); }
.conn.err { background: var(--crit); }
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #04211e; border-color: var(--accent); font-weight: 600; }
.btn-danger { color: var(--crit); }
.btn-ghost { background: none; color: var(--muted); }
.edit-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 8px 16px;
  background: #0b1a22; border-bottom: 1px solid var(--accent);
}
.edit-bar[hidden] { display: none; }
.edit-bar select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; margin-left: 6px; }
.spacer { flex: 1; }
main { padding: 8px; }

/* ---------- widgetit ---------- */
.grid-stack-item-content.widget {
  display: flex; flex-direction: column; overflow: hidden;
  background: linear-gradient(180deg, var(--panel) 0%, #0b111b 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.widget-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.widget-head .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.widget-head .count { color: var(--text); font-family: var(--mono); letter-spacing: 0; }
.widget-head select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; font-size: 11px; text-transform: none; letter-spacing: 0; }
.widget-remove { display: none; background: none; border: 0; color: var(--crit); cursor: pointer; font-size: 16px; line-height: 1; }
body.editing .widget-remove { display: block; }
body.editing .grid-stack-item-content.widget { border-style: dashed; border-color: var(--accent); cursor: move; }
.widget-body { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; }
.widget-body.flush { padding: 0; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; }
.err-note { color: var(--warn); font-size: 12px; padding: 4px 0; }

/* listat */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid rgba(31, 43, 61, .6); }
.list li:last-child { border-bottom: 0; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.crit { background: var(--crit); box-shadow: 0 0 8px var(--crit); }
.dot.info { background: var(--info); }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.li-sub { color: var(--muted); font-size: 12px; }
.li-side { color: var(--muted); font-family: var(--mono); font-size: 12px; white-space: nowrap; text-align: right; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; letter-spacing: .04em; }
.tag.crit { background: rgba(255, 77, 94, .15); color: var(--crit); }
.tag.warn { background: rgba(242, 179, 61, .15); color: var(--warn); }
.tag.ok { background: rgba(60, 207, 122, .12); color: var(--ok); }
.tag.muted { background: var(--panel-2); color: var(--muted); }

/* tunnusluvut */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); grid-auto-rows: 1fr; gap: 8px; height: 100%; }
.kpi { min-height: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; }
.kpi-label { color: var(--muted); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value { font-family: var(--mono); font-size: 26px; font-weight: 600; line-height: 1.1; }
.kpi-value.crit { color: var(--crit); } .kpi-value.warn { color: var(--warn); } .kpi-value.ok { color: var(--ok); }

/* tilannetaso-widget */
.level-big { height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.level-big .lv { font-size: 26px; font-weight: 800; letter-spacing: .1em; }
.level-big .lv.normaali { color: var(--ok); } .level-big .lv.korotettu { color: var(--warn); } .level-big .lv.kriittinen { color: var(--crit); }
.level-big .why { color: var(--muted); font-size: 12px; }

/* tietoturva */
.gauge { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.gauge-ring { --p: 0; width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--c, var(--ok)) calc(var(--p) * 1%), var(--panel-2) 0); }
.gauge-ring span { width: 66px; height: 66px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font-family: var(--mono); font-size: 20px; font-weight: 700; }

/* kello */
.big-clock { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.big-clock .t { font-family: var(--mono); font-size: 44px; font-weight: 600; letter-spacing: .04em; }
.big-clock .d { color: var(--muted); text-transform: capitalize; }

/* kamera */
.cam { position: relative; height: 100%; background: #000; display: grid; place-items: center; text-align: center; color: var(--muted); }
.cam .cam-icon { font-size: 30px; opacity: .5; }
.cam .cam-label { position: absolute; left: 8px; top: 6px; font-size: 11px; color: var(--text); background: rgba(0,0,0,.5); padding: 2px 6px; border-radius: 4px; }
.cam .rec { position: absolute; right: 8px; top: 8px; font-size: 11px; }
.cam p { margin: 6px 16px 0; font-size: 12px; }

/* tulossa */
.coming { height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 6px; color: var(--muted); }
.coming strong { color: var(--text); }

/* kartta */
.map { width: 100%; height: 100%; background: #0a0f17; }
.leaflet-container { font: inherit; background: #0a0f17; }
/* Vaalea OSM-kartta tummaksi tilannekuvaan sopivaksi. */
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.35); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-2); color: var(--text); }
.leaflet-control-attribution { background: rgba(7, 11, 18, .7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }

/* kirjautuminen */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px 28px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 26px; color: #fff; }
.login-brand img { height: 22px; filter: brightness(0) invert(1); }
.login-brand .brand-app { font-size: 22px; }
.login-ctx { color: var(--muted); font-size: 15px; }
.login-ctx::before { content: "|"; color: #475569; margin: 0 10px 0 4px; }
.ms-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px; height: 44px; padding: 0 16px;
  background: #fff; color: #5e5e5e; border: 1px solid #8c8c8c; border-radius: 4px;
  font-family: "Segoe UI", system-ui, sans-serif; font-size: 15px; font-weight: 600; text-decoration: none;
}
.ms-btn:hover { background: #f3f3f3; }
.ms-btn svg { width: 21px; height: 21px; flex: none; }
.login-card .login-error { margin-top: 14px; font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; letter-spacing: .04em; }
.login-card input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 15px; }
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card .btn { padding: 10px; margin-top: 6px; }
.login-error { color: var(--crit); min-height: 1.2em; margin: 0; }
.login-foot { color: var(--muted); font-size: 11px; text-align: center; margin: 20px 0 0; }

/* TV-tila */
body.tv #btn-edit, body.tv .view-tabs, body.tv #btn-logout { display: none; }

@media (max-width: 760px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .topbar-context, .tb-user, #btn-edit, .clock { display: none; }
  .level-badge { font-size: 10px; padding: 4px 8px; }
}
