/* ============================================================
   CORE THEME — CSS Variables + Base Styles
   Supports: dark (default), light, and future themes via data-theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Dark Theme (default) ── */
[data-theme="dark"] {
  color-scheme: dark;
  --bg-base:        #0f1117;
  --bg-surface:     #1a1d27;
  --bg-surface2:    #20243a;
  --bg-hover:       #252940;
  --bg-active:      #2e3354;
  --border:         #2a2d3e;
  --border-subtle:  #1e2130;

  --text-primary:   #e8eaf2;
  --text-secondary: #8b90a7;
  --text-muted:     #555a70;
  --text-inverse:   #0f1117;

  --accent:         #4f6ef7;
  --accent-soft:    rgba(79, 110, 247, 0.12);
  --accent-hover:   #3d5be0;
  --accent-2:       #7c5ef7;

  --success:        #22c55e;
  --success-soft:   rgba(34, 197, 94, 0.12);
  --warning:        #f59e0b;
  --warning-soft:   rgba(245, 158, 11, 0.12);
  --danger:         #ef4444;
  --danger-soft:    rgba(239, 68, 68, 0.12);
  --info:           #06b6d4;
  --info-soft:      rgba(6, 182, 212, 0.12);

  --sidebar-width:      240px;
  --sidebar-collapsed:  64px;
  --topbar-height:      60px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.6);

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;

  --scrollbar-thumb: #2a2d3e;
  --scrollbar-track: #1a1d27;

  --bs-body-bg: var(--bg-base);
  --bs-body-color: var(--text-primary);
  --bs-secondary-color: var(--text-secondary);
  --bs-tertiary-bg: var(--bg-surface2);
  --bs-secondary-bg: var(--bg-surface);
  --bs-border-color: var(--border);
  --bs-border-color-translucent: rgba(255, 255, 255, 0.08);
  --bs-heading-color: var(--text-primary);
  --bs-emphasis-color: var(--text-primary);
  --bs-table-bg: var(--bg-surface);
  --bs-table-color: var(--text-primary);
  --bs-table-striped-bg: var(--bg-surface2);
  --bs-table-striped-color: var(--text-primary);
  --bs-table-hover-bg: var(--bg-hover);
  --bs-table-hover-color: var(--text-primary);
  --bs-table-active-bg: var(--bg-active);
  --bs-table-active-color: var(--text-primary);
  --bs-table-border-color: var(--border);
  --bs-dropdown-bg: var(--bg-surface);
  --bs-dropdown-color: var(--text-secondary);
  --bs-dropdown-link-color: var(--text-secondary);
  --bs-dropdown-link-hover-color: var(--text-primary);
  --bs-dropdown-link-hover-bg: var(--bg-hover);
  --bs-dropdown-border-color: var(--border);
  --bs-modal-bg: var(--bg-surface);
  --bs-modal-color: var(--text-primary);
}

/* ── Light Theme ── */
[data-theme="light"] {
  color-scheme: light;
  --bg-base:        #f0f2f8;
  --bg-surface:     #ffffff;
  --bg-surface2:    #f7f8fc;
  --bg-hover:       #eef0f8;
  --bg-active:      #e4e8f8;
  --border:         #e2e5f0;
  --border-subtle:  #ebedf5;

  --text-primary:   #1a1d2e;
  --text-secondary: #5a6080;
  --text-muted:     #9298b0;
  --text-inverse:   #ffffff;

  --accent:         #4f6ef7;
  --accent-soft:    rgba(79, 110, 247, 0.10);
  --accent-hover:   #3d5be0;
  --accent-2:       #7c5ef7;

  --success:        #16a34a;
  --success-soft:   rgba(22, 163, 74, 0.10);
  --warning:        #d97706;
  --warning-soft:   rgba(217, 119, 6, 0.10);
  --danger:         #dc2626;
  --danger-soft:    rgba(220, 38, 38, 0.10);
  --info:           #0891b2;
  --info-soft:      rgba(8, 145, 178, 0.10);

  --sidebar-width:      240px;
  --sidebar-collapsed:  64px;
  --topbar-height:      60px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.14);

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;

  --scrollbar-thumb: #d0d4e8;
  --scrollbar-track: #f0f2f8;

  --bs-body-bg: var(--bg-base);
  --bs-body-color: var(--text-primary);
  --bs-secondary-color: var(--text-secondary);
  --bs-tertiary-bg: var(--bg-surface2);
  --bs-secondary-bg: var(--bg-surface);
  --bs-border-color: var(--border);
  --bs-border-color-translucent: rgba(0, 0, 0, 0.08);
  --bs-heading-color: var(--text-primary);
  --bs-emphasis-color: var(--text-primary);
  --bs-table-bg: var(--bg-surface);
  --bs-table-color: var(--text-primary);
  --bs-table-striped-bg: var(--bg-surface2);
  --bs-table-striped-color: var(--text-primary);
  --bs-table-hover-bg: var(--bg-hover);
  --bs-table-hover-color: var(--text-primary);
  --bs-table-active-bg: var(--bg-active);
  --bs-table-active-color: var(--text-primary);
  --bs-table-border-color: var(--border);
  --bs-dropdown-bg: var(--bg-surface);
  --bs-dropdown-color: var(--text-secondary);
  --bs-dropdown-link-color: var(--text-secondary);
  --bs-dropdown-link-hover-color: var(--text-primary);
  --bs-dropdown-link-hover-bg: var(--bg-hover);
  --bs-dropdown-border-color: var(--border);
  --bs-modal-bg: var(--bg-surface);
  --bs-modal-color: var(--text-primary);
}


/* ── Global Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 99px; }

/* ============================================================
   LAYOUT WRAPPER
   ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1050;
  transition: width 0.28s cubic-bezier(0.4,0,0.2,1),
              transform 0.28s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

/* Logo */
.sidebar-brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-brand .brand-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  color: #fff;
  font-weight: 700;
  letter-spacing: -1px;
}

.sidebar-brand .brand-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.sidebar.collapsed .brand-text { opacity: 0; pointer-events: none; }

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 16px 20px 6px;
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.sidebar.collapsed .nav-section-label { opacity: 0; }

/* Nav Item */
.nav-item { list-style: none; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 0;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  position: relative;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13.5px;
  font-weight: 500;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-link .nav-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  display: flex; align-items: center; justify-content: center;
}

.nav-link .nav-label {
  flex: 1;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-arrow,
.sidebar.collapsed .nav-badge { opacity: 0; }

.nav-arrow {
  font-size: 11px;
  transition: transform 0.2s ease, opacity 0.2s ease;
  color: var(--text-muted);
}

.nav-link[aria-expanded="true"] .nav-arrow { transform: rotate(90deg); }

/* Badge */
.nav-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  transition: opacity 0.2s ease;
}

/* Sub Menu */
.nav-submenu {
  list-style: none;
  background: var(--bg-base);
  overflow: hidden;
}

.nav-submenu .nav-link {
  padding-left: 46px;
  font-size: 13px;
  font-weight: 400;
}

.nav-submenu .nav-link::after {
  content: '';
  position: absolute;
  left: 32px; top: 50%;
  transform: translateY(-50%);
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.15s;
}

.nav-submenu .nav-link.active::after { background: var(--accent); }

/* Level 3 */
.nav-submenu .nav-submenu .nav-link {
  padding-left: 62px;
  font-size: 12.5px;
}
.nav-submenu .nav-submenu .nav-link::after { left: 48px; }

/* Sidebar collapsed tooltip */
.sidebar.collapsed .nav-link { justify-content: center; }
.sidebar.collapsed .nav-submenu { display: none !important; }

/* Sidebar tooltip on collapsed */
.sidebar.collapsed .nav-link[data-bs-toggle="tooltip"] { position: relative; }

/* Sidebar Footer */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px;
  flex-shrink: 0;
}

.sidebar-footer .user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-footer .user-card:hover { background: var(--bg-hover); }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.user-info { opacity: 1; transition: opacity 0.2s ease; }
.sidebar.collapsed .user-info { opacity: 0; }

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 1040;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  transition: left 0.28s cubic-bezier(0.4,0,0.2,1);
}

.topbar.sidebar-collapsed { left: var(--sidebar-collapsed); }

/* Toggle Button */
.sidebar-toggle {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

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

/* Search */
.topbar-search {
  flex: 1;
  max-width: 380px;
  position: relative;
}

.topbar-search .search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

.topbar-search input {
  width: 100%;
  height: 36px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px 0 36px;
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Topbar Actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.topbar-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.topbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.topbar-btn .badge-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

/* Breadcrumb */
.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 4px;
}
.topbar-breadcrumb .bc-sep { color: var(--border); }
.topbar-breadcrumb .bc-current { color: var(--text-primary); font-weight: 600; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  padding: 24px;
  transition: margin-left 0.28s cubic-bezier(0.4,0,0.2,1);
}

.main-content.sidebar-collapsed { margin-left: var(--sidebar-collapsed); }

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

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  line-height: 1.3;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
}

/* ============================================================
   CARDS
   ============================================================ */
.content-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dashboard-grid.full {
  width: 100%;
}

.card-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-surface);
}

.card-head h5 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
}

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

.card-body { padding: 20px; }
.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: none;
}

.table-responsive {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-secondary);
  --bs-table-striped-bg: var(--bg-surface2);
  --bs-table-striped-color: var(--text-primary);
  --bs-table-hover-bg: var(--bg-hover);
  --bs-table-hover-color: var(--text-primary);
  --bs-table-active-bg: var(--bg-active);
  --bs-table-active-color: var(--text-primary);
  --bs-table-border-color: var(--border);
  color: var(--text-secondary);
  margin-bottom: 0;
}

.table > :not(caption) > * > * {
  background-color: transparent;
  color: inherit;
  border-bottom-color: var(--border);
  box-shadow: none;
}

.table > thead > tr > th {
  background: var(--bg-surface2);
  color: var(--text-muted);
  border-bottom-color: var(--border);
}

.table > tbody > tr:hover > * {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.table-light {
  --bs-table-bg: var(--bg-surface2);
  --bs-table-color: var(--text-primary);
}

/* ============================================================
   THEME TOGGLE
   ============================================================ */
.theme-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

.theme-toggle {
  width: 40px; height: 22px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.theme-toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 0.22s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="light"] .theme-toggle::after { transform: translateX(18px); }

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

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-overlay { display: block; opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  .sidebar.mobile-open ~ .sidebar-overlay,
  .sidebar-overlay.active { opacity: 1; pointer-events: all; }

  .topbar { left: 0 !important; }
  .main-content { margin-left: 0 !important; }

  .topbar-breadcrumb { display: none; }
  .topbar-search { max-width: 200px; }
}

@media (max-width: 575.98px) {
  .topbar-search { display: none; }
  .main-content { padding: 16px 12px; }
}

/* ============================================================
   UTILITY
   ============================================================ */
.text-accent   { color: var(--accent); }
.text-muted-custom { color: var(--text-muted); }
.bg-surface    { background: var(--bg-surface); }
.border-custom { border-color: var(--border) !important; }

.mono { font-family: 'JetBrains Mono', monospace; }
