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

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #222535;
  --border: #2e3147;
  --text: #e8eaf0;
  --text2: #8b90a7;
  --primary: #4f6ef7;
  --primary-dark: #3a57e8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #38bdf8;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* ===== LAYOUT ===== */
#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 240px; min-width: 240px; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transition: width 0.2s;
}
.sidebar-brand {
  padding: 20px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo { width: 32px; height: 32px; background: var(--primary); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 16px; color: white; font-weight: 700; }
.sidebar-brand .brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.3px; }
.sidebar-brand .brand-sub { font-size: 11px; color: var(--text2); }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-section { margin-bottom: 20px; }
.nav-section-title { font-size: 10px; font-weight: 600; color: var(--text2); letter-spacing: 1px;
  text-transform: uppercase; padding: 0 8px; margin-bottom: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  cursor: pointer; color: var(--text2); font-weight: 500; font-size: 13.5px;
  transition: background 0.15s, color 0.15s; text-decoration: none; margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(79, 110, 247, 0.15); color: var(--primary); }
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item .nav-badge { margin-left: auto; background: var(--danger); color: white;
  font-size: 10px; padding: 1px 6px; border-radius: 10px; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 10px; padding: 8px; }
.user-avatar { width: 34px; height: 34px; background: var(--primary); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-weight: 600; color: white; font-size: 13px; flex-shrink: 0; }
.user-name { font-weight: 500; font-size: 13px; }
.user-role { font-size: 11px; color: var(--text2); }
.btn-logout { width: 100%; margin-top: 8px; }

/* Main content */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 56px; background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px; flex-shrink: 0;
}
.topbar-title { font-size: 16px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ===== COMPONENTS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: 7px; border: none; cursor: pointer; font-size: 13.5px; font-weight: 500;
  font-family: inherit; transition: all 0.15s; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #16a34a; }
.btn-warning { background: var(--warning); color: #1a1a1a; }
.btn-warning:hover:not(:disabled) { background: #d97706; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; }

.card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; align-items: center; gap: 16px;
}
.stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.stat-icon.blue { background: rgba(79,110,247,0.15); }
.stat-icon.green { background: rgba(34,197,94,0.15); }
.stat-icon.yellow { background: rgba(245,158,11,0.15); }
.stat-icon.red { background: rgba(239,68,68,0.15); }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.table-actions { display: flex; gap: 6px; }

/* Badge/Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px;
  border-radius: 20px; font-size: 11.5px; font-weight: 500;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.pill-green { background: rgba(34,197,94,0.15); color: var(--success); }
.pill-green::before { background: var(--success); }
.pill-red { background: rgba(239,68,68,0.15); color: var(--danger); }
.pill-red::before { background: var(--danger); }
.pill-yellow { background: rgba(245,158,11,0.15); color: var(--warning); }
.pill-yellow::before { background: var(--warning); }
.pill-blue { background: rgba(79,110,247,0.15); color: var(--primary); }
.pill-blue::before { background: var(--primary); }
.pill-gray { background: var(--bg3); color: var(--text2); }
.pill-gray::before { background: var(--text2); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 9px 12px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 7px; color: var(--text); font-family: inherit; font-size: 13.5px;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
input[type="file"] { padding: 8px; cursor: pointer; }
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.2s ease;
}
.modal-lg { max-width: 780px; }
.modal-header {
  padding: 18px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.btn-close { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; padding: 2px; line-height: 1; }
.btn-close:hover { color: var(--text); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Alert / Toast */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 16px; min-width: 280px; display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow); animation: slideInRight 0.2s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Monitoring stream */
.log-stream { display: flex; flex-direction: column; gap: 6px; max-height: 600px; overflow-y: auto; }
.log-entry {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--bg3); border-radius: 8px; font-size: 12.5px; animation: fadeIn 0.2s ease;
}
.log-entry .log-time { color: var(--text2); white-space: nowrap; font-size: 11px; }
.log-entry .log-icon { font-size: 16px; flex-shrink: 0; }
.log-entry .log-info { flex: 1; min-width: 0; }
.log-entry .log-device { font-weight: 600; }
.log-entry .log-detail { color: var(--text2); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Schedule grid */
.schedule-grid { display: grid; grid-template-columns: 80px repeat(7, 1fr); gap: 4px; }
.schedule-day-header { text-align: center; font-size: 11px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; padding: 6px 4px; }
.schedule-time-label { font-size: 10.5px; color: var(--text2); display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; }
.schedule-cell {
  height: 22px; background: var(--bg3); border-radius: 3px; cursor: pointer; transition: background 0.1s;
}
.schedule-cell:hover { background: rgba(79,110,247,0.3); }
.schedule-cell.selected { background: var(--primary); }

/* ID card preview */
.id-card-preview { width: 100%; aspect-ratio: 85.6/54; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg3); }
.id-card-placeholder { width: 100%; aspect-ratio: 85.6/54; border-radius: 8px; border: 2px dashed var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--text2); font-size: 13px; cursor: pointer; }

/* Device status indicator */
.device-online { display: inline-flex; align-items: center; gap: 6px; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.pulse-dot.active { animation: pulse 2s infinite; }
.pulse-dot.inactive { background: var(--danger); }
.pulse-dot.unknown { background: var(--text2); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Learning mode banner */
.learning-banner {
  background: rgba(245,158,11,0.15); border: 1px solid rgba(245,158,11,0.3);
  border-radius: var(--radius); padding: 16px 20px; display: flex; align-items: center; gap: 12px;
  animation: fadeIn 0.2s ease;
}
.learning-banner.active { border-color: rgba(245,158,11,0.6); }
.learning-banner.danger { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.6); }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.page-btn { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text); cursor: pointer; font-size: 12.5px; }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.page-btn:hover:not(.active) { background: var(--border); }
.page-info { color: var(--text2); font-size: 12.5px; flex: 1; text-align: right; }

/* Tabs */
.tabs { display: flex; gap: 2px; background: var(--bg3); padding: 3px; border-radius: 8px; }
.tab-btn { flex: 1; padding: 7px 16px; border-radius: 6px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text2); background: transparent; font-family: inherit; transition: all 0.15s; }
.tab-btn.active { background: var(--bg2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.3); }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text2); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { color: var(--text); margin-bottom: 8px; }

/* Search */
.search-bar { position: relative; }
.search-bar input { padding-left: 36px; }
.search-bar .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text2); }

/* Chip */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px;
  background: var(--bg3); border: 1px solid var(--border); font-size: 12px; color: var(--text2); }
.chip.uid { font-family: monospace; font-size: 12.5px; color: var(--text); letter-spacing: 0.5px; }

/* Login page */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .logo-icon { width: 56px; height: 56px; background: var(--primary); border-radius: 14px;
  display: flex; align-items: center; justify-content: center; font-size: 28px; color: white; font-weight: 800; margin: 0 auto 12px; }
.login-logo h1 { font-size: 22px; font-weight: 700; }
.login-logo p { color: var(--text2); font-size: 13px; margin-top: 4px; }
.login-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); border-radius: 7px; padding: 10px 14px; color: #f87171; font-size: 13px; margin-bottom: 16px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar-brand .brand-name, .sidebar-brand .brand-sub, .nav-item span:not(.nav-icon) { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .nav-section-title { display: none; }
  .sidebar-footer .user-name, .sidebar-footer .user-role { display: none; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* Misc */
.text-muted { color: var(--text2); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.monospace { font-family: monospace; }
.separator { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.hidden { display: none !important; }

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

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