/* ============================================
   Alert System - Dark Glassmorphism Dashboard
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-start: #0a0a1a;
  --bg-end: #1a1a3e;
  --card-bg: rgba(255, 255, 255, 0.05);
  --card-bg-hover: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-border-hover: rgba(255, 255, 255, 0.15);
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.4);
  --success: #22c55e;
  --success-glow: rgba(34, 197, 94, 0.4);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.4);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.4);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --surface: rgba(255, 255, 255, 0.03);
  --blur: 20px;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.4);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 50%, #12122e 100%);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
              radial-gradient(ellipse at 50% 80%, rgba(59, 130, 246, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Animations --- */
@keyframes pulse-online {
  0%, 100% { box-shadow: 0 0 0 0 var(--success-glow); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

@keyframes pulse-alert {
  0%, 100% { box-shadow: 0 0 0 0 var(--danger-glow); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

@keyframes pulse-alert-bg {
  0%, 100% { box-shadow: 0 0 20px var(--danger-glow), inset 0 0 20px rgba(239, 68, 68, 0.05); }
  50% { box-shadow: 0 0 40px var(--danger-glow), inset 0 0 30px rgba(239, 68, 68, 0.1); }
}

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

@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(100%); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

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

@keyframes gradient-border {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(100%) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(100%) scale(0.95); }
}

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes ripple {
  0% { transform: scale(0); opacity: 0.5; }
  100% { transform: scale(4); opacity: 0; }
}

.page-transition {
  animation: slide-in 0.35s ease-out;
}

/* --- Glassmorphism Card --- */
.glass-card {
  background: var(--card-bg);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all var(--transition);
  box-shadow: var(--shadow);
}

.glass-card:hover {
  background: var(--card-bg-hover);
  border-color: var(--card-border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.glass-card.no-hover:hover {
  transform: none;
  background: var(--card-bg);
  border-color: var(--card-border);
  box-shadow: var(--shadow);
}

.glass-card.alert-active {
  border-color: rgba(239, 68, 68, 0.3);
  animation: pulse-alert-bg 2s ease-in-out infinite;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  box-shadow: 0 4px 15px var(--primary-glow);
}
.btn-primary:hover {
  box-shadow: 0 6px 25px var(--primary-glow);
  filter: brightness(1.1);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #f87171);
  color: white;
  box-shadow: 0 4px 15px var(--danger-glow);
}
.btn-danger:hover {
  box-shadow: 0 6px 25px var(--danger-glow);
  filter: brightness(1.1);
}
.btn-warning {
  background: linear-gradient(135deg, var(--warning), #fbbf24);
  color: #1a1a2e;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}
.btn-warning:hover {
  box-shadow: 0 6px 25px rgba(245, 158, 11, 0.4);
  filter: brightness(1.1);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), #4ade80);
  color: white;
  box-shadow: 0 4px 15px var(--success-glow);
}
.btn-success:hover {
  box-shadow: 0 6px 25px var(--success-glow);
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--card-border);
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-color: var(--card-border-hover);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover {
  background: rgba(99, 102, 241, 0.1);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
  border-radius: var(--radius-xs);
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
  border-radius: var(--radius);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
}

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

.btn .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* --- Inputs --- */
.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: all var(--transition);
  outline: none;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  background: rgba(255, 255, 255, 0.07);
}

.input::placeholder {
  color: var(--text-muted);
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* --- Login Page --- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  position: relative;
}

.login-card::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(135deg, var(--primary), #a855f7, var(--primary), #3b82f6);
  background-size: 300% 300%;
  animation: gradient-border 4s ease infinite;
  z-index: -1;
  opacity: 0.6;
}

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

.login-logo .icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 20px var(--primary-glow));
}

.login-logo h1 {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-primary), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-logo p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 4px;
}

.login-footer {
  text-align: center;
  margin-top: 20px;
}

.login-footer a {
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: color var(--transition);
}
.login-footer a:hover {
  color: var(--primary);
  text-decoration: none;
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 26, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--card-border);
  padding: 0 16px;
  padding-top: var(--safe-top);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  max-width: 1200px;
  margin: 0 auto;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 600;
}

.header-title .bell {
  font-size: 1.3rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hamburger {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 50%;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.hamburger:hover {
  background: rgba(255, 255, 255, 0.08);
}

.hamburger-lines {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 20px;
}
.hamburger-lines span {
  display: block;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: all var(--transition);
}

/* --- Side Menu --- */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}
.menu-overlay.open {
  opacity: 1;
  visibility: visible;
}

.side-menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: rgba(15, 15, 35, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-left: 1px solid var(--card-border);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  display: flex;
  flex-direction: column;
}
.side-menu.open {
  transform: translateX(0);
}

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

.menu-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.menu-items {
  list-style: none;
  flex: 1;
}

.menu-items li {
  margin-bottom: 4px;
}

.menu-items a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
}
.menu-items a:hover,
.menu-items a.active {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}
.menu-items a.active {
  color: var(--primary);
}

.menu-items .icon {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
}

.menu-footer {
  padding-top: 20px;
  border-top: 1px solid var(--card-border);
}

/* --- Stats Bar --- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.stat-card {
  text-align: center;
  padding: 16px 12px;
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-card.stat-total .stat-value { color: var(--primary); }
.stat-card.stat-online .stat-value { color: var(--success); }
.stat-card.stat-alert .stat-value { color: var(--danger); }

/* --- Global Actions --- */
.global-actions {
  display: flex;
  gap: 12px;
  padding: 0 16px 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.global-actions .btn {
  flex: 1;
}

/* --- Device Grid --- */
.device-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 0 16px 100px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .device-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .device-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* --- Device Card --- */
.device-card {
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

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

.device-name {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.device-site {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* --- Status Badge --- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.online {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.status-badge.offline {
  background: rgba(100, 116, 139, 0.15);
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--success);
  animation: pulse-online 2s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--text-muted);
}

/* --- Alarm State --- */
.alarm-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.alarm-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.alarm-status {
  font-size: 0.85rem;
  font-weight: 600;
}

.alarm-status.active {
  color: var(--danger);
}

.alarm-status.inactive {
  color: var(--text-muted);
}

/* --- Alarm Toggle Button --- */
.alarm-toggle {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.alarm-toggle.activate {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(239, 68, 68, 0.1));
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.alarm-toggle.activate:hover {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.3), rgba(239, 68, 68, 0.15));
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.2);
}

.alarm-toggle.deactivate {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(34, 197, 94, 0.1));
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}
.alarm-toggle.deactivate:hover {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.3), rgba(34, 197, 94, 0.15));
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.2);
}

.alarm-toggle:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.alarm-toggle .toggle-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

/* --- Device Meta --- */
.device-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* --- RSSI Bars --- */
.rssi-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
}

.rssi-bars .bar {
  width: 4px;
  border-radius: 1px;
  background: var(--text-muted);
  opacity: 0.3;
  transition: all var(--transition);
}
.rssi-bars .bar:nth-child(1) { height: 4px; }
.rssi-bars .bar:nth-child(2) { height: 7px; }
.rssi-bars .bar:nth-child(3) { height: 11px; }
.rssi-bars .bar:nth-child(4) { height: 16px; }

.rssi-bars .bar.active { opacity: 1; }
.rssi-bars.excellent .bar.active { background: var(--success); }
.rssi-bars.good .bar.active { background: var(--success); }
.rssi-bars.fair .bar.active { background: var(--warning); }
.rssi-bars.poor .bar.active { background: var(--danger); }

/* --- Device Detail Page --- */
.detail-page {
  padding: 0 16px 100px;
  max-width: 600px;
  margin: 0 auto;
}

.detail-back {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.detail-back:hover { color: var(--text-primary); }

.detail-status-block {
  text-align: center;
  padding: 32px 20px;
  margin-bottom: 20px;
}

.detail-device-name {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.detail-site-name {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.big-alarm-btn {
  width: 100%;
  max-width: 300px;
  margin: 20px auto 0;
  padding: 18px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  -webkit-tap-highlight-color: transparent;
}

.big-alarm-btn.activate {
  background: linear-gradient(135deg, var(--danger), #f87171);
  color: white;
  box-shadow: 0 8px 30px var(--danger-glow);
}
.big-alarm-btn.activate:hover {
  box-shadow: 0 12px 40px var(--danger-glow);
  transform: translateY(-2px);
}

.big-alarm-btn.deactivate {
  background: linear-gradient(135deg, var(--success), #4ade80);
  color: white;
  box-shadow: 0 8px 30px var(--success-glow);
}
.big-alarm-btn.deactivate:hover {
  box-shadow: 0 12px 40px var(--success-glow);
  transform: translateY(-2px);
}

.big-alarm-btn:active {
  transform: scale(0.97);
}

.big-alarm-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.big-alarm-btn .spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.detail-section {
  margin-bottom: 20px;
}

.detail-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.info-row:last-child { border-bottom: none; }

.info-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.info-value {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-key-hidden {
  font-family: monospace;
  letter-spacing: 2px;
}

.reveal-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  padding: 2px 6px;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

/* --- History Page --- */
.history-page {
  padding: 16px;
  padding-bottom: 100px;
  max-width: 800px;
  margin: 0 auto;
}

.history-page h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.history-filter {
  margin-bottom: 16px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.history-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
}

.history-icon.activate {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.history-icon.deactivate {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.history-content {
  flex: 1;
  min-width: 0;
}

.history-title {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 2px;
}

.history-detail {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.history-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  align-self: center;
}

.load-more {
  text-align: center;
  padding: 20px;
}

/* --- Settings Page --- */
.settings-page {
  padding: 16px;
  padding-bottom: 100px;
  max-width: 600px;
  margin: 0 auto;
}

.settings-page h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 0.2s ease;
}

.modal-content {
  width: 100%;
  max-width: 400px;
  background: rgba(20, 20, 45, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: scale-in 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.modal-body {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-actions .btn {
  min-width: 80px;
}

/* --- Toast --- */
#toast-root {
  position: fixed;
  top: calc(16px + var(--safe-top));
  right: 16px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: rgba(20, 20, 45, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 500;
  pointer-events: auto;
  animation: toast-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 360px;
}

.toast.removing {
  animation: toast-out 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.toast.success {
  border-left: 3px solid var(--success);
}
.toast.error {
  border-left: 3px solid var(--danger);
}
.toast.warning {
  border-left: 3px solid var(--warning);
}
.toast.info {
  border-left: 3px solid var(--primary);
}

.toast-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* --- FAB --- */
.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 8px 30px var(--primary-glow);
  transition: all var(--transition);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.fab:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 12px 40px var(--primary-glow);
}
.fab:active {
  transform: scale(0.95);
}

/* --- Loading Skeleton --- */
.skeleton {
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.05) 25%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-xs);
}

.skeleton-card {
  height: 180px;
  border-radius: var(--radius);
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  width: 60%;
}

.skeleton-text.full { width: 100%; }
.skeleton-text.short { width: 40%; }

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* --- Utility --- */
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

/* --- Responsive Tweaks --- */
@media (min-width: 640px) {
  .stats-bar {
    padding: 20px;
    gap: 16px;
  }
  .stat-card .stat-value {
    font-size: 2.2rem;
  }
  .global-actions {
    padding: 0 20px 20px;
  }
  .device-grid {
    padding: 0 20px 100px;
    gap: 20px;
  }
  .history-page,
  .settings-page {
    padding: 20px;
    padding-bottom: 100px;
  }
}

@media (min-width: 1024px) {
  .header-inner {
    padding: 0 8px;
  }
}

/* --- Setup Page --- */
.setup-card {
  width: 100%;
  max-width: 440px;
  position: relative;
}
.setup-card::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(135deg, var(--success), #6366f1, var(--success));
  background-size: 300% 300%;
  animation: gradient-border 4s ease infinite;
  z-index: -1;
  opacity: 0.5;
}
