/* ── KOVA Dashboard styles ── */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;

  --green: #3fb950;
  --green-bg: rgba(63, 185, 80, 0.12);
  --orange: #f0883e;
  --orange-bg: rgba(240, 136, 62, 0.12);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, 0.12);
  --blue: #58a6ff;
  --blue-bg: rgba(88, 166, 255, 0.12);

  --radius: 10px;
  --radius-sm: 6px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 22px; color: var(--blue); }
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: 0.04em; }
.logo-sub { font-size: 12px; color: var(--text-muted); margin-left: 4px; }

.refresh-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s infinite;
}

.pulse-dot.error { background: var(--red); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* ── Main ── */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px;
}

/* ── Summary bar ── */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: center;
  transition: transform 0.15s;
}
.summary-card:hover { transform: translateY(-1px); }
.summary-card.online  { border-color: rgba(63,185,80,0.35); }
.summary-card.stale   { border-color: rgba(240,136,62,0.35); }
.summary-card.offline { border-color: rgba(248,81,73,0.35); }

.summary-num {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}
.summary-card.online  .summary-num { color: var(--green); }
.summary-card.stale   .summary-num { color: var(--orange); }
.summary-card.offline .summary-num { color: var(--red); }
.summary-card.total   .summary-num { color: var(--blue); }

.summary-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Alert banner ── */
.alert-banner {
  background: var(--red-bg);
  border: 1px solid rgba(248,81,73,0.4);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--red);
  font-weight: 500;
}
.alert-icon { font-size: 18px; }

/* ── Device grid ── */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

/* ── Device card ── */
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.device-card:hover {
  border-color: var(--blue);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.device-card.status-online  { border-left: 3px solid var(--green); }
.device-card.status-stale   { border-left: 3px solid var(--orange); }
.device-card.status-offline { border-left: 3px solid var(--red); }
.device-card.status-unknown   { border-left: 3px solid var(--text-muted); }
.device-card.status-degraded  { border-left: 3px solid var(--orange); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.device-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.device-location {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.status-badge.online  { background: var(--green-bg);  color: var(--green); }
.status-badge.stale   { background: var(--orange-bg); color: var(--orange); }
.status-badge.offline { background: var(--red-bg);    color: var(--red); }
.status-badge.unknown   { background: rgba(139,148,158,0.15); color: var(--text-muted); }
.status-badge.degraded  { background: var(--orange-bg); color: var(--orange); }

.card-body { display: flex; flex-direction: column; gap: 10px; }

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.card-label { color: var(--text-muted); }
.card-value { font-weight: 500; }

.event-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
.event-chip.high    { background: var(--red-bg);    color: var(--red); }
.event-chip.medium  { background: var(--orange-bg); color: var(--orange); }
.event-chip.low     { background: rgba(210,153,34,0.12); color: #d29922; }
.event-chip.info    { background: var(--blue-bg);   color: var(--blue); }

.card-metrics {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.metric {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}
.metric-icon { font-size: 13px; }

/* ── Loading / empty / error states ── */
.loading-state, .empty-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
  grid-column: 1/-1;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-icon, .error-icon { font-size: 36px; }
.error-icon { color: var(--red); }

.empty-state h3, .error-state h3 {
  font-size: 16px;
  color: var(--text);
}

/* ── Event panel ── */
.panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
}

.event-panel {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  width: 440px;
  max-width: 100vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 300;
  overflow-y: auto;
}

.panel-overlay.open, .event-panel.open {
  display: block;
}

.event-panel-inner { padding: 24px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.panel-header h2 { font-size: 16px; }

.panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}
.panel-close:hover { color: var(--text); }

/* ── Event list ── */
.event-list { display: flex; flex-direction: column; gap: 10px; }

.event-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.event-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.event-type-label {
  font-size: 13px;
  font-weight: 600;
}

.event-time {
  font-size: 11px;
  color: var(--text-muted);
}

.event-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  .event-panel { width: 100vw; }
  .header-inner { padding: 12px 16px; }
  .main { padding: 18px 16px; }
}

@keyframes alertPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.45);
    border-color: rgba(255, 77, 77, 0.85);
  }
  50% {
    box-shadow: 0 0 0 12px rgba(255, 77, 77, 0.08);
    border-color: rgba(255, 77, 77, 1);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 77, 77, 0);
    border-color: rgba(255, 77, 77, 0.85);
  }
}

@keyframes warningPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 179, 71, 0.35);
    border-color: rgba(255, 179, 71, 0.7);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(255, 179, 71, 0.06);
    border-color: rgba(255, 179, 71, 1);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 179, 71, 0);
    border-color: rgba(255, 179, 71, 0.7);
  }
}

.alert-flash {
  animation: alertPulse 1.2s infinite;
}

.warning-flash {
  animation: warningPulse 1.8s infinite;
}

.device-card.alert-flash,
.alert-banner.alert-flash {
  border-width: 2px;
}

.device-card.warning-flash {
  border-width: 2px;
}

/* ── Sensor list (multi-device rooms) ── */
.sensor-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0 4px;
  border-top: 1px solid var(--border);
}

.sensor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.sensor-label {
  color: var(--text-muted);
  font-size: 12px;
}

.sensor-id {
  display: inline-block;
  margin-left: 6px;
  color: var(--text-muted);
  opacity: 0.55;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10.5px;
  letter-spacing: 0.2px;
}

/* ── Vitals row (heart rate + breathing) ── */
.card-vitals {
  display: flex;
  gap: 16px;
  padding: 8px 0 4px;
  border-top: 1px solid var(--border);
}

.vital {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.vital-icon { font-size: 14px; }

/* ── Login Screen ─────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
  padding: 24px;
}

.login-card {
  background: var(--surface, #1e2a3a);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.08);
}

.login-logo { text-align: center; margin-bottom: 20px; }

.login-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 8px;
}

.login-subtitle {
  text-align: center;
  font-size: 14px;
  color: #8899aa;
  margin: 0 0 32px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.login-field { display: flex; flex-direction: column; gap: 6px; }

.login-field label {
  font-size: 13px;
  font-weight: 600;
  color: #aabbcc;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.login-field input {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 15px;
  color: #fff;
  outline: none;
  transition: border-color 0.2s;
}

.login-field input:focus {
  border-color: #3b82f6;
  background: rgba(59,130,246,0.08);
}

.login-field input::placeholder { color: #445566; }

.login-error {
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fca5a5;
}

.login-btn {
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-top: 4px;
}

.login-btn:hover  { background: #2563eb; }
.login-btn:active { transform: scale(0.98); }
.login-btn:disabled { background: #334455; color: #667788; cursor: not-allowed; }

.login-footer {
  text-align: center;
  font-size: 13px;
  color: #556677;
  margin: 24px 0 0;
}

.login-footer a { color: #3b82f6; text-decoration: none; }
.login-footer a:hover { text-decoration: underline; }

.facility-badge {
  background: rgba(59,130,246,0.2);
  border: 1px solid rgba(59,130,246,0.4);
  color: #93c5fd;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.logout-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #aabbcc;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  margin-left: 12px;
}

.logout-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }

/* ── Admin Panel ─────────────────────────────────────────────────────────── */
.admin-tab-btn {
  background: rgba(139,92,246,0.2);
  border: 1px solid rgba(139,92,246,0.4);
  color: #c4b5fd;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  margin-left: 8px;
}
.admin-tab-btn:hover { background: rgba(139,92,246,0.35); color: #fff; }

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  background: var(--surface, #1e2a3a);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.admin-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin: 0;
}

.admin-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  max-width: 1200px;
  margin: 0 auto;
}

.admin-section {
  background: var(--surface, #1e2a3a);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  overflow: hidden;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.admin-section-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  margin: 0;
}

.admin-list { padding: 8px 0; }

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

.admin-table th {
  text-align: left;
  padding: 10px 20px;
  color: #8899aa;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.admin-table td {
  padding: 12px 20px;
  color: #ccd6e0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: rgba(255,255,255,0.03); }

.admin-table code {
  font-size: 11px;
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: #93c5fd;
}

.admin-table small { color: #667788; font-size: 11px; }

.admin-btn-primary {
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.admin-btn-primary:hover { background: #2563eb; }

.admin-btn-sm {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #ccd6e0;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  margin-right: 4px;
  transition: background 0.2s;
}
.admin-btn-sm:hover { background: rgba(255,255,255,0.15); }
.admin-btn-sm.danger { color: #fca5a5; border-color: rgba(239,68,68,0.3); }
.admin-btn-sm.danger:hover { background: rgba(239,68,68,0.15); }

.admin-select {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: #fff;
  width: 100%;
  outline: none;
}

.admin-select-sm {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  color: #fff;
  outline: none;
  margin-right: 6px;
}

.role-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
}
.role-badge.admin   { background: rgba(239,68,68,0.2);   color: #fca5a5; }
.role-badge.manager { background: rgba(59,130,246,0.2);  color: #93c5fd; }
.role-badge.staff   { background: rgba(34,197,94,0.2);   color: #86efac; }

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-dot.online  { background: #22c55e; }
.status-dot.offline { background: #ef4444; }

.admin-empty { color: #556677; padding: 20px; text-align: center; font-size: 13px; }
.admin-error { color: #fca5a5; padding: 20px; text-align: center; font-size: 13px; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface, #1e2a3a);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  width: 100%;
  max-width: 460px;
  z-index: 101;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.modal-header h3 { color: #fff; margin: 0; font-size: 16px; }

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Facility grouping ───────────────────────────────────────────────────── */
.facility-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 16px 4px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 12px;
}
.facility-group-header h3 {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-transform: capitalize;
  margin: 0;
}
.facility-room-count {
  font-size: 12px;
  color: #8899aa;
  background: rgba(255,255,255,0.07);
  padding: 2px 8px;
  border-radius: 10px;
}
.device-grid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  width: 100%;
  margin-bottom: 24px;
  grid-column: 1 / -1;
}
.facility-group-header {
  grid-column: 1 / -1;
}
.facility-group-wrapper {
  grid-column: 1 / -1;
  width: 100%;
}
