/* ================================================================
   AI GUARDIAN — APP SHELL
   Unified sidebar + topbar + global components
   ================================================================ */

/* ── Design Tokens ────────────────────────────────────────────── */
:root {
  --clr-primary:        #E11D48;
  --clr-primary-dark:   #BE123C;
  --clr-primary-glow:   rgba(225, 29, 72, 0.18);
  --clr-primary-subtle: rgba(225, 29, 72, 0.08);

  --sidebar-bg:     #0b1120;
  --sidebar-border: rgba(255,255,255,0.06);
  --sidebar-width:  250px;

  --topbar-h:       60px;
  --topbar-bg:      #ffffff;
  --topbar-border:  #e8eaf0;

  --nav-item-hover:  rgba(255,255,255,0.06);
  --nav-item-active: rgba(225,29,72,0.18);
  --nav-item-active-border: #E11D48;

  --text-sidebar-muted: rgba(255,255,255,0.42);
  --text-sidebar:       rgba(255,255,255,0.78);
  --text-sidebar-strong:rgba(255,255,255,0.96);

  --surface:        #ffffff;
  --surface-2:      #f8f9fc;
  --text-body:      #1e293b;
  --text-muted:     #64748b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-card: 0 1px 4px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.06);
  --shadow-elevated: 0 4px 20px rgba(0,0,0,0.12);

  --transition: 200ms cubic-bezier(.4,0,.2,1);
}

/* ── Reset / Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text-body); background: var(--surface-2); min-height: 100vh; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font: inherit; border: none; background: none; }
svg { display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ── App Layout ───────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.ag-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 200;
  border-right: 1px solid var(--sidebar-border);
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.ag-sidebar::-webkit-scrollbar { width: 4px; }
.ag-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Brand */
.ag-sidebar .sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}
.ag-sidebar .sb-brand-mark {
  width: 34px; height: 34px;
  background: var(--clr-primary);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 10px var(--clr-primary-glow);
}
.ag-sidebar .sb-brand-mark svg { color: white; }
.ag-sidebar .sb-brand-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-sidebar-strong);
  letter-spacing: 0.5px;
  line-height: 1.2;
}
.ag-sidebar .sb-brand-name em {
  display: block;
  font-style: normal;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-sidebar-muted);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-top: 1px;
}

/* Nav section label */
.ag-sidebar .sb-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-sidebar-muted);
  padding: 18px 18px 8px;
}

/* Nav items */
.ag-sidebar .sb-nav { flex: 1; padding-bottom: 8px; }
.ag-sidebar .sb-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  margin: 1px 8px;
  border-radius: 8px;
  color: var(--text-sidebar);
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  position: relative;
  text-decoration: none;
}
.ag-sidebar .sb-nav-item:hover {
  background: var(--nav-item-hover);
  color: var(--text-sidebar-strong);
}
.ag-sidebar .sb-nav-item.active {
  background: var(--nav-item-active);
  color: #fff;
  font-weight: 600;
}
.ag-sidebar .sb-nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--clr-primary);
  border-radius: 0 3px 3px 0;
}
.ag-sidebar .sb-nav-item.sos-item {
  color: #f87171;
  margin-top: 4px;
}
.ag-sidebar .sb-nav-item.sos-item:hover {
  background: rgba(248,113,113,0.12);
  color: #fca5a5;
}
.ag-sidebar .sb-nav-badge {
  margin-left: auto;
  background: var(--clr-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
}
.ag-sidebar .sb-nav-badge:empty { display: none; }

/* User card */
.ag-sidebar .sb-user {
  margin: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background var(--transition);
}
.ag-sidebar .sb-user:hover { background: rgba(255,255,255,0.08); }
.ag-sidebar .sb-user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--clr-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ag-sidebar .sb-user-info { flex: 1; min-width: 0; }
.ag-sidebar .sb-user-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sidebar-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ag-sidebar .sb-user-email {
  font-size: 11px;
  color: var(--text-sidebar-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ag-sidebar .sb-logout-btn {
  color: var(--text-sidebar-muted);
  transition: color var(--transition);
  padding: 2px;
}
.ag-sidebar .sb-logout-btn:hover { color: #f87171; }

/* Sidebar backdrop */
.ag-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
  backdrop-filter: blur(2px);
}
.ag-sidebar-backdrop.visible { display: block; }

/* ── Topbar ───────────────────────────────────────────────────── */
.ag-topbar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.ag-topbar .tb-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.ag-topbar .tb-hamburger:hover { background: var(--surface-2); color: var(--text-body); }
.ag-topbar .tb-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-body);
  flex: 1;
}
.ag-topbar .tb-spacer { flex: 1; }
.ag-topbar .tb-live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(22, 163, 74, 0.1);
  color: #16a34a;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}
.ag-topbar .tb-live-badge .pulse {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #16a34a;
  animation: pulseDot 1.8s ease-in-out infinite;
}
.ag-topbar .tb-sos-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--clr-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  letter-spacing: 0.5px;
}
.ag-topbar .tb-sos-pill:hover {
  background: var(--clr-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--clr-primary-glow);
}
.ag-topbar .tb-icon-btn {
  position: relative;
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.ag-topbar .tb-icon-btn:hover { background: var(--surface-2); color: var(--text-body); }
.ag-topbar .tb-notif-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 8px; height: 8px;
  background: var(--clr-primary);
  border-radius: 50%;
  border: 2px solid var(--topbar-bg);
}

/* ── Main Content Wrapper ─────────────────────────────────────── */
.ag-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.ag-content {
  flex: 1;
  padding: 24px;
}

/* ── Emergency SOS Modal ──────────────────────────────────────── */
.ag-sos-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.ag-sos-modal-overlay.open { display: flex; }
.ag-sos-modal {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  animation: modalSlideUp 0.25s ease;
  box-shadow: var(--shadow-elevated);
}
.ag-sos-modal .sos-ring {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(225, 29, 72, 0.1);
  margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
  animation: pulseDot 1.4s ease-in-out infinite;
}
.ag-sos-modal h2 {
  font-size: 20px; font-weight: 700;
  color: #0f172a; margin-bottom: 10px;
}
.ag-sos-modal p {
  font-size: 14px; color: #64748b;
  line-height: 1.6; margin-bottom: 24px;
}
.ag-sos-modal .sos-modal-actions {
  display: flex; gap: 12px; justify-content: center;
}
.ag-sos-modal .btn-cancel {
  padding: 10px 24px; border-radius: 8px;
  background: #f1f5f9; color: #475569;
  font-weight: 600; font-size: 14px;
  transition: background var(--transition);
}
.ag-sos-modal .btn-cancel:hover { background: #e2e8f0; }
.ag-sos-modal .btn-confirm-sos {
  padding: 10px 24px; border-radius: 8px;
  background: var(--clr-primary); color: #fff;
  font-weight: 700; font-size: 14px;
  transition: background var(--transition);
}
.ag-sos-modal .btn-confirm-sos:hover { background: var(--clr-primary-dark); }

/* ── Notifications Drawer ─────────────────────────────────────── */
.ag-notif-drawer {
  position: fixed;
  top: 0; right: -380px;
  width: 360px;
  height: 100vh;
  background: #fff;
  box-shadow: -4px 0 30px rgba(0,0,0,0.12);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transition: right var(--transition);
}
.ag-notif-drawer.open { right: 0; }
.ag-notif-drawer .nd-header {
  padding: 20px;
  border-bottom: 1px solid #e8eaf0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.ag-notif-drawer .nd-header h2 {
  font-size: 16px; font-weight: 700;
  color: #0f172a; flex: 1;
}
.ag-notif-drawer .nd-close {
  width: 32px; height: 32px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: #64748b;
  transition: background var(--transition);
}
.ag-notif-drawer .nd-close:hover { background: #f1f5f9; color: #0f172a; }
.ag-notif-drawer .nd-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.ag-notif-drawer .nd-item {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.ag-notif-drawer .nd-item:hover { background: #f8f9fc; border-color: #e8eaf0; }
.ag-notif-drawer .nd-item.unread { background: rgba(225,29,72,0.04); border-color: rgba(225,29,72,0.12); }
.ag-notif-drawer .nd-item-title { font-size: 13px; font-weight: 600; color: #0f172a; margin-bottom: 3px; }
.ag-notif-drawer .nd-item-body { font-size: 12.5px; color: #64748b; line-height: 1.5; }
.ag-notif-drawer .nd-item-time { font-size: 11px; color: #94a3b8; margin-top: 4px; }
.ag-notif-drawer .nd-empty {
  text-align: center; padding: 40px 20px;
  color: #94a3b8; font-size: 13.5px;
}

/* ── Global Toast ─────────────────────────────────────────────── */
.ag-toast-stack {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.ag-toast {
  background: #1e293b;
  color: #f8fafc;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  max-width: 340px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ag-toast.show { opacity: 1; transform: translateY(0); }
.ag-toast.success { background: #15803d; }
.ag-toast.danger  { background: var(--clr-primary); }
.ag-toast.info    { background: #1e40af; }

/* ── Keyframes ────────────────────────────────────────────────── */
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}
@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .ag-sidebar {
    transform: translateX(-100%);
  }
  .ag-sidebar.open {
    transform: translateX(0);
  }
  .ag-main {
    margin-left: 0;
  }
  .ag-topbar .tb-hamburger {
    display: flex;
  }
  .ag-topbar .tb-title {
    font-size: 14px;
  }
  .ag-content {
    padding: 16px;
  }
}

/* ── Shared Page Utilities ────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: #0f172a;
  display: flex; align-items: center; gap: 10px;
}
.page-header p {
  font-size: 14px;
  color: #64748b;
  margin-top: 6px;
  line-height: 1.6;
}
.ag-card {
  background: #fff;
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-card);
  border: 1px solid #e8eaf0;
}
.ag-card + .ag-card { margin-top: 20px; }
.ag-card-title {
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--clr-primary);
  color: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  cursor: pointer;
  border: none;
}
.btn-primary:hover {
  background: var(--clr-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--clr-primary-glow);
}
.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: #64748b;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid #e2e8f0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  cursor: pointer;
}
.btn-ghost:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}
.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: var(--clr-primary);
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1.5px solid var(--clr-primary);
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}
.btn-danger:hover {
  background: var(--clr-primary);
  color: #fff;
}
