:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --emerald-700: #047857;
  --emerald-600: #059669;
  --emerald-100: #d1fae5;
  --emerald-50: #ecfdf5;
  --amber-700: #b45309;
  --amber-600: #d97706;
  --amber-100: #fef3c7;
  --amber-50: #fffbeb;
  --red-700: #b91c1c;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --red-50: #fef2f2;
  --sky-700: #0369a1;
  --sky-100: #e0f2fe;
  --indigo-600: #4f46e5;
  --indigo-50: #eef2ff;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.18);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
}

/* Boot Screen */
.boot-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #f8fafc;
}

.boot-card {
  text-align: center;
  padding: 2rem;
}

.boot-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #10b981;
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}

.boot-title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.boot-sub {
  margin: 0;
  font-size: 13px;
  color: #94a3b8;
}

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

/* Login Screen */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top left, #064e3b 0%, #0f172a 55%, #020617 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border-radius: 18px;
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #059669, #047857);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  flex-shrink: 0;
}

.login-brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  color: var(--slate-900);
}

.login-brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 5px;
}

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 9px 12px;
  background: #ffffff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--emerald-600);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

.textarea {
  resize: vertical;
  min-height: 76px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

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

.btn-primary {
  background: var(--emerald-600);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--emerald-700);
}

.btn-dark {
  background: var(--slate-900);
  color: #ffffff;
}

.btn-dark:hover {
  background: var(--slate-800);
}

.btn-amber {
  background: var(--amber-600);
  color: #ffffff;
}

.btn-amber:hover {
  background: var(--amber-700);
}

.btn-danger {
  background: var(--red-600);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--red-700);
}

.btn-outline {
  background: #ffffff;
  border-color: var(--border-strong);
  color: #334155;
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

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

.btn-block {
  width: 100%;
}

.alert-box {
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 12.5px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}

.alert-error {
  background: var(--red-50);
  border-color: #fecaca;
  color: var(--red-700);
}

.alert-warning {
  background: var(--amber-50);
  border-color: #fde68a;
  color: var(--amber-700);
}

.alert-success {
  background: var(--emerald-50);
  border-color: #a7f3d0;
  color: var(--emerald-700);
}

/* Main App Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 272px;
  background: var(--slate-900);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid #1e293b;
  transition: background 0.2s, border-color 0.2s;
}

.sidebar.alert-warning-state {
  background: #231806;
  border-right-color: #b45309;
}

.sidebar.alert-deficit-state {
  background: #280a0f;
  border-right-color: #dc2626;
}

.sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 11px;
}

.sidebar-title {
  font-size: 15px;
  font-weight: 800;
  color: #ffffff;
  margin: 0;
}

.sidebar-sub {
  font-size: 11px;
  color: #94a3b8;
  margin: 1px 0 0;
}

.sidebar-balance-box {
  margin: 14px 14px 8px;
  padding: 12px 13px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-balance-box.warning {
  background: rgba(217, 119, 6, 0.18);
  border-color: rgba(245, 158, 11, 0.6);
}

.sidebar-balance-box.deficit {
  background: rgba(220, 38, 38, 0.2);
  border-color: rgba(248, 113, 113, 0.7);
}

.sidebar-balance-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin-bottom: 4px;
}

.sidebar-balance-value {
  font-size: 19px;
  font-weight: 800;
  color: #34d399;
}

.sidebar-balance-box.warning .sidebar-balance-value {
  color: #fbbf24;
}

.sidebar-balance-box.deficit .sidebar-balance-value {
  color: #f87171;
}

.sidebar-threshold-note {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.35;
  color: #cbd5e1;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 10px;
  overflow-y: auto;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 4px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.nav-item.active {
  background: var(--emerald-600);
  color: #ffffff;
  font-weight: 600;
}

.nav-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nav-dot.warning { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25); }
.nav-dot.deficit { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3); }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
}

.user-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.user-chip-name {
  font-weight: 700;
  color: #ffffff;
  font-size: 13px;
}

.user-chip-role {
  font-size: 11px;
  color: #94a3b8;
}

/* Main Content */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.mobile-menu-btn {
  display: none;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-weight: 700;
}

.topbar-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--slate-900);
}

.topbar-subtitle {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
}

.search-box {
  flex: 1;
  max-width: 440px;
  min-width: 220px;
  position: relative;
}

.search-input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px 34px 8px 34px;
  background: #f8fafc;
  font-size: 13px;
}

.search-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--emerald-600);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: #64748b;
  pointer-events: none;
  font-size: 13px;
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: #e2e8f0;
  color: #334155;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-banner {
  background: #eef2ff;
  border-bottom: 1px solid #c7d2fe;
  padding: 8px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: #312e81;
}

.content-body {
  padding: 20px;
  flex: 1;
}

/* Cards & Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-card.warn {
  border-color: #f59e0b;
  background: #fffbeb;
}

.kpi-card.danger {
  border-color: #ef4444;
  background: #fef2f2;
}

.kpi-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 21px;
  font-weight: 800;
  color: var(--slate-900);
}

.kpi-value.emerald { color: var(--emerald-700); }
.kpi-value.amber { color: var(--amber-700); }
.kpi-value.red { color: var(--red-700); }

.kpi-sub {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--slate-900);
}

.panel-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.chart-wrap {
  position: relative;
  height: 290px;
  width: 100%;
}

.chart-wrap-tall {
  position: relative;
  height: 320px;
  width: 100%;
}

/* Excel Dual-Pane Ledger */
.excel-dual {
  display: grid;
  grid-template-columns: minmax(330px, 0.92fr) minmax(480px, 1.35fr);
  gap: 14px;
  align-items: start;
}

.excel-sheet {
  background: #ffffff;
  border: 1px solid #94a3b8;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.excel-banner {
  padding: 9px 12px;
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #94a3b8;
}

.excel-banner.transport { background: #d9ead3; color: #14532d; }
.excel-banner.cantine { background: #fce5cd; color: #78350f; }

.table-scroll {
  overflow-x: auto;
  max-height: 700px;
  overflow-y: auto;
}

.excel-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.excel-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #e2e8f0;
  color: #0f172a;
  font-weight: 700;
  text-align: left;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  white-space: nowrap;
}

.excel-table td {
  border: 1px solid #cbd5e1;
  padding: 4px 7px;
  vertical-align: middle;
}

.excel-table tr:hover td {
  background: #f8fafc;
}

.excel-table td.num, .excel-table th.num {
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
}

.excel-table td.yellow-col {
  background: #fef9c3;
  font-weight: 700;
}

.excel-table td.gray-col {
  background: #f1f5f9;
  text-align: center;
}

.excel-section-row td {
  font-weight: 800;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px;
}

.excel-section-row.car td { background: #dbeafe; color: #1e3a8a; }
.excel-section-row.cantine-sec td { background: #ffedd5; color: #9a3412; }
.excel-section-row.annexes td { background: #e2e8f0; color: #334155; }
.excel-section-row.plats td { background: #fef3c7; color: #78350f; }

.excel-total-row td {
  font-weight: 800;
  background: #ecfdf5;
  color: #065f46;
}

.excel-grand-total td {
  font-weight: 800;
  background: #0f172a;
  color: #ffffff;
}

.excel-net-row td {
  font-weight: 800;
  background: #fee2e2;
  color: #991b1b;
}

.excel-net-row.positive td {
  background: #d1fae5;
  color: #065f46;
}

.cell-input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 12.5px;
}

.cell-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--emerald-600);
}

.cell-input.num {
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-green { background: var(--emerald-100); color: var(--emerald-700); }
.badge-amber { background: var(--amber-100); color: var(--amber-700); }
.badge-red { background: var(--red-100); color: var(--red-700); }
.badge-slate { background: #e2e8f0; color: #334155; }
.badge-sky { background: var(--sky-100); color: var(--sky-700); }

/* Summary Cards */
.summary-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 14px;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 14px;
  background: var(--surface-alt);
}

.summary-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.summary-card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--slate-900);
}

.summary-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
  padding: 8px;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.summary-metric-label {
  font-size: 10.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.summary-metric-val {
  font-size: 12.5px;
  font-weight: 700;
}

.major-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.major-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 4px 0;
  border-top: 1px dashed #cbd5e1;
}

.narrative-box {
  margin-top: 9px;
  font-size: 12px;
  color: #334155;
  background: #ffffff;
  border-left: 3px solid var(--emerald-600);
  padding: 7px 9px;
  border-radius: 4px;
}

/* Standard Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 9px 10px;
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table tr:hover td {
  background: #f8fafc;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}

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

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.modal-body {
  padding: 18px 20px;
}

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Toast */
.toast-stack {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--slate-900);
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  max-width: 360px;
}

.toast.error { background: var(--red-700); }
.toast.success { background: var(--emerald-700); }

/* Responsive */
@media (max-width: 1100px) {
  .excel-dual {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 50;
    transition: left 0.2s ease;
  }
  .sidebar.open {
    left: 0;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

@media print {
  .sidebar, .topbar, .no-print {
    display: none !important;
  }
  body {
    background: #ffffff;
  }
  .content-body {
    padding: 0;
  }
  .table-scroll {
    max-height: none;
    overflow: visible;
  }
}
