/* ============================================================
   TailAdmin-inspired stylesheet
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-width: 280px;
  --header-height: 64px;

  /* Sidebar */
  --sidebar-bg: #1C2434;
  --sidebar-border: #313D4A;
  --sidebar-hover: #313D4A;
  --sidebar-text: #DEE4EE;
  --sidebar-muted: #8A99AF;

  /* Layout */
  --body-bg: #F1F5F9;
  --header-bg: #FFFFFF;
  --card-bg: #FFFFFF;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --card-radius: 12px;

  /* Colors */
  --primary: #3C50E0;
  --primary-light: rgba(60,80,224,0.1);
  --success: #10B981;
  --success-light: rgba(16,185,129,0.1);
  --warning: #F59E0B;
  --warning-light: rgba(245,158,11,0.1);
  --danger: #EF4444;
  --danger-light: rgba(239,68,68,0.1);
  --info: #06B6D4;
  --info-light: rgba(6,182,212,0.1);

  /* Text */
  --text-primary: #1D2A39;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --border: #E2E8F0;

  --font: 'Outfit', 'Inter', system-ui, sans-serif;
}

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--body-bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, width 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #313D4A transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #313D4A; border-radius: 2px; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-height);
  padding: 0 24px;
  border-bottom: 1px solid var(--sidebar-border);
  text-decoration: none;
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 38px;
  height: 38px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  color: white;
  font-weight: 700;
  font-size: 18px;
  white-space: nowrap;
}

.sidebar-nav {
  padding: 12px;
  flex: 1;
}

.sidebar-section-label {
  color: var(--sidebar-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 12px;
  margin: 18px 0 6px;
}

.sidebar-nav ul { list-style: none; padding: 0; margin: 0; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
  margin-bottom: 2px;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
}

.sidebar-item:hover { background: var(--sidebar-hover); color: #fff; }

.sidebar-item.active { background: rgba(255,255,255,0.07); color: #fff; }

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.sidebar-item i { font-size: 18px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-item-text { overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-db-info { font-size: 12px; color: var(--sidebar-muted); line-height: 1.8; }
.sidebar-db-info .connected    { color: #10B981; }
.sidebar-db-info .disconnected { color: #F59E0B; }

/* ---- HEADER ---- */
.header {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 90;
  transition: left 0.3s ease;
  gap: 12px;
}

.header-toggle {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.header-toggle:hover { background: var(--body-bg); color: var(--text-primary); }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  font-family: var(--font);
}

.header-btn:hover { background: var(--body-bg); border-color: #CBD5E1; color: var(--text-primary); }

.header-btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.header-btn-primary:hover { background: #3347cc; border-color: #3347cc; color: white; }

/* Dropdown */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  min-width: 160px;
  padding: 6px;
  z-index: 200;
  display: none;
}

.dropdown-menu.show { display: block; }

.dropdown-item {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  transition: background 0.1s;
}

.dropdown-item:hover { background: var(--body-bg); }
.dropdown-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

/* ---- MAIN LAYOUT ---- */
.main-wrapper {
  margin-left: var(--sidebar-width);
  padding-top: var(--header-height);
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}

.page-content { padding: 24px; }

/* Page Header */
.page-header { margin-bottom: 24px; }

.page-header h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.breadcrumb a { color: var(--primary); text-decoration: none; }

/* ---- CARDS ---- */
.card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
}

.card-body { padding: 24px; }

.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }

/* ---- STAT CARDS ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  padding: 20px 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: box-shadow 0.2s;
}

.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon-blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon-green  { background: var(--success-light); color: var(--success); }
.stat-icon-orange { background: var(--warning-light); color: var(--warning); }
.stat-icon-red    { background: var(--danger-light);  color: var(--danger);  }

.stat-info { flex: 1; min-width: 0; }
.stat-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-change { font-size: 12px; margin-top: 8px; display: flex; align-items: center; gap: 3px; }
.stat-change-up      { color: var(--success); }
.stat-change-down    { color: var(--danger); }
.stat-change-neutral { color: var(--text-muted); }

/* ---- CHARTS GRID ---- */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

/* ---- USER LIST ---- */
.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.user-item:last-child { border-bottom: none; }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-when { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---- TABLES ---- */
.table-wrapper { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead th {
  padding: 12px 16px;
  background: #F8FAFC;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

tbody td {
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #F8FAFC; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-blue    { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger  { background: var(--danger-light);  color: var(--danger);  }

/* ---- FOOTER ---- */
.footer {
  padding: 16px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

/* ---- COLLAPSED SIDEBAR ---- */
body.sidebar-collapsed .sidebar { width: 72px; }

body.sidebar-collapsed .sidebar-logo-text,
body.sidebar-collapsed .sidebar-item-text,
body.sidebar-collapsed .sidebar-section-label,
body.sidebar-collapsed .sidebar-db-info { display: none; }

body.sidebar-collapsed .sidebar-item { justify-content: center; padding: 10px; }
body.sidebar-collapsed .sidebar-logo  { justify-content: center; padding: 0; }

body.sidebar-collapsed .main-wrapper { margin-left: 72px; }
body.sidebar-collapsed .header       { left: 72px; }

/* ---- DARK MODE ---- */
body.theme-dark {
  --body-bg: #111827;
  --card-bg: #1F2937;
  --header-bg: #1F2937;
  --text-primary: #F9FAFB;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --border: #374151;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

body.theme-dark thead th           { background: #111827; }
body.theme-dark tbody tr:hover     { background: #111827; }
body.theme-dark .header-btn        { background: #1F2937; border-color: #374151; color: #9CA3AF; }
body.theme-dark .header-btn:hover  { background: #111827; }
body.theme-dark .header-btn-primary        { background: var(--primary); border-color: var(--primary); color: #fff; }
body.theme-dark .header-btn-primary:hover  { background: #3347cc; border-color: #3347cc; }
body.theme-dark .dropdown-menu     { background: #1F2937; border-color: #374151; }
body.theme-dark .dropdown-item     { color: #F9FAFB; }
body.theme-dark .dropdown-item:hover { background: #111827; }

/* ---- RESPONSIVE ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; }
  .main-wrapper { margin-left: 0 !important; }
  .header { left: 0 !important; }
  .charts-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
