:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f0f3f9; --border: #d9dfeb; --text: #121826; --muted: #5b6577;
  --primary: #0b3d91; --primary-ink: #ffffff; --primary-soft: #e6edfb; --accent: #0e8f8a;
  --ok: #1a9b5a; --warn: #d98a00; --crit: #d6293e; --off: #8b94a6; --info: #2f6fdb;
  --ok-soft: #e3f5ec; --warn-soft: #fdf1d8; --crit-soft: #fde6e9; --off-soft: #eceef3;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
  --radius: 10px; --nav-w: 218px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0d121c; --surface: #151c29; --surface-2: #1b2434; --border: #28344a; --text: #e8edf6; --muted: #98a3b8;
  --primary: #5b8def; --primary-ink: #08101f; --primary-soft: #1b2a47; --accent: #34c7c0;
  --ok: #3ccf86; --warn: #f2b134; --crit: #ff6477; --off: #7c869a; --info: #6ea3ff;
  --ok-soft: #12301f; --warn-soft: #36290c; --crit-soft: #3a1620; --off-soft: #222a3a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d121c; --surface: #151c29; --surface-2: #1b2434; --border: #28344a; --text: #e8edf6; --muted: #98a3b8;
    --primary: #5b8def; --primary-ink: #08101f; --primary-soft: #1b2a47; --accent: #34c7c0;
    --ok: #3ccf86; --warn: #f2b134; --crit: #ff6477; --off: #7c869a; --info: #6ea3ff;
    --ok-soft: #12301f; --warn-soft: #36290c; --crit-soft: #3a1620; --off-soft: #222a3a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 10px; } h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: var(--mono); } .right { text-align: right; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* shell */
.shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); grid-template-rows: 56px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { height: 38px; width: 38px; display: block; border-radius: 50%; background: #fff; object-fit: cover; box-shadow: 0 0 0 1px var(--border); }
.brand .logo-fallback { width: 34px; height: 34px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; }
.brand .t1 { font-weight: 700; font-size: 15px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .t2 { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.nav { background: var(--surface); border-right: 1px solid var(--border); padding: 10px 8px; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; background: var(--crit); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.nav .sep { height: 1px; background: var(--border); margin: 8px 6px; }
.main { overflow-y: auto; overflow-x: hidden; min-width: 0; padding: 20px 24px 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }

/* components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .cols-auto { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.split.xray { grid-template-columns: minmax(0, 2.2fr) minmax(260px, 1fr); }
.split.assets { grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); }
.page-head h1 { overflow-wrap: anywhere; }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 14px; align-items: start; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; } .row.tight { gap: 6px; } .row.between { justify-content: space-between; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, var(--border)); }
.btn.sm { padding: 4px 9px; font-size: 12px; } .btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; } .seg button.active { background: var(--primary); color: var(--primary-ink); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
textarea { min-height: 70px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; } label.field > span { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; margin: 4px 0 12px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--off-soft); color: var(--off); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn, .badge.warning { background: var(--warn-soft); color: var(--warn); }
.badge.crit, .badge.critical { background: var(--crit-soft); color: var(--crit); } .badge.info { background: var(--primary-soft); color: var(--info); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--off); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.crit { background: var(--crit); }
.dot.run { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; } table.t tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.15; } .kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v.ok { color: var(--ok); } .kpi .v.warn { color: var(--warn); } .kpi .v.crit { color: var(--crit); }
.bar { height: 7px; border-radius: 4px; background: var(--off-soft); overflow: hidden; } .bar > i { display: block; height: 100%; border-radius: 4px; background: var(--ok); }
.bar > i.warn { background: var(--warn); } .bar > i.crit { background: var(--crit); } .bar > i.info { background: var(--info); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; font-weight: 500; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); } .tabs a:hover { text-decoration: none; color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert-box { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 12px; }
.alert-box.warn { background: var(--warn-soft); border-color: var(--warn); } .alert-box.err { background: var(--crit-soft); border-color: var(--crit); }
.alert-box.ok { background: var(--ok-soft); border-color: var(--ok); }
pre.code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 6px 0; white-space: pre-wrap; word-break: break-all; }

/* modal / drawer / toast */
.overlay { position: fixed; inset: 0; background: rgba(8,12,22,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: min(560px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { width: min(860px, 100%); }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal header h2 { margin: 0; } .modal .body { padding: 16px 18px; overflow-y: auto; } .modal footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--surface); border-left: 1px solid var(--border); box-shadow: -10px 0 40px rgba(0,0,0,.25); z-index: 40; display: flex; flex-direction: column; }
.drawer header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.drawer .body { padding: 16px 18px; overflow-y: auto; flex: 1; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); animation: slidein .2s ease-out; cursor: pointer; }
.toast.ok { border-left-color: var(--ok); } .toast.warn { border-left-color: var(--warn); } .toast.crit, .toast.err { border-left-color: var(--crit); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* x-ray */
.xray-wrap { position: relative; width: 100%; aspect-ratio: 5 / 3; background: #0b1426; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); user-select: none; }
.xray-wrap img.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.xray-wrap.adding { cursor: crosshair; }
.hot { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; border: 3px solid #fff; background: var(--off); box-shadow: 0 0 0 2px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.45); cursor: pointer; transition: transform .1s; z-index: 3; }
.hot:hover, .hot.sel { transform: scale(1.25); z-index: 6; }
.hot.ok { background: var(--ok); } .hot.warn { background: var(--warn); } .hot.crit { background: var(--crit); animation: pulse 1.2s infinite; } .hot.offline, .hot.unknown { background: var(--off); }
.hot.drag { cursor: grabbing; }
@keyframes pulse { 0% { box-shadow: 0 0 0 2px rgba(0,0,0,.35), 0 0 0 0 rgba(214,41,62,.7); } 100% { box-shadow: 0 0 0 2px rgba(0,0,0,.35), 0 0 0 16px rgba(214,41,62,0); } }
.part-box { position: absolute; border: 2px dashed rgba(125,211,252,.8); border-radius: 8px; pointer-events: none; z-index: 2; }
.part-box span { position: absolute; top: -9px; left: 8px; font-size: 10px; background: #0b1426; color: #7dd3fc; padding: 0 5px; border-radius: 3px; }
.tip { position: absolute; z-index: 10; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: var(--shadow); font-size: 12px; pointer-events: none; min-width: 170px; transform: translate(14px, -50%); }
.tip b { display: block; margin-bottom: 3px; }
.sensor-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.sensor-row:hover, .sensor-row.sel { background: var(--surface-2); border-color: var(--border); }
.sensor-row .nm { flex: 1; min-width: 0; } .sensor-row .nm div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* heat grid */
.room-title { display: flex; align-items: baseline; gap: 8px; margin: 18px 0 8px; } .room-title h2 { margin: 0; }
.mtiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.mtile { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--off); border-radius: 8px; padding: 9px 11px; cursor: pointer; display: block; color: var(--text); }
.mtile:hover { text-decoration: none; box-shadow: var(--shadow); border-color: var(--primary); }
.mtile.ok { border-left-color: var(--ok); } .mtile.warn { border-left-color: var(--warn); } .mtile.crit { border-left-color: var(--crit); }
.mtile .code { font-weight: 700; } .mtile .nm { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mtile .score { font-size: 20px; font-weight: 700; } .mtile .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 11px; color: var(--muted); }

/* chart */
.chart { width: 100%; height: 260px; position: relative; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .grid line { stroke: var(--border); stroke-width: 1; } .chart text { fill: var(--muted); font-size: 10.5px; }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 1.8; } .chart .area { fill: color-mix(in srgb, var(--primary) 14%, transparent); }
.chart .lim-warn { stroke: var(--warn); stroke-dasharray: 5 4; } .chart .lim-crit { stroke: var(--crit); stroke-dasharray: 5 4; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.sw { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #0b3d91 0%, #0a2a66 55%, #0e8f8a 160%); }
.login-card { background: var(--surface); border-radius: 14px; padding: 28px 28px 22px; width: min(400px, 100%); box-shadow: 0 25px 60px rgba(0,0,0,.35); }
.login-card .logos { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; } .login-card .logos img { height: 56px; width: 56px; border-radius: 50%; background: #fff; object-fit: cover; box-shadow: 0 0 0 1px var(--border); }

@media (max-width: 1000px) { .split, .split.xray, .split.assets { grid-template-columns: minmax(0, 1fr); } .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: 56px auto 1fr; }
  .nav { display: flex; overflow-x: auto; padding: 6px; border-right: 0; border-bottom: 1px solid var(--border); } .nav a { white-space: nowrap; margin: 0 2px; } .nav .sep { display: none; }
  .main { padding: 14px 14px 40px; } .cols-2, .cols-3, .cols-4, .form-grid { grid-template-columns: 1fr; }
  .brand .t2 { display: none; }
  .brand .t1 { max-width: 150px; }
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar .btn.sm { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
