*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:             #0d1117;
  --surface:        #161b22;
  --surface-hover:  #1c2128;
  --border:         rgba(255,255,255,0.08);
  --text:           #e6edf3;
  --text-muted:     #8b949e;
  --text-faint:     #484f58;
  --primary:        #40916c;
  --primary-bright: #52b788;
  --primary-dim:    rgba(82,183,136,0.12);
  --danger:         #f85149;
  --danger-dim:     rgba(248,81,73,0.12);
  --warning:        #f6c344;
  --warning-dim:    rgba(246,195,68,0.12);
  --radius:         8px;
  --radius-sm:      4px;
  --sidebar-w:      15.7rem;  /* 220px at 14px base */
}

html {
  /* Scales smoothly: 14px at 1440px wide, 11px floor, 14px ceiling */
  font-size: clamp(11px, 0.972vw, 14px);
}
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.sidebar-header {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo-mark {
  width: 32px; height: 32px;
  background: var(--primary-dim);
  border: 1px solid rgba(82,183,136,0.2);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary-bright);
  flex-shrink: 0;
}
.logo-title { font-size: 14px; font-weight: 700; letter-spacing: 0.08em; }
.logo-sub   { font-size: 10px; color: var(--text-faint); margin-top: -2px; }

.sidebar-nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
  text-decoration: none;
}
.nav-item:hover  { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--primary-dim); color: var(--primary-bright); font-weight: 500; }
.nav-item svg    { flex-shrink: 0; width: 16px; height: 16px; }

.sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ws-indicator { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text-faint); }
.ws-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s, box-shadow 0.3s;
  flex-shrink: 0;
}
.ws-dot.connected    { background: var(--primary-bright); box-shadow: 0 0 6px rgba(82,183,136,0.5); }
.ws-dot.disconnected { background: var(--danger); }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s;
}
.logout-btn:hover { color: var(--danger); }
.logout-btn svg { flex-shrink: 0; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.login-logo-mark {
  width: 48px; height: 48px;
  background: var(--primary-dim);
  border: 1px solid rgba(82,183,136,0.3);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary-bright);
  flex-shrink: 0;
}
.login-brand     { font-size: 20px; font-weight: 700; letter-spacing: 0.08em; }
.login-brand-sub { font-size: 11px; color: var(--text-faint); margin-top: -2px; }
.login-hint      { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; }
.login-field     { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.login-label     { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.login-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.login-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); }
.login-input::placeholder { color: var(--text-faint); }
.login-error { font-size: 12px; color: var(--danger); min-height: 18px; margin-bottom: 4px; }
.login-btn { width: 100%; justify-content: center; margin-top: 4px; padding: 10px; font-size: 14px; }

/* ── Main ────────────────────────────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; overflow-x: hidden; min-width: 0; }
.page { padding: 24px; max-width: 1400px; margin: 0 auto; min-width: 0; }

.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ── KPI Grid ────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: default;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}
.kpi-card:hover {
  border-color: rgba(82,183,136,0.3);
  box-shadow: 0 0 0 1px rgba(82,183,136,0.15), 0 8px 24px rgba(64,145,108,0.15);
  transform: translateY(-1px);
}
.kpi-label { font-size: 10px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 10px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1; }
.kpi-unit  { font-size: 12px; color: var(--text-muted); margin-left: 3px; }
.kpi-sub   { font-size: 11px; color: var(--primary-bright); margin-top: 6px; }

/* ── Floor Grid ──────────────────────────────────────────────────────── */
.floor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}
.floor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.floor-card:hover {
  border-color: rgba(82,183,136,0.4);
  box-shadow: 0 0 0 1px rgba(82,183,136,0.15);
}
.floor-name   { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.floor-meta   { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.floor-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  font-size: 10px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  border: 1px solid;
  white-space: nowrap;
}
.badge-green  { background: var(--primary-dim);    color: var(--primary-bright); border-color: rgba(82,183,136,0.3); }
.badge-yellow { background: var(--warning-dim);    color: var(--warning);        border-color: rgba(246,195,68,0.3); }
.badge-red    { background: var(--danger-dim);     color: var(--danger);         border-color: rgba(248,81,73,0.3);  }
.badge-gray   { background: rgba(255,255,255,0.05); color: var(--text-muted);   border-color: var(--border); }

/* ── Layouts ─────────────────────────────────────────────────────────── */
.two-col   { display: grid; grid-template-columns: 18.6rem 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ── Point List ──────────────────────────────────────────────────────── */
.point-list { overflow-y: auto; }
.point-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  gap: 8px;
}
.point-item:hover  { background: var(--surface-hover); }
.point-item.active { background: var(--primary-dim); }
.point-item:last-child { border-bottom: none; }
.point-name   { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.point-bacnet { font-size: 10px; font-family: 'Consolas', 'SF Mono', monospace; color: var(--text-faint); opacity: 0.7; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.point-ddc    { font-size: 10px; color: var(--text-faint); margin-top: 1px; opacity: 0.55; }
.point-value { font-size: 12px; font-weight: 600; color: var(--primary-bright); white-space: nowrap; text-align: right; min-width: 70px; }
.point-value.stale { color: var(--text-faint); }

/* flash when a search result is highlighted */
@keyframes row-flash {
  0%   { background: rgba(82,183,136,0.18); }
  100% { background: transparent; }
}
.search-highlight { animation: row-flash 2s ease-out; }

/* ── Search ──────────────────────────────────────────────────────────── */
.search-input { height: 28px; font-size: 11px !important; }

.search-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
}

.search-suggestion {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.search-suggestion:last-child { border-bottom: none; }
.search-suggestion:hover,
.search-suggestion.focused    { background: var(--surface-hover); }

.sugg-label  { font-size: 12px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sugg-meta   { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.sugg-bacnet { font-size: 10px; font-family: 'Consolas', 'SF Mono', monospace; color: var(--text-faint); }
.sugg-floor  { font-size: 10px; color: var(--text-faint); background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; }
.sugg-unit   { font-size: 10px; color: var(--text-faint); }

mark.search-hi {
  background: rgba(82,183,136,0.25);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
  font-style: normal;
}

/* ── Detail Panel ────────────────────────────────────────────────────── */
.detail-metric { font-size: 32px; font-weight: 700; }
.detail-unit   { font-size: 16px; color: var(--text-muted); margin-left: 4px; }
.detail-ts     { font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.chart-wrapper { position: relative; height: 190px; margin-top: 14px; }

/* ── Controls / Forms ────────────────────────────────────────────────── */
.control-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 14px; }
.form-group  { display: flex; flex-direction: column; gap: 4px; }
.form-label  { font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.form-input {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  padding: 7px 10px; font-size: 13px; outline: none;
  transition: border-color 0.15s;
  width: 100px;
}
.form-input:focus { border-color: var(--primary); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; border: 1px solid;
  cursor: pointer; transition: opacity 0.15s; white-space: nowrap;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary-bright); color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: 0.82; }
.btn-danger  { background: var(--danger-dim); border-color: rgba(248,81,73,0.4); color: var(--danger); }
.btn-danger:hover:not(:disabled)  { opacity: 0.8; }
.btn-ghost   { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover:not(:disabled)   { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Period Selector ─────────────────────────────────────────────────── */
.period-bar {
  display: flex; gap: 3px;
  background: var(--bg); padding: 3px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.period-btn {
  padding: 4px 12px; border-radius: 4px; font-size: 12px; font-weight: 500;
  border: none; background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.period-btn:hover  { color: var(--text); }
.period-btn.active { background: var(--surface); color: var(--text); }

/* ── Alerts ──────────────────────────────────────────────────────────── */
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.alert-title { font-size: 13px; font-weight: 600; }
.alert-meta  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Control Log ─────────────────────────────────────────────────────── */
.log-list { display: flex; flex-direction: column; gap: 5px; }
.log-item {
  display: flex; gap: 10px; padding: 8px 12px;
  background: var(--bg); border-radius: var(--radius-sm);
  font-size: 12px; border: 1px solid var(--border);
}
.log-ts     { color: var(--text-faint); white-space: nowrap; flex-shrink: 0; }
.log-action { color: var(--text); font-weight: 500; flex-shrink: 0; }
.log-msg    { color: var(--text-muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-ok     { color: var(--primary-bright); flex-shrink: 0; }
.log-fail   { color: var(--danger); flex-shrink: 0; }

/* ── Section Header ──────────────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title  { font-size: 14px; font-weight: 600; }
.section-sub    { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Empty / Loading ─────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 32px;
  color: var(--text-faint); font-size: 13px; gap: 10px;
  text-align: center;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary-bright);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Miscellaneous ───────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.sep-label { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.08em; padding: 6px 12px 4px; }

.floor-btn {
  width: 100%; padding: 7px 12px; border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-muted); cursor: pointer;
  transition: background 0.12s, color 0.12s; text-align: left;
  border: none; background: transparent; display: flex; justify-content: space-between; align-items: center;
}
.floor-btn:hover  { background: var(--surface-hover); color: var(--text); }
.floor-btn.active { background: var(--primary-dim); color: var(--primary-bright); font-weight: 500; }

.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary-bright);
  box-shadow: 0 0 6px rgba(82,183,136,0.5);
  animation: pulse-anim 2s ease-in-out infinite;
}
@keyframes pulse-anim {
  0%, 100% { box-shadow: 0 0 4px rgba(82,183,136,0.4); }
  50%       { box-shadow: 0 0 10px rgba(82,183,136,0.8); }
}

/* ── Flash animation for live value updates ──────────────────────────── */
@keyframes flash-green {
  0%   { color: var(--primary-bright); }
  100% { color: var(--text); }
}
.value-flash { animation: flash-green 1.2s ease-out forwards; }

/* ── Toast notifications ─────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 16px;
  font-size: 13px; color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: toast-in 0.2s ease-out;
  max-width: 300px;
}
.toast.success { border-color: rgba(82,183,136,0.5); }
.toast.error   { border-color: rgba(248,81,73,0.5); color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ── Scrollbar ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Responsive ──────────────────────────────────────────────────────── */
/* fluid font-size handles most scaling — these only change layout structure */
@media (max-width: 960px) {
  .two-col   { grid-template-columns: 1fr; }
  .three-col { grid-template-columns: 1fr 1fr; }
  .kpi-grid  { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .sidebar { width: 56px; }
  .sidebar .logo-title, .sidebar .logo-sub, .nav-item span, .sidebar-footer span { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/*  Multi-variable Compare  */
.compare-toggle-active {
  color: var(--primary-bright) !important;
  border-color: rgba(82,183,136,0.45) !important;
  background: var(--primary-dim) !important;
}
.compare-dot-btn {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text-faint);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 6px;
  padding: 0;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.compare-dot-btn:hover { border-color: var(--text-muted); transform: scale(1.2); }
.compare-dot-btn.active {
  background: var(--dot-c, var(--primary-bright));
  border-color: var(--dot-c, var(--primary-bright));
}
.cmp-legend-item {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cmp-c, var(--primary));
  border-radius: var(--radius-sm);
  padding: 5px 8px 5px 7px;
  font-size: 11px; max-width: 260px;
}
.cmp-legend-name {
  color: var(--text); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 160px; flex: 1;
}
.cmp-legend-unit { color: var(--text-faint); font-size: 10px; flex-shrink: 0; }
.cmp-legend-rm {
  background: transparent; border: none;
  color: var(--text-faint); cursor: pointer;
  font-size: 10px; padding: 0 1px; line-height: 1;
  flex-shrink: 0; transition: color 0.12s;
}
.cmp-legend-rm:hover { color: var(--danger); }

/*  Live Operations  unified plot  */
.live-page { display: flex; flex-direction: column; height: 100%; }
.live-grid {
  display: grid;
  grid-template-columns: 14.3rem 20.7rem 1fr;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.plot-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--text-faint);
  background: transparent;
  flex-shrink: 0;
  margin-right: 7px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: inline-block;
}
.plot-active-row { background: rgba(82,183,136,0.06) !important; }
.plot-active-row:hover { background: rgba(82,183,136,0.10) !important; }
.lv-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
}
.lv-header { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.lv-name {
  font-size: 11px; color: var(--text-muted); font-weight: 500;
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lv-val  { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1; }
.lv-unit { font-size: 11px; color: var(--text-faint); margin-left: 2px; }
.lv-ts   { font-size: 10px; color: var(--text-faint); margin-top: 3px; }
.lv-rm {
  background: none; border: none;
  color: var(--text-faint); cursor: pointer;
  font-size: 10px; padding: 0 2px; line-height: 1;
  flex-shrink: 0; transition: color 0.12s;
}
.lv-rm:hover { color: var(--danger); }
@media (max-width: 860px)  { .live-grid { grid-template-columns: 1fr; overflow-y: auto; } }
