/* ==========================================================================
   Convo Monitor – UI/UX Design System (Pinx Admin Visual Base)
   Specification: HotelEar_UIUX_Design.md & skill.md
   Stack: Django + Vanilla HTML/CSS/JS + LiveKit
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Pinx Core Tokens (Light Mode - Calm by default) */
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #f1f2f7;
  --border: #e7e9f0;
  --border-light: #f0f2f7;
  --border-dark: #d5d9e5;

  --text: #141726;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --text-muted: #6b7280;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-2: #8b5cf6;
  --primary-soft: #eef0ff;
  --primary-ink: #ffffff;

  --success: #10b981;
  --success-hover: #059669;
  --success-soft: #e7f8f2;
  --ok: var(--success);

  --warning: #f59e0b;
  --warning-hover: #d97706;
  --warning-soft: #fef4e2;
  --warning-text: #92400e;
  --warn: var(--warning);

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-soft: #fdecec;

  --info: #3b82f6;
  --info-hover: #2563eb;
  --info-soft: #e9f1fe;
  --low: var(--info);
  --medium: var(--warning);
  --high: var(--danger);

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.05);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.07), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.12), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-3: 0 12px 40px -8px rgba(15, 23, 42, 0.28), 0 -4px 24px rgba(15, 23, 42, 0.12);

  /* Convo Monitor Specific Tokens */
  --live: var(--success);
  --alert: var(--danger);
  --meter-ok: var(--success);
  --meter-warn: var(--warning);
  --meter-high: var(--danger);
  --meter-track: var(--surface-3);
  --alert-pulse: 0 0 0 0 rgba(239, 68, 68, 0.45);

  /* Layout Constants */
  --sidebar-w: 264px;
  --sidebar-w-mini: 72px;
  --sidebar-collapsed-w: 74px;
  --topbar-h: 68px;
  --topbar-h-sm: 56px;
  --bottom-nav-h: 56px;
  --sheet-radius: 22px;
  --field-h: 48px;
  --content-pad: 16px;
  --content-pad-lg: 20px;

  /* Motion tokens (Premium Shell spec §8.1) */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --dur-slow: 260ms;
  --dur-page: 320ms;

  /* Shell surfaces (blurred app-like chrome) */
  --overlay: rgba(15, 23, 42, 0.5);
  --topbar-bg: rgba(255, 255, 255, 0.8);
  --bottom-nav-bg: rgba(255, 255, 255, 0.88);
  --sheet-bg: var(--surface);

  /* Safe areas (viewport-fit=cover) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
}

/* Dark Theme Overrides */
html[data-theme="dark"], body[data-theme="dark"] {
  --bg: #0f121d;
  --surface: #171b2c;
  --surface-2: #1e2338;
  --surface-3: #252b45;
  --border: #282f4c;
  --border-light: #20263d;
  --border-dark: #373f62;

  --text: #f3f4f8;
  --text-2: #9ba1b6;
  --text-3: #6b728d;
  --text-muted: #9ba1b6;

  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-2: #a78bfa;
  --primary-soft: rgba(99, 102, 241, 0.16);

  --success: #10b981;
  --success-hover: #34d399;
  --success-soft: rgba(16, 185, 129, 0.16);

  --warning: #f59e0b;
  --warning-hover: #fbbf24;
  --warning-soft: rgba(245, 158, 11, 0.16);
  --warning-text: #fcd34d;

  --danger: #f87171;
  --danger-hover: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.18);

  --info: #60a5fa;
  --info-hover: #3b82f6;
  --info-soft: rgba(59, 130, 246, 0.16);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 45px rgba(0, 0, 0, 0.6);

  --meter-track: #23283e;

  --overlay: rgba(0, 0, 0, 0.6);
  --topbar-bg: rgba(11, 13, 18, 0.8);
  --bottom-nav-bg: rgba(15, 18, 24, 0.9);
}

/* ==========================================================================
   Base Styles & Reset
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

h1, h2, h3, h4 {
  color: var(--text);
  font-weight: 700;
  margin-top: 0;
  letter-spacing: -0.015em;
}

h1 { font-size: 23px; line-height: 1.3; margin-bottom: 4px; }
h2 { font-size: 15px; line-height: 1.4; margin-bottom: 12px; }
h3 { font-size: 13.5px; line-height: 1.4; margin-bottom: 8px; }

.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.inline { display: inline; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 18px; }

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

/* ==========================================================================
   App Shell Architecture (Pinx Sidebar + Main Area)
   ========================================================================== */
.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: width 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.brand:hover {
  text-decoration: none;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.nav-section-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 0 12px;
  margin-bottom: 6px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  transition: all 0.15s ease;
  position: relative;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Main Content Area */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Sticky Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
}

/* Hotel Switcher Dropdown in Topbar */
.hotel-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.hotel-switcher select {
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 0;
  margin: 0;
  outline: none;
  cursor: pointer;
  min-height: auto;
  width: auto;
}

/* Global Search */
.global-search {
  position: relative;
  max-width: 320px;
  width: 100%;
}

.global-search input {
  width: 100%;
  padding: 7px 12px 7px 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text);
  min-height: 36px;
  margin: 0;
}

.global-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.search-shortcut {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text-3);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ws-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.ws-state.on {
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.3);
  background: var(--success-soft);
}

.ws-state.off {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
  background: var(--danger-soft);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* Privacy & Legal Safety Banner */

/* Global Alert Stack (Section 5.1) */
.alert-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 28px 0;
}

.alert-banner {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  animation: slide-alert 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm);
}

.alert-banner--medium {
  background: var(--warning-soft);
  border-color: var(--warning);
}

.alert-banner__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.alert-banner__text strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.alert-banner__text span {
  font-size: 12.5px;
  color: var(--text-2);
}

@keyframes slide-alert {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Content Container */
.content {
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 28px 60px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

/* ==========================================================================
   Pinx Cards & KPI Grid (Section 6.2)
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
  position: relative;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.card + .card {
  margin-top: 20px;
}

.grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.grid-2 {
  display: grid;
  gap: 20px;
  grid-template-columns: 2fr 1fr;
}

/* KPI Stat Cards */
.stat-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  margin-bottom: 22px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat .label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.stat .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.stat .meta-trend {
  font-size: 11.5px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 4px;
}

.hotel-section {
  margin-bottom: 28px;
}

.hotel-section > h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  margin-bottom: 14px;
}

/* ==========================================================================
   Device Card (Section 5.2)
   ========================================================================== */
.device-card {
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 22px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.device-card:hover {
  box-shadow: var(--shadow);
}

.device-card.alerting {
  border: 2px solid var(--danger);
  background: var(--danger-soft);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.18);
  animation: pulse-danger 1.8s infinite;
}

@keyframes pulse-danger {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.device-card .head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.device-card .name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.device-card .meta {
  font-size: 12.5px;
  color: var(--text-2);
}

.device-card .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* Hardware Status Dot */
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  background: var(--text-3);
  flex-shrink: 0;
}

.status-dot.ACTIVE {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.status-dot.OFFLINE {
  background: var(--danger);
}

.status-dot.PENDING {
  background: var(--warning);
}

.status-dot.DISABLED {
  background: var(--text-3);
}

.status-dot.warn {
  background: var(--warning);
  animation: blink 1.2s infinite;
}

/* Level Meter (Section 5.3) */
.meter {
  position: relative;
  height: 9px;
  border-radius: 999px;
  background: var(--meter-track);
  overflow: hidden;
}

.meter .fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--level, 0) * 100%);
  background: var(--meter-ok);
  border-radius: 999px;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.25s ease;
}

.meter.warm .fill {
  background: var(--meter-warn);
}

.meter.hot .fill {
  background: var(--meter-high);
}

/* ==========================================================================
   Badges (Section 5.6)
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}

.badge-alert {
  background: var(--danger);
  color: #fff;
  font-weight: 700;
}

.sev-LOW, .badge--info {
  background: var(--info-soft);
  color: var(--info);
}

.sev-MEDIUM, .badge--warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.sev-HIGH, .badge--danger {
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
}

.st-OPEN {
  background: var(--danger-soft);
  color: var(--danger);
}

.st-ACKNOWLEDGED {
  background: var(--warning-soft);
  color: var(--warning);
}

.st-RESOLVED, .badge--success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-listening {
  background: var(--primary);
  color: #fff;
}

.badge-listening::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: blink 1.2s infinite;
}

@keyframes blink {
  50% { opacity: 0.3; }
}

/* ==========================================================================
   Buttons (Pinx Style)
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  white-space: nowrap;
  transition: all 0.15s ease;
  user-select: none;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-dark);
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #fff;
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.btn-warn {
  background: var(--warning);
  border-color: var(--warning);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-sm {
  padding: 5px 11px;
  min-height: 32px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
  min-height: 48px;
  border-radius: 12px;
}

.btn-block {
  width: 100%;
}

/* ==========================================================================
   Dropdown Menus & Action Menus
   ========================================================================== */
.dropdown {
  position: relative;
  display: inline-flex;
}

.dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dropdown-menu {
  position: absolute;
  min-width: 175px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.16), 0 8px 10px -6px rgba(15, 23, 42, 0.1);
  padding: 6px;
  z-index: 10050;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: dropdownFadeIn 0.12s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  border: none;
  border-radius: 6px;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
  user-select: none;
  min-height: 32px;
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.dropdown-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  font-size: 13px;
  flex-shrink: 0;
}

.dropdown-item--danger {
  color: var(--danger);
}

.dropdown-item--danger:hover,
.dropdown-item--danger:focus-visible {
  background: var(--danger-soft);
  color: var(--danger);
}

.dropdown-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 2px;
}

/* ==========================================================================
   Forms, Inputs & Filters
   ========================================================================== */
label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 12px;
}

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  min-height: 40px;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  outline: 0;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

input[type=checkbox], input[type=radio] {
  display: inline-block;
  width: 17px;
  height: 17px;
  min-height: 17px;
  margin: 0 7px 0 0;
  cursor: pointer;
  accent-color: var(--primary);
}

input[type=range] {
  padding: 0;
  min-height: auto;
  accent-color: var(--primary);
}

textarea {
  min-height: 85px;
  resize: vertical;
}

.check {
  display: flex;
  align-items: center;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}

.form-grid {
  display: grid;
  gap: 8px 18px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}

.filters {
  display: grid;
  gap: 10px 16px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  align-items: end;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
}

.filters label {
  margin: 0;
}

.alert {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  font-weight: 700;
  background: var(--surface-2);
}

tbody tr.clickable {
  cursor: pointer;
  transition: background 0.12s ease;
}

tbody tr.clickable:hover {
  background: var(--surface-2);
}

tbody tr.new {
  animation: flash-row 2.5s ease-out;
}

@keyframes flash-row {
  from { background: var(--danger-soft); }
  to { background: transparent; }
}

.pager {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs button,
.tabs a.tab,
.tabs .tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 11px 18px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: all 0.15s ease;
  position: relative;
}

.tabs button:hover,
.tabs a.tab:hover,
.tabs .tab:hover {
  color: var(--text);
  text-decoration: none;
}

.tabs button:focus-visible,
.tabs a.tab:focus-visible,
.tabs .tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tabs button.active,
.tabs button.is-active,
.tabs a.tab.is-active,
.tabs .tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tabs .tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 7px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  background: var(--surface-3);
  color: var(--text-2);
}

.tabs .tab.is-active .tab-badge,
.tabs a.tab.is-active .tab-badge,
.tabs button.active .tab-badge {
  background: var(--primary-soft);
  color: var(--primary);
}

/* Slide-in Edit Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 60;
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  /* Hidden (not just transparent) when closed, so the closed drawer costs nothing to draw.
     No backdrop blur: blurring the whole page every frame made the drawer slow to open on phones. */
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0s;
}

.drawer {
  background: var(--surface);
  width: min(540px, 100%);
  height: 100%;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

.drawer-backdrop.open .drawer {
  transform: translateX(0);
}

.drawer-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-foot {
  padding: 18px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface-2);
}

/* Pinx Toggle Switch */
.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}

.switch-input {
  appearance: none;
  width: 40px;
  height: 22px;
  background: var(--surface-3);
  border: 1px solid var(--border-dark);
  border-radius: 9999px;
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0;
  flex-shrink: 0;
}

.switch-input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.switch-input:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.switch-input:checked::after {
  transform: translateX(18px);
}

.switch-input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Thresholds Slider & Live Meter */
.slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.slider-val {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
}

.slider-input {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
  margin: 4px 0;
}

/* ==========================================================================
   Listen Panel (Section 5.4 - Slide-in Drawer / Dock)
   ========================================================================== */

.listen-dock {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(600px, calc(100% - 32px));
  box-shadow: var(--shadow-lg);
}

.listen-dock .close {
  margin-left: auto;
}

/* ==========================================================================
   Timeline (Section 5.5)
   ========================================================================== */
.timeline-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.timeline-card__head h2 { margin: 0; }

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  position: relative;
  padding: 0 0 16px 22px;
}

/* connector line between dots; stops at the last event */
.timeline li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 14px;
  bottom: -2px;
  width: 2px;
  background: var(--border);
  border-radius: 1px;
}

.timeline li:last-child { padding-bottom: 0; }

.timeline li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-3);
  box-shadow: 0 0 0 3px var(--surface);
}

.timeline li.k-DETECTED::before, .timeline li.k-MERGED::before {
  background: var(--danger);
}

.timeline li.k-NOTIFIED::before, .timeline li.k-ESCALATED::before {
  background: var(--warning);
}

.timeline li.k-ACKNOWLEDGED::before, .timeline li.k-LISTEN::before {
  background: var(--primary);
}

.timeline li.k-RESOLVED::before, .timeline li.k-FALSE_ALARM::before {
  background: var(--success);
}

.timeline .tl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13.5px;
}

.timeline .tl-title { min-width: 0; }

.timeline .tl-msg {
  margin-top: 2px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-2);
  overflow-wrap: anywhere;
}

.timeline .when {
  flex-shrink: 0;
  color: var(--text-3);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Timeline scrolls inside its card. Phones: capped height. Desktop: see .incident-grid below. */
.timeline {
  max-height: 420px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 10px 4px 0;
  margin-right: -10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.timeline::-webkit-scrollbar { width: 6px; }
.timeline::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* fade only while more events are hidden below; gone once scrolled to the end */
.timeline.has-more {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent);
}

/* Desktop: the side column takes the main column's height (height:0 + min-height:100% keeps it
   from growing the row), and the timeline card fills what is left so both columns end on one line. */
@media (min-width: 861px) {
  .incident-grid > .stack:last-child {
    height: 0;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  .incident-grid > .stack:last-child > * { flex-shrink: 0; }
  .incident-grid #timeline-card {
    flex: 1 1 auto;
    min-height: 260px;
    display: flex;
    flex-direction: column;
  }
  .incident-grid .timeline { flex: 1 1 0; min-height: 0; max-height: none; }
}

.note {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--surface-2);
}

.note + .note {
  margin-top: 10px;
}

/* ==========================================================================
   Histogram Bar Chart (Reports)
   ========================================================================== */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 200px;
  padding: 12px 4px 4px;
  overflow-x: auto;
}

.bars .bar {
  flex: 1 0 12px;
  display: flex;
  flex-direction: column-reverse;
  min-width: 12px;
  position: relative;
  border-radius: 4px 4px 0 0;
  background: var(--surface-3);
}

.bars .bar:hover {
  outline: 2px solid var(--primary);
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-2);
  margin-top: 10px;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -1px;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(600px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  margin-bottom: 16px;
}

.modal .modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
  flex-wrap: wrap;
}

.code-box {
  font-family: var(--font-mono);
  font-size: 26px;
  letter-spacing: 0.16em;
  text-align: center;
  padding: 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  margin: 12px 0;
  user-select: all;
  background: var(--surface-2);
  color: var(--primary);
  font-weight: 700;
}

/* ==========================================================================
   Toasts (Section 5.8)
   ========================================================================== */
.toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100% - 32px));
}

.toast {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 12px 30px 12px 16px;
  animation: slide-toast 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.incident { background: var(--danger-soft); }

.toast .toast-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease;
}

.toast .toast-close:hover {
  color: var(--text);
}

.toast .t-title {
  font-weight: 700;
  margin-bottom: 3px;
  font-size: 13.5px;
}

.toast .t-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

@keyframes slide-toast {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ==========================================================================
   Login Screen (Section 6.1)
   ========================================================================== */
.login-wrap {
  min-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: min(420px, 100%);
  padding: 32px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.notice-small {
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  margin: 18px 0 0;
}

.empty {
  text-align: center;
  color: var(--text-3);
  padding: 32px 16px;
  font-size: 13.5px;
}

/* Mobile shell (bottom nav, drawer, responsive rules) moved to:
   layout.css / components.css / hotelear.css / motion.css (loaded after this file). */
