/* ════════════════════════════════════════════
   E-Facture Connect — Design System
   Theme : Dark Navy + Orange Accent
   ════════════════════════════════════════════ */

:root {
  /* Couleurs principales */
  --primary: #1B4F72;
  --primary-light: #2980B9;
  --primary-dark: #0e3451;
  --accent: #E67E22;
  --accent-light: #F39C12;
  --accent-dark: #d35400;

  /* Fond & surfaces */
  --bg-body: #0a1628;
  --bg-surface: #111d33;
  --bg-card: #162340;
  --bg-card-hover: #1a2d52;
  --bg-input: #0e1a2e;
  --bg-sidebar: #0c1829;

  /* Texte */
  --text-primary: #e8edf3;
  --text-secondary: #8899aa;
  --text-muted: #5a6a7a;
  --text-inverse: #ffffff;

  /* Statuts */
  --success: #27AE60;
  --success-bg: rgba(39, 174, 96, 0.15);
  --warning: #F39C12;
  --warning-bg: rgba(243, 156, 18, 0.15);
  --error: #E74C3C;
  --error-bg: rgba(231, 76, 60, 0.15);
  --info: #3498DB;
  --info-bg: rgba(52, 152, 219, 0.15);
  --accent-bg: rgba(230, 126, 34, 0.15);

  /* Bordures */
  --border: #1e3350;
  --border-light: #253d5e;
  --border-focus: var(--accent);

  /* Divers */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --transition: 0.2s ease;

  /* Layout */
  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
  --header-height: 60px;
}

/* ════════════════════════════════════════════
   RESET & BASE
   ════════════════════════════════════════════ */

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

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
}

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

code {
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
  color: var(--accent);
}

/* ════════════════════════════════════════════
   ÉCRAN DE CHARGEMENT
   ════════════════════════════════════════════ */

#splash-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-body);
}

.splash-content { text-align: center; }
.splash-icon { font-size: 48px; margin-bottom: 16px; }
.splash-content h1 { font-size: 1.8rem; font-weight: 700; color: var(--text-primary); }
.splash-content p { color: var(--text-secondary); margin-top: 4px; }

.splash-loader {
  width: 40px; height: 40px; margin: 24px auto 0;
  border: 3px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ════════════════════════════════════════════
   ÉCRAN D'AUTHENTIFICATION
   ════════════════════════════════════════════ */

#auth-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}

.auth-container {
  width: 100%; max-width: 420px;
}

.auth-header {
  text-align: center; margin-bottom: 32px;
}

.auth-logo { font-size: 48px; margin-bottom: 12px; }
.auth-header h1 { font-size: 1.6rem; font-weight: 700; }
.auth-header p { color: var(--text-secondary); font-size: 0.9rem; }

.auth-form {
  background: var(--bg-card);
  padding: 32px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.auth-form h2 { font-size: 1.2rem; margin-bottom: 24px; text-align: center; }

.auth-switch {
  text-align: center; margin-top: 16px;
  font-size: 0.85rem; color: var(--text-secondary);
}

/* ════════════════════════════════════════════
   LAYOUT PRINCIPAL
   ════════════════════════════════════════════ */

#app-screen {
  display: flex; min-height: 100vh;
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width var(--transition);
}

#sidebar.collapsed { width: var(--sidebar-collapsed); }
#sidebar.collapsed .nav-label,
#sidebar.collapsed .sidebar-title,
#sidebar.collapsed .user-email { display: none; }

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

.sidebar-logo { font-size: 24px; }
.sidebar-title { font-weight: 700; font-size: 1rem; white-space: nowrap; }

.nav-menu {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  margin-bottom: 2px;
  white-space: nowrap;
}

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

.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
}

.nav-item .material-icons-round { font-size: 22px; }

.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex; align-items: center; gap: 8px;
  overflow: hidden;
}

.user-email {
  font-size: 0.75rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 140px;
}

/* ── CONTENU PRINCIPAL ── */
#main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
  transition: margin-left var(--transition);
  max-width: 100%;
}

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

/* ════════════════════════════════════════════
   PAGES
   ════════════════════════════════════════════ */

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

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

.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.header-actions { display: flex; gap: 8px; }

/* ════════════════════════════════════════════
   CARTES & STATS
   ════════════════════════════════════════════ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}

.card h2 { font-size: 1.1rem; font-weight: 600; }

.card h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 1rem; font-weight: 600; margin-bottom: 16px;
  color: var(--text-primary);
}

.card h3 .material-icons-round { color: var(--accent); font-size: 20px; }

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
}

.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
}

.stat-icon .material-icons-round { font-size: 24px; color: var(--text-primary); }
.stat-value { font-size: 1.5rem; font-weight: 700; display: block; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); }

/* ════════════════════════════════════════════
   FORMULAIRES
   ════════════════════════════════════════════ */

.form-row {
  display: flex; gap: 16px; margin-bottom: 16px;
}

.form-group {
  flex: 1;
  margin-bottom: 12px;
}

.form-group.flex-2 { flex: 2; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.15);
}

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

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238899aa'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 20px;
  padding-right: 32px;
}

.form-actions {
  display: flex; gap: 12px; justify-content: flex-end;
  padding-top: 16px;
}

/* ════════════════════════════════════════════
   BOUTONS
   ════════════════════════════════════════════ */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn .material-icons-round { font-size: 18px; }

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

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--border-light); }

.btn-accent {
  background: var(--success);
  color: white;
}
.btn-accent:hover { background: #219a52; }

.btn-danger {
  background: var(--error);
  color: white;
}
.btn-danger:hover { background: #c0392b; }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: var(--bg-card); color: var(--text-primary); }

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

/* ════════════════════════════════════════════
   TABLEAU
   ════════════════════════════════════════════ */

.table-container { overflow-x: auto; }

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

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 14px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

tr { transition: background var(--transition); }
tr:hover { background: var(--bg-card-hover); }
tr { cursor: pointer; }

/* ════════════════════════════════════════════
   BADGES DE STATUT
   ════════════════════════════════════════════ */

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-draft { background: var(--info-bg); color: var(--info); }
.badge-validated { background: var(--success-bg); color: var(--success); }
.badge-submitted { background: var(--warning-bg); color: var(--warning); }
.badge-accepted { background: var(--success-bg); color: var(--success); }
.badge-paid { background: rgba(39, 174, 96, 0.25); color: #2ecc71; }
.badge-cancelled { background: var(--error-bg); color: var(--error); }
.badge-rejected { background: var(--error-bg); color: var(--error); }
.badge-success { background: var(--success-bg); color: var(--success); }

/* ════════════════════════════════════════════
   LIGNES DE FACTURE
   ════════════════════════════════════════════ */

.lines-table {
  margin-bottom: 16px;
}

.lines-header {
  display: grid;
  grid-template-columns: 3fr 0.7fr 0.8fr 1fr 0.7fr 1fr 40px;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.line-row {
  display: grid;
  grid-template-columns: 3fr 0.7fr 0.8fr 1fr 0.7fr 1fr 40px;
  gap: 8px;
  padding: 8px 12px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.line-row:hover { background: var(--bg-card-hover); }

.line-row input, .line-row select {
  padding: 6px 8px;
  font-size: 0.85rem;
}

.line-total {
  font-weight: 600;
  text-align: right;
  color: var(--accent);
}

.btn-remove-line {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 4px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center;
}
.btn-remove-line:hover { color: var(--error); background: var(--error-bg); }

/* ── TOTAUX ── */
.invoice-totals {
  margin-left: auto;
  max-width: 320px;
  padding-top: 16px;
}

.totals-row {
  display: flex; justify-content: space-between;
  padding: 6px 0;
  font-size: 0.9rem;
}

.totals-row.total-ttc {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  border-top: 2px solid var(--accent);
  padding-top: 10px;
  margin-top: 6px;
}

/* ════════════════════════════════════════════
   FILTRES
   ════════════════════════════════════════════ */

.filters-bar {
  display: flex; gap: 12px;
  margin-bottom: 20px;
}

.filter-group select, .filter-group input {
  min-width: 180px;
}

/* ════════════════════════════════════════════
   PAGINATION
   ════════════════════════════════════════════ */

.pagination {
  display: flex; justify-content: center; gap: 8px;
  margin-top: 20px;
}

.pagination button {
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
}
.pagination button:hover { background: var(--bg-card-hover); }
.pagination button.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ════════════════════════════════════════════
   MODALE
   ════════════════════════════════════════════ */

.modal-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 540px;
  max-height: 80vh;
  overflow-y: auto;
}

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

.modal-header h2 { font-size: 1.1rem; }
.modal-body { padding: 24px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ════════════════════════════════════════════
   TOASTS
   ════════════════════════════════════════════ */

#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column-reverse; gap: 8px;
}

.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  min-width: 280px;
  max-width: 440px;
}

.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error { border-left: 4px solid var(--error); }
.toast.toast-info { border-left: 4px solid var(--info); }
.toast.toast-warning { border-left: 4px solid var(--warning); }

.toast-message { flex: 1; font-size: 0.85rem; }
.toast-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 18px;
}

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }

/* ════════════════════════════════════════════
   ALERTES
   ════════════════════════════════════════════ */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-top: 12px;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(231, 76, 60, 0.3);
}

/* ════════════════════════════════════════════
   DETAIL FACTURE
   ════════════════════════════════════════════ */

.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 20px; margin-bottom: 20px;
}

.detail-section h3 {
  font-size: 0.8rem; font-weight: 600;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 8px;
}

.detail-field {
  margin-bottom: 8px;
}

.detail-label {
  font-size: 0.72rem; color: var(--text-muted);
  text-transform: uppercase;
}

.detail-value {
  font-size: 0.95rem; font-weight: 500;
}

/* ════════════════════════════════════════════
   UTILITAIRES
   ════════════════════════════════════════════ */

.hidden { display: none !important; }
.screen { min-height: 100vh; }
.link { color: var(--accent); font-size: 0.85rem; }
.link:hover { text-decoration: underline; }

.empty-state {
  text-align: center; padding: 40px;
  color: var(--text-muted); font-size: 0.9rem;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }

/* ════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════ */

@media (max-width: 768px) {
  #sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }
  #sidebar.mobile-open { transform: translateX(0); }

  #main-content { margin-left: 0; padding: 16px; }

  .form-row { flex-direction: column; gap: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .filters-bar { flex-direction: column; }

  .lines-header { display: none; }
  .line-row {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 12px;
    position: relative;
  }
}
