@import url('https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400;14..32,500;14..32,600;14..32,700&display=swap');

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: 'Inter', sans-serif; font-size: 13.5px;
       background: var(--bg); color: var(--text-1); }

:root {
  --bg: #EEF2F8; --surface: #FFFFFF; --surface-2: #F5F7FC; --border: #DDE3EF;
  --text-1: #0C1426; --text-2: #4A5568; --text-3: #8898AA;
  --accent: #2563EB; --accent-hover: #1D4ED8; --accent-bg: #EFF6FF; --accent-text: #1E40AF;
  --sb-bg: #111827; --sb-border: #1F2937; --sb-text: #9CA3AF;
  --sb-active-bg: #1F2937; --sb-active-text: #F9FAFB; --sb-active-icon: #3B82F6;
  --st-available: #16A34A; --st-available-bg: #F0FDF4;
  --st-charging:  #2563EB; --st-charging-bg:  #EFF6FF;
  --st-faulted:   #DC2626; --st-faulted-bg:   #FEF2F2;
  --st-offline:   #9CA3AF; --st-offline-bg:   #F3F4F6;
  --st-warning:   #D97706; --st-warning-bg:   #FFFBEB;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --sp-3: 8px; --sp-4: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1120; --surface: #131F30; --surface-2: #182438; --border: #1E2E44;
    --text-1: #EEF2F8; --text-2: #8DA2C0; --text-3: #4B6480;
    --accent-bg: #172040; --accent-text: #93C5FD;
    --st-available-bg: #0A1F0E; --st-charging-bg: #0F1C38;
    --st-faulted-bg: #1F0E0E; --st-offline-bg: #1A1E24; --st-warning-bg: #1F1608;
  }
}

/* Shell */
.shell { display: flex; height: 100dvh; overflow: hidden; }
.main  { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.content { flex: 1; overflow-y: auto; padding: 22px 24px; }

/* Sidebar */
.sidebar { width: 220px; background: var(--sb-bg); border-right: 1px solid var(--sb-border);
           display: flex; flex-direction: column; padding: 16px 0; }
.sidebar-logo { padding: 0 16px 20px; display: flex; align-items: center; gap: 10px; }
.logo-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent);
             display: flex; align-items: center; justify-content: center; }
.nav-section-label { font-size: 10px; font-weight: 600; text-transform: uppercase;
                     letter-spacing: .07em; color: var(--sb-text); padding: 12px 16px 4px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 8px 16px;
            color: var(--sb-text); text-decoration: none; border-radius: 6px; margin: 0 8px;
            font-size: 13.5px; transition: background .12s, color .12s; }
.nav-item:hover, .nav-item.active { background: var(--sb-active-bg); color: var(--sb-active-text); }
.nav-item.active svg { color: var(--sb-active-icon); }
.tenant-chip { margin-top: auto; padding: 12px 16px; display: flex; align-items: center;
               gap: 10px; color: var(--sb-text); font-size: 12px; border-top: 1px solid var(--sb-border); }
.tenant-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent);
                 display: flex; align-items: center; justify-content: center;
                 color: white; font-size: 11px; font-weight: 700; flex-shrink: 0; }

/* Topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border);
          height: 56px; padding: 0 24px; display: flex; align-items: center; gap: 14px; }
.topbar-title { font-size: 19px; font-weight: 700; letter-spacing: -.02em; color: var(--text-1); }
.topbar-spacer { flex: 1; }
.topbar-date { font-size: 12px; color: var(--text-3); }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; }
.kpi-label { font-size: 11.5px; color: var(--text-3); margin-bottom: 6px; }
.kpi-val   { font-size: 26px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi-meta  { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }
.delta-up   { color: var(--st-available); }
.delta-down { color: var(--st-faulted); }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 18px 20px; margin-bottom: 20px; }
.card-title { font-size: 13.5px; font-weight: 600; margin-bottom: 14px; }

/* Table */
table { width: 100%; border-collapse: collapse; }
th { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
     color: var(--text-3); padding: 8px 12px; text-align: left; background: var(--surface-2); }
td { font-size: 13.5px; color: var(--text-2); padding: 10px 12px; border-top: 1px solid var(--border); }

/* Status pill */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px;
        border-radius: 99px; font-size: 11.5px; font-weight: 500; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-available { background: var(--st-available-bg); color: var(--st-available); }
.pill-charging  { background: var(--st-charging-bg);  color: var(--st-charging); }
.pill-faulted   { background: var(--st-faulted-bg);   color: var(--st-faulted); }
.pill-offline   { background: var(--st-offline-bg);   color: var(--st-offline); }
.pill-warning   { background: var(--st-warning-bg);   color: var(--st-warning); }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.4 } }
.pill-charging::before { animation: pulse 1.4s infinite; }

/* Protocol tag */
.proto-tag { background: var(--accent-bg); color: var(--accent-text); font-size: 10.5px;
             font-weight: 700; padding: 2px 7px; border-radius: 4px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: none; cursor: pointer;
       border-radius: var(--r-sm); font-family: inherit; font-weight: 500; transition: background .12s; }
.btn-md { padding: 8px 14px; font-size: 13.5px; }
.btn-sm { padding: 5px 10px;  font-size: 12px; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; color: var(--text-1); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger  { background: var(--st-faulted-bg); color: var(--st-faulted); }

/* Modal */
.modal-bg   { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
              display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal      { background: var(--surface); border-radius: var(--r-lg); max-width: 430px; width: 100%; }
.modal-head { display: flex; align-items: center; justify-content: space-between;
              padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-x    { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-3); }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px;
              border-top: 1px solid var(--border); }

/* Form fields */
.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-label { font-size: 12px; font-weight: 500; color: var(--text-2); }
.form-field input, .form-field select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 10px; font-size: 13.5px; color: var(--text-1); font-family: inherit;
  outline: none; transition: border-color .12s; }
.form-field input:focus, .form-field select:focus { border-color: var(--accent); }
.form-hint { font-size: 11.5px; color: var(--text-3); }

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text-1); color: var(--bg);
         padding: 10px 16px; border-radius: var(--r); font-size: 13.5px; z-index: 200;
         transition: opacity .25s; }
.toast.fade { opacity: 0; }

/* Login */
.login-shell { min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card  { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
               padding: 36px 32px; width: 360px; }
.login-logo  { width: 40px; height: 40px; border-radius: 10px; background: var(--accent);
               margin: 0 auto 20px; }
.login-title { font-size: 19px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.login-sub   { font-size: 12px; color: var(--text-3); text-align: center; margin-bottom: 24px; }
.login-error { background: var(--st-faulted-bg); color: var(--st-faulted); padding: 8px 12px;
               border-radius: var(--r-sm); font-size: 12px; margin-bottom: 14px; }

/* Energy bar chart */
.energy-chart { width: 100%; max-width: 100%; height: auto; display: block; }
.energy-bar { fill: currentColor; opacity: 0.15; color: var(--text-1); }
.energy-bar-today { fill: var(--accent); opacity: 1; }
.energy-grid { stroke: var(--border); stroke-width: 1; }
.energy-label { font-size: 8.5px; fill: var(--text-3); }
.energy-label-today { font-weight: 700; fill: var(--text-1); }

.login-card .btn { width: 100%; justify-content: center; }
.sidebar-brand { font-size: 14px; font-weight: 700; color: var(--sb-active-text); }
.muted { color: var(--text-3); }

/* Filter bar */
.filter-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 7px 10px; font-size: 13px;
  color: var(--text-1); font-family: inherit; outline: none; }
.filter-bar select { min-width: 160px; }
.filter-bar .spacer { flex: 1; }

/* Badge active / inactive in pill */
.pill-active   { background: var(--st-available-bg); color: var(--st-available); }
.pill-inactive { background: var(--st-offline-bg);   color: var(--st-offline); }
.pill-completed { background: var(--st-available-bg); color: var(--st-available); }

/* Monospace ID tag in table */
.id-tag { font-family: monospace; font-size: 12px; color: var(--accent); }

/* Session summary line */
.session-summary { font-size: 12px; color: var(--text-3); margin-bottom: 12px; }

/* Back link */
.back-link { display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
             color: var(--text-3); text-decoration: none; margin-bottom: 14px; }
.back-link:hover { color: var(--text-1); }

/* Detail header */
.detail-header { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.detail-header h1 { margin: 0; flex: 1; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.name-link { color: var(--accent); text-decoration: none; font-weight: 500; }
.name-link:hover { text-decoration: underline; }

/* Topbar user avatar */
.topbar-user { position: relative; }

.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 700; font-family: inherit;
  border: none; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: opacity .12s;
}
.user-avatar:hover { opacity: .85; }

.user-overlay-backdrop {
  position: fixed; inset: 0; z-index: 49;
}

.user-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); min-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 50; overflow: hidden;
}

.user-dropdown-header {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
}
.user-dropdown-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.user-dropdown-name  { font-size: 13.5px; font-weight: 600; color: var(--text-1); }
.user-dropdown-email { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }

.user-dropdown-divider { height: 1px; background: var(--border); margin: 2px 0; }

.user-dropdown-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 16px; font-size: 13.5px; color: var(--text-2);
  text-decoration: none; cursor: pointer; background: none;
  border: none; width: 100%; text-align: left; font-family: inherit;
  transition: background .1s;
}
.user-dropdown-item:hover { background: var(--surface-2); color: var(--text-1); }
.user-dropdown-signout { color: var(--st-faulted); }
.user-dropdown-signout:hover { background: var(--st-faulted-bg); color: var(--st-faulted); }
.user-dropdown-form { margin: 0; }

/* Security hub */
.page-lead { font-size: 13.5px; color: var(--text-2); margin: 0 0 16px; }
.security-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px; margin-top: 8px;
}
.security-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 20px; text-decoration: none;
  color: var(--text-1); transition: border-color .12s, box-shadow .12s;
  cursor: pointer;
}
.security-card:hover {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}
.security-card-icon {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  background: var(--accent-bg); display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; color: var(--accent);
}
.security-card-body  { flex: 1; }
.security-card-title { font-size: 14px; font-weight: 600; margin-bottom: 3px; }
.security-card-desc  { font-size: 12px; color: var(--text-3); }
.security-card-arrow { font-size: 20px; color: var(--text-3); }

/* Form actions row */
.form-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px;
}

/* Generic form input (for password page) */
.form-input {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 8px 10px; font-size: 13.5px;
  color: var(--text-1); font-family: inherit; width: 100%; outline: none;
}
.form-input:focus { border-color: var(--accent); }

.api-key-row { display: flex; align-items: center; gap: 8px; }
.api-key-row .totp-key { flex: 1; margin: 0; }

/* OTP input */
.otp-input {
  font-size: 22px; letter-spacing: .25em; text-align: center;
  width: 100%; padding: 10px; font-family: monospace;
}

/* TOTP setup */
.totp-setup { margin-top: 16px; }
.totp-qr {
  width: 256px;
  height: 256px;
  margin: 12px 0;
  line-height: 0;
  background: #fff;
  border-radius: var(--r-sm);
  overflow: hidden;
}
.totp-qr svg { display: block; width: 256px; height: 256px; }
.totp-key-label { font-size: 12px; color: var(--text-3); margin: 8px 0 4px; }
.totp-key {
  display: block; font-family: monospace; font-size: 13px; letter-spacing: .1em;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 8px 12px; word-break: break-all;
}

/* Recovery codes */
.recovery-codes-block {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 16px; margin-top: 14px;
}
.recovery-codes-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 12px 0;
}
.recovery-codes-grid code {
  font-family: monospace; font-size: 13px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px 10px;
  text-align: center;
}

/* Settings description text */
.settings-desc { font-size: 13.5px; color: var(--text-2); margin-bottom: 14px; }
.settings-actions { display: flex; gap: 8px; }
.totp-setup-actions { display: flex; gap: 8px; margin-top: 12px; }

/* MFA recovery link */
.mfa-recovery-link { text-align: center; margin-top: 14px; font-size: 12px; color: var(--text-3); }
.mfa-recovery-link a { color: var(--accent); text-decoration: none; }

.command-result {
  margin-top: 10px; padding: 8px 12px; font-size: 12px;
  border-radius: var(--r-sm); background: var(--accent-bg); color: var(--accent-text);
}

/* passkey list */
.passkey-list { display: flex; flex-direction: column; gap: 0; }
.passkey-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.passkey-row:last-child { border-bottom: none; }
.passkey-row__icon { font-size: 1.4rem; flex-shrink: 0; }
.passkey-row__info { flex: 1; }
.passkey-row__name { font-weight: 600; color: var(--text-1); }
.passkey-row__meta { font-size: .78rem; color: var(--text-3); margin-top: 2px; }

/* login divider */
.login-divider {
  display: flex; align-items: center; gap: var(--sp-3);
  margin: var(--sp-4) 0; color: var(--text-3); font-size: .85rem;
}
.login-divider::before, .login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.btn--outline {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-1);
}
.btn--outline:hover { background: var(--surface-2); }
.btn--full { width: 100%; justify-content: center; }
