/* ============================================================
   CRM ARCANUM — Design System
   Noir · Or · Épuré · Ultra-premium
   ============================================================ */

:root {
  --noir:        #080808;
  --noir-card:   #111111;
  --noir-border: #1e1e1e;
  --noir-hover:  #181818;
  --or:          #c9a84c;
  --or-clair:    #e2c97e;
  --or-sombre:   #8a6d2f;
  --or-bg:       rgba(201, 168, 76, 0.07);
  --blanc:       #f5f2ec;
  --gris:        #6b6b6b;
  --gris-clair:  #3a3a3a;

  --urgent:      #c0392b;
  --attention:   #d4a017;
  --info:        var(--or);
  --succes:      #4a7c59;

  --font-serif:  'Cormorant Garamond', 'Garamond', Georgia, serif;
  --font-sans:   'Montserrat', 'Helvetica Neue', Arial, sans-serif;

  --radius:      2px;
  --shadow:      0 4px 32px rgba(0,0,0,0.6);
  --transition:  0.2s ease;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--noir);
  color: var(--blanc);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 300;
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   TYPOGRAPHIE
   ============================================================ */

h1, h2, h3, .serif {
  font-family: var(--font-serif);
  font-weight: 400;
  letter-spacing: 0.04em;
}

h1 { font-size: 2rem;   color: var(--or-clair); }
h2 { font-size: 1.4rem; color: var(--blanc);    }
h3 { font-size: 1.1rem; color: var(--or);       }

.or        { color: var(--or); }
.or-clair  { color: var(--or-clair); }
.gris      { color: var(--gris); }
.muted     { color: var(--gris); font-size: 0.8rem; }

.uppercase {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.7rem;
  font-weight: 500;
}

/* ============================================================
   LAYOUT
   ============================================================ */

.layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--noir-card);
  border-right: 1px solid var(--noir-border);
  display: flex;
  flex-direction: column;
  padding: 2rem 0 1.5rem;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 0 1.5rem 2rem;
  border-bottom: 1px solid var(--noir-border);
  margin-bottom: 1.5rem;
}

.sidebar-logo .wordmark {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  letter-spacing: 0.25em;
  color: var(--or);
  text-transform: uppercase;
  display: block;
}

.sidebar-logo .sub {
  font-size: 0.6rem;
  letter-spacing: 0.3em;
  color: var(--gris);
  text-transform: uppercase;
  display: block;
  margin-top: 2px;
}

.sidebar nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.5rem;
  color: var(--gris);
  text-decoration: none;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: var(--transition);
  border-left: 2px solid transparent;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  color: var(--or);
  background: var(--or-bg);
  border-left-color: var(--or);
}

.sidebar nav .nav-section {
  padding: 1.2rem 1.5rem 0.4rem;
  font-size: 0.6rem;
  letter-spacing: 0.3em;
  color: var(--gris-clair);
  text-transform: uppercase;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.5rem 0;
  border-top: 1px solid var(--noir-border);
}

.sidebar-footer a {
  font-size: 0.7rem;
  color: var(--gris);
  text-decoration: none;
  letter-spacing: 0.1em;
  transition: var(--transition);
}

.sidebar-footer a:hover { color: var(--or); }

/* ---- Main content ---- */
.main {
  margin-left: 220px;
  flex: 1;
  padding: 2.5rem 2.5rem 4rem;
  max-width: 1400px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 2.5rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--noir-border);
}

.page-header h1 { margin: 0; }

/* ============================================================
   CARTES & PANELS
   ============================================================ */

.card {
  background: var(--noir-card);
  border: 1px solid var(--noir-border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.card-gold {
  border-color: var(--or-sombre);
  background: linear-gradient(135deg, var(--noir-card) 0%, rgba(201,168,76,0.04) 100%);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--noir-border);
}

.card-header h3 { margin: 0; }

/* ---- Grille de stats ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--noir-card);
  border: 1px solid var(--noir-border);
  border-radius: var(--radius);
  padding: 1.2rem 1.5rem;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 2px; height: 100%;
  background: var(--or);
  opacity: 0.6;
}

.stat-card .value {
  font-family: var(--font-serif);
  font-size: 2rem;
  color: var(--or-clair);
  line-height: 1;
  display: block;
}

.stat-card .label {
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gris);
  margin-top: 0.3rem;
  display: block;
}

/* ============================================================
   TABLEAUX
   ============================================================ */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--noir-border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead th {
  background: var(--noir-card);
  color: var(--gris);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--noir-border);
  font-weight: 500;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--noir-border);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover      { background: var(--noir-hover); }

tbody td {
  padding: 0.85rem 1rem;
  vertical-align: middle;
}

/* ============================================================
   BADGES & STATUTS
   ============================================================ */

.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 2px;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}

.badge-or       { background: var(--or-bg);    color: var(--or);     border: 1px solid var(--or-sombre); }
.badge-urgent   { background: rgba(192,57,43,.15); color: #e74c3c;   border: 1px solid rgba(192,57,43,.3); }
.badge-attention{ background: rgba(212,160,23,.12); color: #e6b800;  border: 1px solid rgba(212,160,23,.3); }
.badge-succes   { background: rgba(74,124,89,.15);  color: #6db987;  border: 1px solid rgba(74,124,89,.3); }
.badge-neutre   { background: rgba(255,255,255,.05); color: var(--gris); border: 1px solid var(--noir-border); }

/* Thermomètre */
.thermo-froide   { color: #6b9dc2; }
.thermo-tiede    { color: #c2a96b; }
.thermo-chaude   { color: #c26b6b; }
.thermo-signee   { color: var(--or); }

/* ============================================================
   FORMULAIRES
   ============================================================ */

.form-group {
  margin-bottom: 1.2rem;
}

label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gris);
  margin-bottom: 0.4rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="datetime-local"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--noir);
  border: 1px solid var(--noir-border);
  border-radius: var(--radius);
  color: var(--blanc);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 300;
  padding: 0.7rem 1rem;
  transition: border-color var(--transition);
  outline: none;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--or-sombre);
  box-shadow: 0 0 0 1px var(--or-sombre);
}

textarea { resize: vertical; min-height: 90px; }

select option { background: var(--noir-card); }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* ============================================================
   BOUTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-or {
  background: var(--or);
  color: var(--noir);
}
.btn-or:hover {
  background: var(--or-clair);
}

.btn-outline {
  background: transparent;
  color: var(--or);
  border: 1px solid var(--or-sombre);
}
.btn-outline:hover {
  background: var(--or-bg);
  border-color: var(--or);
}

.btn-ghost {
  background: transparent;
  color: var(--gris);
  border: 1px solid var(--noir-border);
}
.btn-ghost:hover {
  color: var(--blanc);
  border-color: var(--gris-clair);
}

.btn-danger {
  background: transparent;
  color: #e74c3c;
  border: 1px solid rgba(192,57,43,.4);
}
.btn-danger:hover {
  background: rgba(192,57,43,.1);
}

.btn-sm {
  padding: 0.35rem 0.9rem;
  font-size: 0.6rem;
}

/* ============================================================
   ALERTES DASHBOARD
   ============================================================ */

.alertes-zone {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.alerte-item {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.85rem 1.2rem;
  border-radius: var(--radius);
  border-left: 3px solid;
  font-size: 0.82rem;
  position: relative;
}

.alerte-item.urgent {
  background: rgba(192,57,43,.08);
  border-color: #c0392b;
}
.alerte-item.attention {
  background: rgba(212,160,23,.07);
  border-color: #d4a017;
}
.alerte-item.info {
  background: var(--or-bg);
  border-color: var(--or);
}

.alerte-item .alerte-icon {
  font-size: 1rem;
  line-height: 1.4;
  flex-shrink: 0;
}

.alerte-item .alerte-resolve {
  margin-left: auto;
  flex-shrink: 0;
}

/* ============================================================
   TIMELINE CLIENTE
   ============================================================ */

.timeline {
  display: flex;
  gap: 0;
  margin: 1rem 0;
  overflow-x: auto;
}

.timeline-step {
  flex: 1;
  min-width: 80px;
  text-align: center;
  position: relative;
}

.timeline-step::before {
  content: '';
  position: absolute;
  top: 12px;
  left: 50%;
  right: -50%;
  height: 1px;
  background: var(--noir-border);
  z-index: 0;
}

.timeline-step:last-child::before { display: none; }

.timeline-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--noir-border);
  border: 1px solid var(--gris-clair);
  margin: 0 auto 0.4rem;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
}

.timeline-step.done   .timeline-dot { background: var(--or);     border-color: var(--or); }
.timeline-step.active .timeline-dot { background: var(--noir);   border-color: var(--or); box-shadow: 0 0 0 3px var(--or-bg); }

.timeline-label {
  font-size: 0.55rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gris);
}
.timeline-step.done   .timeline-label { color: var(--or); }
.timeline-step.active .timeline-label { color: var(--blanc); }

/* ============================================================
   PAGE LOGIN
   ============================================================ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(201,168,76,0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(201,168,76,0.03) 0%, transparent 50%),
    var(--noir);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 3.5rem 3rem;
  text-align: center;
}

.login-wordmark {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  letter-spacing: 0.35em;
  color: var(--or);
  text-transform: uppercase;
  display: block;
  margin-bottom: 0.2rem;
}

.login-sub {
  font-size: 0.6rem;
  letter-spacing: 0.45em;
  color: var(--gris);
  text-transform: uppercase;
  display: block;
  margin-bottom: 3rem;
}

.login-divider {
  width: 40px;
  height: 1px;
  background: var(--or-sombre);
  margin: 0 auto 2.5rem;
}

.login-card .form-group {
  text-align: left;
  margin-bottom: 1.5rem;
}

.login-card input[type="password"] {
  text-align: center;
  letter-spacing: 0.3em;
  font-size: 1.1rem;
  background: rgba(255,255,255,0.02);
  border-color: var(--gris-clair);
}

.login-card input[type="password"]:focus {
  border-color: var(--or-sombre);
  background: rgba(201,168,76,0.03);
}

.login-card .btn-or {
  width: 100%;
  justify-content: center;
  padding: 0.85rem;
  font-size: 0.65rem;
  letter-spacing: 0.3em;
  margin-top: 0.5rem;
}

.login-error {
  background: rgba(192,57,43,.1);
  border: 1px solid rgba(192,57,43,.3);
  color: #e74c3c;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.78rem;
  margin-bottom: 1.2rem;
  text-align: center;
}

.login-timeout {
  background: var(--or-bg);
  border: 1px solid var(--or-sombre);
  color: var(--or);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.78rem;
  margin-bottom: 1.2rem;
  text-align: center;
}

.login-footer {
  margin-top: 3rem;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--gris-clair);
}

/* ============================================================
   UTILITAIRES
   ============================================================ */

.flex          { display: flex; }
.flex-center   { display: flex; align-items: center; justify-content: center; }
.flex-between  { display: flex; align-items: center; justify-content: space-between; }
.gap-sm        { gap: 0.5rem; }
.gap-md        { gap: 1rem; }
.gap-lg        { gap: 1.5rem; }
.mt-sm         { margin-top: 0.5rem; }
.mt-md         { margin-top: 1rem; }
.mt-lg         { margin-top: 2rem; }
.mb-sm         { margin-bottom: 0.5rem; }
.mb-md         { margin-bottom: 1rem; }
.mb-lg         { margin-bottom: 2rem; }

.text-right    { text-align: right; }
.text-center   { text-align: center; }
.nowrap        { white-space: nowrap; }

.pseudo-deesse {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--or-clair);
}

.identite-masquee {
  filter: blur(4px);
  user-select: none;
  cursor: pointer;
  transition: filter 0.3s;
}
.identite-masquee:hover { filter: blur(2px); }
.identite-masquee.revealed { filter: none; }

/* Séparateur doré */
.sep {
  border: none;
  border-top: 1px solid var(--noir-border);
  margin: 1.5rem 0;
}

.sep-or {
  border: none;
  border-top: 1px solid var(--or-sombre);
  margin: 1.5rem 0;
  opacity: 0.5;
}

/* Scrollbar */
::-webkit-scrollbar             { width: 4px; height: 4px; }
::-webkit-scrollbar-track       { background: var(--noir); }
::-webkit-scrollbar-thumb       { background: var(--gris-clair); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--or-sombre); }

/* ============================================================
   RESPONSIVE — TOPBAR MOBILE
   ============================================================ */

.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--noir-card);
  border-bottom: 1px solid var(--noir-border);
  align-items: center;
  justify-content: space-between;
  padding: 0 1.2rem;
  z-index: 200;
}

.topbar-logo {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  letter-spacing: 0.25em;
  color: var(--or);
  text-transform: uppercase;
}

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 1px;
  background: var(--or);
  transition: var(--transition);
}

.hamburger.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* Overlay fond */
.sidebar-overlay {
  display: none !important;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 150;
}
@media (max-width: 768px) {
  .sidebar-overlay         { display: none !important; }
  .sidebar-overlay.visible { display: block !important; }
}

/* ============================================================
   SIGNATURE ÉLECTRONIQUE
   ============================================================ */

.signature-wrap {
  border: 1px solid var(--noir-border);
  border-radius: var(--radius);
  background: #fff;
  position: relative;
  touch-action: none;
}

.signature-wrap canvas {
  display: block;
  width: 100%;
  cursor: crosshair;
}

.sign-page {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--noir);
}

.sign-card {
  width: 100%;
  max-width: 680px;
  background: var(--noir-card);
  border: 1px solid var(--noir-border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
}

.sign-card h1 {
  font-size: 1.4rem;
  margin-bottom: 0.3rem;
}

.sign-doc {
  background: var(--noir);
  border: 1px solid var(--noir-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.5rem 0;
  font-size: 0.85rem;
  line-height: 1.9;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ============================================================
   MEDIA QUERIES
   ============================================================ */

@media (max-width: 1024px) {
  .main {
    padding: 2rem 1.5rem 3rem;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (max-width: 768px) {
  /* Topbar visible */
  .topbar { display: flex; }

  /* Sidebar devient overlay */
  .sidebar {
    left: -240px;
    transition: left 0.25s ease;
    z-index: 160;
    width: 240px;
    min-width: 240px;
    padding-top: 56px; /* compenser la topbar */
  }

  .sidebar.open { left: 0; }

  /* Main prend toute la largeur */
  .main {
    margin-left: 0;
    padding: 1.2rem 1rem 3rem;
    margin-top: 56px;
  }

  /* Stats grid 2 colonnes */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .stat-card .value { font-size: 1.5rem; }

  /* Page header empile */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
  }

  /* Flex layout empile */
  .flex.gap-lg {
    flex-direction: column;
  }

  /* Agenda prend toute la largeur */
  div[style*="width:300px"] {
    width: 100% !important;
  }

  /* Form rows 1 colonne */
  .form-row {
    grid-template-columns: 1fr;
  }

  /* Login card padding réduit */
  .login-card {
    padding: 2.5rem 1.5rem;
  }

  /* Card padding réduit */
  .card { padding: 1.2rem 1rem; }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  h1 { font-size: 1.4rem; }

  .btn { padding: 0.6rem 1rem; }

  .sign-card { padding: 1.5rem 1rem; }
}

/* ============================================================
   RESPONSIVE — AJOUTS PHASE 12
   ============================================================ */

/* ---- Tables : scroll horizontal sur mobile ---- */
@media (max-width: 768px) {
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 600px;
  }

  /* Kanban : colonnes empilées verticalement */
  .kanban,
  .kanban-board {
    flex-direction: column !important;
    overflow-x: visible !important;
  }

  .kanban-col,
  .kanban-col {
    width: 100% !important;
    min-width: unset !important;
  }

  /* Vignettes : 1 colonne sur mobile */
  .vignettes-grid {
    grid-template-columns: 1fr !important;
  }

  /* Prescripteurs / vignettes génériques 2 colonnes → 1 */
  .prescr-grid {
    grid-template-columns: 1fr !important;
  }

  /* Vue toggle bouton */
  .view-toggle {
    display: flex;
    gap: .5rem;
    flex-shrink: 0;
  }

  /* Formulaire : sections flex empilées */
  .form-section-row {
    flex-direction: column !important;
  }

  /* Sidebar agenda : full width */
  .agenda-sidebar {
    width: 100% !important;
    flex-shrink: 0;
  }

  /* Boutons actions : wrap */
  .actions-row {
    flex-wrap: wrap;
    gap: .5rem;
  }

  /* Desktop-only éléments cachés */
  .desktop-only {
    display: none !important;
  }
}

@media (max-width: 480px) {
  /* Stat cards : valeur plus petite */
  .stat-card .value { font-size: 1.25rem; }
  .stat-card .label { font-size: .6rem; }

  /* Boutons full-width dans un formulaire seul */
  .btn-fullwidth { width: 100%; }

  /* Kanban cards : padding réduit */
  .kanban-card { padding: .6rem; }

  /* Tables : texte encore plus petit */
  table { font-size: .75rem; }
  th, td { padding: .5rem .4rem; }

  /* page-header : h1 plus petit */
  .page-header h1 { font-size: 1.2rem; }

  /* Form groups : labels compressés */
  .form-group label { font-size: .7rem; }

  /* Badges inline */
  .badge { font-size: .55rem; padding: .2rem .4rem; }

  /* Vignette card compact */
  .vignette-card, .prescr-card {
    padding: .75rem !important;
  }
}
