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

:root {
  --sidebar-w: 220px;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning-bg: #fef3c7;
  --warning-border: #f59e0b;
  --warning-text: #92400e;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --sidebar-bg: #f8fafc;
  --sidebar-text: #64748b;
  --sidebar-active: #2563eb;
  --sidebar-active-bg: #eff6ff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --bg-alt: #f8faff;
}

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

.screen { width: 100%; min-height: 100vh; }
.hidden { display: none !important; }

/* ─── LOGIN ─────────────────────────────────────────────────────────────────── */
#login-screen { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); }
.login-box { background: var(--surface); border-radius: var(--radius-lg); padding: 2.5rem; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 2rem; }
.logo-icon { width: 56px; height: 56px; background: var(--accent); color: white; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; margin: 0 auto 1rem; }
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ─── MAIN LAYOUT ───────────────────────────────────────────────────────────── */
#main-screen { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); display: flex; flex-direction: column; flex-shrink: 0; position: fixed; top: 0; left: 0; height: 100vh; z-index: 10; border-right: 1px solid #e2e8f0; }
.sidebar-logo { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 1.25rem 1rem; border-bottom: 1px solid #e2e8f0; color: #1e293b; font-weight: 600; font-size: 15px; text-align: center; }
.sidebar-nav { flex: 1; padding: 1rem 0.5rem; display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 0.6rem 0.75rem; color: var(--sidebar-text); text-decoration: none; border-radius: var(--radius); font-size: 14px; transition: all 0.15s; cursor: pointer; background: none; border: none; width: 100%; text-align: left; }
.nav-item:hover { background: #f1f5f9; color: #374151; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 500; }
.sidebar-footer { padding: 1rem; border-top: 1px solid #e2e8f0; display: flex; align-items: center; gap: 8px; }
.user-info { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; }
.avatar { width: 32px; height: 32px; background: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.user-text { flex: 1; min-width: 0; overflow: hidden; }
.user-name { font-size: 13px; color: #1e293b; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content { margin-left: var(--sidebar-w); flex: 1; padding: 2rem; min-height: 100vh; }

/* ─── PAGES ─────────────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 0.75rem; }
.page-header h2 { font-size: 20px; font-weight: 600; }
.badge-count { font-size: 12px; color: var(--text-muted); margin-top: 2px; display: block; }

/* ─── FILTERS ────────────────────────────────────────────────────────────────── */
.filters { display: flex; gap: 8px; margin-bottom: 1.25rem; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { padding: 0.45rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; background: var(--surface); color: var(--text); outline: none; transition: border 0.15s; }
.filters input { width: 240px; }
.filters input:focus, .filters select:focus { border-color: var(--accent); }

/* ─── TABLE ─────────────────────────────────────────────────────────────────── */
.table-wrapper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: #f9fafb; padding: 0.75rem 1rem; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th[data-sort] { cursor: pointer; user-select: none; }
.data-table th[data-sort]:hover { color: var(--text); }
.sort-icon { display: inline-block; width: 10px; font-style: normal; text-transform: none; }
.data-table td { padding: 0.75rem 1rem; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f0f4ff; cursor: pointer; }
.empty-state { text-align: center; color: var(--text-light); padding: 3rem 1rem !important; cursor: default !important; }
.data-table tbody tr.empty-state:hover { background: transparent; }
.num-cell { text-align: right; font-family: 'Courier New', monospace; white-space: nowrap; }
.sub-text { font-size: 11px; color: var(--text-muted); display: block; }

/* ─── PAGINATION ─────────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 0.75rem 1rem; font-size: 13px; color: var(--text-muted); }

/* ─── BADGES ─────────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 500; }
.badge-admin   { background: #dcfce7; color: #15803d; }
.badge-viewer  { background: #f1f5f9; color: #475569; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger  { background: #fef2f2; color: #dc2626; }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }

/* ─── BUTTONS ────────────────────────────────────────────────────────────────── */
.btn { padding: 0.5rem 1rem; border-radius: var(--radius); border: 1px solid transparent; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-full { width: 100%; justify-content: center; padding: 0.65rem 1rem; }
.btn-icon { background: transparent; border: none; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; transition: all 0.15s; }
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 12px; }

/* ─── FORMS ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; color: var(--text); background: var(--surface); outline: none; transition: border 0.15s; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ─── ALERTS ─────────────────────────────────────────────────────────────────── */
.alert { padding: 0.6rem 0.75rem; border-radius: var(--radius); font-size: 13px; margin-top: 0.5rem; }
.alert-danger { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert-warning { background: var(--warning-bg); border: 1px solid var(--warning-border); color: var(--warning-text); }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; }

/* ─── MODALS ─────────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 600px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); max-height: 90vh; display: flex; flex-direction: column; }
.modal-lg { max-width: 860px; }
.modal-sm { max-width: 420px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-shrink: 0; }

/* ─── SETTINGS / ADMIN TABS ───────────────────────────────────────────────────── */
.admin-tabs { display: flex; flex-wrap: wrap; gap: 0; border-bottom: 1px solid var(--border); background: var(--bg-alt); padding-top: 8px; padding-left: 1rem; margin-bottom: 1.5rem; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.admin-tab-btn { background: none; border: 1px solid transparent; border-bottom: none; padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--text-muted); border-radius: var(--radius) var(--radius) 0 0; margin-right: 2px; margin-bottom: -1px; transition: all 0.12s; }
.admin-tab-btn:hover { background: var(--surface); color: var(--text); }
.admin-tab-btn.active { background: var(--surface); color: var(--text); font-weight: 600; border-color: var(--border); border-bottom-color: var(--surface); }
.settings-content { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow); max-width: 640px; }

/* ─── TOAST NOTIFICATIONS ────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1e293b; color: #f1f5f9; padding: 0.75rem 1.25rem; border-radius: var(--radius); font-size: 13px; box-shadow: 0 4px 20px rgba(0,0,0,0.25); display: flex; align-items: center; gap: 8px; min-width: 240px; max-width: 380px; animation: slideIn 0.25s ease; }
.toast.success { background: #14532d; }
.toast.error   { background: #7f1d1d; }
.toast.warning { background: #78350f; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── LOADING ────────────────────────────────────────────────────────────────── */
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.7); z-index: 500; display: flex; align-items: center; justify-content: center; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── CONFIRM DIALOG ─────────────────────────────────────────────────────────── */
.confirm-text { font-size: 15px; color: var(--text); margin-bottom: 1.5rem; }

/* ─── MOBILE TOPBAR ──────────────────────────────────────────────────────────── */
.mobile-topbar { display: none; position: fixed; top: 0; left: 0; right: 0; height: 56px; background: var(--sidebar-bg); z-index: 50; align-items: center; padding: 0 1rem; gap: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); border-bottom: 1px solid var(--border); }
.mobile-menu-btn { background: transparent; border: none; color: #64748b; padding: 8px; cursor: pointer; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; }
.mobile-topbar-title { color: #1e293b; font-weight: 600; font-size: 16px; flex: 1; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 390; }
.sidebar-overlay.open { display: block; }

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .mobile-topbar { display: flex; }
  .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; z-index: 400; }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; padding: 1rem; padding-top: calc(56px + 1rem); }
  .table-wrapper { overflow-x: auto; }
  .data-table { min-width: 760px; }
  .form-row { grid-template-columns: 1fr; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { max-height: 92vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-lg, .modal-sm { max-width: 100%; }
  .modal-body { padding: 1rem; }
  .modal-header { padding: 1rem; }
  .modal-footer { padding: 0.75rem 1rem; flex-wrap: wrap; }
}

/* ─── DARK MODE ──────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  html { color-scheme: dark; }
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-light: #475569;
    --sidebar-bg: #0b1120;
    --sidebar-text: #64748b;
    --sidebar-active: #f1f5f9;
    --sidebar-active-bg: #1d4ed8;
    --shadow: 0 1px 3px rgba(0,0,0,0.5);
    --bg-alt: #1a2840;
  }
  select { color-scheme: dark; background: var(--surface); color: var(--text); border-color: var(--border); }
  option { background: #1e293b; color: #e2e8f0; }
  .data-table th { background: #111e2e; }
  .data-table tbody tr:hover { background: #172133; }
  .data-table td { border-bottom-color: #1e2d42; }
  .badge-admin { background: #14532d; color: #86efac; }
  .badge-viewer { background: #1e293b; color: #94a3b8; }
  .alert-danger { background: #450a0a; border-color: #991b1b; color: #fca5a5; }
  .alert-success { background: #052e16; border-color: #166534; color: #86efac; }
  .alert-info { background: #1e3a5f; border-color: #2563eb; color: #93c5fd; }
  .modal-overlay { background: rgba(0,0,0,0.7); }
  .sidebar-overlay { background: rgba(0,0,0,0.75); }
  .sidebar { border-right-color: transparent; }
  .sidebar-logo { border-bottom-color: #1e293b; color: #f1f5f9; }
  .nav-item:hover { background: #334155; color: #cbd5e1; }
  .sidebar-footer { border-top-color: #1e293b; }
  .user-name { color: #e2e8f0; }
  .btn-ghost { color: var(--text-muted); border-color: var(--border); }
  .btn-ghost:hover { background: var(--border); color: var(--text); }
  .btn-icon:hover { background: rgba(255,255,255,0.08); }
  .form-group input:focus, .form-group select:focus, .form-group textarea:focus { box-shadow: 0 0 0 3px rgba(37,99,235,0.3); }
  .admin-tabs { background: var(--surface); }
  .admin-tab-btn.active { background: var(--bg); color: var(--text); border-bottom-color: var(--bg); }
  .settings-content { border-color: var(--border); }
}
