/* Cockpit Engine — Artisan ledger design system.
   Shell + CRUD shared across OHM/Vulkan/Nails. See tokens.css for variables.
   Bans: gradients, glassmorphism, pill radius, side-stripes >1px, gradient text. */

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* === LAYOUT ============================================================= */
.layout { display: flex; min-height: 100vh; min-height: 100dvh; }

/* === SIDEBAR (desktop only) ============================================= */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  display: none;
  flex-direction: column;
}
.sidebar-header {
  padding: var(--space-xl) var(--space-lg) var(--space-lg);
  padding-top: calc(var(--space-xl) + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border-soft);
}
.sidebar-brand {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 400;
  color: var(--accent-ink);
  letter-spacing: 0.01em;
  /* Gold hairline signature — no gradient text. */
  border-bottom: 1px solid var(--accent);
  padding-bottom: 2px;
}
.sidebar-nav { list-style: none; padding: var(--space-md) 0; flex: 1; overflow-y: auto; }
.sidebar-nav li { padding: 0 var(--space-md); }
.sidebar-nav li a {
  display: block;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--fs-md);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: color var(--dur-instant) var(--ease-out),
              background var(--dur-instant) var(--ease-out);
}
.sidebar-nav li a:hover { color: var(--text); background: var(--surface-2); }
.sidebar-nav li a.active { color: var(--accent-ink); background: var(--accent-soft); font-weight: 500; }
.sidebar-footer { padding: var(--space-md) var(--space-lg); border-top: 1px solid var(--border-soft); }
.sidebar-logout {
  color: var(--text-dim);
  font-size: var(--fs-sm);
}
.sidebar-logout:hover { color: var(--accent-ink); }

/* === SIDEBAR DEROULANTS (fix-sidebar-20260713) ========================= */
/* Categories depliables : bouton-titre pleine largeur (meme gabarit que les
   liens nav) + sous-liste repliable via max-height. L etat .open est pose par
   Jinja au rendu (categorie de la page courante) puis bascule au clic (JS
   inline de base.html). Identique en sidebar desktop (>=1024px) et en drawer
   mobile (body.drawer-open). Les sous-liens heritent de .sidebar-nav li a
   (hover + .active) et sont indentes d un cran par la cascade des <li>. */
.sidebar-cat {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-sm); width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--fs-md); font-weight: 500;
  border-radius: var(--radius-sm);
  -webkit-appearance: none; appearance: none; text-align: left;
  transition: color var(--dur-instant) var(--ease-out),
              background var(--dur-instant) var(--ease-out);
}
.sidebar-cat:hover { color: var(--accent-ink); background: var(--surface-2); }
.sidebar-chevron { flex-shrink: 0; transition: transform var(--dur-settle) var(--ease-out); }
.sidebar-group.open > .sidebar-cat .sidebar-chevron { transform: rotate(90deg); }
.sidebar-subnav {
  list-style: none; max-height: 0; overflow: hidden;
  transition: max-height var(--dur-settle) var(--ease-out);
}
.sidebar-group.open > .sidebar-subnav { max-height: 24rem; }

/* === MAIN =============================================================== */
.main { flex: 1; min-width: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  padding: var(--space-md) var(--space-lg);
  /* PWA iPhone plein ecran : pousser la topbar sous la barre de statut iOS
     (heure / wifi / batterie), sinon le burger et le titre sont sous la zone
     systeme non cliquable. env(safe-area-inset-top)=0 hors iOS standalone. */
  padding-top: calc(var(--space-md) + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  display: flex; align-items: center; gap: var(--space-md);
  position: sticky; top: 0; z-index: 20;
  min-height: var(--topbar-h);
}
.topbar-brand {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  color: var(--accent-ink);
  border-bottom: 1px solid var(--accent);
  padding-bottom: 1px;
}
.topbar-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  color: var(--text);
  flex: 1;
}

/* fix-theme-20260714 : bouton bascule clair/sombre (topbar, pousse a droite). */
.theme-toggle {
  margin-left: auto;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--touch); min-height: var(--touch);
  padding: 0;
  background: transparent; border: 0;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--dur-instant) var(--ease-out);
}
.theme-toggle:hover { color: var(--accent-ink); }
.theme-toggle .ic-moon { display: none; }
:root[data-theme="light"] .theme-toggle .ic-sun { display: none; }
:root[data-theme="light"] .theme-toggle .ic-moon { display: inline; }

.content {
  padding: var(--space-lg);
  padding-bottom: calc(var(--space-2xl) + env(safe-area-inset-bottom, 0px));
  flex: 1;
  min-width: 0;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  animation: fadeIn var(--dur-settle) var(--ease-out);
}

/* === DESKTOP BREAKPOINT ================================================= */
@media (min-width: 1024px) {
  .sidebar { display: flex; }
  .main { margin-left: var(--sidebar-w); }
  .topbar-brand { display: none; } /* brand déjà dans sidebar */
  .content { padding-bottom: var(--space-2xl); }
}

/* === BUTTONS ============================================================ */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  min-height: var(--touch);
  padding: 0 var(--space-lg);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  transition: background var(--dur-instant) var(--ease-out),
              border-color var(--dur-instant) var(--ease-out),
              color var(--dur-instant) var(--ease-out);
}
.btn-primary {
  background: var(--accent-ink);
  color: var(--bg);
  border-color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  padding: 0 var(--space-md);
}
.btn-ghost:hover { color: var(--accent-ink); }
.btn-danger {
  background: transparent;
  color: var(--danger-ink);
  border-color: var(--danger);
  border-width: 1px;
}
.btn-danger:hover { background: var(--danger); color: var(--bg); }
button:active { opacity: 0.75; }

/* === FAB (new-event floating button, mobile bottom-right) =============== */
.fab {
  position: fixed;
  right: var(--space-md);
  bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px;
  border-radius: var(--radius-sm);
  background: var(--accent-ink);
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 500;
  box-shadow: var(--shadow-deep);
  z-index: 30;
  transition: background var(--dur-instant) var(--ease-out);
}
.fab:hover { background: var(--accent); }
@media (min-width: 1024px) {
  .fab { bottom: var(--space-lg); right: var(--space-lg); }
}

/* === FORM fields ======================================================== */
.field { display: flex; flex-direction: column; gap: var(--space-2xs); margin-bottom: var(--space-md); }
.field label {
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}
.field input,
.field select,
.field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  min-height: var(--touch);
  transition: border-color var(--dur-instant) var(--ease-out);
}
.field textarea { min-height: calc(var(--touch) * 1.5); resize: vertical; }
.field input:focus,
.field select:focus,
.field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 30%, transparent); } /* fix-uiwave-20260710 */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-sm); }
@media (max-width: 600px) {
  .field-row { grid-template-columns: 1fr; gap: 0; }
}

/* === MODAL ============================================================== */
.modal-back {
  position: fixed; inset: 0;
  background: oklch(10% 0.015 70 / 0.7);
  display: none; align-items: center; justify-content: center;
  z-index: 100;
  padding: var(--space-md);
  padding-top: calc(var(--space-md) + env(safe-area-inset-top, 0px));
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
}
.modal-back.open { display: flex; animation: fadeIn var(--dur-settle) var(--ease-out); }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-lg);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 2*var(--space-md));
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 2*var(--space-md));
  overflow-y: auto;
  box-shadow: var(--shadow-deep);
}
.modal h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--fs-xl);
  color: var(--text);
  margin-bottom: var(--space-md);
}
.modal-actions { display: flex; gap: var(--space-sm); justify-content: flex-end; margin-top: var(--space-md); flex-wrap: wrap; }
.modal-actions .btn-danger { margin-right: auto; }
@media (max-width: 600px) {
  .modal { padding: var(--space-md); }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn-primary,
  .modal-actions .btn-secondary,
  .modal-actions .btn-danger { width: 100%; margin-right: 0; }
}

/* === CRUD generic (used by stock/crm/devis/boutique/formations) ========= */
.crud-page { display: flex; flex-direction: column; gap: var(--space-lg); }
.crud-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-sm); flex-wrap: wrap;
}
.section-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 400;
  color: var(--text);
}
.crud-list { display: flex; flex-direction: column; gap: var(--space-sm); }
.crud-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md) var(--space-lg);
  display: flex; flex-direction: column; gap: var(--space-2xs);
  transition: border-color var(--dur-instant) var(--ease-out);
}
.crud-card:hover { border-color: var(--accent); }
.crud-card-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  color: var(--text);
  display: flex; align-items: baseline; gap: var(--space-sm);
  flex-wrap: wrap;
}
.crud-card-details {
  display: flex; gap: var(--space-md); flex-wrap: wrap;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.crud-card-desc { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--space-2xs); }
.crud-card-actions { display: flex; gap: var(--space-sm); flex-wrap: wrap; margin-top: var(--space-sm); }
.btn-small { min-height: var(--touch, 48px);
  min-height: 44px;
  padding: 0 var(--space-md);
  font-size: var(--fs-xs);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all var(--dur-instant) var(--ease-out);
}
.btn-small:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-small.danger { color: var(--danger-ink); border-color: transparent; }
.btn-small.danger:hover { border-color: var(--danger); background: var(--danger); color: var(--bg); }

.crud-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}
.form-actions { display: flex; gap: var(--space-sm); justify-content: flex-end; }
.form-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  min-height: var(--touch);
  width: 100%;
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 30%, transparent); }

/* === BADGES (replaces coloured status pills) ============================ */
.badge {
  display: inline-flex; align-items: center;
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 2px var(--space-xs);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.badge-planifie   { color: var(--text-muted);  border-color: var(--border); }
.badge-en_cours   { color: var(--accent-ink);  border-color: var(--accent); }
.badge-termine    { color: var(--ok);          border-color: var(--ok); }
.badge-annule     { color: var(--text-dim);    border-color: var(--border-soft); text-decoration: line-through; }

/* === CATEGORY DOTS (couleur métier, petites, pas en background) ========= */
.cat-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px oklch(12% 0 0 / 0.4);  /* subtle halo — dots pop off dark */
}
.cat-dot-electricite { background: var(--cat-electricite); }
.cat-dot-plaquo      { background: var(--cat-plaquo); }
.cat-dot-menuiserie  { background: var(--cat-menuiserie); }
.cat-dot-autre       { background: var(--cat-autre); }

/* === KPI (legacy, kept for dashboard.html) ============================== */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-sm); margin-bottom: var(--space-lg); }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md) var(--space-lg);
  display: flex; flex-direction: column; gap: var(--space-2xs);
}
.kpi-label {
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 400;
  color: var(--text);
}

/* === EMPTY state ======================================================== */
.empty-state {
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
.empty-state-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  color: var(--text);
  margin-bottom: var(--space-xs);
}

/* === MOBILE RESPONSIVE ================================================== */
@media (max-width: 600px) {
  .content { padding: var(--space-md) var(--space-sm); padding-bottom: calc(var(--space-2xl) + env(safe-area-inset-bottom, 0px)); }
  /* padding-top safe-area REAFFIRME : le shorthand ci-dessous ecraserait le
     calc() de la regle .topbar de base -> header sous la status bar iPhone. */
  .topbar { padding: var(--space-sm) var(--space-md); padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px)); }
  .topbar-title { font-size: var(--fs-md); }
  .section-title { font-size: var(--fs-lg); }
  .crud-card { padding: var(--space-sm) var(--space-md); }
}


/* === MOBILE NAV DRAWER (#9) ============================================= */
.nav-toggle { display: none; background: transparent; border: 0; color: var(--text); cursor: pointer; padding: 4px; margin-right: 6px; line-height: 0; }
.drawer-overlay { display: none; }
@media (max-width: 1023px) {
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; min-width: var(--touch); min-height: var(--touch); padding: 0; margin-left: calc(-1 * var(--space-sm)); }
  .sidebar {
    display: flex;
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: min(82vw, 300px);
    z-index: 60;
  }
  body.drawer-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.45); }
  .drawer-overlay {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5);
    opacity: 0; pointer-events: none; transition: opacity .25s ease; z-index: 55;
  }
  body.drawer-open .drawer-overlay { opacity: 1; pointer-events: auto; }
}
@media (min-width: 1024px) { .nav-toggle, .drawer-overlay { display: none !important; } }

/* === ANTI-OVERFLOW MOBILE === */
/* clip (iOS 16+) ne cree pas de scroll container : les position:sticky
   internes (barre visites, recherche express) restent actifs. hidden = fallback. */
@media (max-width: 1023px) { .content { overflow-x: hidden; overflow-x: clip; } }
