/* CRM WEB - feuille de style principale */

:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-border: #e2e6ec;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.topbar-brand a { font-weight: 700; font-size: 1.1rem; color: var(--color-text); }
.topbar-nav { display: flex; gap: 0.25rem; flex: 1; }
.topbar-nav a {
  color: var(--color-text-muted);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  font-weight: 500;
}
.topbar-nav a:hover { background: var(--color-bg); text-decoration: none; }
.topbar-nav a.active { background: #eaf0fe; color: var(--color-primary); }
.topbar-user { display: flex; align-items: center; gap: 1rem; font-size: 0.85rem; }
.topbar-user .user-name { color: var(--color-text); font-weight: 600; }
.topbar-user small { color: var(--color-text-muted); font-weight: 400; }

.app-main { flex: 1; padding: 1.5rem; max-width: 1400px; width: 100%; margin: 0 auto; }
.app-main-plain { display: flex; align-items: center; justify-content: center; max-width: none; }
.app-footer { text-align: center; color: var(--color-text-muted); font-size: 0.8rem; padding: 1rem; }

/* Flash messages */
.flash { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 500; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-warning { background: #fef3c7; color: #92400e; }
.flash-info { background: #dbeafe; color: #1e40af; }

/* Auth */
.auth-wrapper { display: flex; align-items: center; justify-content: center; min-height: 80vh; width: 100%; }
.auth-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
}
.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.auth-subtitle { color: var(--color-text-muted); margin: 0 0 1.5rem; }
.auth-card label { display: block; margin: 1rem 0 0.35rem; font-weight: 600; font-size: 0.85rem; }
.auth-card input { width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: 0.95rem; }
.btn-block { width: 100%; margin-top: 1.5rem; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; flex-wrap: wrap; gap: 0.75rem; }
.page-header h1 { margin: 0; font-size: 1.5rem; }
.page-subtitle { color: var(--color-text-muted); margin: 0.15rem 0 0; }
.page-header-actions { display: flex; gap: 0.5rem; align-items: center; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-surface);
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn-secondary { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-bg); text-decoration: none; }
.btn-danger { background: #fff; color: var(--color-danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; text-decoration: none; }
.btn-link { background: none; color: var(--color-text-muted); }
.btn-link-inline { background: none; border: none; color: var(--color-primary); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: inherit;
}
.stat-card:hover { text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--color-text-muted); font-size: 0.85rem; }
.stat-card-warning .stat-value { color: var(--color-warning); }

/* Layout helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; margin-bottom: 1.25rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.panel { background: var(--color-surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.panel-header h2 { margin: 0; }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: 0.65rem 0.9rem; text-align: left; border-bottom: 1px solid var(--color-border); }
.table th { background: #f9fafb; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); }
.table tbody tr:hover { background: #fafbfd; }
.table-compact th, .table-compact td { padding: 0.5rem 0.7rem; font-size: 0.88rem; }
.table-actions a, .table-actions form { margin-right: 0.6rem; font-size: 0.85rem; }
.empty-state { color: var(--color-text-muted); text-align: center; padding: 1.5rem; }

/* Filter bar */
.filter-bar { display: flex; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: 0.9rem; }
.filter-bar input[type=search] { flex: 1; min-width: 200px; }
.inline-filter select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-border); border-radius: var(--radius); }

/* Forms */
.form-card { background: var(--color-surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; max-width: 720px; }
.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.85rem; }
.form-row input[type=text], .form-row input[type=email], .form-row input[type=password],
.form-row input[type=number], .form-row input[type=date], .form-row select, .form-row textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-family: inherit;
}
.form-row input:disabled { background: var(--color-bg); color: var(--color-text-muted); }
.form-row-checkbox label { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
.form-row-checkbox input { width: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: 0.75rem; align-items: center; margin-top: 1.25rem; }
.form-hint { color: var(--color-text-muted); font-size: 0.85rem; }
.detail-list { display: grid; grid-template-columns: 120px 1fr; gap: 0.4rem 1rem; margin: 0; }
.detail-list dt { color: var(--color-text-muted); font-weight: 600; }
.detail-list dd { margin: 0; }

/* Badges */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--color-bg); color: var(--color-text-muted); }
.badge-success { background: #dcfce7; color: #166534; }
.badge-muted { background: #f1f5f9; color: #64748b; }
.badge-stage-nouveau { background: #e0e7ff; color: #3730a3; }
.badge-stage-contacte { background: #dbeafe; color: #1e40af; }
.badge-stage-relance { background: #fef3c7; color: #92400e; }
.badge-stage-rdv { background: #fae8ff; color: #86198f; }
.badge-stage-proposition { background: #cffafe; color: #155e75; }
.badge-stage-gagne { background: #dcfce7; color: #166534; }
.badge-stage-perdu { background: #fee2e2; color: #991b1b; }

.text-danger { color: var(--color-danger); font-weight: 600; }

/* Kanban */
.kanban-board { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.kanban-column { background: #eceff3; border-radius: var(--radius); min-width: 250px; max-width: 270px; flex: 0 0 auto; display: flex; flex-direction: column; max-height: calc(100vh - 220px); }
.kanban-column-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 0.9rem; font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.02em; color: var(--color-text-muted); }
.kanban-count { background: #fff; border-radius: 999px; padding: 0.1rem 0.55rem; font-size: 0.75rem; }
.kanban-cards { padding: 0 0.6rem 0.6rem; overflow-y: auto; flex: 1; min-height: 60px; }
.kanban-cards.drag-over { background: #dde3ec; border-radius: var(--radius); }
.kanban-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  cursor: grab;
  border: 1px solid transparent;
}
.kanban-card:hover { border-color: var(--color-primary); }
.kanban-card.dragging { opacity: 0.5; }
.kanban-card-late { border-left: 3px solid var(--color-danger); }
.kanban-card-title { font-weight: 600; margin-bottom: 0.25rem; }
.kanban-card-client { color: var(--color-text-muted); font-size: 0.82rem; margin-bottom: 0.4rem; }
.kanban-card-action { font-size: 0.82rem; margin-bottom: 0.4rem; }
.kanban-card-footer { display: flex; justify-content: space-between; align-items: center; font-size: 0.78rem; color: var(--color-text-muted); }
.kanban-card-owner { background: var(--color-bg); border-radius: 999px; padding: 0.1rem 0.5rem; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal-overlay[hidden] { display: none; }
.modal { background: var(--color-surface); border-radius: var(--radius); width: 100%; max-width: 620px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border); }
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--color-text-muted); line-height: 1; }
.modal-body { padding: 1.25rem; overflow-y: auto; }
.modal-footer { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-top: 1px solid var(--color-border); }
.modal-footer-right { display: flex; gap: 0.6rem; }

.notes-list { max-height: 180px; overflow-y: auto; margin-bottom: 0.75rem; }
.note-item { border-bottom: 1px solid var(--color-border); padding: 0.5rem 0; font-size: 0.85rem; }
.note-item:last-child { border-bottom: none; }
.note-meta { color: var(--color-text-muted); font-size: 0.75rem; margin-bottom: 0.2rem; }
.note-add { display: flex; flex-direction: column; gap: 0.5rem; }
.note-add textarea { width: 100%; padding: 0.5rem; border: 1px solid var(--color-border); border-radius: var(--radius); font-family: inherit; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-nav { overflow-x: auto; }
}
