/* ================================================================
   ConsultPro Manager — main.css
   Mobile-first : 375px → 768px → 1024px
================================================================ */

/* --- Variables CSS --- */
:root {
  --primary:     #2563eb;
  --primary-dk:  #1d4ed8;
  --success:     #16a34a;
  --warning:     #d97706;
  --danger:      #dc2626;
  --info:        #0ea5e9;
  --purple:      #7c3aed;
  --muted:       #6b7280;
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --surface2:    #f8fafc;
  --border:      #e2e8f0;
  --text:        #0f172a;
  --text-sm:     #475569;
  --radius:      0.5rem;
  --radius-lg:   0.75rem;
  --shadow:      0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --nav-h:       60px;
  --bottom-h:    64px;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  padding-bottom: var(--bottom-h);
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font-family: var(--font); }
input, select, textarea { width: 100%; }

/* --- Top bar mobile --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--primary);
  color: #fff;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
  box-shadow: var(--shadow-md);
}
.topbar__logo {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  min-width: 20px;
  text-align: center;
}

/* --- Bottom nav mobile --- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 300;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  height: var(--bottom-h);
  align-items: center;
}
.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.65rem;
  padding: 0.25rem 0;
  transition: color 0.15s;
}
.bottom-nav__item svg { width: 22px; height: 22px; }
.bottom-nav__item.active { color: var(--primary); }
.bottom-nav__item:hover { color: var(--primary); text-decoration: none; }

/* --- Container --- */
.container {
  max-width: 100%;
  padding: 0.75rem;
}

/* --- Cards --- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-sm);
}
.card-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}
.card-label {
  font-size: 0.75rem;
  color: var(--muted);
}

/* --- KPI Grid --- */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 0.875rem;
  border-left: 3px solid var(--primary);
}
.kpi-card.success { border-left-color: var(--success); }
.kpi-card.warning { border-left-color: var(--warning); }
.kpi-card.danger  { border-left-color: var(--danger); }
.kpi-card.purple  { border-left-color: var(--purple); }
.kpi-card__value  {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}
.kpi-card__label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.kpi-card__sub {
  font-size: 0.75rem;
  color: var(--text-sm);
  margin-top: 4px;
}

/* --- Progress bar --- */
.progress {
  background: var(--border);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.4s ease;
}
.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger  { background: var(--danger); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { opacity: 0.88; text-decoration: none; }
.btn:active { opacity: 0.75; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-success  { background: var(--success); color: #fff; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-info     { background: var(--info);    color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-outline  { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-sm       { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-lg       { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-full     { width: 100%; justify-content: center; }
.btn-ai       { background: linear-gradient(135deg, #7c3aed, #2563eb); color: #fff; }
.btn-ai:hover { opacity: 0.9; }

/* --- Forms --- */
.form-group    { margin-bottom: 1rem; }
.form-label    { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-sm); margin-bottom: 0.3rem; }
.form-label .req { color: var(--danger); }
.form-control  {
  display: block; width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  line-height: 1.5;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-control.error { border-color: var(--danger); }
select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2rem; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-error    { font-size: 0.75rem; color: var(--danger); margin-top: 0.25rem; }
.form-hint     { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.form-row      { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 700;
  white-space: nowrap;
}
.badge-primary   { background: #dbeafe; color: #1e40af; }
.badge-success   { background: #dcfce7; color: #166534; }
.badge-warning   { background: #fef9c3; color: #92400e; }
.badge-danger    { background: #fee2e2; color: #991b1b; }
.badge-info      { background: #e0f2fe; color: #075985; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-gris      { background: #f3f4f6; color: #6b7280; }
.badge-purple    { background: #ede9fe; color: #5b21b6; }

/* --- Alerts --- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  border-left: 3px solid;
}
.alert-success { background: #f0fdf4; border-color: var(--success); color: #166534; }
.alert-danger  { background: #fef2f2; border-color: var(--danger);  color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: var(--warning);  color: #92400e; }
.alert-info    { background: #f0f9ff; border-color: var(--info);    color: #075985; }

/* --- Tables --- */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th {
  text-align: left; padding: 0.6rem 0.75rem;
  background: var(--surface2); font-size: 0.75rem;
  font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:hover td { background: var(--surface2); }
tr:last-child td { border-bottom: none; }

/* --- Page header --- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 0 0.5rem;
  margin-bottom: 0.5rem;
}
.page-title {
  font-size: 1.1rem; font-weight: 800; color: var(--text);
}
.page-subtitle {
  font-size: 0.78rem; color: var(--muted); margin-top: 2px;
}

/* --- List items --- */
.list-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.875rem;
  margin-bottom: 0.5rem;
  display: flex; flex-direction: column; gap: 0.35rem;
  border-left: 3px solid transparent;
  transition: box-shadow 0.15s;
}
.list-item:hover { box-shadow: var(--shadow-md); }
.list-item.alerte { border-left-color: var(--danger); }
.list-item.warning { border-left-color: var(--warning); }
.list-item__title { font-weight: 700; font-size: 0.95rem; }
.list-item__meta  { font-size: 0.78rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.list-item__actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.25rem; }

/* --- Tabs --- */
.tabs {
  display: flex; gap: 0.25rem; margin-bottom: 1rem;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
}
.tab {
  padding: 0.5rem 0.875rem; font-size: 0.82rem; font-weight: 600;
  border: none; background: none; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  white-space: nowrap; transition: color 0.15s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* --- IA Panel --- */
.ai-panel {
  background: linear-gradient(135deg, #f5f3ff 0%, #eff6ff 100%);
  border: 1px solid #c4b5fd;
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-top: 0.75rem;
}
.ai-panel__header {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 700; color: #5b21b6; margin-bottom: 0.75rem;
}
.ai-panel__content {
  font-size: 0.875rem; line-height: 1.7; color: var(--text);
  white-space: pre-wrap;
}
.ai-loading {
  display: flex; align-items: center; gap: 0.5rem;
  color: var(--muted); font-size: 0.875rem;
}
.ai-spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Toast notifications --- */
#toast-container {
  position: fixed; top: 70px; right: 0.75rem; z-index: 9999;
  display: flex; flex-direction: column; gap: 0.5rem;
  max-width: calc(100vw - 1.5rem);
}
.toast {
  background: var(--surface);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  display: flex; align-items: flex-start; gap: 0.5rem;
  min-width: 240px;
  animation: slideIn 0.2s ease;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end;
  padding: 0;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1rem;
  animation: slideUp 0.2s ease;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--muted); }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* --- Stats row --- */
.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem; text-align: center;
}
.stat-box {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 0.6rem;
}
.stat-box__val   { font-size: 1rem; font-weight: 800; }
.stat-box__label { font-size: 0.65rem; color: var(--muted); }

/* --- Kanban --- */
.kanban-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0.5rem; }
.kanban-board  { display: flex; gap: 0.75rem; min-width: max-content; padding: 0.25rem; }
.kanban-col {
  width: 240px; min-height: 200px;
  background: var(--surface2);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.kanban-col__header {
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  font-size: 0.75rem; font-weight: 700;
  display: flex; justify-content: space-between; align-items: center;
  color: #fff;
}
.kanban-col__count {
  background: rgba(255,255,255,.25);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.7rem;
}
.kanban-col__body { padding: 0.5rem; flex: 1; }
.kanban-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.4rem;
  cursor: grab;
  transition: box-shadow 0.15s, transform 0.15s;
  border-left: 3px solid transparent;
}
.kanban-card:active  { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.5; transform: rotate(1deg); }
.kanban-card.alerte  { border-left-color: var(--danger); }
.kanban-card__name   { font-weight: 700; font-size: 0.85rem; }
.kanban-card__meta   { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.kanban-card__amount { font-size: 0.78rem; color: var(--success); font-weight: 600; }
.kanban-card__actions { display: flex; gap: 0.3rem; margin-top: 0.4rem; }
.kanban-add {
  display: flex; align-items: center; gap: 0.3rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.78rem; color: var(--muted);
  cursor: pointer; border-radius: var(--radius);
  text-decoration: none; transition: background 0.15s;
}
.kanban-add:hover { background: var(--border); color: var(--text); text-decoration: none; }

/* --- Detail grid --- */
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
.detail-row { display: flex; gap: 0.5rem; }
.detail-label { font-size: 0.78rem; color: var(--muted); min-width: 110px; flex-shrink: 0; }
.detail-value { font-size: 0.875rem; font-weight: 600; color: var(--text); }

/* --- Separator --- */
.sep { height: 1px; background: var(--border); margin: 0.75rem 0; }

/* --- Helpers --- */
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-muted   { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-sm      { font-size: 0.82rem; }
.text-xs      { font-size: 0.72rem; }
.fw-bold      { font-weight: 700; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.d-flex { display: flex; }
.gap-2  { gap: 0.5rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }
.hidden { display: none !important; }

/* Couleur de fond impayé retard */
.row-alerte { background: #fff5f5 !important; }

/* --- Responsive 768px --- */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .bottom-nav { display: none; }

  .layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: 100vh;
  }

  .sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }
  .sidebar__logo {
    padding: 0.5rem 1.25rem 1rem;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
  }
  .sidebar__nav a {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.6rem 1.25rem;
    color: var(--text-sm);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
  }
  .sidebar__nav a:hover { background: var(--bg); color: var(--primary); }
  .sidebar__nav a.active { background: #eff6ff; color: var(--primary); font-weight: 700; border-right: 2px solid var(--primary); }
  .sidebar__nav a svg { width: 18px; height: 18px; flex-shrink: 0; }

  .main-area { overflow: hidden; }
  .topbar { display: none; }

  .container { padding: 1.5rem; max-width: 1200px; }
  .kpi-grid  { grid-template-columns: repeat(4, 1fr); }
  .form-row  { grid-template-columns: 1fr 1fr; }
  .modal-overlay { align-items: center; padding: 1rem; }
  .modal { border-radius: var(--radius-lg); max-width: 600px; margin: auto; }
}

/* --- Responsive 1024px --- */
@media (min-width: 1024px) {
  .layout { grid-template-columns: 240px 1fr; }
  .container { padding: 2rem; }
}

/* ================================================================
   PATCH v1.1 — Layout centré grands écrans + corrections
================================================================ */

/* Centrage layout sur grands écrans */
@media (min-width: 1280px) {
  body {
    background: #cbd5e1;
  }
  .layout {
    max-width: 1440px;
    margin: 0 auto;
    box-shadow: 0 0 0 1px rgba(0,0,0,.06), 0 8px 40px rgba(0,0,0,.12);
    min-height: 100vh;
    background: var(--bg);
  }
}

/* Sidebar plus soignée */
@media (min-width: 768px) {
  .sidebar {
    background: #1e293b;
    border-right: none;
  }
  .sidebar__logo {
    color: #fff;
    border-bottom-color: rgba(255,255,255,.1);
    padding: 1.25rem 1.25rem 1rem;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
  }
  .sidebar__logo span {
    color: #60a5fa;
  }
  .sidebar__nav a {
    color: #94a3b8;
    border-radius: 0;
    padding: 0.625rem 1.25rem;
    font-size: 0.84rem;
    letter-spacing: 0.01em;
  }
  .sidebar__nav a:hover {
    background: rgba(255,255,255,.06);
    color: #f1f5f9;
  }
  .sidebar__nav a.active {
    background: rgba(96,165,250,.12);
    color: #60a5fa;
    border-right: 2px solid #60a5fa;
    font-weight: 600;
  }
  .sidebar__nav a svg {
    width: 17px;
    height: 17px;
    opacity: 0.85;
  }
  .sidebar__sep {
    height: 1px;
    background: rgba(255,255,255,.08);
    margin: 0.4rem 1.25rem;
  }
  .sidebar__footer {
    margin-top: auto;
    padding: 0.875rem 1.25rem;
    font-size: 0.72rem;
    color: #475569;
    border-top: 1px solid rgba(255,255,255,.07);
  }
  .sidebar__section-label {
    padding: 0.6rem 1.25rem 0.2rem;
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #475569;
  }
}

/* Fix filtre recovery — row plus robuste */
.filter-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.filter-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.filter-row .form-control {
  width: auto;
}
.filter-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-sm);
  white-space: nowrap;
  cursor: pointer;
}

/* Topbar desktop : masqué */
@media (min-width: 768px) {
  .topbar { display: none; }
}

/* Main area background */
.main-area {
  background: var(--bg);
  min-height: 100vh;
}

/* ── Lucide Icons ── */
[data-lucide] {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  stroke-width: 1.75;
}
.page-title [data-lucide] { width: 22px; height: 22px; opacity: .7; }
.btn [data-lucide]         { width: 14px; height: 14px; }
.btn-lg [data-lucide]      { width: 16px; height: 16px; }
.card-title [data-lucide]  { width: 15px; height: 15px; opacity: .7; }
.badge [data-lucide]       { width: 11px; height: 11px; }
