@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,400;0,9..144,500;0,9..144,600;0,9..144,700;0,9..144,800;1,9..144,400&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap');

:root {
  --ivory:         #faf8f4;
  --ivory-deep:    #f2ede2;
  --ivory-sunk:    #ebe5d6;

  --ink:           #1a1a1a;
  --ink-soft:      #3c3c3a;
  --stone:         #6b6b68;
  --stone-light:   #9e9a90;

  --rule:          #e8e4dc;
  --rule-strong:   #1a1a1a;

  --brand-primary: #1F497D;
  --brand-accent:  #b85c2e;
  --brand-accent-deep: #8f4420;

  --success:       #3d7a4e;
  --warning:       #b78520;
  --danger:        #a83232;

  --font-display:  'Fraunces', Georgia, serif;
  --font-body:     'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:     'IBM Plex Mono', ui-monospace, monospace;

  --ease:          cubic-bezier(0.22, 0.61, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--ivory);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
}

/* Grain texture — très subtile, posée sur l'ivoire */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.10 0 0 0 0 0.09 0 0 0 0 0.08 0 0 0 0.08 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

::selection { background: var(--ink); color: var(--ivory); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

.hidden { display: none !important; }

/* ── Shell : sidebar + main ── */
.shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
  transition: grid-template-columns 0.3s var(--ease);
}
.shell.sidebar-collapsed { grid-template-columns: 0 1fr; }

/* ── Sidebar ── */
.sidebar {
  border-right: 1px solid var(--rule-strong);
  background: var(--ivory);
  padding: 28px 24px 32px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
  z-index: 5;
  transition: opacity 0.2s var(--ease);
}
.shell.sidebar-collapsed .sidebar {
  padding-left: 0;
  padding-right: 0;
  opacity: 0;
  pointer-events: none;
  border-right: 0;
  overflow: hidden;
}

/* Bouton de toggle sidebar — ≡ (fermé) / × (ouvert), sans texte */
.sidebar-toggle {
  position: fixed;
  top: 18px;
  left: 240px;
  z-index: 200;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  color: var(--ink);
  border: 0;
  cursor: pointer;
  transition: left 0.3s var(--ease), opacity 0.25s var(--ease), color 0.2s var(--ease);
}
.sidebar-toggle:hover { color: var(--brand-accent); }

.sidebar-toggle-icon { position: relative; width: 20px; height: 14px; }
.sidebar-toggle-bar {
  position: absolute;
  left: 0;
  height: 2px;
  background: currentColor;
  transition: all 0.3s var(--ease);
}
.sidebar-toggle-bar:nth-child(1) { top: 0;   width: 20px; }
.sidebar-toggle-bar:nth-child(2) { top: 6px; width: 14px; }
.sidebar-toggle-bar:nth-child(3) { top: 12px; width: 17px; }

/* ≡ → × quand sidebar ouverte */
.shell:not(.sidebar-collapsed) .sidebar-toggle-bar:nth-child(1) {
  top: 6px; transform: rotate(45deg); width: 20px;
}
.shell:not(.sidebar-collapsed) .sidebar-toggle-bar:nth-child(2) {
  opacity: 0; width: 0;
}
.shell:not(.sidebar-collapsed) .sidebar-toggle-bar:nth-child(3) {
  top: 6px; transform: rotate(-45deg); width: 20px;
}

/* Quand sidebar fermée (collapsed) */
.shell.sidebar-collapsed .sidebar-toggle { left: 18px; }

/* Bouton toujours visible, même au scroll */

/* ── Responsive ── */
@media (max-width: 1280px) {
  .main { padding: 40px 32px 56px; }
}
@media (max-width: 1024px) {
  /* Sidebar en overlay drawer (par-dessus le main) */
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    opacity: 1;
    transition: transform 0.3s var(--ease);
    z-index: 150;
    box-shadow: 4px 0 24px rgba(26, 26, 26, 0.12);
  }
  .shell.sidebar-open .sidebar { transform: translateX(0); }
  .shell.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 26, 0.4);
    z-index: 140;
    backdrop-filter: blur(2px);
  }
  .sidebar-toggle { left: 16px; }
  .shell.sidebar-open .sidebar-toggle { left: 240px; }
  .shell.sidebar-open .sidebar-toggle-label-close { display: inline; }
  .shell.sidebar-open .sidebar-toggle-label-open  { display: none; }
  .shell:not(.sidebar-open) .sidebar-toggle-label-close { display: none; }
  .shell:not(.sidebar-open) .sidebar-toggle-label-open  { display: inline; }
  .main { padding: 64px 24px 48px; }
  .view-title { font-size: 30px; }
}
@media (max-width: 768px) {
  .main { padding: 64px 16px 40px; }
  .view-head {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .view-meta { text-align: left; }
  .view-title { font-size: 24px; }
  .panel-head {
    grid-template-columns: 36px 1fr;
    padding: 18px 18px 14px;
    gap: 12px;
  }
  .panel-head .panel-hint { display: none; }
  .panel-body { padding: 20px 18px 24px; }
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}
.sidebar-brand-client-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.sidebar-brand-client-row .sidebar-brand-client {
  margin-top: 0;
}
.sidebar-tenant-logo {
  display: block;
  max-height: 32px;
  max-width: 40px;
  width: auto;
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-brand-name {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
  margin-top: 6px;
}
.sidebar-brand-client {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
  color: var(--stone);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-top: 10px;
}

.sidebar-dossier {
  padding: 14px 16px;
  background: var(--ivory-deep);
  border-left: 2px solid var(--brand-accent);
}
.sidebar-dossier-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--stone);
  margin-bottom: 6px;
}
.sidebar-dossier-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink);
  margin-bottom: 4px;
}
.sidebar-dossier-lot {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

.sidebar-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--stone-light);
  margin-bottom: 10px;
  padding-left: 2px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--stone);
  background: transparent;
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s var(--ease);
  width: 100%;
}
.nav-item:hover { color: var(--ink); background: var(--ivory-deep); }
.nav-item[hidden] { display: none; }

.nav-item-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: inherit;
  opacity: 0.7;
  letter-spacing: 0.08em;
}
.nav-item-label {
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 400;
  letter-spacing: -0.005em;
  color: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-item-marker {
  font-family: var(--font-mono);
  font-size: 10px;
  color: inherit;
  opacity: 0.6;
}

.nav-item.done { color: var(--ink); }
.nav-item.done .nav-item-marker { color: var(--success); opacity: 1; }

.nav-item.active {
  color: var(--ink);
  background: var(--ivory-deep);
  border-left-color: var(--brand-accent);
}
.nav-item.active .nav-item-num,
.nav-item.active .nav-item-marker { color: var(--brand-accent); opacity: 1; }

.nav-children {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0 6px 34px;
  padding-left: 12px;
  border-left: 1px solid var(--rule);
}
.nav-child {
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 12.5px;
  color: var(--stone);
  background: none;
  border: 0;
  border-left: 2px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s var(--ease);
  margin-left: -14px;
  padding-left: 12px;
}
.nav-child:hover { color: var(--ink); }
.nav-child.active {
  color: var(--ink);
  border-left-color: var(--brand-accent);
  font-weight: 500;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--stone-light);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-logout {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--stone);
  padding: 0;
  text-align: left;
  opacity: 0.7;
  transition: opacity 0.15s, color 0.15s;
}
.btn-logout:hover { opacity: 1; color: var(--ink); }

/* Retour Atelier (sidebar, mode dossier) */
.sidebar-back {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--stone);
  padding: 2px 0;
  text-transform: uppercase;
  text-decoration: none;
  transition: color 0.2s var(--ease);
}
.sidebar-back:hover { color: var(--ink); }

/* Mode sidebar : home vs dossier */
body.mode-home    .sidebar-nav-dossier,
body.mode-home    .sidebar-back,
body.mode-home    #sidebar-dossier-block { display: none !important; }
body.mode-dossier .sidebar-nav-home      { display: none !important; }

/* ── Main ── */
.main {
  padding: 40px 56px 72px;
  min-width: 0;
  position: relative;
}

.view-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 32px;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--rule-strong);
}
.view-crumb {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--stone);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.view-crumb .sep { color: var(--stone-light); margin: 0 8px; }
.view-title {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--ink);
}
.view-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--stone);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: right;
}
.view-meta b { color: var(--brand-accent); font-weight: 500; }

.view { animation: rise 0.5s var(--ease) both; }
.view > section { animation: rise 0.5s var(--ease) both; animation-delay: 0.08s; }
.view > section + section { animation-delay: 0.14s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Section (card) ── */
.panel {
  background: var(--ivory);
  border: 1px solid var(--rule);
  margin-bottom: 28px;
  position: relative;
}
.panel-head {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: baseline;
  padding: 22px 32px 18px;
  border-bottom: 1px solid var(--rule);
  gap: 16px;
}
.panel-index {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--brand-accent);
  letter-spacing: 0.1em;
}
.panel-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.15;
}
.panel-hint {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--stone);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.panel-body { padding: 28px 32px 32px; }

/* ── Typography primitives ── */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--stone);
  font-weight: 500;
}
.mono  { font-family: var(--font-mono); }
.serif { font-family: var(--font-display); }

/* ── Form ── */
.field { margin-bottom: 24px; }
.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink);
  margin-bottom: 10px;
}
.field-label-hint {
  font-family: var(--font-body);
  font-size: 11px;
  font-style: italic;
  text-transform: none;
  letter-spacing: 0;
  color: var(--stone-light);
  font-weight: 400;
}
.input,
.select,
.textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: 0;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%231a1a1a' stroke-width='1.3'><path d='M1 1l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}
.input[type="number"] { font-family: var(--font-mono); }
.input:hover,
.select:hover,
.textarea:hover { border-color: var(--stone-light); }
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--ink);
  background: var(--ivory-deep);
}
.textarea { resize: vertical; min-height: 92px; line-height: 1.55; }
.input::placeholder,
.textarea::placeholder { color: var(--stone-light); font-style: italic; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 13px 24px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  text-transform: uppercase;
  white-space: nowrap;
}
.btn-primary {
  background: var(--brand-accent);
  color: var(--ivory);
  border-color: var(--brand-accent);
}
.btn-primary:hover { background: var(--brand-accent-deep); border-color: var(--brand-accent-deep); }
.btn-primary:disabled {
  background: var(--ivory-sunk);
  color: var(--stone-light);
  border-color: var(--rule);
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--ivory);
  color: var(--ink);
  border-color: var(--ink);
}
.btn-secondary:hover { background: var(--ink); color: var(--ivory); }
.btn-ghost {
  background: transparent;
  color: var(--stone);
  border-color: var(--rule);
  padding: 11px 18px;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--ink); }
.btn-success { background: var(--success); color: var(--ivory); border-color: var(--success); }
.btn-success:hover { filter: brightness(0.9); }
.btn-danger  { background: var(--danger);  color: var(--ivory); border-color: var(--danger); }
.btn-danger:hover { filter: brightness(0.9); }

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0.8;
}
@keyframes spin { to { transform: rotate(360deg); } }
