/* ============================================
   Layout — Header, Sidebar, Content, Responsive
   ============================================ */

/* ========== HEADER ========== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--bg-header);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  border-bottom: 3px solid var(--color-primary);
}
.site-header__inner {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  gap: var(--space-4);
}
.site-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-primary);
  font-weight: var(--font-bold);
  font-size: var(--text-base);
  text-decoration: none;
  flex-shrink: 0;
}
.site-header__brand:hover { color: var(--color-primary-dark); opacity: 1; }
.site-header__brand img {
  height: var(--logo-h);
  width: auto;
  object-fit: contain;
}
.site-header__spacer { flex: 1; }
.site-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Dark mode toggle */
.theme-toggle {
  background: var(--bg-muted);
  border: none;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: var(--text-base);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.theme-toggle:hover { background: var(--color-primary-bg); color: var(--color-primary); }

/* Notification bell */
.notif-menu { position: relative; }
.notif-bell {
  position: relative;
  background: var(--bg-muted);
  border: none;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: var(--text-base);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.notif-bell:hover { background: var(--color-primary-bg); color: var(--color-primary); }
.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--color-danger, #c0392b);
  color: #fff;
  font-size: 10px;
  font-weight: var(--font-bold);
  line-height: 16px;
  text-align: center;
  display: none;
}
.notif-badge--show,
.notif-badge:not([hidden]) { display: block; }
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(360px, calc(100vw - 24px));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  display: none;
  z-index: 210;
  overflow: hidden;
}
.notif-dropdown.show { display: block; animation: modalSlideIn var(--transition-fast) ease-out; }
.notif-dropdown__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}
.notif-dropdown__markall {
  border: none;
  background: none;
  color: var(--color-primary);
  font-size: var(--text-xs);
  cursor: pointer;
  padding: 0;
}
.notif-dropdown__markall:hover { text-decoration: underline; }
.notif-dropdown__body {
  max-height: 360px;
  overflow-y: auto;
}
.notif-empty {
  margin: 0;
  padding: var(--space-5);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.notif-list { display: flex; flex-direction: column; }
.notif-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  text-decoration: none;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-muted); }
.notif-item--unread { background: var(--color-primary-bg); }
.notif-item__title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  line-height: 1.35;
}
.notif-item__body {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.notif-item__time {
  font-size: 11px;
  color: var(--text-muted, var(--text-secondary));
  margin-top: 2px;
}
.notif-dropdown__footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  text-align: center;
}
.notif-dropdown__footer a {
  color: var(--color-primary);
  text-decoration: none;
}
.notif-dropdown__footer a:hover { text-decoration: underline; }

/* Sidebar toggle */
.sidebar-toggle {
  background: var(--bg-muted);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: var(--text-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--color-primary-bg); color: var(--color-primary); }

/* User menu */
.user-menu {
  position: relative;
}
.user-menu__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-muted);
  border: none;
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  padding: 4px 14px 4px 4px;
  cursor: pointer;
  font-size: var(--text-sm);
  transition: background var(--transition-fast);
}
.user-menu__trigger:hover { background: var(--color-primary-bg); }
.user-menu__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-bold);
  font-size: var(--text-xs);
  text-transform: uppercase;
}
.user-menu__dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 300px;
  max-width: 90vw;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-2);
  display: none;
  z-index: 200;
}
.user-menu__dropdown.show { display: block; animation: modalSlideIn var(--transition-fast) ease-out; }
.user-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.user-menu__item:hover { background: var(--bg-muted); }
.user-menu__item--danger { color: var(--color-danger); }
.user-menu__divider { height: 1px; background: var(--border); margin: var(--space-2) 0; }

/* ========== APP LAYOUT ========== */
.app-layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}
.main-content {
  flex: 1;
  min-width: 0;
  padding: var(--space-6) var(--space-6) var(--space-8);
  transition: margin-left var(--transition-slow);
}
.main-content .breadcrumb,
.breadcrumbs {
  margin-bottom: var(--space-4);
}
.content-wrapper {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  transition: width var(--transition-slow), min-width var(--transition-slow);
  overflow: hidden;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  z-index: 50;
}
.sidebar--collapsed { width: 0; min-width: 0; }

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) 0;
}
.sidebar__section {
  padding: var(--space-3) var(--space-4) var(--space-1);
  font-size: 10px;
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-sidebar-muted);
  opacity: 0.7;
}
.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-4);
  color: var(--text-sidebar);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  text-decoration: none;
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
  margin: 1px var(--space-2);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.sidebar__link:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-inverse);
}
.sidebar__link--active {
  background: var(--bg-sidebar-active);
  border-left-color: var(--color-accent);
  color: var(--text-inverse);
  font-weight: var(--font-semibold);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.sidebar__link--child {
  padding-left: calc(var(--space-4) + var(--space-6));
  font-size: var(--text-xs);
}
.sidebar__link i { width: 18px; text-align: center; font-size: var(--text-sm); }

.sidebar__footer {
  padding: var(--space-4);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: var(--text-xs);
  color: var(--text-sidebar-muted);
  opacity: 0.7;
}

/* ========== FOOTER ========== */
.site-footer {
  text-align: center;
  padding: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.site-footer a { color: var(--text-muted); text-decoration: underline; }

/* ========== SIDEBAR OVERLAY (mobile) ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 49;
}
.sidebar-overlay.show { display: block; }

/* ========== RESPONSIVE ========== */

/* Tablet: 992px */
@media (max-width: 992px) {
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    height: calc(100vh - var(--header-h));
    transform: translateX(-100%);
    z-index: 51;
    transition: transform var(--transition-slow);
  }
  .sidebar--open { transform: translateX(0); }
  .sidebar--collapsed { width: var(--sidebar-w); min-width: var(--sidebar-w); transform: translateX(-100%); }
  .main-content { margin-left: 0; padding: var(--space-4); }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}

/* Mobile: 768px */
@media (max-width: 768px) {
  :root { --header-h: 56px; }

  .site-header { padding: 0 var(--space-3); }
  .site-header__brand span { display: none; }
  .site-header__brand img { height: 36px; }

  .main-content { padding: var(--space-3); }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: var(--space-3); }
  .stat-card { padding: var(--space-3); }
  .stat-card__value { font-size: var(--text-xl); }

  .card__header { padding: var(--space-3) var(--space-4); flex-wrap: wrap; }
  .card__body { padding: var(--space-4); }

  .quick-actions { flex-direction: column; }
  .quick-actions .btn { justify-content: center; }

  thead th { font-size: 10px; padding: 8px 10px; }
  tbody td { padding: 10px 12px; font-size: var(--text-xs); }

  .toast-container { left: 12px; right: 12px; top: var(--space-4); }
  .toast { min-width: auto; max-width: 100%; }

  .modal-content { border-radius: var(--radius-lg); max-width: 100%; }
}

/* Large screens */
@media (min-width: 1400px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Profile summary inside user menu — modern contact-card style */
.user-menu__profile-summary {
  margin: var(--space-1) 0;
}

.user-menu__summary-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-1) var(--space-3);
}

.user-menu__summary-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
}

.user-menu__summary-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-menu__summary-name {
  font-weight: 600;
  font-size: var(--text-sm);
  line-height: 1.35;
  color: var(--text-primary);
}

.user-menu__summary-email {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu__summary-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) var(--space-1) 0;
  border-top: 1px solid var(--border);
}

.user-menu__summary-tags .capsule-tag__container {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  margin: 0;
}

.user-menu__summary-tags .capsule-tag {
  font-size: 10px;
  padding: 3px 9px;
  margin: 1px;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.user-menu__summary-tags .capsule-tag::before {
  display: none;
}

.user-menu__summary-tags .capsule-tag:hover {
  transform: translateY(-1px);
}

/* Dark mode overrides */
.dark-mode .user-menu__summary-avatar {
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

/* Centre capsule colour variant */
.capsule-tag--center {
  background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 4px rgba(13, 148, 136, 0.2);
}
.capsule-tag--center:hover {
  box-shadow: 0 4px 8px rgba(13, 148, 136, 0.3);
}

/* Dark mode header overrides */
.dark-mode .site-header {
  border-bottom-color: var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.dark-mode .site-header__brand img {
  background: #fff;
  padding: 6px 8px;
  border-radius: var(--radius-md);
}
.dark-mode .theme-toggle,
.dark-mode .notif-bell,
.dark-mode .sidebar-toggle,
.dark-mode .user-menu__trigger {
  background: rgba(255,255,255,0.08);
}
.dark-mode .theme-toggle:hover,
.dark-mode .notif-bell:hover,
.dark-mode .sidebar-toggle:hover,
.dark-mode .user-menu__trigger:hover {
  background: rgba(255,255,255,0.15);
}

/* Print */
@media print {
  .site-header, .sidebar, .sidebar-overlay, .site-footer,
  .btn, .toast-container, .modal-overlay, .theme-toggle, .notif-bell, .sidebar-toggle { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 0 !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  thead th { background: #333 !important; color: #fff !important; -webkit-print-color-adjust: exact; }
}
