/* =============================================================
   SHESS — "Breaker Panel" design system (v2 — "Voltage" palette)
   ---------------------------------------------------------------
   One shared identity for a utility-ops dashboard: hostel wardens
   watching IoT smart-plug energy meters. Every status in the app —
   a plug online/offline, a room active/suspended, an alert open/
   resolved, usage within/over baseline — renders through the same
   small glowing "LED" dot, echoing the indicator lights on the
   physical meters and breakers this system watches.

   Palette (named — variable names kept from v1 for stability, only
   the hex values were refreshed, so no markup/class names changed):
     ink       #0F172A  near-black cool-navy panel body / sidebar / text
     surface   #F1F5F9  cool pale page background
     brass     #4F46E5  signature accent — electric indigo ("current")
     volt      #16A34A  "good" status — on / normal / within baseline
     breaker   #DC2626  "attention" status — heavy / over baseline
     line      #E2E8F0  hairline borders

   Type: IBM Plex Sans (UI + headings), IBM Plex Mono (numbers —
   watts, kWh, MAC addresses, timestamps read like a meter display).
   ============================================================= */

:root {
  --ink: #0F172A;
  --ink-2: #1E293B;
  --ink-muted: #64748B;
  --surface: #F1F5F9;
  --card: #FFFFFF;
  --line: #E2E8F0;

  --brass: #4F46E5;
  --brass-deep: #4338CA;
  --brass-tint: #E5E3FB;

  --volt: #16A34A;
  --volt-deep: #15803D;
  --volt-tint: #DCFCE7;

  --breaker: #DC2626;
  --breaker-deep: #B91C1C;
  --breaker-tint: #FEE2E2;

  --slate: #64748B;
  --slate-deep: #334155;
  --slate-tint: #E7EAF0;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 24px -16px rgba(15, 23, 42, .18);

  /* Re-theme Bootstrap's own CSS-variable-driven components (buttons,
     badges, alerts, borders, links) so every existing .btn-*/.bg-*/
     .alert-* class across the app picks up this palette automatically. */
  --bs-font-sans-serif: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--surface);
  --bs-border-color: var(--line);
  --bs-link-color: var(--brass-deep);
  --bs-link-hover-color: var(--brass);

  --bs-primary: var(--brass);
  --bs-primary-rgb: 79, 70, 229;
  --bs-success: var(--volt);
  --bs-success-rgb: 22, 163, 74;
  --bs-danger: var(--breaker);
  --bs-danger-rgb: 220, 38, 38;
  --bs-warning: #D97706;
  --bs-warning-rgb: 217, 119, 6;
  --bs-secondary: var(--ink-muted);
  --bs-secondary-rgb: 100, 116, 139;
  --bs-dark: var(--ink);
  --bs-dark-rgb: 15, 23, 42;

  --bs-success-bg-subtle: var(--volt-tint);
  --bs-success-border-subtle: #BBF7D0;
  --bs-success-text-emphasis: var(--volt-deep);
  --bs-danger-bg-subtle: var(--breaker-tint);
  --bs-danger-border-subtle: #FECACA;
  --bs-danger-text-emphasis: var(--breaker-deep);
  --bs-warning-bg-subtle: #FEF3C7;
  --bs-warning-border-subtle: #FDE68A;
  --bs-warning-text-emphasis: #92400E;
  --bs-info-bg-subtle: #E0F2FE;
  --bs-info-border-subtle: #BAE6FD;
  --bs-info-text-emphasis: #075985;
}

* { box-sizing: border-box; }

html, body {
  background: var(--surface);
  color: var(--ink);
}

body { font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif; }

h1, h2, h3, h4, h5, h6 {
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.mono, td.mono, .meter-value, code {
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
}

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* ===== App shell ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: var(--ink);
  color: #C7CCD6;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, .06);
  transition: width .18s ease;
}

.sidebar .brand-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: 1.35rem 1rem 1.1rem 1.25rem;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: #fff;
  text-decoration: none;
  flex: 1;
  min-width: 0;
}
.sidebar .brand:hover { color: #fff; }
.sidebar .brand svg { flex-shrink: 0; color: var(--brass); }
.sidebar .brand-label { display: block; min-width: 0; overflow: hidden; }
.sidebar .brand-name { display: block; font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; line-height: 1.15; white-space: nowrap; }
.sidebar .brand-sub { display: block; font-size: .66rem; text-transform: uppercase; letter-spacing: .09em; color: #6B7280; margin-top: 2px; white-space: nowrap; }

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid rgba(125, 211, 252, .35);
  background: var(--ink-2);
  color: #7DD3FC;
  transition: transform .18s ease, background-color .15s ease, color .15s ease, border-color .15s ease;
}
.sidebar-toggle:hover { background: #0EA5E9; border-color: #0EA5E9; color: #fff; }
.sidebar-toggle i { font-size: .9rem; }

.sidebar-nav { list-style: none; margin: .5rem 0 0; padding: 0 .75rem; flex: 1; }
.sidebar-nav li + li { margin-top: 2px; }
.sidebar-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: #AEB4C0;
  text-decoration: none;
  font-size: .89rem;
  font-weight: 500;
  transition: background-color .15s ease, color .15s ease;
}
.sidebar-nav a:hover { background: var(--ink-2); color: #fff; }
.sidebar-nav a.active { background: var(--ink-2); color: #fff; }
.sidebar-nav a.active .nav-led { background: var(--brass); box-shadow: 0 0 0 3px rgba(79, 70, 229, .28); }
.sidebar-nav .nav-led { width: 6px; height: 6px; border-radius: 50%; background: #3A4150; flex-shrink: 0; }
.sidebar-nav .bi { font-size: 1rem; width: 1.1rem; text-align: center; flex-shrink: 0; }
.sidebar-nav .nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav .nav-count {
  margin-left: auto;
  background: var(--breaker);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  padding: .12rem .42rem;
  border-radius: 999px;
}

.sidebar-foot { padding: 1rem 1.25rem 1.35rem; border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar-foot .user-name { color: #fff; font-size: .85rem; font-weight: 600; overflow-wrap: anywhere; }
.sidebar-foot .user-role {
  display: inline-block;
  margin-top: 3px;
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--brass);
  font-weight: 700;
}
.sidebar-foot .btn-logout {
  margin-top: .85rem;
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  color: #AEB4C0;
  text-decoration: none;
}
.sidebar-foot .btn-logout:hover { color: #fff; }

/* ===== Collapsible side panel (desktop only — the mobile off-canvas
   drawer already opens/closes like a panel and keeps full labels) ===== */
@media (min-width: 992px) {
  html[data-sidebar="collapsed"] .sidebar { width: 76px; }

  html[data-sidebar="collapsed"] .sidebar .brand-row {
    flex-direction: column;
    padding: 1.1rem .5rem;
    gap: .65rem;
  }
  html[data-sidebar="collapsed"] .sidebar .brand { justify-content: center; flex: 0 0 auto; }
  html[data-sidebar="collapsed"] .sidebar .brand-label { display: none; }
  html[data-sidebar="collapsed"] .sidebar .sidebar-toggle { transform: rotate(180deg); }

  html[data-sidebar="collapsed"] .sidebar .sidebar-nav { padding: 0 .5rem; }
  html[data-sidebar="collapsed"] .sidebar .sidebar-nav a { justify-content: center; padding: .65rem; gap: 0; }
  html[data-sidebar="collapsed"] .sidebar .sidebar-nav .nav-led { display: none; }
  html[data-sidebar="collapsed"] .sidebar .sidebar-nav .nav-label { display: none; }
  html[data-sidebar="collapsed"] .sidebar .sidebar-nav .nav-count {
    position: absolute;
    top: 2px;
    right: 2px;
    margin-left: 0;
    font-size: .6rem;
    padding: .05rem .3rem;
  }

  html[data-sidebar="collapsed"] .sidebar .sidebar-foot { padding: 1rem .5rem 1.2rem; }
  html[data-sidebar="collapsed"] .sidebar .sidebar-foot .user-name,
  html[data-sidebar="collapsed"] .sidebar .sidebar-foot .user-role { display: none; }
  html[data-sidebar="collapsed"] .sidebar .btn-logout { justify-content: center; }
  html[data-sidebar="collapsed"] .sidebar .btn-logout .nav-label { display: none; }
}

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.topbar .eyebrow { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-muted); font-weight: 600; display: block; }
.topbar h1 { font-size: 1.3rem; margin: 0; }

.page-content { padding: 1.75rem; flex: 1; }
@media (max-width: 575.98px) { .page-content { padding: 1.1rem; } }

/* ===== Cards ===== */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card); }
.card-body { padding: 1.25rem; }

/* ===== Meter tiles (stat cards) ===== */
.meter-tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1rem 1.15rem;
  position: relative;
  overflow: hidden;
  height: 100%;
}
.meter-tile::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: var(--tile-tone, var(--slate));
}
.meter-tile .meter-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-muted); font-weight: 700; }
.meter-tile .meter-value { font-size: 1.9rem; font-weight: 600; margin-top: .2rem; color: var(--ink); line-height: 1.1; }
.meter-tile[data-tone="brass"] { --tile-tone: var(--brass); }
.meter-tile[data-tone="volt"] { --tile-tone: var(--volt); }
.meter-tile[data-tone="breaker"] { --tile-tone: var(--breaker); }
.meter-tile[data-tone="slate"] { --tile-tone: var(--slate); }
.meter-tile[data-tone="breaker"] .meter-value { color: var(--breaker-deep); }
.meter-tile[data-tone="slate"] .meter-value { color: var(--slate-deep); }

/* ===== Status pill / LED — the app's one recurring signature ===== */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .24rem .58rem .24rem .48rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-pill .led { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status-pill.tone-volt { background: var(--volt-tint); color: var(--volt-deep); }
.status-pill.tone-volt .led { background: var(--volt); box-shadow: 0 0 0 2px rgba(22, 163, 74, .25); }
.status-pill.tone-breaker { background: var(--breaker-tint); color: var(--breaker-deep); }
.status-pill.tone-breaker .led { background: var(--breaker); box-shadow: 0 0 0 2px rgba(220, 38, 38, .22); }
.status-pill.tone-slate { background: var(--slate-tint); color: var(--slate-deep); }
.status-pill.tone-slate .led { background: var(--slate); }
.status-pill.tone-brass { background: var(--brass-tint); color: var(--brass-deep); }
.status-pill.tone-brass .led { background: var(--brass); box-shadow: 0 0 0 2px rgba(79, 70, 229, .22); }

/* ===== Live / refresh indicator ===== */
.live-pill { display: inline-flex; align-items: center; gap: .4rem; font-size: .76rem; color: var(--ink-muted); font-weight: 600; transition: opacity .2s ease; opacity: 0; }
.live-pill .live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--volt); box-shadow: 0 0 0 3px var(--volt-tint); flex-shrink: 0; }

/* ===== Buttons ===== */
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: .875rem; }
.btn-primary { color: #fff; }
.unit-toggle .btn, .metric-toggle .btn { min-width: 90px; }

/* ===== Tables ===== */
.table thead th {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-muted);
  font-weight: 700;
  border-bottom-width: 1px;
  background: transparent;
  white-space: nowrap;
}
.table > :not(caption) > * > * { border-bottom-color: var(--line); }
.table-hover > tbody > tr:hover > * { background-color: var(--surface); }
th small, th .th-sub { display: block; font-weight: 500; color: var(--ink-muted); text-transform: none; letter-spacing: 0; font-size: .68rem; margin-top: 2px; }

/* ===== Forms ===== */
.form-control, .form-select {
  border-radius: var(--radius-sm);
  border-color: var(--line);
}
.form-control:focus, .form-select:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 .2rem var(--brass-tint);
}
.form-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); font-weight: 700; }
.form-text { font-size: .78rem; }

/* ===== Dashboard filter/search bar ===== */
.filter-bar .form-label { margin-bottom: .3rem; }
.filter-bar .btn-clear-filters { flex-shrink: 0; }
@media (max-width: 767.98px) {
  .filter-bar .row > div { margin-bottom: 0; }
}

/* ===== Room leaderboard cards (Dashboard: top rooms by consumption) ===== */
.room-rank-scroll {
  max-height: 640px;
  overflow-y: auto;
  padding-right: .25rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}
.room-rank-scroll::-webkit-scrollbar { width: 8px; }
.room-rank-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.room-rank-scroll::-webkit-scrollbar-track { background: transparent; }

.room-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: .85rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.room-card .rank {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--brass);
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
}
.room-card .rank.top3 { background: var(--brass); color: #fff; }
.room-card .room-id { min-width: 90px; }
.room-card .room-id .room-number { font-weight: 700; font-size: 1.05rem; }
.room-card .room-id .room-mac { font-size: .72rem; color: var(--ink-muted); }
.room-card .room-usage { text-align: right; margin-left: auto; }
.room-card .room-usage .meter-value { font-size: 1.3rem; }
.room-card .room-usage .meter-label { font-size: .64rem; }
.room-card .room-pills { display: flex; gap: .4rem; flex-wrap: wrap; }
.room-card .room-meta { font-size: .74rem; color: var(--ink-muted); width: 100%; }

/* ===== Auth pages (login / forgot / reset password) ===== */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  background-image: radial-gradient(rgba(79, 70, 229, .22) 1px, transparent 1px);
  background-size: 22px 22px;
  padding: 2rem 1rem;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 14px;
  padding: 2.1rem 1.9rem;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .55);
}
.auth-brand { display: flex; align-items: center; gap: .6rem; justify-content: center; color: var(--ink); }
.auth-brand svg { color: var(--brass); flex-shrink: 0; }
.auth-brand .brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: -0.01em; }
.auth-sub { text-align: center; color: var(--ink-muted); font-size: .8rem; margin: .2rem 0 1.35rem; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .form-control, .form-select, .sidebar-nav a { transition-duration: .15s; }
}
