:root {
  --sidebar-w: 260px;
  --sidebar-collapsed-w: 72px;
  --topbar-h: 64px;
  --transition: cubic-bezier(0.22, 1, 0.36, 1);
}

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

body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
}

/* ═══════════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--c-surface);
  border-right: 1px solid rgba(var(--ink-rgb), 0.06);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: width 0.3s var(--transition);
  overflow: hidden;
}

.sidebar-header {
  padding: 1.5rem 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(var(--ink-rgb), 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
}
.sidebar-logo {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 1.35rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.sidebar-logo span {
  color: var(--primary);
}
.sidebar-tag {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.6rem;
  font-family: "Space Mono", monospace;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--teal);
  background: rgba(var(--teal-rgb), 0.08);
  padding: 2px 8px;
  border-radius: 100px;
  vertical-align: middle;
  white-space: nowrap;
}

/* Collapse toggle button */
.sidebar-collapse-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1.5px solid rgba(var(--ink-rgb), 0.08);
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background 0.2s,
    border-color 0.2s,
    transform 0.3s var(--transition);
}
.sidebar-collapse-btn:hover {
  border-color: rgba(var(--ink-rgb), 0.2);
  background: var(--cream-d);
}
.sidebar-collapse-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--ink-s);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s var(--transition);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.nav-section {
  padding: 0 1rem;
  margin-bottom: 0.5rem;
}
.nav-section-label {
  font-size: 0.65rem;
  font-family: "Space Mono", monospace;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-m);
  padding: 0.75rem 0.5rem 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.2s;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-s);
  text-decoration: none;
  transition:
    background 0.2s,
    color 0.2s;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover {
  background: rgba(var(--ink-rgb), 0.03);
  color: var(--ink);
}
.nav-item.active {
  background: rgba(var(--primary-rgb), 0.06);
  color: var(--primary);
  font-weight: 600;
}
.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-item-text {
  overflow: hidden;
  white-space: nowrap;
  transition:
    opacity 0.2s,
    width 0.3s;
}
.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: "Space Mono", monospace;
  background: var(--primary);
  color: var(--c-surface);
  padding: 1px 7px;
  border-radius: 100px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(var(--ink-rgb), 0.05);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--c-surface);
  flex-shrink: 0;
}
.user-info {
  min-width: 0;
  overflow: hidden;
  transition:
    opacity 0.2s,
    width 0.3s;
}
.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.role-pill {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  background: rgba(var(--primary-rgb), 0.1);
  color: var(--primary);
  letter-spacing: 0.02em;
}
.btn-logout {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.4;
  padding: 4px;
  transition: opacity 0.2s;
  flex-shrink: 0;
}
.btn-logout:hover {
  opacity: 0.8;
}
.btn-logout svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ═══════ COLLAPSED SIDEBAR (desktop) ═══════ */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-w);
}
.sidebar.collapsed .sidebar-header {
  padding: 1.5rem 0.9rem 1.25rem;
  justify-content: center;
}
.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .sidebar-tag {
  display: none;
}
.sidebar.collapsed .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}
.sidebar.collapsed .nav-section {
  padding: 0 0.6rem;
}
.sidebar.collapsed .nav-section-label {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}
.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 0.7rem;
  border-radius: 12px;
}
.sidebar.collapsed .nav-item-text,
.sidebar.collapsed .nav-badge {
  opacity: 0;
  width: 0;
  overflow: hidden;
}
.sidebar.collapsed .sidebar-footer {
  padding: 1rem 0.6rem;
}
.sidebar.collapsed .user-info,
.sidebar.collapsed .btn-logout {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* Tooltip on collapsed icons */
.sidebar.collapsed .nav-item {
  position: relative;
}
.sidebar.collapsed .nav-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--ink);
  color: var(--c-surface);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 200;
}
.sidebar.collapsed .nav-item:hover::after {
  opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════════════════ */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  transition: margin-left 0.3s var(--transition);
}
body.sidebar-collapsed .main {
  margin-left: var(--sidebar-collapsed-w);
}

/* ═══════ TOP BAR ═══════ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid rgba(var(--ink-rgb), 0.05);
  background: rgba(var(--surface-rgb), 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left h1 {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}
.topbar-left p {
  font-size: 0.85rem;
  color: var(--ink-s);
  margin-top: 2px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1.5px solid rgba(var(--ink-rgb), 0.08);
  background: var(--c-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  position: relative;
}
.topbar-btn:hover {
  border-color: rgba(var(--ink-rgb), 0.2);
  box-shadow: 0 2px 8px rgba(var(--ink-rgb), 0.06);
}
.topbar-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink-s);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.topbar-btn .notif-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  border: 2px solid var(--c-surface);
}

/* Mobile hamburger */
.mobile-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1.5px solid rgba(var(--ink-rgb), 0.08);
  background: var(--c-surface);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.mobile-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Content area */
.content {
  padding: 2rem;
}

/* ═══════════════════════════════════════════════════════════════════
   STATS GRID
   ═══════════════════════════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--c-surface);
  border: 1px solid rgba(var(--ink-rgb), 0.05);
  border-radius: 16px;
  padding: 1.5rem;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(var(--ink-rgb), 0.06);
}
.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.stat-trend {
  font-size: 0.7rem;
  font-weight: 700;
  font-family: "Space Mono", monospace;
  padding: 2px 8px;
  border-radius: 100px;
}
.stat-trend.up {
  color: var(--green);
  background: rgba(var(--green-rgb), 0.08);
}
.stat-trend.down {
  color: var(--red);
  background: rgba(var(--red-rgb), 0.08);
}
.stat-value {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}
.stat-label {
  font-size: 0.8rem;
  color: var(--ink-m);
}

/* ═══════════════════════════════════════════════════════════════════
   CONTENT PANELS
   ═══════════════════════════════════════════════════════════════════ */
.section-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.panel {
  background: var(--c-surface);
  border: 1px solid rgba(var(--ink-rgb), 0.05);
  border-radius: 16px;
  padding: 1.5rem;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.panel-title {
  font-weight: 700;
  font-size: 0.95rem;
}
.panel-action {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s;
}
.panel-action:hover {
  color: var(--primary-h);
}

/* Activity list */
.activity-list {
  list-style: none;
}
.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(var(--ink-rgb), 0.04);
}
.activity-item:last-child {
  border-bottom: none;
}
.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.activity-dot.green {
  background: var(--green);
}
.activity-dot.amber {
  background: var(--secondary);
}
.activity-dot.blue {
  background: var(--blue);
}
.activity-dot.accent {
  background: var(--primary);
}
.activity-text {
  flex: 1;
  font-size: 0.85rem;
  color: var(--ink-s);
}
.activity-text strong {
  color: var(--ink);
  font-weight: 600;
}
.activity-time {
  font-size: 0.7rem;
  font-family: "Space Mono", monospace;
  color: var(--ink-m);
  white-space: nowrap;
}

/* Quick actions */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.qa-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 1.25rem 0.75rem;
  border-radius: 14px;
  border: 1.5px solid rgba(var(--ink-rgb), 0.06);
  background: var(--cream);
  cursor: pointer;
  transition:
    border-color 0.2s,
    transform 0.15s,
    box-shadow 0.2s;
  text-decoration: none;
  color: var(--ink);
  font-family: inherit;
}
.qa-btn:hover {
  border-color: rgba(var(--ink-rgb), 0.15);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(var(--ink-rgb), 0.05);
}
.qa-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.qa-btn span {
  font-size: 0.8rem;
  font-weight: 600;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--ink-m);
}
.empty-state svg {
  width: 48px;
  height: 48px;
  fill: none;
  stroke: var(--cream-d);
  stroke-width: 1.5;
  margin-bottom: 1rem;
}
.empty-state p {
  font-size: 0.85rem;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(var(--ink-rgb), 0.4);
  z-index: 99;
}
.sidebar-overlay.show {
  display: block;
}

/* ═══════════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s var(--transition);
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: var(--primary);
  color: var(--c-surface);
  box-shadow: 0 2px 4px rgba(var(--primary-rgb), 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-h);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(var(--primary-rgb), 0.3);
}

.btn-secondary {
  background: var(--surface, var(--c-surface));
  color: var(--ink);
  border: 1px solid var(--border, rgba(var(--ink-rgb), 0.15));
}

.btn-secondary:hover:not(:disabled) {
  background: var(--cream-d);
  color: var(--primary);
  border-color: var(--primary);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ═══════════════════════════════════════════════════════════════════
   FORMS & INPUTS
   ═══════════════════════════════════════════════════════════════════ */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-s);
  margin-bottom: 0.5rem;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1.5px solid rgba(var(--ink-rgb), 0.1);
  background: var(--c-surface);
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  transition: all 0.2s var(--transition);
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.1);
}

.form-group input::placeholder {
  color: var(--ink-m);
  opacity: 0.5;
}

.form-error {
  color: var(--red);
  font-size: 0.8rem;
  font-weight: 500;
  margin-top: 0.5rem;
  display: none;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Switch styling */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s var(--transition);
}
.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: rgba(var(--surface-rgb), 1);
  transition: 0.4s var(--transition);
}
input:checked + .slider {
  background-color: var(--primary);
}
input:checked + .slider:before {
  transform: translateX(22px);
}
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(var(--ink-rgb), 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
}
.modal-content {
  background: var(--c-surface);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 24px;
  padding: 2rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

body.modal-open {
  overflow: hidden !important;
}

/* ═══════════════════════════════════════════════════════════════════
   CUSTOM SCROLLBARS
   ═══════════════════════════════════════════════════════════════════ */
/* Global */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(var(--primary-rgb), 0.2);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* Slim for Sidebar & Modals */
.sidebar-content::-webkit-scrollbar,
.modal-content::-webkit-scrollbar,
.nav-section::-webkit-scrollbar {
  width: 4px;
}

.sidebar-content::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb {
  background: rgba(var(--primary-rgb), 0.15);
}

/* Firefox */
.sidebar-content,
.modal-content,
.nav-section {
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--primary-rgb), 0.2) transparent;
}

@keyframes modalPop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--ink-m);
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  body, html {
    overflow-x: hidden;
    position: relative;
    width: 100%;
  }
  .sidebar {
    width: var(--sidebar-w) !important;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar.collapsed {
    width: var(--sidebar-w) !important;
  }
  .sidebar-collapse-btn {
    display: none;
  }
  .main {
    margin-left: 0 !important;
    overflow-x: hidden;
    max-width: 100vw;
  }
  .mobile-toggle {
    display: flex;
  }
  .topbar {
    padding: 1rem;
  }
  .panel-header, .card-header {
    flex-wrap: wrap;
    gap: 1rem;
  }
  .content {
    padding: 1.25rem;
  }
  .section-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Table Utilities ─── */
.table-responsive {
  width: 100% !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  margin-bottom: 1rem !important;
  display: block !important;
}

.table-responsive table {
  min-width: 650px !important;
  width: 100% !important;
}

.table-responsive::-webkit-scrollbar {
  height: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 10px;
}
