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

:root {
  --primary: #C4222A;
  --primary-light: #fef2f2;
  --danger: #dc3545;
  --success: #28a745;
  --warning: #ffc107;
  --info: #17a2b8;
  --text: #333;
  --text-muted: #888;
  --border: #e0e0e0;
  --bg: #f5f5f5;
  --white: #fff;
  --sidebar-width: 220px;
}

body {
  font-family: 'Roboto', sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* === Sidebar === */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
  border-right: 3px solid transparent;
  transition: background 0.15s;
}
.nav-item:hover { background: #f9f9f9; }
.nav-item.active {
  background: var(--primary-light);
  border-right-color: var(--primary);
  font-weight: 500;
}
.nav-item svg { flex-shrink: 0; }

.nav-sub {
  display: block;
  padding: 5px 16px 5px 42px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  transition: background 0.15s;
}
.nav-sub:hover { color: var(--text); background: #f9f9f9; }
.nav-sub.active { color: var(--primary); font-weight: 500; }

.badge-count {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.user-info { display: flex; flex-direction: column; margin-bottom: 6px; }
.user-name { font-weight: 500; }
.user-role { color: var(--text-muted); font-size: 12px; text-transform: capitalize; }
.logout-link { color: var(--primary); text-decoration: none; font-size: 12px; }
.logout-link:hover { text-decoration: underline; }

/* Hamburger (mobile) */
.hamburger {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
}

/* === Content === */
.content-with-sidebar {
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
  min-height: 100vh;
}
.content-full {
  padding: 24px 32px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }

/* === KPI Cards === */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--white);
  border-radius: 8px;
  padding: 20px;
  border: 1px solid var(--border);
}
.kpi-label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 700; }

/* === Tables === */
.table-responsive { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.table th, .table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th {
  background: #fafafa;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.table tr:last-child td { border-bottom: none; }

/* === Sections === */
.section {
  margin-top: 24px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}
.section h2 { font-size: 16px; margin-bottom: 16px; }

/* === Alertes === */
.alertes-list { display: flex; flex-direction: column; gap: 8px; }
.alerte-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.alerte-danger { border-left: 4px solid var(--danger); background: #fff5f5; }
.alerte-warning { border-left: 4px solid var(--warning); background: #fffbeb; }
.alerte-info { border-left: 4px solid var(--info); background: #f0f9ff; }
.alerte-badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px; white-space: nowrap; }
.badge-danger { background: var(--danger); color: white; }
.badge-warning { background: var(--warning); color: #333; }
.badge-info { background: var(--info); color: white; }
.alerte-message { flex: 1; font-size: 13px; }

/* === Badges === */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: #eee;
}
.badge-danger { background: var(--danger); color: white; }
.badge-success { background: var(--success); color: white; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #a91d24; }
.btn-outline { background: white; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: #f5f5f5; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--danger); color: white; }
.btn-block { width: 100%; justify-content: center; }

/* === Forms === */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(196, 34, 42, 0.1);
}

.form-inline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 16px;
  align-items: end;
}

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-bar select, .filter-bar input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.synthese-bar {
  display: flex;
  gap: 24px;
  padding: 12px 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  font-size: 14px;
}

/* === Login === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 32px;
  text-align: center;
}
.login-card h1 { color: var(--primary); font-size: 24px; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 24px; }
.login-card .form-group { text-align: left; }

/* === Text utilities === */
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-center { text-align: center; }

/* === Alerts === */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

/* === Veille === */
.veille-card {
  padding: 16px;
  background: #f9f9f9;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.veille-date { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.veille-content { font-size: 14px; white-space: pre-line; }

/* === Detail === */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.detail-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}
.detail-card h3 { font-size: 15px; margin-bottom: 12px; color: var(--primary); }
.detail-card p { font-size: 13px; margin-bottom: 6px; }

/* === Biens grid === */
.biens-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}
.bien-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}
.bien-card h3 { font-size: 16px; margin-bottom: 6px; }
.bien-card h3 a { color: var(--text); text-decoration: none; }
.bien-card h3 a:hover { color: var(--primary); }
.bien-meta { display: flex; gap: 12px; margin: 8px 0; font-size: 13px; color: var(--text-muted); }
.bien-card p { font-size: 13px; margin-bottom: 4px; }

/* === IA Chat === */
.ia-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 20px;
  height: calc(100vh - 120px);
}

.ia-context {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 13px;
  align-self: start;
}
.ia-context h3 { font-size: 14px; margin-bottom: 12px; color: var(--primary); }
.ia-context p { margin-bottom: 6px; }

.ia-chat {
  display: flex;
  flex-direction: column;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.chat-assistant {
  align-self: flex-start;
  background: #f0f0f0;
  border-bottom-left-radius: 4px;
}

.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
}
.disclaimer {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 6px 10px;
  background: #fff8e1;
  border-radius: 4px;
}
.chat-input-row {
  display: flex;
  gap: 8px;
}
.chat-input-row input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.chat-input-row input:focus {
  outline: none;
  border-color: var(--primary);
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid #e0e0e0;
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === FIFO badges === */
.fifo-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.3px;
}
.fifo-solde { background: #EAF3DE; color: #27500A; }
.fifo-partiel { background: #FAEEDA; color: #633806; }
.fifo-impaye { background: #FCEBEB; color: #791F1F; }

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.modal-card {
  background: var(--white);
  border-radius: 10px;
  padding: 28px 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 18px; margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }
  .content-with-sidebar {
    margin-left: 0;
    padding: 16px;
    padding-top: 56px;
  }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .ia-layout { grid-template-columns: 1fr; height: auto; }
  .filter-bar { flex-direction: column; align-items: stretch; }
}
