/* ============================================================================
   CATHEDIS ERP — Styles principaux
   ============================================================================
   Branding CATHEDIS : rouge #f00011 -> #c0000d
   Police : Segoe UI (native Windows) — pas de Google Fonts (app offline)
   Layout : sidebar fixe + zone de contenu dynamique
   ============================================================================ */

/* ── Variables ── */
:root {
  --primary: #c0000d;
  --primary-dark: #8b0000;
  --primary-light: #f00011;
  --primary-bg: #fff0f0;
  --primary-border: #f4a0a5;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;

  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #2563eb;
  --info-bg: #dbeafe;

  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);

  --sidebar-width: 240px;
  --header-height: 56px;

  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Consolas', 'Courier New', monospace;
}

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

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

/* ── App Layout ── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Header (barre titre) ── */
.app-header {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  -webkit-app-region: drag; /* permet de deplacer la fenetre */
  user-select: none;
  z-index: 100;
}

.app-header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header-logo img {
  height: 32px;
}

.app-header-logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
}

.app-header-logo .subtitle {
  font-size: 11px;
  opacity: 0.8;
  font-weight: 400;
  letter-spacing: 0.5px;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-app-region: no-drag;
}

.header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
  font-family: var(--font);
}

.header-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* ── Menu deroulant d'en-tete (Parametres) ── */
.header-dropdown {
  position: relative;
  display: inline-block;
}
.header-dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 1000;
}
.header-dropdown.open .header-dropdown-menu {
  display: block;
}
.header-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.header-dropdown-item:hover {
  background: var(--surface-alt);
  color: var(--primary);
}

/* ── Sidebar ── */
.app-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

/* Citation CATHEDIS, collee en bas a gauche de la sidebar (memes "quotes" que le login) */
.sidebar-quote {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding: 12px 18px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0), var(--surface) 32%);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 7px;
  align-items: flex-start;
  min-height: 44px;
}
.sidebar-quote-mark {
  font-size: 22px;
  line-height: 0.9;
  color: #f00011;
  font-weight: 800;
  flex: 0 0 auto;
}
.sidebar-quote-text {
  font-style: italic;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  transition: opacity 0.45s ease;
}
.sidebar-quote-text.fading { opacity: 0; }

.sidebar-section {
  margin-bottom: 8px;
}

.sidebar-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 8px 20px 6px;
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;          /* titre = bouton replier/deplier */
  user-select: none;
}
.sidebar-section-title:hover {
  opacity: 0.8;
}

/* Chevron a droite du titre : pointe vers le bas (deplie), vers la droite (replie) */
.sidebar-section-title::after {
  content: "";
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  opacity: 0.7;
  flex: 0 0 auto;
}
.sidebar-section.collapsed .sidebar-section-title::after {
  transform: rotate(-45deg);
}

/* ── Animation d'ouverture / fermeture des sections ──
   Le <ul.sidebar-nav> est enveloppe dans .sidebar-nav-wrap par
   js/sidebar-collapse.js. On anime la hauteur via grid-template-rows
   1fr -> 0fr (permet d'animer jusqu'a la hauteur naturelle, ce que
   height:auto ne permet pas), avec un fondu du contenu. */
.sidebar-nav-wrap {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-section.collapsed .sidebar-nav-wrap {
  grid-template-rows: 0fr;
}
.sidebar-nav-wrap > .sidebar-nav {
  overflow: hidden;
  min-height: 0;
  transition: opacity 0.22s ease;
}
.sidebar-section.collapsed .sidebar-nav-wrap > .sidebar-nav {
  opacity: 0;
}
/* Premier rendu : pas d'animation (sinon repli visible au demarrage) */
.sidebar-no-anim .sidebar-nav-wrap,
.sidebar-no-anim .sidebar-nav-wrap > .sidebar-nav {
  transition: none !important;
}

/* ── Couleur d'identification par section (auto-attribuee, persistee localStorage) ──
   La variable --section-color est posee par js/section-colors.js sur chaque
   .sidebar-section. Toute nouvelle section recoit automatiquement une couleur
   libre => repere visuel immediat. */
.sidebar-section[data-section-color] {
  box-shadow: inset 3px 0 0 var(--section-color);
}
.sidebar-section[data-section-color] .sidebar-section-title {
  color: var(--section-color);
}
.sidebar-section[data-section-color] .sidebar-section-title::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--section-color);
  flex: 0 0 auto;
}

.sidebar-nav {
  list-style: none;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 3px solid transparent;
  cursor: pointer;
}

.sidebar-nav li a:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.sidebar-nav li a.active {
  background: var(--primary-bg);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.sidebar-nav li a .nav-icon {
  display: none;   /* icones emoji masquees (menu en texte seul) */
}

.sidebar-nav li a .nav-badge {
  margin-left: auto;
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 10px;
  font-family: var(--font-mono);
}

/* ── Content Area ── */
.app-content {
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

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

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

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

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

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Stat Cards (dashboard) ── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .stat-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: white;
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-dark);
}
.btn-secondary:hover { background: var(--surface-alt); border-color: var(--primary-border); }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { filter: brightness(0.9); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { filter: brightness(0.9); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

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

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

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

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

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

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

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

.form-error {
  font-size: 11px;
  color: var(--danger);
  margin-top: 4px;
}

/* ── Tables ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background: var(--surface-alt);
  border-bottom: 2px solid var(--border);
}

.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.data-table tbody tr:hover {
  background: var(--surface-alt);
}

.data-table tbody tr.selected {
  background: var(--primary-bg);
}

/* --- Tri par colonne --- */
.data-table th.th-sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 22px;
}
.data-table th.th-sortable::after {
  content: '\2195'; /* ⇕ */
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.28;
  font-size: 10px;
}
.data-table th.th-sortable:hover::after { opacity: 0.55; }
.data-table th.th-sortable.sorted-asc::after { content: '\25B2'; opacity: 0.95; } /* ▲ */
.data-table th.th-sortable.sorted-desc::after { content: '\25BC'; opacity: 0.95; } /* ▼ */

/* --- Recherche par colonne --- */
.data-table thead tr.filter-row th {
  padding: 4px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.data-table thead tr.filter-row input.col-filter {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}
.data-table thead tr.filter-row input.col-filter:focus {
  outline: none;
  border-color: var(--primary, #f00011);
  box-shadow: 0 0 0 2px var(--primary-bg, rgba(240,0,17,0.08));
}

.data-table .cell-mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.data-table .cell-amount {
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: right;
}

.data-table .cell-actions {
  text-align: right;
  white-space: nowrap;
}

/* ── AG Grid (surcouche des tableaux .data-table) ──
   Theme Quartz reskinne aux couleurs CATHEDIS + police Segoe UI. */
.ag-erp-grid {
  --ag-font-family: var(--font);
  --ag-font-size: 13px;
  --ag-foreground-color: var(--text);
  --ag-border-color: var(--border);
  --ag-row-border-color: var(--border);
  --ag-header-background-color: var(--surface-alt);
  --ag-header-foreground-color: var(--text-secondary);
  --ag-header-column-resize-handle-color: var(--border-dark);
  --ag-odd-row-background-color: #ffffff;
  --ag-row-hover-color: var(--surface-alt);
  --ag-selected-row-background-color: var(--primary-bg);
  --ag-active-color: var(--primary-light);
  --ag-range-selection-border-color: var(--primary-light);
  --ag-input-focus-border-color: var(--primary-light);
  --ag-cell-horizontal-padding: 14px;
  --ag-borders: solid 1px;
  --ag-wrapper-border-radius: var(--radius);
  width: 100%;
}
.ag-erp-grid .ag-header-cell-text {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ag-erp-grid .ag-erp-center { text-align: center; }
.ag-erp-grid .ag-erp-actions { text-align: right; }
/* Boutons / badges conserves dans les cellules : compacts pour tenir dans 40px */
.ag-erp-grid .ag-cell .btn { padding: 3px 8px; font-size: 12px; vertical-align: middle; }
.ag-erp-grid .ag-cell .badge,
.ag-erp-grid .ag-cell .pill { vertical-align: middle; }

/* ── Toolbar (au dessus des tables) ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 400px;
}

.toolbar-search input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
}

.toolbar-search input:focus {
  outline: none;
  border-color: var(--primary);
}

.toolbar-search::before {
  content: '\1F50D';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* ── Badges / Tags ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger);  }
.badge-info    { background: var(--info-bg);    color: var(--info);    }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* Modales pilotees par le style inline `display:flex` (achats, echeancier,
   creances, paie freelance...) : les rendre visibles des qu'elles passent en
   display:flex, sans dependre de la classe .open. Sans ceci, le `opacity:0;
   visibility:hidden` de .modal-overlay les laisse invisibles meme ouvertes. */
.modal-overlay[style*="display: flex"],
.modal-overlay[style*="display:flex"] {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--danger); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface-alt);
}

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 280px;
}

.toast-success { background: var(--success); color: white; }
.toast-error   { background: var(--danger);  color: white; }
.toast-warning { background: var(--warning); color: white; }
.toast-info    { background: var(--info);    color: white; }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Tabs (dans les pages) ── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 20px;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Utilities ── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-mono   { font-family: var(--font-mono); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
