/* ============================================================
   EMS Portal — Main Stylesheet
   ============================================================ */

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

:root {
  /* Sensori brand colours */
  --sensori-navy: #1a2744;
  --sensori-navy-dark: #111c33;
  --sensori-navy-light: #243052;
  --sensori-blue: #2e6fce;
  --sensori-blue-light: #4a8fe0;

  --sidebar-bg: var(--sensori-navy);
  --sidebar-text: #c8d6e5;
  --sidebar-muted: rgba(200, 214, 229, 0.45);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active-bg: rgba(46, 111, 206, 0.25);
  --sidebar-active-text: #7eb3ff;
  --sidebar-active-border: var(--sensori-blue);
  --sidebar-width: 240px;

  --accent: var(--sensori-blue);
  --accent-hover: #1d5ab8;
  --success: #1d9e75;
  --warning: #e9a021;
  --danger: #e24b4a;

  --bg-page: #f4f6f9;
  --bg-card: #ffffff;
  --bg-secondary: #f8f9fb;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --radius: 10px;
  --radius-sm: 6px;

  --meter-color-1: #2563eb;
  --meter-color-2: #1d9e75;
  --meter-color-3: #e9a021;
  --meter-color-4: #e24b4a;
  --meter-color-5: #8b5cf6;
  --meter-color-6: #ec4899;
  --meter-color-7: #06b6d4;
  --meter-color-8: #f97316;
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text-primary); background: var(--bg-page); }

a { color: inherit; text-decoration: none; }

/* ===================== Layout ===================== */

.ems-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ===================== Top banner ===================== */

.top-banner {
  background: var(--sensori-navy-dark);
  border-bottom: 3px solid var(--sensori-blue);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 64px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  z-index: 100;
}

.top-banner::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent, transparent 40px, rgba(46,111,206,0.04) 40px, rgba(46,111,206,0.04) 41px),
    repeating-linear-gradient(0deg, transparent, transparent 40px, rgba(46,111,206,0.04) 40px, rgba(46,111,206,0.04) 41px);
  pointer-events: none;
}

.banner-left {
  display: flex;
  align-items: center;
  gap: 20px;
  position: relative;
  z-index: 1;
}

.banner-logo-img {
  height: 34px;
  width: auto;
  display: block;
}

.banner-divider {
  width: 1px;
  height: 28px;
  background: rgba(255,255,255,0.15);
}

.banner-product-name {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.banner-right {
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.banner-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: rgba(255,255,255,0.7);
}

.banner-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sensori-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.banner-user-name {
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  font-weight: 500;
}

.banner-logout-form {
  display: inline-flex;
}
.banner-logout {
  font: inherit;
  font-size: 12px;
  color: rgba(255,255,255,0.45);
  background: transparent;
  padding: 5px 12px;
  border: 0.5px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
.banner-logout:hover {
  color: #fff;
  border-color: rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.06);
}

/* ===================== Body below banner ===================== */

.ems-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===================== Sidebar ===================== */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-nav {
  padding: 8px 0;
  border-bottom: 0.5px solid var(--sidebar-border);
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background 0.12s;
}
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left: 2px solid var(--sidebar-active-border);
  padding-left: 16px;
}
.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.sidebar-section {
  padding: 12px 18px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
  flex-shrink: 0;
}

.site-tree {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 8px;
}

.site-tree::-webkit-scrollbar { width: 4px; }
.site-tree::-webkit-scrollbar-track { background: transparent; }
.site-tree::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 18px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background 0.1s;
  position: relative;
}
.tree-item:hover { background: var(--sidebar-hover); }
.tree-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); border-left: 2px solid var(--sidebar-active-border); padding-left: 16px; }
.tree-item svg { flex-shrink: 0; opacity: 0.7; }

.tree-site { padding-left: 30px; font-size: 12px; }
.tree-meter { padding-left: 44px; font-size: 12px; color: rgba(200,214,229,0.85); }
.tree-meter:hover { color: #fff; }
.tree-submeter { padding-left: 58px; font-size: 11.5px; color: var(--sidebar-muted); cursor: default; }

.tree-client-name { font-size: 13px; font-weight: 500; color: #d1dde9; }
.tree-client-name .chevron { margin-left: auto; transition: transform 0.2s; }
.tree-client-name.open .chevron { transform: rotate(180deg); }

.tree-children { display: none; }
.tree-children.open { display: block; }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 0.5px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name { font-size: 12px; font-weight: 500; color: #d1dde9; }
.user-logout { font-size: 11px; color: var(--sidebar-muted); }
.user-logout:hover { color: #fff; }

/* ===================== Main content ===================== */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-page);
}

/* ===================== Topbar ===================== */

.topbar {
  background: var(--bg-card);
  border-bottom: 0.5px solid var(--border);
  padding: 10px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.topbar-breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.breadcrumb-client, .breadcrumb-site { color: var(--text-secondary); }
.breadcrumb-meter { color: var(--text-primary); font-weight: 500; }
.breadcrumb-sep { color: var(--text-muted); }

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.date-picker input[type="date"],
.date-picker input[type="month"],
.date-picker select {
  border: none;
  background: transparent;
  font-size: 12px;
  color: var(--text-primary);
  font-family: inherit;
  cursor: pointer;
  outline: none;
  padding: 0;
  max-width: 140px;
}

.period-toggle, .chart-type-toggle, .breakdown-type-toggle, .tc-mode-toggle, .tc-chart-type-toggle {
  display: flex;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* .chart-type-toggle's container is shared with the legacy .chart-type-btn
   (Meter Comparison, untouched) — .ctt-btn is the reusable createChartTypeToggle()
   component's own button class (Single/Sub/Virtual Meter, Weather Point,
   Foresight zone-temp, Sustainability trend), kept distinct so its JS-driven
   click handling never collides with bindPeriodControls' global listener. */

/* Sits as its own block below a chart-header (not as a flex item inside
   .topbar-controls, like .period-toggle/.chart-type-toggle) — inline-flex
   so it hugs its two buttons instead of stretching the full card width. */
.breakdown-type-toggle {
  display: inline-flex;
}

.period-btn, .chart-type-btn, .ctt-btn, .breakdown-type-btn, .tc-mode-btn, .tc-chart-type-btn {
  padding: 5px 12px;
  font-size: 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.1s, color 0.1s;
}

.chart-type-btn, .ctt-btn, .breakdown-type-btn, .tc-chart-type-btn { padding: 5px 10px; }

.period-btn:hover, .chart-type-btn:hover, .ctt-btn:hover, .breakdown-type-btn:hover, .tc-mode-btn:hover, .tc-chart-type-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.period-btn.active, .chart-type-btn.active, .ctt-btn.active, .breakdown-type-btn.active, .tc-mode-btn.active, .tc-chart-type-btn.active { background: var(--accent); color: #fff; }

/* ===================== Time Comparison — custom date range panel ===================== */

.tc-custom-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 20px;
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin: 0 22px 14px;
}

.tc-custom-period {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tc-custom-period-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}

.tc-custom-to {
  font-size: 12px;
  color: var(--text-muted);
}

.tc-custom-date {
  padding: 7px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
}

.tc-custom-resolution {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tc-custom-resolution label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.tc-custom-resolution select { min-width: 130px; }

.tc-custom-note {
  font-size: 12px;
  color: var(--text-muted);
  flex-basis: 100%;
}

/* ===================== Scrollable page body ===================== */

.page-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===================== KPI cards ===================== */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 18px 22px 0;
  flex-shrink: 0;
}

.kpi-row.kpi-row-fit { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi-cost-note { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.export-cost-option { display: flex !important; align-items: center; gap: 8px; text-transform: none !important;
  letter-spacing: 0 !important; font-weight: 500 !important; font-size: 13px !important; }
.export-cost-option input { width: auto; }

.kpi-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.kpi-accent {
  height: 3px;
  border-radius: 2px;
  margin-bottom: 10px;
}

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.kpi-meter-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.02em;
}

.kpi-unit {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.kpi-trend {
  font-size: 11px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 3px;
}
.kpi-trend.up { color: var(--danger); }
.kpi-trend.down { color: var(--success); }

.kpi-coverage-warning {
  font-size: 10.5px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--warning);
}

/* ===================== Charts ===================== */

.chart-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 0 22px;
  margin-bottom: 14px;
  position: relative;
}

.chart-card:first-of-type { margin-top: 14px; }

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  /* Reserves room for the absolutely-positioned .chart-download button
     (top-right of the card) so it never overlaps a header's own
     right-side controls (period toggles, the breakdown chart-type
     toggle, foresight's AC-unit picker). A no-op on the many headers
     that only have a title/subtitle. */
  padding-right: 36px;
}

/* ===================== Chart image export (PNG/JPEG) ===================== */
/* Injected once per .chart-card by initChartDownloadButtons() in main.js —
   absolutely positioned against the card itself (not .chart-header), so it
   sits in the same top-right spot regardless of how a given page's header
   markup is structured. */

.chart-download {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 5;
}

.chart-download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--sensori-navy);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chart-download-btn:hover { background: var(--bg-card); border-color: var(--sensori-blue); color: var(--sensori-blue); }

.chart-download-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  min-width: 168px;
  background: var(--bg-card);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
  padding: 4px;
}
.chart-download-menu.open { display: block; }

.chart-download-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 4px;
  font-family: inherit;
}
.chart-download-menu button:hover { background: var(--bg-secondary); color: var(--sensori-blue); }

/* ===================== Doughnut centre label (virtual meter breakdown) ===================== */

.doughnut-center-label {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  pointer-events: none;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.chart-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.legend-row {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.legend-line {
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ===================== Home dashboard (command centre) ===================== */

.home-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px 22px 4px;
}

.home-greeting {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.home-date {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.home-header-pills {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.home-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 0.5px solid var(--border-strong);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.home-pill-carbon { font-weight: 500; color: var(--text-primary); }

.home-sites-section {
  margin: 0 22px 14px;
}

.home-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.site-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.site-card-empty {
  grid-column: 1 / -1;
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
}

.site-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.site-card-header {
  padding-bottom: 8px;
  border-bottom: 0.5px solid var(--border);
}

.site-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.site-card-client {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

.site-card-metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.site-card-metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  flex-shrink: 0;
}

.site-card-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.site-card-unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.site-card-value-sm {
  font-size: 12.5px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: right;
}

.site-card-empty-metric {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.site-card-links {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  border-top: 0.5px solid var(--border);
  flex-wrap: wrap;
}

.site-card-links a {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--accent);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: rgba(46, 111, 206, 0.08);
}

.site-card-links a:hover { background: rgba(46, 111, 206, 0.16); }

.site-card-link-disabled {
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 4px 10px;
  opacity: 0.55;
}

/* ---- Sustainability summary section ---- */

.sustain-mvlm {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 0.5px solid var(--border);
}

.sustain-mvlm-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.sustain-mvlm-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.sustain-progress-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sustain-progress-row {
  display: grid;
  grid-template-columns: 140px 1fr 90px;
  align-items: center;
  gap: 10px;
}

.sustain-progress-label {
  font-size: 12.5px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sustain-progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--bg-secondary);
  overflow: hidden;
}

.sustain-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.2s ease;
}

.sustain-progress-pct {
  font-size: 11.5px;
  color: var(--text-secondary);
  text-align: right;
}

.sustain-leu {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 0.5px solid var(--border);
}

.sustain-leu-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.sustain-leu-chip {
  display: inline-block;
  font-size: 11.5px;
  color: var(--text-primary);
  background: rgba(233, 160, 33, 0.12);
  border: 0.5px solid rgba(233, 160, 33, 0.3);
  padding: 4px 10px;
  border-radius: 999px;
  margin: 0 6px 6px 0;
}

/* ===================== Meter selector bar (comparison) ===================== */

.meter-selector-bar {
  background: var(--bg-card);
  border-bottom: 0.5px solid var(--border);
  padding: 10px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.meter-selector-title {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 500;
}

.meter-checkboxes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.meter-check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 0.5px solid var(--border-strong);
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.15s, background 0.15s;
}

.meter-check-label:hover { border-color: var(--accent); }
.meter-check-label:has(input:checked) { border-color: var(--accent); background: rgba(37,99,235,0.05); }

.meter-check-label input[type="checkbox"] { width: 13px; height: 13px; accent-color: var(--accent); cursor: pointer; }

.meter-check-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.meter-check-name { font-weight: 500; color: var(--text-primary); }
.meter-check-site { font-size: 11px; color: var(--text-muted); }

/* ===================== Summary table ===================== */

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.summary-table th {
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 0.5px solid var(--border);
  background: var(--bg-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-table td {
  padding: 9px 12px;
  color: var(--text-primary);
  border-bottom: 0.5px solid var(--border);
}

.summary-table tr:last-child td { border-bottom: none; }
.summary-table tr:hover td { background: var(--bg-secondary); }

.meter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.change-up { color: var(--danger); }
.change-down { color: var(--success); }

/* ===================== Empty state ===================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  padding: 40px;
  color: var(--text-secondary);
}

.empty-state h2 { font-size: 20px; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.empty-state p { font-size: 14px; margin-bottom: 24px; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); }

/* ===================== Settings / account pages ===================== */

.settings-header { padding: 24px 28px 4px; }
.settings-title { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.settings-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.settings-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 18px 28px;
  max-width: 520px;
}

.settings-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 13.5px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row-label { color: var(--text-secondary); }
.settings-row-value { color: var(--text-primary); font-weight: 500; text-align: right; }

.settings-message {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin: 0 28px 14px;
}
.settings-message-success {
  background: rgba(29, 158, 117, 0.08);
  color: var(--success);
  border: 0.5px solid rgba(29, 158, 117, 0.25);
}
.settings-message-error {
  background: rgba(226, 75, 74, 0.08);
  color: var(--danger);
  border: 0.5px solid rgba(226, 75, 74, 0.25);
}

/* ===================== Login ===================== */

.login-body {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
  background: var(--sensori-navy);
}

.login-shell {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

/* Left brand panel */
.login-brand-panel {
  flex: 1;
  background: var(--sensori-navy);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 48px;
  position: relative;
  overflow: hidden;
}

.login-brand-panel::before {
  content: '';
  position: absolute;
  top: -80px;
  right: -80px;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: rgba(46, 111, 206, 0.08);
  pointer-events: none;
}

.login-brand-panel::after {
  content: '';
  position: absolute;
  bottom: -60px;
  left: -60px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: rgba(46, 111, 206, 0.06);
  pointer-events: none;
}

.login-brand-content {
  position: relative;
  z-index: 1;
}

.login-brand-logo {
  height: 48px;
  width: auto;
  display: block;
  margin-bottom: 28px;
}

.login-brand-product {
  font-size: 22px;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.02em;
  margin-bottom: 12px;
}

.login-brand-tagline {
  font-size: 14px;
  color: rgba(200, 214, 229, 0.6);
  font-style: italic;
  letter-spacing: 0.01em;
}

.login-brand-footer {
  font-size: 12px;
  color: rgba(200, 214, 229, 0.4);
  position: relative;
  z-index: 1;
}

/* Right form panel */
.login-form-panel {
  width: 440px;
  min-width: 440px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
}

.login-form-inner {
  width: 100%;
  max-width: 340px;
}

.login-form-header {
  margin-bottom: 32px;
}

.login-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--sensori-navy);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.login-error {
  background: rgba(226, 75, 74, 0.08);
  color: var(--danger);
  border: 0.5px solid rgba(226, 75, 74, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--sensori-navy);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-group input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input::placeholder { color: var(--text-muted); }
.form-group input:focus { border-color: var(--sensori-blue); }

.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--sensori-navy);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
  letter-spacing: 0.02em;
  transition: background 0.15s;
}

.login-btn:hover { background: var(--sensori-navy-light); }

/* Password reset pages share the login shell (registration/auth_base.html). */
.login-btn-link { display: block; text-align: center; text-decoration: none; box-sizing: border-box; }

.login-footer-link {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
}
.login-footer-link a { color: var(--sensori-blue); text-decoration: none; font-weight: 500; }
.login-footer-link a:hover { text-decoration: underline; }

.login-notice {
  background: rgba(46, 111, 206, 0.07);
  color: var(--sensori-navy);
  border: 0.5px solid rgba(46, 111, 206, 0.25);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 16px;
}

.login-help { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }
.login-help ul { margin: 4px 0 0; padding-left: 18px; }

/* ===================== Public action page (InsightAction) ===================== */
/* No sidebar/nav — the assignee has no EMS account, so this page loads
   standalone (see templates/foresight/action_public.html), styled for
   a phone screen someone might be reading on-site with one hand. */

.action-page-body {
  min-height: 100vh;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
}

.action-page-header {
  background: var(--sensori-navy);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.action-page-logo { height: 26px; }

.action-page-header-title {
  color: var(--sidebar-text);
  font-size: 13px;
}

.action-page-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 40px;
}

.action-page-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  padding: 24px 22px;
  width: 100%;
  max-width: 520px;
}

.action-page-site {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.action-page-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.action-page-title {
  font-size: 21px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 10px;
}

.action-page-body-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.action-page-meta {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 22px;
}

.action-page-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
}

.action-page-meta-row-block { flex-direction: column; gap: 4px; }

.action-page-meta-label { color: var(--text-muted); flex-shrink: 0; }
.action-page-meta-value { color: var(--text-primary); font-weight: 500; text-align: right; }
.action-page-meta-row-block .action-page-meta-value { text-align: left; font-weight: 400; line-height: 1.5; }

.action-page-form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.action-page-form textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  resize: vertical;
  margin-bottom: 16px;
}

.action-page-complete-btn {
  width: 100%;
  padding: 16px;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 52px;
}

.action-page-complete-btn:hover { background: #178a67; }

.action-page-complete-state {
  text-align: center;
  padding: 20px 0 4px;
}

.action-page-complete-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 10px;
}

.action-page-complete-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.action-page-complete-notes {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-secondary);
  text-align: left;
  line-height: 1.5;
}

.action-page-cancelled-state {
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
}

.action-page-footer {
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-muted);
}

@media (max-width: 480px) {
  .action-page-card { padding: 20px 16px; }
  .action-page-title { font-size: 19px; }
}

/* ===================== Submeter legend ===================== */

.submeter-legend {
  display: flex;
  gap: 14px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

/* ===================== Sidebar section headers ===================== */
/* ENERGY / FORESIGHT / SUSTAINABILITY / WEATHER — the four site-level
   sections. .tree-section-header carries all the shared layout and
   typography (uppercase, muted text, chevron rotation for the two
   collapsible ones); the legacy .tree-subsection-link/.tree-weather-header
   classes below it now only add what's actually specific to that one
   section (hover/active accent, or nothing at all). Every section's own
   icon gets its brand colour via .icon-* below, set directly on the
   <svg> (which uses stroke="currentColor") so the icon can be coloured
   independently of the label text next to it. */

.tree-section-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 18px 5px 30px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  transition: background 0.1s, color 0.1s;
  text-decoration: none;
}
.tree-section-header:hover { background: var(--sidebar-hover); color: rgba(255,255,255,0.85); }
.tree-section-header .chevron { margin-left: auto; transition: transform 0.2s; flex-shrink: 0; }
.tree-section-header.open .chevron { transform: rotate(180deg); }

.icon-energy { color: var(--sensori-blue); }
.icon-foresight { color: var(--foresight-accent); }
.icon-sustainability { color: var(--success); }
.icon-weather { color: #7eb3ff; }
.icon-water { color: #38bdf8; }

/* Foresight — single link, not collapsible. (Sustainability's own hover/
   active accent lives in sustainability.css, right next to its other
   sidebar-link rules — kept there rather than duplicated here.) */
.tree-subsection-link:hover { color: #c4b5fd; }
.tree-subsection-link.active-foresight {
  background: rgba(124,58,237,0.2);
  color: #c4b5fd;
  border-left: 2px solid var(--foresight-accent);
  padding-left: 28px;
}

/* ===================== Comparison sidebar checkboxes ===================== */

.comp-check-label {
  cursor: pointer;
  user-select: none;
}

.comp-check-label input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--sensori-blue);
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 2px;
}

.comp-check-label:hover {
  background: var(--sidebar-hover);
}

.btn-clear-selection {
  padding: 5px 12px;
  font-size: 12px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.btn-clear-selection:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Weather section header — collapsible, layout/typography from .tree-section-header above. */
.tree-weather-header:hover { color: #cfe4ff; }

.tree-weather-point {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 18px 5px 44px;
  font-size: 11.5px;
  color: rgba(29,158,117,0.85);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s;
}
.tree-weather-point:hover { background: var(--sidebar-hover); color: #1d9e75; }
.tree-weather-point.active { color: #1d9e75; font-weight: 500; border-left: 2px solid #1d9e75; padding-left: 42px; }

/* ===================== Virtual meter tree items ===================== */

.tree-icon-sigma {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  opacity: 0.85;
  color: #a78bfa;
}
.tree-virtual-meter.active .tree-icon-sigma { color: #c4b5fd; }
/* ===================== Navigation dropdown ===================== */

.nav-dropdown-wrapper {
  position: relative;
}

.nav-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  color: var(--sidebar-text);
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: background 0.12s;
}
.nav-dropdown-btn:hover { background: var(--sidebar-hover); }
.nav-dropdown-btn.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left: 2px solid var(--sidebar-active-border);
  padding-left: 16px;
}
.nav-dropdown-btn .nav-chevron {
  margin-left: auto;
  transition: transform 0.2s;
}
.nav-dropdown-btn.open .nav-chevron {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  display: none;
  background: rgba(0,0,0,0.2);
  border-left: 2px solid var(--sidebar-active-border);
  margin-left: 8px;
}
.nav-dropdown-menu.open { display: block; }

.nav-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 18px 7px 28px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: background 0.1s;
}
.nav-dropdown-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-dropdown-item.active { color: var(--sidebar-active-text); }

/* ===================== Date navigation arrows ===================== */

.date-arrow {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
  font-family: inherit;
}
.date-arrow:hover { color: var(--sensori-blue); }
/* ===================== View switcher dropdown ===================== */

.view-switcher {
  position: relative;
}

.view-switcher-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  font-size: 12px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: border-color 0.15s;
  white-space: nowrap;
}
.view-switcher-btn:hover { border-color: var(--sensori-blue); }
.view-switcher-btn .nav-chevron { transition: transform 0.2s; margin-left: 2px; }
.view-switcher-btn.open .nav-chevron { transform: rotate(180deg); }

.view-switcher-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--bg-card);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 100;
  min-width: 180px;
  overflow: hidden;
}
.view-switcher-menu.open { display: block; }

.view-switcher-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-primary);
  text-decoration: none;
  transition: background 0.1s;
  white-space: nowrap;
}
.view-switcher-item:hover { background: var(--bg-secondary); }
.view-switcher-item.active { color: var(--sensori-blue); font-weight: 500; }

/* ===================== Responsive — mobile nav (JS-injected) ===================== */
/* main.js injects the hamburger button, sidebar close button, backdrop and
   mobile user/signout footer into the DOM on load. They stay hidden here so
   desktop/tablet layouts are untouched; the mobile media query below turns
   them on. */

.hamburger-btn,
.sidebar-close-btn,
.sidebar-backdrop,
.sidebar-mobile-footer {
  display: none;
}

/* ===================== Responsive — shared touch/tablet+mobile rules ===================== */

@media (max-width: 1024px) {
  .period-btn,
  .chart-type-btn,
  .ctt-btn,
  .breakdown-type-btn,
  .tc-mode-btn,
  .tc-chart-type-btn,
  .date-arrow,
  .view-switcher-btn,
  .btn-clear-selection,
  .banner-logout {
    min-height: 44px;
  }

  .tc-custom-panel { flex-direction: column; align-items: stretch; }
  .tc-custom-period { flex-wrap: wrap; }
  .tc-custom-date { flex: 1; min-width: 0; }

  .chart-download-btn {
    width: 36px;
    height: 36px;
  }
  .chart-download-menu button {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .date-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .nav-item,
  .tree-item,
  .nav-dropdown-item,
  .view-switcher-item {
    min-height: 44px;
  }

  .comp-check-label {
    min-height: 44px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .comp-check-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
  }

  .kpi-label,
  .form-group label,
  .settings-row-label,
  .settings-row-value {
    font-size: 14px;
  }
}

/* ===================== Tablet: 768px – 1024px ===================== */

@media (min-width: 768px) and (max-width: 1024px) {
  .top-banner { padding: 0 18px; }
  .banner-logo-img { height: 28px; }
  .banner-product-name { font-size: 11px; }
  .banner-divider { height: 22px; }

  .sidebar {
    width: 48px;
    min-width: 48px;
    position: relative;
    z-index: 60;
    transition: width 0.18s ease;
  }
  .sidebar:hover,
  .sidebar.sidebar-expanded {
    width: 240px;
    min-width: 240px;
  }
  .sidebar:not(:hover):not(.sidebar-expanded) .nav-item,
  .sidebar:not(:hover):not(.sidebar-expanded) .tree-item,
  .sidebar:not(:hover):not(.sidebar-expanded) .sidebar-section,
  .sidebar:not(:hover):not(.sidebar-expanded) .tree-subsection-link,
  .sidebar:not(:hover):not(.sidebar-expanded) .tree-weather-header,
  .sidebar:not(:hover):not(.sidebar-expanded) .tree-water-header {
    font-size: 0;
  }
  .sidebar:not(:hover):not(.sidebar-expanded) .nav-item,
  .sidebar:not(:hover):not(.sidebar-expanded) .tree-item {
    padding-left: 16px;
    padding-right: 16px;
    justify-content: center;
  }
  .site-tree { overflow-x: hidden; }

  .kpi-row { grid-template-columns: repeat(4, minmax(0,1fr)) !important; gap: 8px; }
  .kpi-card { padding: 10px 12px; }
  .kpi-value { font-size: 18px; }
}

/* ===================== Mobile: < 768px ===================== */

@media (max-width: 767px) {
  .top-banner { padding: 0 12px; height: 56px; }
  .banner-logo-img { height: 26px; }
  .banner-divider,
  .banner-product-name,
  .banner-right {
    display: none;
  }

  .hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
  }

  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 280px;
    min-width: 280px;
    max-width: 86vw;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  .sidebar.mobile-open { transform: translateX(0); }

  .sidebar-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 5;
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
  }

  .sidebar-backdrop {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
  }
  .sidebar-backdrop.open { display: block; }

  .sidebar-mobile-footer {
    flex-shrink: 0;
    border-top: 0.5px solid var(--sidebar-border);
    padding: 12px 16px;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }
  .sidebar.mobile-open .sidebar-mobile-footer { display: flex; }
  .sidebar-mobile-footer .banner-user { display: flex; align-items: center; gap: 10px; }
  .sidebar-mobile-footer .banner-user-name { color: #fff; font-size: 14px; }
  .sidebar-mobile-logout-form .banner-logout { min-height: 36px; }

  body.comparison-mode .sidebar.mobile-open {
    width: 100vw;
    min-width: 100vw;
    max-width: 100vw;
  }

  /* Topbar controls stack full-width */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
  }
  .topbar-breadcrumb { flex-wrap: wrap; font-size: 13px; }
  .topbar-controls {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 8px;
  }

  .date-picker { width: 100%; justify-content: center; font-size: 14px; }
  .date-picker #datePickerInner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1;
  }
  .date-picker input,
  .date-picker select {
    max-width: none;
    flex: 1;
    font-size: 14px;
  }

  .period-toggle {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }
  .period-btn { justify-content: center; font-size: 14px; }

  .chart-type-toggle { width: 100%; flex-wrap: wrap; }
  .chart-type-btn, .ctt-btn { flex: 1; justify-content: center; }

  .btn-clear-selection { width: 100%; justify-content: center; }

  .kpi-row {
    grid-template-columns: repeat(2, minmax(0,1fr)) !important;
    padding: 12px 12px 0;
    gap: 10px;
  }
  .kpi-value { font-size: 18px; }

  .chart-card { margin: 0 12px 12px; padding: 14px; }
  .chart-card:first-of-type { margin-top: 12px; }
  .page-body { padding: 12px; }

  .chart-card > div:has(> canvas) { height: 180px !important; }

  .chart-card:has(> .summary-table) { overflow-x: auto; }
  .summary-table { min-width: 480px; }

  .settings-card { margin: 14px 12px; }
  .settings-header { padding: 18px 16px 4px; }
  .settings-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
  .settings-row-value { text-align: left; }

  .login-brand-panel { display: none; }
  .login-form-panel { width: 100%; min-width: 0; padding: 32px 20px; }

  .home-header { padding: 16px 12px 4px; flex-direction: column; align-items: flex-start; }
  .home-greeting { font-size: 17px; }
  .home-sites-section { margin: 0 12px 12px; }
  .site-card-grid { grid-template-columns: 1fr; }

  .sustain-progress-row { grid-template-columns: 1fr; gap: 4px; }
  .sustain-progress-pct { text-align: left; }
  .sustain-mvlm { flex-direction: column; align-items: flex-start; }

  .export-page { padding: 12px; }
  .export-card { padding: 14px; margin-bottom: 12px; }
  .export-inline-row { flex-direction: column; gap: 0; }
  .export-date-row { flex-direction: column; gap: 0; }
  .export-preset-row { gap: 6px; }
  .export-preset-btn { flex: 1 1 calc(50% - 6px); text-align: center; }
  .export-actions { flex-direction: column; align-items: stretch; }
  .export-actions .btn-primary,
  .export-actions .btn-secondary { justify-content: center; }
}

/* ===================== Export page ===================== */

.topbar-export-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  background: var(--sensori-navy);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  transition: background 0.15s;
}
.topbar-export-btn:hover { background: var(--sensori-navy-light); }

.export-page {
  max-width: 720px;
  padding: 22px 28px 40px;
}

.export-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 16px;
}

.export-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.export-card-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
}

.export-select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
  outline: none;
}
.export-select:focus { border-color: var(--sensori-blue); }

.export-meter-list {
  max-height: 320px;
  overflow-y: auto;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 0;
}

.export-empty-hint {
  padding: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.export-meter-group-title {
  padding: 8px 14px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.export-meter-subgroup-title {
  padding: 6px 14px 2px 30px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.export-no-data-hint {
  font-size: 11px;
  font-weight: 400;
  font-style: italic;
  color: var(--text-muted);
}

.export-meter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 13.5px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}
.export-meter-row:hover { background: var(--bg-secondary); }
.export-meter-row input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--sensori-blue);
  cursor: pointer;
  flex-shrink: 0;
}
.export-meter-row-nested { padding-left: 30px; }

.export-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.export-preset-btn {
  padding: 7px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.export-preset-btn:hover { border-color: var(--sensori-blue); }
.export-preset-btn.active {
  background: var(--sensori-navy);
  border-color: var(--sensori-navy);
  color: #fff;
}

.export-date-row {
  display: flex;
  gap: 16px;
}
.export-date-row .form-group { flex: 1; margin-bottom: 0; }
.export-date-row input[type="date"] {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
}

.export-inline-row {
  display: flex;
  gap: 16px;
}
.export-inline-row .form-group { flex: 1; margin-bottom: 0; }

.export-message {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.export-message-warning {
  background: rgba(230, 168, 23, 0.1);
  color: #92660b;
  border: 0.5px solid rgba(230, 168, 23, 0.3);
}
.export-message-error {
  background: rgba(226, 75, 74, 0.08);
  color: var(--danger);
  border: 0.5px solid rgba(226, 75, 74, 0.25);
}

.export-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.export-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: export-spin 0.7s linear infinite;
}

@keyframes export-spin {
  to { transform: rotate(360deg); }
}

/* ===================== Sidebar — light theme ===================== */
/* Light body with navy text; the top banner stays navy for the brand.
   Tokens are redefined on .sidebar itself (not :root) because the
   public action page's navy header also reads --sidebar-text.

   Hierarchy, left to right:
     Client           bold navy, flush
       Site           indented, pin icon
       │ ENERGY / FORESIGHT / SUSTAINABILITY / WEATHER   small caps, coloured icon
       │ │ Meter      thin guide lines mark each nested level
       │ │   Sub-meter
   Active page: pale blue fill, 3px blue bar, semibold — drawn with an
   inset box-shadow so it never shifts the row's padding. */

.sidebar {
  --sidebar-bg: #f5f7fb;
  --sidebar-text: #1a2744;
  --sidebar-secondary: #3d4b66;
  --sidebar-muted: #6b7895;
  --sidebar-border: rgba(26, 39, 68, 0.10);
  --sidebar-guide: rgba(26, 39, 68, 0.14);
  --sidebar-hover: rgba(26, 39, 68, 0.06);
  --sidebar-active-bg: rgba(46, 111, 206, 0.10);
  --sidebar-active-text: #1d4fa0;
  --sidebar-active-border: var(--sensori-blue);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
}

.sidebar .sidebar-section {
  color: var(--sidebar-muted);
  font-weight: 600;
}

.sidebar .site-tree::-webkit-scrollbar-thumb { background: rgba(26, 39, 68, 0.15); }

/* Active state — one style for every kind of row. */
.sidebar .nav-item.active,
.sidebar .tree-item.active,
.sidebar .tree-subsection-link.active-foresight,
.sidebar .tree-subsection-link.sustainability-link.active-sustainability,
.sidebar .tree-weather-point.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
  border-left: none;
  box-shadow: inset 3px 0 0 var(--sidebar-active-border);
}
.sidebar .nav-item,
.sidebar .nav-item.active { padding-left: 18px; }
.sidebar .nav-item.sustainability-nav.active,
.sidebar .nav-item.sustainability-nav.active svg { color: var(--sidebar-active-text); stroke: currentColor; }

/* Level 1 — client */
.sidebar .tree-client-name {
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 700;
  padding-left: 14px;
  margin-top: 4px;
}

/* Level 2 — site */
.sidebar .tree-site,
.sidebar .tree-site.active {
  padding-left: 26px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--sidebar-text);
}
.sidebar .tree-site .chevron { margin-left: auto; transition: transform 0.2s; }
.sidebar .tree-site.open .chevron { transform: rotate(180deg); }

/* Everything under a site hangs off one guide line. */
.sidebar .tree-site + .tree-children {
  margin-left: 32px;
  border-left: 1px solid var(--sidebar-guide);
}

/* Level 3 — section headings */
.sidebar .tree-section-header,
.sidebar .tree-subsection-link.active-foresight,
.sidebar .tree-subsection-link.sustainability-link.active-sustainability {
  padding: 7px 14px 5px 12px;
  margin-top: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
}
.sidebar .tree-section-header:hover,
.sidebar .tree-subsection-link:hover,
.sidebar .tree-subsection-link.sustainability-link:hover,
.sidebar .tree-weather-header:hover,
.sidebar .tree-water-header:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.sidebar .tree-subsection-link.active-foresight,
.sidebar .tree-subsection-link.sustainability-link.active-sustainability { color: var(--sidebar-active-text); }
.sidebar .icon-weather { color: #4a8fe0; }
.sidebar .icon-water { color: #0ea5e9; }
.sidebar .tree-water-meter svg { color: #0ea5e9; }

/* Level 4 — meters / weather points, on their own guide line */
.sidebar .tree-energy-header + .tree-children,
.sidebar .tree-weather-header + .tree-children,
.sidebar .tree-water-header + .tree-children {
  margin-left: 18px;
  border-left: 1px solid var(--sidebar-guide);
}
.sidebar .tree-meter,
.sidebar .tree-meter.active,
.sidebar .tree-weather-point,
.sidebar .tree-weather-point.active {
  padding-left: 12px;
  font-size: 12.5px;
  color: var(--sidebar-secondary);
}
.sidebar .tree-meter:hover,
.sidebar .tree-weather-point:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }

/* Level 5 — sub-meters: a further indent with its own short guide */
.sidebar .tree-submeter,
.sidebar .tree-submeter.active {
  padding-left: 28px;
  font-size: 12px;
  color: var(--sidebar-muted);
  cursor: pointer;
}
.sidebar .tree-submeter::before {
  content: '';
  position: absolute;
  left: 18px;
  top: 0;
  bottom: 0;
  border-left: 1px solid var(--sidebar-guide);
}
.sidebar .tree-submeter:hover { color: var(--sidebar-text); }

.sidebar .tree-meter.active,
.sidebar .tree-submeter.active,
.sidebar .tree-weather-point.active { color: var(--sidebar-active-text); }

/* Breakdown group — virtual meters shown under a site total (display_under),
   e.g. Plaza 211 Total by circuit type. Set apart from the side totals listed
   as peers: a small "Breakdown" caption, a pie icon, and a dashed guide line
   in the brand blue instead of the solid grey sub-meter guide. */
.sidebar .tree-breakdown-group { position: relative; margin: 2px 0 4px; }
.sidebar .tree-breakdown-label {
  padding: 3px 18px 2px 28px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}
.sidebar .tree-breakdown-meter svg { color: var(--sensori-blue); flex-shrink: 0; }
.sidebar .tree-breakdown-meter::before { border-left: 1px dashed var(--sensori-blue); opacity: 0.6; }
@media (min-width: 768px) and (max-width: 1024px) {
  .sidebar:not(:hover):not(.sidebar-expanded) .tree-breakdown-label { display: none; }
}

/* Mobile drawer footer (cloned from the navy banner) */
.sidebar .sidebar-mobile-footer .banner-user-name { color: var(--sidebar-text); }
.sidebar .sidebar-mobile-footer .banner-logout {
  color: var(--sidebar-secondary);
  border-color: var(--sidebar-guide);
}
.sidebar .sidebar-mobile-footer .banner-logout:hover {
  color: var(--sidebar-text);
  background: var(--sidebar-hover);
}

/* Tablet icon rail: no indents or guide lines while collapsed. */
@media (min-width: 768px) and (max-width: 1024px) {
  .sidebar:not(:hover):not(.sidebar-expanded) .tree-children {
    margin-left: 0;
    border-left: none;
  }
  .sidebar:not(:hover):not(.sidebar-expanded) .tree-submeter::before { display: none; }
}

@media (max-width: 767px) {
  .sidebar { box-shadow: 4px 0 24px rgba(26, 39, 68, 0.25); }
}

/* ===================== Manage users ===================== */

.users-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.users-card { max-width: 980px; }
.users-client-picker { margin: 14px 28px 0; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.users-client-picker select {
  padding: 8px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
}
.users-table-wrap { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.users-table td { padding: 10px; border-bottom: 1px solid var(--border); color: var(--text-primary); vertical-align: top; }
.users-row-inactive td { color: var(--text-muted); }
.users-name { font-weight: 600; }
.users-meta { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.users-actions a { color: var(--sensori-blue); font-weight: 500; white-space: nowrap; }
.users-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.users-badge-on { background: rgba(29, 158, 117, 0.1); color: var(--success); }
.users-badge-wait { background: rgba(239, 159, 39, 0.12); color: #b4700f; }
.users-badge-off { background: var(--bg-secondary); color: var(--text-muted); }
.users-empty { font-size: 13px; color: var(--text-secondary); }
.users-audit { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.users-audit li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 0.5px solid var(--border); flex-wrap: wrap; }
.users-audit li:last-child { border-bottom: none; }
.users-audit-when { color: var(--text-secondary); white-space: nowrap; min-width: 120px; }
.users-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--sensori-navy);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.users-choice { display: flex !important; align-items: center; gap: 8px; font-size: 13.5px !important; font-weight: 400 !important;
  text-transform: none !important; letter-spacing: 0 !important; color: var(--text-primary) !important; margin: 0 0 6px !important; }
.form-group .users-choice input { width: auto; padding: 0; }
.users-error { font-size: 12px; color: var(--danger); margin-top: 6px; }
.users-warning { font-size: 13px; color: var(--text-primary); background: rgba(239, 159, 39, 0.1); border-radius: var(--radius-sm); padding: 10px 12px; margin: 14px 0; }
.users-password { font-family: ui-monospace, Consolas, monospace; font-size: 16px; letter-spacing: 0.04em; user-select: all; }
.users-inline-form { margin-top: 10px; }
.users-danger { color: var(--danger); }

@media (max-width: 767px) {
  .users-client-picker { margin: 12px 16px 0; }
}

/* ===================== Tariffs ===================== */

.tariff-card { max-width: 1000px; }
.tariff-card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.tariff-card-head .settings-card-title { margin-bottom: 0; }
.tariff-unit { font-weight: 400; color: var(--text-secondary); margin-left: 6px; }
.tariff-table-wrap { overflow-x: auto; }
.tariff-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tariff-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-secondary); padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tariff-table td { padding: 8px; border-bottom: 0.5px solid var(--border); vertical-align: top; }
.tariff-past td { color: var(--text-secondary); }
.tariff-date { white-space: nowrap; }
.tariff-badge {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 9px; font-size: 11px; font-weight: 600;
  background: rgba(29, 158, 117, 0.1); color: var(--success);
}
.tariff-badge-future { background: rgba(37, 99, 235, 0.08); color: var(--sensori-blue); }
.tariff-meta { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.tariff-empty { font-size: 13px; color: var(--text-secondary); }
.tariff-actions { white-space: nowrap; }
.tariff-actions a { color: var(--sensori-blue); font-weight: 500; margin-right: 10px; }
.tariff-delete-form { display: inline; }
.link-button { background: none; border: none; padding: 0; color: var(--danger); font: inherit; font-weight: 500; cursor: pointer; }
.tariff-visibility { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 13px; margin-top: 8px; }
.tariff-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 18px; }
.tariff-fields .tariff-wide { grid-column: 1 / -1; }
.tariff-fields input, .tariff-fields select, .tariff-fields textarea, .tariff-edit-table input, .tariff-edit-table select {
  width: 100%; padding: 8px 10px; border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: 13.5px; background: var(--bg-card); color: var(--text-primary);
}
.tariff-fields .tariff-check input, .tariff-edit-table input[type="checkbox"] { width: auto; }
.tariff-edit-table td { min-width: 90px; }
.tariff-add-row { margin-top: 10px; }
.tariff-preview { border-color: var(--sensori-blue); }
.tariff-preview-total { font-size: 24px; font-weight: 700; color: var(--text-primary); }
.tariff-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 28px 28px; }
@media (max-width: 767px) {
  .tariff-buttons { margin: 0 12px 20px; }
}

/* ===================== Client dashboard ===================== */

.cd-header-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cd-client-picker { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.cd-client-picker select, .cd-input {
  padding: 8px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: 13.5px;
  width: 100%;
}
.cd-client-picker select { width: auto; }
.cd-editbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 12px 28px 0; padding: 10px 14px;
  background: rgba(37, 99, 235, 0.06); border: 0.5px solid rgba(37, 99, 235, 0.25); border-radius: var(--radius-sm);
}
.cd-editbar-label { font-size: 13px; color: var(--text-secondary); }
/* Their display rules would otherwise override the hidden attribute. */
.cd-editbar[hidden], .cd-header-controls [hidden], #cdMessage[hidden] { display: none; }
.cd-editbar-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.cd-msg-btn { margin-left: 10px; padding: 4px 10px; font-size: 12.5px; }

.cd-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 14px 28px 28px;
  align-items: start;
}
.cd-size-full { grid-column: 1 / -1; }
.cd-widget {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 0;
}
.cd-editing .cd-widget { border-style: dashed; border-color: var(--sensori-blue); cursor: grab; }
.cd-dragging { opacity: 0.5; }
.cd-widget-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.cd-widget-title { font-size: 14px; font-weight: 600; color: var(--text-primary); margin: 0; overflow-wrap: anywhere; }
.cd-ctrls { display: flex; gap: 4px; flex-wrap: wrap; }
.cd-ctrl {
  padding: 3px 8px; font-size: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-secondary); color: var(--text-primary); cursor: pointer;
}
.cd-ctrl:disabled { opacity: 0.4; cursor: default; }
.cd-empty { font-size: 13px; color: var(--text-secondary); padding: 8px 0; }
.cd-muted { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.cd-alarm { color: var(--danger) !important; }
.cd-big { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.cd-unit { font-size: 12px; color: var(--text-secondary); }
.cd-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.cd-tile { min-width: 0; }
.cd-tile-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); margin-bottom: 4px; }
.cd-links { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 12.5px; }
.cd-cost-tiles { margin-top: 12px; padding-top: 10px; border-top: 0.5px solid var(--border); }
.cd-link { color: var(--sensori-blue); font-weight: 500; }
.cd-chart { position: relative; height: 240px; margin-top: 8px; }
.cd-chart-sm { height: 150px; }
.cd-chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.cd-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.cd-rows { display: flex; flex-direction: column; margin-top: 10px; }
.cd-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0;
  border-bottom: 0.5px solid var(--border); font-size: 13px; color: var(--text-primary);
}
.cd-row:last-child { border-bottom: none; }
.cd-row-link { text-decoration: none; }
.cd-row-link:hover .cd-row-name { color: var(--sensori-blue); }
.cd-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cd-row-value { font-weight: 600; white-space: nowrap; }
.cd-sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.cd-site { border: 0.5px solid var(--border); border-radius: var(--radius-sm); padding: 12px; min-width: 0; }
.cd-site-name { font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }
.cd-site-metric .kpi-trend { display: inline-block; margin-top: 2px; }
.cd-target { display: block; padding: 8px 0; border-bottom: 0.5px solid var(--border); text-decoration: none; color: inherit; }
.cd-target:last-child { border-bottom: none; }
.cd-target .sustain-progress-bar { margin: 6px 0 2px; }

.cd-panel-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.35); z-index: 90; }
.cd-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 91;
  background: var(--bg-card); box-shadow: -8px 0 24px rgba(15, 23, 42, 0.18);
  display: flex; flex-direction: column;
}
.cd-panel[hidden], .cd-panel-backdrop[hidden] { display: none; }
.cd-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 0.5px solid var(--border); }
.cd-panel-title { font-weight: 600; }
.cd-panel-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-secondary); }
.cd-panel-body { padding: 16px 18px; overflow-y: auto; }
.cd-type {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left;
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-card); color: var(--text-primary);
}
.cd-type:hover:not(:disabled) { border-color: var(--sensori-blue); }
.cd-type:disabled { opacity: 0.5; cursor: default; }
.cd-type-name { font-weight: 600; font-size: 13.5px; }
.cd-field label { margin-bottom: 6px; }
.cd-checks { max-height: 260px; overflow-y: auto; }
.cd-checkgroup { border: none; padding: 0; margin: 0 0 8px; }
.cd-checkgroup legend { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.cd-form-buttons { display: flex; gap: 8px; margin: 6px 0 14px; }
.cd-preview .cd-widget { cursor: default; }

@media (max-width: 767px) {
  .cd-grid { grid-template-columns: 1fr; padding: 12px 12px 20px; gap: 12px; }
  .cd-size-full { grid-column: auto; }
  .cd-editbar { margin: 10px 12px 0; }
  .cd-widget { padding: 14px; }
  .cd-chart { height: 200px; }
}
