/* =====================================================================
   DoorLock Cloud — Premium Glassmorphism UI
   ===================================================================== */

:root[data-theme="dark"] {
  --bg-0: #0b0e14;
  --bg-1: #10141d;
  --bg-grad-1: #1a2036;
  --bg-grad-2: #0d1117;
  --glass-bg: rgba(255, 255, 255, 0.055);
  --glass-border: rgba(255, 255, 255, 0.09);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --text-1: #eef1f8;
  --text-2: #9aa3b5;
  --text-3: #6b7386;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --input-bg: rgba(255, 255, 255, 0.05);
  --hover-bg: rgba(255, 255, 255, 0.06);
  --sidebar-bg: rgba(13, 16, 24, 0.75);
  --table-border: rgba(255, 255, 255, 0.06);
}

:root[data-theme="light"] {
  --bg-0: #eef1f7;
  --bg-1: #f7f8fb;
  --bg-grad-1: #dfe6f7;
  --bg-grad-2: #f4f6fb;
  --glass-bg: rgba(255, 255, 255, 0.6);
  --glass-border: rgba(15, 23, 42, 0.08);
  --glass-shadow: 0 8px 32px rgba(30, 41, 59, 0.08);
  --text-1: #131826;
  --text-2: #565f77;
  --text-3: #8b93a7;
  --accent: #4f46e5;
  --accent-2: #0891b2;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --input-bg: rgba(15, 23, 42, 0.035);
  --hover-bg: rgba(15, 23, 42, 0.04);
  --sidebar-bg: rgba(255, 255, 255, 0.7);
  --table-border: rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at 15% 15%, var(--bg-grad-1) 0%, transparent 45%),
    radial-gradient(circle at 85% 85%, var(--bg-grad-2) 0%, transparent 50%),
    var(--bg-0);
  background-attachment: fixed;
  color: var(--text-1);
  min-height: 100vh;
  transition: background-color .3s ease, color .3s ease;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

a { text-decoration: none; }

/* ---------- Glass primitives ---------- */
.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
}

.btn-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--input-bg); border: 1px solid var(--glass-border);
  color: var(--text-1); transition: all .18s ease;
}
.btn-icon:hover { background: var(--hover-bg); transform: translateY(-1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
}
.btn-glow { box-shadow: 0 4px 20px rgba(99, 102, 241, .35); }
.btn-glow:hover { box-shadow: 0 6px 26px rgba(99, 102, 241, .5); transform: translateY(-1px); }
.btn-outline-light { border-color: var(--glass-border); color: var(--text-1); }
.btn-outline-light:hover { background: var(--hover-bg); color: var(--text-1); border-color: var(--glass-border); }

.input-group-glass .input-group-text,
.input-group-glass .form-control,
.select-glass {
  background: var(--input-bg) !important;
  border: 1px solid var(--glass-border) !important;
  color: var(--text-1) !important;
}
.input-group-glass .form-control::placeholder { color: var(--text-3); }
.select-glass:focus, .input-group-glass .form-control:focus { box-shadow: 0 0 0 3px rgba(99, 102, 241, .18); }

/* =====================================================================
   LOGIN SCREEN
   ===================================================================== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden; padding: 20px;
}
.login-bg-orb {
  position: absolute; border-radius: 50%; filter: blur(90px); opacity: .35; z-index: 0;
}
.orb1 { width: 420px; height: 420px; background: var(--accent); top: -100px; left: -100px; }
.orb2 { width: 380px; height: 380px; background: var(--accent-2); bottom: -120px; right: -80px; }
.login-card { width: 100%; max-width: 400px; padding: 2.5rem; position: relative; z-index: 1; }
.brand-icon {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 1rem;
  display: flex; align-items: center; justify-content: center; font-size: 1.6rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 8px 24px rgba(99, 102, 241, .4);
}
.brand-icon.sm { width: 36px; height: 36px; font-size: 1rem; margin: 0; }

/* =====================================================================
   APP SHELL
   ===================================================================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px; flex-shrink: 0; background: var(--sidebar-bg);
  border-right: 1px solid var(--glass-border); backdrop-filter: blur(20px);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 1050;
  transition: transform .25s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1.25rem 1.1rem; }
.brand-text { font-weight: 700; font-size: 1.02rem; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .5rem .75rem; display: flex; flex-direction: column; gap: 3px; }
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: .8rem; padding: .65rem .9rem; border-radius: 12px;
  color: var(--text-2); font-size: .92rem; font-weight: 500; transition: all .15s ease;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-nav .nav-link:hover { background: var(--hover-bg); color: var(--text-1); }
.sidebar-nav .nav-link.active {
  background: linear-gradient(135deg, rgba(99,102,241,.18), rgba(34,211,238,.12));
  color: var(--text-1); box-shadow: inset 0 0 0 1px rgba(99,102,241,.25);
}

.sidebar-footer { padding: 1rem; border-top: 1px solid var(--glass-border); display: flex; align-items: center; gap: .6rem; }
.user-chip { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9rem;
}
.user-chip-info { min-width: 0; }
.user-chip-info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1040; }

.main-area { flex: 1; margin-left: 260px; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  margin: 14px 18px 0; padding: .7rem 1rem; display: flex; align-items: center; gap: 1rem;
  position: sticky; top: 14px; z-index: 900;
}
.topbar-search {
  flex: 1; display: flex; align-items: center; gap: .6rem; background: var(--input-bg);
  border: 1px solid var(--glass-border); border-radius: 12px; padding: .5rem .9rem; max-width: 420px;
}
.topbar-search input { background: transparent; border: none; outline: none; color: var(--text-1); width: 100%; font-size: .9rem; }
.topbar-search i { color: var(--text-3); }
.topbar-actions { display: flex; align-items: center; gap: .6rem; margin-left: auto; }

.live-pill {
  display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; font-family: 'JetBrains Mono', monospace;
  background: var(--input-bg); border: 1px solid var(--glass-border); padding: .4rem .75rem; border-radius: 999px; color: var(--text-2);
}
.live-pill i { color: var(--success); animation: pulse-dot 1.8s infinite; }

.notif-dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); display: none;
}

.content-area { padding: 1.25rem 1.5rem 3rem; }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.section-head h2 { font-weight: 700; font-size: 1.4rem; margin-bottom: .15rem; }

/* =====================================================================
   STAT CARDS
   ===================================================================== */
.stat-card {
  border-radius: 18px; padding: 1.1rem 1.25rem; position: relative; overflow: hidden;
  background: var(--glass-bg); border: 1px solid var(--glass-border); backdrop-filter: blur(20px);
}
.stat-card .stat-icon {
  width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; margin-bottom: .6rem;
}
.stat-card .stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat-card .stat-label { color: var(--text-2); font-size: .8rem; margin-top: .3rem; }
.stat-card .stat-trend { position: absolute; top: 1rem; right: 1.1rem; font-size: .74rem; font-weight: 600; }

/* =====================================================================
   TABLES
   ===================================================================== */
.table-dash { color: var(--text-1); }
.table-dash thead th {
  color: var(--text-3); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 600; border-bottom: 1px solid var(--table-border); padding-bottom: .75rem;
}
.table-dash td { border-bottom: 1px solid var(--table-border); padding: .8rem .6rem; font-size: .87rem; vertical-align: middle; }
.table-dash tr:last-child td { border-bottom: none; }
.table-dash tr:hover td { background: var(--hover-bg); }

.badge-status { padding: .3rem .65rem; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.badge-online { background: rgba(52,211,153,.15); color: var(--success); }
.badge-offline { background: rgba(248,113,113,.15); color: var(--danger); }
.badge-locked { background: rgba(251,191,36,.15); color: var(--warning); }
.badge-unlocked { background: rgba(52,211,153,.15); color: var(--success); }
.badge-enabled { background: rgba(52,211,153,.15); color: var(--success); }
.badge-disabled { background: rgba(248,113,113,.15); color: var(--danger); }
.badge-granted { background: rgba(52,211,153,.15); color: var(--success); }
.badge-denied { background: rgba(248,113,113,.15); color: var(--danger); }
.badge-neutral { background: var(--input-bg); color: var(--text-2); }

/* =====================================================================
   DOOR CONTROL CARDS
   ===================================================================== */
.door-card { border-radius: 20px; padding: 1.5rem; }
.door-visual {
  width: 90px; height: 90px; margin: 0 auto 1rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 2.2rem;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent));
  position: relative;
}
.door-visual::before {
  content: ''; position: absolute; inset: 5px; border-radius: 50%; background: var(--bg-1);
}
.door-visual i { position: relative; z-index: 1; }
.door-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: 1.2rem; }
.door-actions .btn { border-radius: 12px; font-size: .84rem; }

/* =====================================================================
   MISC
   ===================================================================== */
.confirm-icon { font-size: 2.2rem; color: var(--warning); }
.dropdown-menu { background: var(--glass-bg) !important; backdrop-filter: blur(20px); border: 1px solid var(--glass-border) !important; }

@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.skeleton { background: linear-gradient(90deg, var(--input-bg) 25%, var(--hover-bg) 50%, var(--input-bg) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.progress-glass { height: 8px; border-radius: 999px; background: var(--input-bg); overflow: hidden; }
.progress-glass .bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }

/* Chart.js needs a size-constrained parent, or responsive:true causes it to grow forever */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap-lg { height: 280px; }
.chart-wrap-sm { height: 220px; }
@media (max-width: 575.98px) {
  .chart-wrap-lg { height: 220px; }
  .chart-wrap-sm { height: 200px; }
}

/* Toasts */
.toast { background: var(--glass-bg) !important; backdrop-filter: blur(20px); border: 1px solid var(--glass-border) !important; color: var(--text-1); }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-area { margin-left: 0; }
  .topbar { margin: 10px 10px 0; }
  .content-area { padding: 1rem; }
  .topbar-search { max-width: none; }
}

@media (max-width: 575.98px) {
  .section-head { flex-direction: column; align-items: flex-start; }
  .login-card { padding: 1.75rem; }
}