/**
 * L'Afficherie Dashboard v2 - Design System
 * Style moderne, épuré, professionnel
 */

/* ===== Variables ===== */
:root {
  /* Couleurs principales */
  --bg: #f1f5f9;
  --bg-subtle: #e2e8f0;
  --card: #ffffff;
  --card-hover: #fafafa;

  /* Texte */
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  /* Bordures */
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  /* Accent (Indigo) */
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-dark: #4f46e5;
  --accent-bg: #eef2ff;

  /* Sidebar */
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #334155;
  --sidebar-text: #cbd5e1;
  --sidebar-text-active: #ffffff;
  --sidebar-border: rgba(255,255,255,0.08);

  /* États */
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --error: #ef4444;
  --error-bg: #fee2e2;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 10px 10px -5px rgba(0,0,0,0.03);

  /* Layout */
  --sidebar-width: 260px;
  --topbar-height: 70px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* ===== Layout Principal ===== */
.app {
  display: flex;
  height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

.sidebar__brand {
  padding: 24px 20px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar__brand img {
  width: 140px;
  height: auto;
  display: block;
  margin: 0 auto;
  filter: brightness(1.1);
}

.sidebar__nav {
  padding: 16px 12px;
  flex: 1;
}

.sidebar__section {
  margin-bottom: 8px;
}

.sidebar__section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 12px 12px 8px;
}

/* Navigation Items */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.nav-item.is-active {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.nav-item__icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

.nav-item__icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.75;
}

.nav-item.is-active .nav-item__icon {
  opacity: 1;
}

/* Sous-menu */
.sidebar__sub {
  margin-left: 20px;
  padding-left: 12px;
  border-left: 1px solid var(--sidebar-border);
  margin-top: 4px;
  margin-bottom: 8px;
}

.nav-item--sub {
  font-size: 13px;
  padding: 8px 12px;
}

.nav-item--sub .nav-item__icon {
  width: 18px;
  height: 18px;
}

.nav-item--sub .nav-item__icon svg {
  width: 16px;
  height: 16px;
}

/* Éléments verrouillés (accès restreint) */
.sidebar .nav-item.nav-item--locked,
.sidebar span.nav-item--locked {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 500;
  opacity: 0.4 !important;
  cursor: pointer;
  position: relative;
  transition: opacity 0.15s ease;
  background: transparent !important;
  border: 1px solid transparent;
  text-decoration: none;
}

.sidebar .nav-item.nav-item--locked:hover,
.sidebar span.nav-item--locked:hover {
  opacity: 0.55 !important;
  background: rgba(255, 255, 255, 0.03) !important;
}

.sidebar .nav-item--locked.nav-item--sub,
.sidebar span.nav-item--locked.nav-item--sub {
  font-size: 13px;
  padding: 8px 12px;
}

.nav-item__lock {
  margin-left: auto;
  width: 14px;
  height: 14px;
  opacity: 0.8;
  color: var(--sidebar-text);
}

.nav-item__lock svg {
  width: 14px;
  height: 14px;
}

/* Modal accès restreint */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.modal-overlay.is-visible {
  display: flex;
}

.modal-box {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  max-width: 360px;
  width: calc(100% - 40px);
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  animation: modalIn 0.2s ease;
}

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

.modal-box__icon {
  width: 48px;
  height: 48px;
  background: var(--error-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--error);
}

.modal-box__icon svg {
  width: 24px;
  height: 24px;
}

.modal-box__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.modal-box__text {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-box__btn {
  width: 100%;
}

/* Séparateur */
.sidebar__sep {
  height: 1px;
  background: var(--sidebar-border);
  margin: 12px 0;
}

/* Footer Sidebar */
.sidebar__footer {
  padding: 16px;
  border-top: 1px solid var(--sidebar-border);
  margin-top: auto;
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  margin-bottom: 8px;
}

.sidebar__user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 13px;
}

.sidebar__user-info {
  flex: 1;
  min-width: 0;
}

.sidebar__user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--sidebar-text-active);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

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

.sidebar__version {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

/* ===== Main Content ===== */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg);
}

.main::-webkit-scrollbar {
  width: 8px;
}

.main::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.main::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(241, 245, 249, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__hamburger {
  display: none;
}

.topbar__left h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.topbar__subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Date Picker */
.date-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 4px;
}

.date-picker__presets {
  display: flex;
  align-items: center;
  gap: 2px;
}

.date-picker__preset {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: calc(var(--radius) - 2px);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.date-picker__preset:not(.is-active):hover {
  color: var(--text);
  background: var(--bg);
}

.date-picker__preset.is-active,
.date-picker__preset.is-active:hover {
  background: #4f46e5;
  color: white;
}

.date-picker__divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.date-picker__custom {
  position: relative;
}

.date-picker__toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.date-picker__toggle:hover {
  color: var(--text);
  background: var(--bg);
}

.date-picker__toggle.is-active {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.date-picker__chevron {
  transition: transform var(--transition-fast);
}

.date-picker__toggle.is-active .date-picker__chevron {
  transform: rotate(180deg);
}

.date-picker__dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  padding: 16px;
  z-index: 1000;
}

.date-picker__dropdown.is-open {
  display: block;
}

.date-picker__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 200px;
}

.date-picker__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.date-picker__field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.date-picker__field input[type="date"] {
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: border-color var(--transition-fast);
  width: 100%;
}

.date-picker__field input[type="date"]:hover {
  border-color: var(--text-muted);
}

.date-picker__field input[type="date"]:focus {
  outline: none;
  border-color: var(--primary);
}

.date-picker__form .btn {
  margin-top: 4px;
}

.topbar__separator {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 8px;
}

/* Legacy Date Range Form (keep for backwards compatibility) */
.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.date-range input[type="date"] {
  border: none;
  background: transparent;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}

.date-range input[type="date"]:focus {
  outline: none;
}

.date-range__sep {
  color: var(--text-muted);
  font-size: 12px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg);
  border-color: var(--text-muted);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn--primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn--success {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.btn--success:hover {
  background: #059669;
  border-color: #059669;
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}

.btn--ghost:hover {
  background: var(--bg-subtle);
}

/* Bouton déconnexion sidebar */
.btn--logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn--logout:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

.btn--logout .nav-item__icon {
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

.btn--logout:hover .nav-item__icon {
  opacity: 1;
}

.btn--sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn--lg {
  padding: 12px 24px;
  font-size: 15px;
}

.btn__icon {
  width: 16px;
  height: 16px;
}

.btn.is-loading {
  pointer-events: none;
  opacity: 0.7;
}

.btn.is-loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 4px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Content ===== */
.content {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ===== Grid System ===== */
.grid {
  display: grid;
  gap: 16px;
}

.grid--2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid--3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid--4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid--2-1 {
  grid-template-columns: 2fr 1fr;
}

@media (max-width: 1200px) {
  .grid--4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .grid--2, .grid--3, .grid--4, .grid--2-1 {
    grid-template-columns: 1fr;
  }
}

/* ===== Cards ===== */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

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

.card__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.card__body {
  padding: 20px;
}

.card--flush .card__body {
  padding: 0;
}

/* ===== KPI Cards ===== */
.kpi-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.kpi-card__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 8px;
}

.kpi-card__value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.kpi-card__value--success { color: var(--success); }
.kpi-card__value--warning { color: var(--warning); }
.kpi-card__value--error { color: var(--error); }

.kpi-card__sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.kpi-card__trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  margin-left: 8px;
}

.kpi-card__trend--up {
  background: var(--success-bg);
  color: var(--success);
}

.kpi-card__trend--down {
  background: var(--error-bg);
  color: var(--error);
}

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

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

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg);
}

td {
  font-size: 14px;
  color: var(--text);
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg);
}

.text-right { text-align: right; }
.text-center { text-align: center; }

/* Table footer */
tfoot th, tfoot td {
  font-weight: 600;
  background: var(--bg);
  border-top: 2px solid var(--border);
}

/* ===== Pills & Tags ===== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.tag--site {
  background: var(--accent-bg);
  color: var(--accent);
}

.tag--mp {
  background: #fef3c7;
  color: #d97706;
}

.tag--success {
  background: var(--success-bg);
  color: var(--success);
}

.tag--error {
  background: var(--error-bg);
  color: var(--error);
}

/* ===== Chips ===== */
.chip {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 20px;
}

/* ===== Progress Bar ===== */
.progress {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 3px;
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition-fast);
}

.form-input:hover {
  border-color: var(--text-muted);
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Input Stack */
.input-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== Toast Notifications ===== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-xl);
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast--success {
  background: var(--success);
}

.toast--error {
  background: var(--error);
}

.toast__icon {
  width: 18px;
  height: 18px;
}

/* ===== Channel Table Styles ===== */
.channel-name {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.channel-name__label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

/* ===== Utilities ===== */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-secondary); }
.small { font-size: 12px; }
.mini { font-size: 11px; }
.strong { font-weight: 600; }
.bold { font-weight: 700; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ===== Responsive ===== */
@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    max-height: none;
    flex-direction: column;
    padding: 12px;
  }

  .sidebar__brand {
    padding: 0 0 12px 0;
    border: none;
    width: 100%;
  }

  .sidebar__brand img {
    width: 100px;
    margin: 0;
  }

  .sidebar__nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0;
    width: 100%;
  }

  .sidebar__sub {
    display: none;
  }

  .sidebar__footer {
    display: none;
  }

  .main {
    margin-left: 0;
    height: auto;
    overflow: visible;
  }

  .topbar {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .content {
    padding: 16px;
  }
}

/* Hide sidebar overlay on desktop */
.sidebar__overlay {
  display: none;
}

/* ===== Mobile Responsive (< 768px) ===== */
@media (max-width: 768px) {
  body {
    overflow: auto;
  }

  .sidebar__overlay {
    display: block;
  }

  /* Sidebar mobile - hidden by default */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    flex-direction: column;
    padding: 0;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
  }

  .sidebar__brand {
    padding: 24px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    width: 100%;
  }

  .sidebar__brand img {
    width: 140px;
    margin: 0 auto;
  }

  .sidebar__nav {
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 16px 12px;
    width: 100%;
  }

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

  /* Overlay */
  .sidebar__overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 999;
  }

  .sidebar.is-open ~ .sidebar__overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  /* Main content */
  .main {
    margin-left: 0;
    height: auto;
    overflow: visible;
  }

  /* Topbar */
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
  }

  .topbar__left {
    flex: 1;
    min-width: 0;
  }

  .topbar__left h1 {
    font-size: 18px;
  }

  .topbar__actions {
    width: 100%;
    flex-wrap: wrap;
  }

  /* Hamburger button */
  .topbar__hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    margin-right: 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition-fast);
  }

  .topbar__hamburger:hover {
    background: var(--bg-subtle);
  }

  .topbar__hamburger svg {
    width: 20px;
    height: 20px;
    color: var(--text);
  }

  /* Content */
  .content {
    padding: 16px;
  }

  /* Grids */
  .grid--2,
  .grid--3,
  .grid--4,
  .grid--2-1 {
    grid-template-columns: 1fr;
  }

  /* KPI cards */
  .kpi-card {
    padding: 16px;
  }

  .kpi-card__value {
    font-size: 24px;
  }

  /* Date picker */
  .date-picker {
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    padding: 6px;
  }

  .date-picker__presets {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }

  .date-picker__preset {
    padding: 6px 10px;
    font-size: 12px;
  }

  .date-picker__divider {
    display: none;
  }

  .date-picker__dropdown {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
  }

  .topbar__separator {
    width: 100%;
    height: 1px;
    margin: 8px 0;
  }

  /* Date range (legacy) */
  .date-range {
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
  }

  .date-range input[type="date"] {
    flex: 1;
    min-width: 120px;
  }

  /* Tables */
  .table-wrapper {
    margin: 0 -16px;
    padding: 0 16px;
  }

  th, td {
    padding: 10px 12px;
    font-size: 13px;
  }

  /* Cards */
  .card__header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
  }

  .card__body {
    padding: 16px;
  }

  /* Pills inline */
  .flex.gap-2 {
    flex-wrap: wrap;
  }

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

  /* Buttons */
  .btn {
    padding: 12px 16px;
  }

  .btn--sm {
    padding: 10px 14px;
  }
}

/* ===== Small Mobile (< 480px) ===== */
@media (max-width: 480px) {
  .topbar__left h1 {
    font-size: 16px;
  }

  .kpi-card__value {
    font-size: 22px;
  }

  .kpi-card__label {
    font-size: 11px;
  }

  th, td {
    padding: 8px 10px;
    font-size: 12px;
  }

  .tag {
    font-size: 10px;
    padding: 2px 6px;
  }

  .chip {
    font-size: 11px;
    padding: 3px 8px;
  }
}

/* ===== Touch Devices ===== */
@media (pointer: coarse) {
  .btn {
    min-height: 44px;
  }

  .nav-item {
    min-height: 44px;
  }

  .form-input {
    min-height: 44px;
  }

  th, td {
    padding: 14px 12px;
  }
}

/* ===== Chart Containers ===== */
.chart-container {
  position: relative;
  height: 280px;
  padding: 16px;
}

.chart-container--small {
  height: 200px;
}

.chart-container--donut {
  height: 240px;
  max-width: 300px;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .chart-container {
    height: 220px;
    padding: 12px;
  }

  .chart-container--small {
    height: 160px;
  }
}

/* ===== Print Styles ===== */
@media print {
  .sidebar, .topbar, .topbar__hamburger, .sidebar__overlay {
    display: none !important;
  }

  .main {
    margin-left: 0;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}
