/* Header */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 12px rgba(0,0,0,.15);
}
.logo { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.logo-icon { width: 36px; height: 36px; background: linear-gradient(135deg, var(--accent), var(--accent2)); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; color: #fff; box-shadow: 0 2px 8px rgba(79,142,247,.35); }
.logo-text { font-weight: 800; font-size: 18px; letter-spacing: .5px; color: var(--text-strong); }
.logo-sub { font-size: 10px; color: var(--muted); margin-top: 1px; letter-spacing: .2px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* Layout */
.container { max-width: 1400px; margin: 0 auto; padding: 24px; padding-top: 70px; }

/* Buttons */
.btn {
  padding: 7px 16px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 600; transition: all .18s; display: inline-flex; align-items: center; gap: 6px; font-family: inherit;
}
.btn i { font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(79,142,247,.25); }
.btn-primary:hover { background: #3b7de8; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,142,247,.35); }
.btn-primary:active { transform: translateY(0); }
.btn-danger { background: var(--red); color: #fff; box-shadow: 0 2px 8px rgba(239,68,68,.25); }
.btn-danger:hover { background: #da373e; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(239,68,68,.35); }
.btn-danger:active { transform: translateY(0); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg3); border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; }
.btn-sm { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); cursor: pointer; font-size: 11px; font-weight: 600; transition: all .15s; display: inline-flex; align-items: center; gap: 4px; font-family: inherit; }
.btn-sm i { font-size: 10px; }
.btn-sm:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-sm-danger:hover { background: var(--red); border-color: var(--red); color: #fff; }

/* ── Toast Notification System ───────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast-item {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg2); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 12px 14px 14px 14px;
  font-size: 13px; color: var(--text); line-height: 1.5;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  max-width: 320px; min-width: 200px;
  pointer-events: all; position: relative; overflow: hidden;
  transform: translateX(calc(100% + 28px)); opacity: 0;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1), opacity .3s;
}
.toast-item.toast-show { transform: translateX(0); opacity: 1; }
.toast-item.toast-hide { transform: translateX(calc(100% + 28px)); opacity: 0; transition: transform .25s ease-in, opacity .25s; }
.toast-item.success { border-left-color: #10b981; }
.toast-item.error   { border-left-color: #ef4444; }
.toast-item.warning { border-left-color: #f59e0b; }
.toast-item.info    { border-left-color: var(--accent); }
.toast-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.toast-item.success .toast-icon { color: #10b981; }
.toast-item.error   .toast-icon { color: #ef4444; }
.toast-item.warning .toast-icon { color: #f59e0b; }
.toast-item.info    .toast-icon { color: var(--accent); }
.toast-text { flex: 1; }
.toast-close {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 0 0 0 4px;
  flex-shrink: 0; margin-top: -1px;
  transition: color .15s;
}
.toast-close:hover { color: var(--text); }
.toast-progress {
  position: absolute; bottom: 0; left: 0; height: 3px;
  border-radius: 0 0 0 6px; width: 100%; transform-origin: left;
}
.toast-item.success .toast-progress { background: #10b981; }
.toast-item.error   .toast-progress { background: #ef4444; }
.toast-item.warning .toast-progress { background: #f59e0b; }
.toast-item.info    .toast-progress { background: var(--accent); }
/* Legacy single-toast fallback (backward compat) */
#toast { display: none; }

/* Theme Switcher */
.theme-switcher {
  position: relative; width: 52px; height: 28px; cursor: pointer;
  background: var(--bg3); border: 1.5px solid var(--border);
  border-radius: 99px; transition: background .2s, border-color .2s;
  display: flex; align-items: center; padding: 3px 4px;
  flex-shrink: 0;
}
.theme-switcher:hover { border-color: var(--accent); }
.theme-switcher-thumb {
  position: absolute; top: 3px; left: 4px;
  width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), background .2s;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1;
}
[data-theme="light"] .theme-switcher-thumb { transform: translateX(24px); }
.theme-switcher-icons {
  width: 100%; display: flex; justify-content: space-between;
  padding: 0 2px; pointer-events: none; position: relative; z-index: 1;
}
.theme-switcher-icons span { font-size: 10px; line-height: 1; opacity: .45; transition: opacity .2s; }
[data-theme="dark"] .theme-switcher-icons .icon-dark { opacity: 1; }
[data-theme="light"] .theme-switcher-icons .icon-light { opacity: 1; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 200; display: none; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 460px; max-width: 95vw; box-shadow: var(--shadow); }
.modal-title { font-size: 15px; font-weight: 700; color: var(--text-strong); margin-bottom: 16px; }
.form-group { margin-bottom: 14px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; display: block; text-transform: uppercase; letter-spacing: .4px; }
.form-input { width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: var(--text); font-size: 13px; outline: none; }
.form-input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Dynamic modal overlay (used by JS-created modals) */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-content { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 460px; max-width: 95vw; box-shadow: var(--shadow); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 4px 8px; }
.modal-close:hover { color: var(--text); }
.modal-body { }

/* User badge */
.user-badge { display: flex; align-items: center; gap: 10px; cursor: pointer; position: relative; padding: 6px 8px; border-radius: 8px; transition: all .15s ease; }
.user-badge:hover { background: var(--bg3); }
.user-info { display: flex; flex-direction: column; gap: 2px; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0; overflow: hidden; }
.user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-pill { font-size: 10px; padding: 1px 7px; border-radius: 99px; font-weight: 700; }
.role-admin  { background: rgba(239,68,68,.15);  color: var(--red); }
.role-analis { background: rgba(79,142,247,.15);  color: var(--accent); }
.role-viewer { background: rgba(100,116,139,.15); color: var(--muted); }
.user-dropdown { position: absolute; top: 42px; right: 0; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 32px rgba(0,0,0,0.15); min-width: 200px; z-index: 500; display: none; overflow: hidden; animation: slideDown 0.2s ease; }
.user-dropdown.open { display: block; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.dropdown-item { padding: 12px 16px; font-size: 13px; font-weight: 500; color: var(--text); cursor: pointer; display: flex; align-items: center; gap: 12px; transition: all .15s ease; }
.dropdown-item i { font-size: 14px; color: var(--muted); width: 16px; text-align: center; transition: color .15s ease; }
.dropdown-item:hover { background: var(--bg3); color: var(--accent); }
.dropdown-item:hover i { color: var(--accent); }
.dropdown-item.dropdown-danger { color: var(--red); }
.dropdown-item.dropdown-danger i { color: var(--red); }
.dropdown-item.dropdown-danger:hover { background: rgba(239,68,68,0.1); color: var(--red); }
.dropdown-divider { border-top: 1px solid var(--border); margin: 6px 0; }

/* Profile avatar upload */
.profile-avatar-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 20px; }
.profile-avatar-img  { width: 84px; height: 84px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; color: #fff; overflow: hidden; flex-shrink: 0; position: relative; cursor: pointer; border: 3px solid var(--border); transition: border-color .15s; }
.profile-avatar-img:hover { border-color: var(--accent); }
.profile-avatar-img img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-avatar-img .avatar-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.45); border-radius: 50%; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .15s; font-size: 20px; color: #fff; }
.profile-avatar-img:hover .avatar-overlay { opacity: 1; }
.profile-avatar-hint { font-size: 11px; color: var(--muted); }

/* Section nav bar */
.section-nav { position: fixed; top: 58px; left: 0; right: 0; z-index: 95; background: var(--bg2); border-bottom: 1px solid var(--border); padding: 0 12px; display: flex; align-items: center; overflow-x: auto; gap: 2px; scrollbar-width: none; height: 46px; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.section-nav::-webkit-scrollbar { display: none; }
.section-nav a { text-decoration: none; }
.section-nav-item { display: flex; align-items: center; gap: 7px; padding: 8px 14px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; border-radius: 8px; transition: color .15s, background .15s; user-select: none; position: relative; border-bottom: 2px solid transparent; }
.section-nav-item i { font-size: 13px; }
.section-nav-item:hover { color: var(--text); background: var(--bg3); }
.section-nav-item.active { color: var(--accent); background: rgba(79,142,247,.08); border-bottom-color: var(--accent); }
.section-nav-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; margin: 0 4px; }
.section-nav-item.admin-nav { color: var(--red); }
.section-nav-item.admin-nav:hover { background: rgba(239,68,68,.07); color: var(--red); }
.section-nav-item.admin-nav.active { color: var(--red); border-bottom-color: var(--red); background: rgba(239,68,68,.06); }

/* Notification Bell */
.notif-bell { position: relative; cursor: pointer; width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center; background: var(--bg3); border: 1px solid var(--border); transition: background .15s, border-color .15s; flex-shrink: 0; font-size: 15px; }
.notif-bell:hover { border-color: var(--accent); color: var(--accent); background: var(--hover); }
.notif-badge { position: absolute; top: 3px; right: 3px; background: var(--red); color: #fff; font-size: 9px; font-weight: 700; border-radius: 99px; min-width: 14px; height: 14px; padding: 0 3px; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.notif-badge.hidden { display: none; }
.notif-panel { position: absolute; top: 44px; right: 0; width: 360px; max-height: 480px; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 600; display: none; flex-direction: column; overflow: hidden; }
.notif-panel.open { display: flex; }
.notif-panel-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.notif-panel-title { font-size: 13px; font-weight: 700; color: var(--text-strong); }
.notif-list { overflow-y: auto; flex: 1; }
.notif-item { padding: 11px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; display: flex; gap: 10px; align-items: flex-start; }
.notif-item:hover { background: var(--hover); }
.notif-item.unread { background: rgba(79,142,247,.06); }
.notif-item.unread:hover { background: rgba(79,142,247,.12); }
.notif-dot { width: 7px; height: 7px; background: var(--accent); border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.notif-dot.read { background: transparent; border: 1px solid var(--border); }
.notif-content .notif-title { font-size: 12px; font-weight: 600; color: var(--text); line-height: 1.4; }
.notif-content .notif-body  { font-size: 11px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.notif-content .notif-time  { font-size: 10px; color: var(--muted); margin-top: 3px; }
.notif-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }

/* Loading */
.loading { text-align: center; padding: 40px; color: var(--muted); }
.spinner { display: inline-block; width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin-bottom: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state h3 { color: var(--text); margin-bottom: 8px; }

/* Date input */
.date-input { height: 34px; padding: 0 10px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 12px; outline: none; cursor: pointer; }
.date-input:focus { border-color: var(--accent); }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 299; display: none; }
.drawer-backdrop.open { display: block; }

/* Light mode shadows */
[data-theme="light"] .stat-card,
[data-theme="light"] .chart-card,
[data-theme="light"] .table-card,
[data-theme="light"] .search-bar { box-shadow: var(--shadow); }
[data-theme="light"] header { box-shadow: 0 1px 8px rgba(0,0,0,.06); }
[data-theme="light"] tr:hover td { background: rgba(37,99,235,.05); }

/* Responsive */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
  .p3-grid-2, .p3-grid-3, .nlp-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 12px; padding-top: 110px; }
}

/* Login overlay */
#loginOverlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px 36px;
  width: 380px; max-width: 96vw;
  box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon { width: 56px; height: 56px; font-size: 24px; margin: 0 auto 14px; border-radius: 16px; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 4px 16px rgba(79,142,247,.35); }
.login-logo h1 { font-size: 22px; font-weight: 800; color: var(--text-strong); }
.login-logo p  { font-size: 12px; color: var(--muted); margin-top: 4px; }
.login-error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: var(--red); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; display: none; }
.login-error.show { display: block; }
