/* ============================================================
   SmartBuzz — Main Stylesheet  (fully responsive)
   ============================================================ */

:root {
  --primary:       #4F46E5;
  --primary-dark:  #3730A3;
  --primary-light: #818CF8;
  --accent:        #06B6D4;
  --success:       #10B981;
  --warning:       #F59E0B;
  --danger:        #EF4444;
  --dark:          #0F172A;
  --gray-900:      #111827;
  --gray-800:      #1F2937;
  --gray-700:      #374151;
  --gray-600:      #4B5563;
  --gray-500:      #6B7280;
  --gray-400:      #9CA3AF;
  --gray-300:      #D1D5DB;
  --gray-200:      #E5E7EB;
  --gray-100:      #F3F4F6;
  --white:         #FFFFFF;
  --sidebar-width: 260px;
  --header-height: 60px;
  --radius:        8px;
  --radius-lg:     12px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08);
  --shadow-md:     0 4px 12px rgba(0,0,0,.12);
  --shadow-lg:     0 10px 30px rgba(0,0,0,.15);
  --transition:    0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; height: auto; }

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

/* ── Sidebar Overlay (mobile backdrop) ───────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition);
  will-change: transform;
}

.sidebar-logo {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
  min-height: var(--header-height);
}
.sidebar-logo .logo-icon {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800; color: white;
  flex-shrink: 0;
}
.sidebar-logo .logo-text {
  font-size: 17px; font-weight: 700;
  color: white; letter-spacing: -0.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; overflow-x: hidden; }
.nav-section-title {
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--gray-500);
  padding: 10px 20px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: var(--gray-400);
  font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
  border-left: 3px solid transparent;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover  { background: rgba(255,255,255,.05); color: white; }
.nav-item.active {
  background: rgba(79,70,229,.2);
  color: var(--primary-light);
  border-left-color: var(--primary);
}
.nav-item .nav-icon  { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-left: auto; background: var(--danger);
  color: white; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 20px;
}

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); flex-shrink: 0; }
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius);
  cursor: pointer; transition: background var(--transition);
}
.sidebar-user:hover { background: rgba(255,255,255,.05); }
.sidebar-user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); display: flex;
  align-items: center; justify-content: center;
  color: white; font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role  { font-size: 11px; color: var(--gray-500); }

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

/* ── Top Header ──────────────────────────────────────────── */
.top-header {
  height: var(--header-height);
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center;
  padding: 0 20px; gap: 12px;
  position: sticky; top: 0; z-index: 50;
  flex-shrink: 0;
}
.top-header .page-title {
  font-size: 17px; font-weight: 700; color: var(--gray-900);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-header .header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Page Body ───────────────────────────────────────────── */
.page-body { padding: 24px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--gray-900); }
.card-body  { padding: 20px; }

/* ── Stat Cards ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px; background: var(--primary);
}
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before  { background: var(--danger); }
.stat-card.accent::before  { background: var(--accent); }
.stat-card.primary::before { background: var(--primary); }
.stat-label { font-size: 11px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--gray-900); line-height: 1.1; margin-bottom: 4px; }
.stat-icon  { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 28px; opacity: .08; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer;
  border: none; transition: all var(--transition);
  white-space: nowrap; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn-primary   { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-success   { background: var(--success); color: white; }
.btn-warning   { background: var(--warning); color: white; }
.btn-danger    { background: var(--danger);  color: white; }
.btn-outline   { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 5px; }
.form-label .required { color: var(--danger); margin-left: 3px; }
.form-control {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--gray-300); border-radius: var(--radius);
  font-size: 14px; color: var(--gray-900);
  background: white; transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  -webkit-appearance: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.form-hint  { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--danger);  margin-top: 4px; font-weight: 500; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: white; min-width: 500px; }
thead { background: var(--gray-100); }
th { padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
td { padding: 12px 14px; font-size: 13px; color: var(--gray-800); border-bottom: 1px solid var(--gray-100); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-100); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-danger  { background: #FEE2E2; color: #991B1B; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-primary { background: #EDE9FE; color: #4C1D95; }
.badge-gray    { background: var(--gray-200); color: var(--gray-700); }
.badge-accent  { background: #CFFAFE; color: #164E63; }

/* ── Progress ────────────────────────────────────────────── */
.progress { height: 8px; background: var(--gray-200); border-radius: 20px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 20px; background: var(--primary); transition: width 0.4s ease; }
.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger  { background: var(--danger); }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 14px; display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 16px;
}
.alert-success { background: #D1FAE5; color: #065F46; border-left: 4px solid var(--success); }
.alert-danger  { background: #FEE2E2; color: #991B1B; border-left: 4px solid var(--danger); }
.alert-warning { background: #FEF3C7; color: #92400E; border-left: 4px solid var(--warning); }
.alert-info    { background: #DBEAFE; color: #1E40AF; border-left: 4px solid #3B82F6; }

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
  opacity: 0; visibility: hidden; transition: all var(--transition);
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: white; border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform var(--transition);
  max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-title  { font-size: 16px; font-weight: 700; }
.modal-close  { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--gray-500); padding: 4px; min-width: 32px; }
.modal-body   { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; flex-wrap: wrap; }

/* ── Auth pages ──────────────────────────────────────────── */
.auth-page {
  min-height: 100vh; display: flex;
  background: linear-gradient(135deg, #0F172A 0%, #1E1B4B 50%, #0F172A 100%);
}
.auth-left {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 60px;
  color: white;
}
.auth-right {
  width: 480px; background: white;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 48px 40px;
}
.auth-card  { width: 100%; }
.auth-logo  { font-size: 22px; font-weight: 800; color: var(--primary); margin-bottom: 28px; display: flex; align-items: center; gap: 10px; }
.auth-title { font-size: 24px; font-weight: 800; color: var(--gray-900); margin-bottom: 6px; }
.auth-subtitle { font-size: 14px; color: var(--gray-500); margin-bottom: 28px; }

/* ── Misc ────────────────────────────────────────────────── */
.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--gray-200); }
.divider span { font-size: 12px; color: var(--gray-500); white-space: nowrap; }

.pagination { display: flex; align-items: center; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.page-btn { min-width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border: 1.5px solid var(--gray-300); border-radius: var(--radius); background: white; font-size: 13px; font-weight: 600; cursor: pointer; transition: all var(--transition); color: var(--gray-700); text-decoration: none; }
.page-btn:hover  { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: white; }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state .empty-icon  { font-size: 44px; margin-bottom: 14px; opacity: .4; }
.empty-state .empty-title { font-size: 18px; font-weight: 700; color: var(--gray-700); margin-bottom: 6px; }

#toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast {
  background: var(--dark); color: white;
  padding: 12px 16px; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  min-width: 240px; max-width: 380px;
  animation: slideIn .3s ease;
  border-left: 4px solid var(--primary);
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideIn  { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { to   { transform: translateX(120%); opacity: 0; } }

/* ─────────────────────────────────────────────────────────
   RESPONSIVE — Tablet (≤1024px)
───────────────────────────────────────────────────────── */
@media (max-width: 1024px) {

  /* Sidebar: off-canvas on mobile/tablet */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  /* Main takes full width */
  .main-content { margin-left: 0; }

  /* Auth: hide left panel */
  .auth-left  { display: none; }
  .auth-right { width: 100%; padding: 40px 32px; }

  /* Stats: 2 columns */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }

  /* Page padding */
  .page-body { padding: 16px; }

  /* Card header wraps */
  .card-header { flex-wrap: wrap; }

  /* Notification dropdown: full width on tablet */
  #notif-panel, #admin-notif-panel {
    position: fixed !important;
    right: 8px !important;
    top: calc(var(--header-height) + 4px) !important;
    width: calc(100vw - 16px) !important;
    max-width: 380px !important;
  }
}

/* ─────────────────────────────────────────────────────────
   RESPONSIVE — Mobile (≤640px)
───────────────────────────────────────────────────────── */
@media (max-width: 640px) {

  :root { --header-height: 56px; }

  /* Stats: 2 tight columns */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card  { padding: 14px 14px; }
  .stat-value { font-size: 20px; }
  .stat-icon  { font-size: 22px; }

  /* Page body */
  .page-body { padding: 12px; }

  /* Cards */
  .card-body  { padding: 14px; }
  .card-header { padding: 12px 14px; }

  /* Buttons: allow wrap */
  .btn { font-size: 13px; padding: 8px 12px; }
  .btn-sm { padding: 5px 8px; font-size: 11px; }

  /* Top header */
  .top-header { padding: 0 12px; gap: 8px; }
  .top-header .page-title { font-size: 15px; }

  /* Forms */
  .form-control { font-size: 16px; } /* prevents iOS zoom */

  /* Tables: horizontal scroll with card border */
  .table-wrap { border-radius: var(--radius); }
  .card > .table-wrap { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
  td, th { padding: 10px 10px; }

  /* Modals: full screen on small phones */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 90vh;
  }
  .modal-overlay.open .modal { transform: translateY(0); }

  /* Auth page */
  .auth-right { padding: 28px 20px; min-height: 100vh; justify-content: flex-start; padding-top: 48px; }

  /* Grid layouts: stack to single column */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns:1fr 320px"],
  [style*="grid-template-columns:1fr 360px"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns:220px 1fr"],
  [style*="grid-template-columns:1fr 480px"] {
    grid-template-columns: 1fr !important;
  }

  /* Action button rows: wrap */
  div[style*="display:flex"][style*="gap"] > .btn,
  div[style*="display:flex"][style*="gap"] > form { flex-shrink: 0; }

  /* Notification badge */
  #toast-container { right: 8px; top: 8px; max-width: calc(100vw - 16px); }
  .toast { min-width: 0; max-width: 100%; font-size: 13px; }

  /* Sidebar footer user info: truncate */
  .sidebar-user .user-name { max-width: 120px; }

  /* Table action buttons: compact */
  td .btn + .btn { margin-left: 2px; }
}

/* ─────────────────────────────────────────────────────────
   RESPONSIVE — Very small phones (≤380px)
───────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card  { padding: 12px; }
  .page-body  { padding: 8px; }
  .card-body  { padding: 12px; }
  .btn        { padding: 7px 10px; font-size: 12px; }
  .auth-right { padding: 20px 16px; }
}

/* ── Utility ─────────────────────────────────────────────── */
.d-none   { display: none !important; }
.d-mobile { display: none; }
@media (max-width: 640px) { .d-mobile { display: block; } .d-desktop { display: none !important; } }
.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.overflow-x-auto { overflow-x: auto; -webkit-overflow-scrolling: touch; }
