:root {
  /* Original Blue Palette - Reverted per user request */
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --accent: #3b82f6; 
  --accent-soft: rgba(59, 130, 246, 0.1);
  --accent-hover: #2563eb;
  --border: #e2e8f0;
  --success: #10b981;
  --danger: #ef4444;
  --gold: #eab308;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 4px 6px -1px rgba(0,0,0,0.05);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.08);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1);
  --glass: rgba(255, 255, 255, 0.7);
}

body.dark-mode {
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --border: #334155;
  --accent-soft: rgba(59, 130, 246, 0.2);
  --glass: rgba(30, 41, 59, 0.8);
}

/* Global Smoothness & Performance */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body {
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  letter-spacing: -0.01em;
  line-height: 1.5;
}

/* ── SKELETON LOADING ── */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-card-hover) 25%, var(--border) 50%, var(--bg-card-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

/* ── ANIMATIONS ── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in {
  opacity: 0;
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  will-change: transform, opacity;
}

/* ── SCROLLBARS ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ── LOGIN SCREEN ── */
.login-bg {
  position: fixed; inset: 0; z-index: 1000;
  background: radial-gradient(circle at top left, var(--accent-soft), var(--bg-main));
  display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow-y: auto;
}
.login-card {
  background: var(--bg-card);
  padding: 48px;
  border-radius: 24px;
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 36px; font-weight: 800; line-height: 0.9;
  letter-spacing: -2px; margin-bottom: 32px;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.login-heading { font-size: 28px; font-weight: 800; letter-spacing: -1px; margin-bottom: 8px; }
.login-subtext { color: var(--text-secondary); margin-bottom: 32px; }
.login-group { margin-bottom: 20px; }
.login-group label { display: block; font-size: 13px; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.login-input {
  width: 100%; padding: 14px 16px; border: 1.5px solid var(--border);
  background: var(--bg-main); border-radius: 12px; font-size: 15px; font-weight: 500;
  transition: all 0.2s; color: var(--text-primary); outline: none;
}
.login-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.login-submit {
  width: 100%; padding: 16px; background: var(--accent); color: white;
  border-radius: 12px; font-weight: 700; font-size: 16px; border: none;
  cursor: pointer; transition: all 0.2s; margin-top: 12px;
}
.login-submit:hover { transform: translateY(-2px); background: var(--accent-hover); box-shadow: 0 8px 20px rgba(192, 124, 58, 0.3); }

/* ── APP LAYOUT ── */
.app-layout { display: flex; height: 100dvh; width: 100%; overflow: hidden; }

.sidebar {
  width: 280px; flex-shrink: 0;
  background: #ffffff;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 32px 20px;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-backdrop {
  position: fixed; inset: 0; background: transparent;
  z-index: 90; display: none; opacity: 1; transition: none;
}
.sidebar-backdrop.active { display: block; opacity: 1; }
.sidebar-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 28px; font-weight: 800; line-height: 0.9;
  letter-spacing: -2px; margin-bottom: 48px;
  color: var(--accent);
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; margin-bottom: 4px;
  border-radius: 12px; font-weight: 600; font-size: 14px;
  color: var(--text-secondary); cursor: pointer;
  border: none; background: transparent; transition: all 0.2s;
  text-align: left; width: 100%;
}
.nav-item:hover { background: var(--accent-soft); color: var(--accent); }
.nav-item.active { background: var(--accent); color: white; box-shadow: 0 8px 16px rgba(192, 124, 58, 0.2); }

.sidebar-footer { margin-top: auto; padding-top: 24px; border-top: 1px solid var(--border); }
.user-widget { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.user-avatar {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px;
}
.user-name { font-weight: 700; font-size: 14px; }
.user-role { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; font-weight: 700; letter-spacing: 0.05em; }

.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }

.topbar {
  height: 80px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 40px; background: var(--bg-card);
  border-bottom: 1px solid var(--border); z-index: 90;
}
.page-title { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.topbar-actions { display: flex; gap: 12px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text-primary); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s; position: relative;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); color: white; border-radius: 20px;
  font-size: 10px; font-weight: 800; padding: 2px 6px;
  border: 2px solid var(--bg-card);
}

.page-content { flex: 1; padding: 40px; overflow-y: auto; overflow-x: hidden; }

/* ── GRID & CARDS ── */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; }

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

.stat-card { position: relative; overflow: hidden; }
.stat-value { font-family: 'Space Grotesk', sans-serif; font-size: 36px; font-weight: 800; margin-bottom: 4px; }
.stat-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── TABLES ── */
.table-wrap {
  width: 100%; border-radius: var(--radius); border: 1px solid var(--border);
  overflow: hidden; background: var(--bg-card); box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; text-align: left; }
th {
  padding: 16px 24px; background: var(--bg-card-hover);
  font-size: 11px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.1em;
  border-bottom: 1px solid var(--border);
}
td { padding: 18px 24px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr:last-child td { border-bottom: none; }

.pill {
  padding: 4px 12px; border-radius: 100px;
  font-size: 11px; font-weight: 800; text-transform: uppercase;
}
.pill.active { background: #dcfce7; color: #166534; }
.pill.pending { background: #fef9c3; color: #854d0e; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: 10px; font-weight: 700; font-size: 14px;
  cursor: pointer; transition: all 0.2s; border: none;
}
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(192, 124, 58, 0.3); }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-card-hover); border-color: var(--text-secondary); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── MODALS ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.2);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  transition: opacity 0.2s;
}
.modal-overlay.hidden { display: none !important; }
.modal-content {
  background: var(--bg-card); border-radius: 24px; width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.modal-header {
  padding: 24px 32px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-close { background: var(--bg-card-hover); border: none; font-size: 24px; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; color: var(--text-secondary); }

/* ── MOBILE ADAPTATION ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: -280px; top: 0; bottom: 0;
    transition: transform 0.3s ease;
  }
  .sidebar.mobile-active { transform: translateX(280px); }
  .topbar { padding: 0 20px; height: 70px; }
  .page-content { padding: 20px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-title { font-size: 18px; }
  .mobile-toggle { display: flex !important; margin-right: 12px; }
}

.mobile-toggle { display: none; background: transparent; border: none; color: var(--text-primary); cursor: pointer; }

.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: skeletonPulse 1.5s infinite linear;
  border-radius: 12px;
}
@keyframes skeletonPulse { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── UTILS ── */
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-24 { margin-top: 24px; }
.fw-800 { font-weight: 800; }
.fw-700 { font-weight: 700; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text-secondary); }
.hidden { display: none !important; }

/* MESSAGING FIX */
#msg-app {
  display: flex; height: calc(100dvh - 180px); background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
#active-chat-area { display: flex; flex-direction: column; flex: 1; }
#chat-messages-scroll { flex: 1; overflow-y: auto; padding: 24px; }

/* REFRESH SPIN */
/* ── MOBILE RESPONSIVENESS (CONSOLIDATED) ── */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px; /* Start off-screen to the left */
    right: auto;
    bottom: 0;
    width: 280px;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 20px 0 50px rgba(0,0,0,0.15);
    display: flex !important; /* Ensure it's not hidden by other rules */
  }
  
  .sidebar.mobile-active {
    transform: translateX(280px); /* Slide into view from the left */
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 900;
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  
  .sidebar-backdrop.active {
    display: block;
    opacity: 1;
  }

  .topbar { padding: 0 16px; height: 64px; }
  .page-title { font-size: 16px; }
  .topbar-actions { gap: 8px; }
  .icon-btn svg { width: 18px; height: 18px; }
  .page-content { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  
  .mobile-toggle { display: block !important; }
}

@media (max-width: 400px) {
  .topbar-actions .icon-btn:nth-child(2), 
  .topbar-actions .icon-btn:nth-child(3) { display: none; }
}

.toast-container { position: fixed; top: 20px; right: 20px; z-index: 10000; pointer-events: none; }
@media (max-width: 768px) {
  .toast-container { top: auto; bottom: 20px; right: 10px; left: 10px; }
  .toast { width: auto; }
}

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spinning { animation: spin 1s linear infinite; }
.hidden { display: none !important; }
