/* Cuisine 2D — feuille de style */
:root {
  --bg: #f4f2ee; --surface: #ffffff; --surface-2: #faf9f6; --line: #e3dfd6; --line-2: #cfc9bc;
  --ink: #1f2328; --ink-2: #5b6168; --ink-3: #8a8f96;
  --accent: #b45309; --accent-ink: #ffffff; --accent-soft: #fdf1e3;
  --ok: #15803d; --ok-soft: #e7f6ec; --err: #b91c1c; --err-soft: #fdeceb; --warn: #a16207; --warn-soft: #fef6dc;
  --wood: #ead9bd; --wood-line: #c9ad80;
  --radius: 10px; --shadow: 0 1px 2px rgba(31,35,40,.06), 0 2px 8px rgba(31,35,40,.04);
  --side: 232px; --top: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.08rem; } h3 { font-size: .98rem; }
h1 small, h2 small { font-weight: 400; color: var(--ink-2); font-size: .8em; margin-left: .3em; }
code, .mono { font-family: var(--mono); font-size: .9em; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3em; }
.muted { color: var(--ink-2); } .small { font-size: .86rem; }
[hidden] { display: none !important; }

/* ---------- Barre du haut et menu ---------- */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--top); display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: #23201c; color: #f4efe6; }
.brand { color: inherit; font-weight: 700; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 16px; }
.brand.big { font-size: 1.3rem; color: var(--ink); margin-bottom: .3em; }
.icon-btn { background: none; border: 0; color: inherit; padding: 8px; border-radius: 8px; cursor: pointer; }
.menu-toggle { display: none; }
.save-status { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: .85rem; color: #d9d2c5; }
.save-status .dot { width: 9px; height: 9px; border-radius: 50%; background: #8a8f96; }
.save-status[data-state="pending"] .dot { background: #eab308; }
.save-status[data-state="saving"] .dot { background: #eab308; animation: pulse 1s infinite; }
.save-status[data-state="saved"] .dot { background: #22c55e; }
.save-status[data-state="error"] { color: #fecaca; }
.save-status[data-state="error"] .dot { background: #ef4444; }
.save-status .retry { background: #ef4444; color: #fff; border: 0; border-radius: 6px; padding: 4px 10px; font: inherit; cursor: pointer; }
@keyframes pulse { 50% { opacity: .3; } }

.shell { display: flex; min-height: calc(100vh - var(--top)); }
.sidebar { width: var(--side); flex: none; background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px;
  display: flex; flex-direction: column; gap: 2px; position: sticky; top: var(--top); height: calc(100vh - var(--top)); }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--ink); font-weight: 500; }
.sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar svg { flex: none; opacity: .8; }
.sidebar .logout { margin-top: auto; }
.sidebar .logout button { width: 100%; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 9px; color: var(--ink-2); cursor: pointer; font: inherit; }
.main { flex: 1; min-width: 0; padding: 22px 26px 60px; max-width: 1400px; }

.crumbs { font-size: .85rem; color: var(--ink-3); margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs b { color: var(--ink-2); font-weight: 500; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.actions, .row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-actions { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
form.inline { display: inline; margin: 0; }

/* ---------- Cartes et grilles ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 10px; margin: 6px 0 10px; }
.card-head h2 { margin: 0; }
details.card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: '▸'; color: var(--ink-3); transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.card > summary h2 { margin: 0; }
details.card[open] > summary { margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.cards .card { margin: 0; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.two-col.left-narrow { grid-template-columns: 300px minmax(0, 1fr); }
.two-col.even { grid-template-columns: 1fr 1fr; }
.sticky { position: sticky; top: calc(var(--top) + 16px); }
.empty { color: var(--ink-2); text-align: center; padding: 26px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat span { display: block; color: var(--ink-2); font-size: .85rem; }
.stat b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.quick-item { display: block; color: var(--ink); margin: 0; }
.quick-item:hover { border-color: var(--accent); text-decoration: none; }
.quick-item small { display: block; color: var(--ink-2); }

.list { display: flex; flex-direction: column; }
.list.card { padding: 6px; }
.list-item { display: flex; justify-content: space-between; gap: 12px; padding: 11px 12px; border-radius: 8px; color: var(--ink); }
.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item.active { background: var(--accent-soft); }
.list-item small { display: block; color: var(--ink-2); font-size: .83rem; }
.list-item .right { text-align: right; flex: none; }

.project-link { display: block; color: var(--ink); }
.project-link:hover { text-decoration: none; }
.project-link h3 { margin-bottom: 4px; }
.project-link small { display: block; color: var(--ink-2); }
.caisson-card .dims { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.code { display: inline-block; background: #23201c; color: #fff; border-radius: 5px; padding: 0 7px; font-family: var(--mono); font-size: .85em; }

/* ---------- Badges, messages ---------- */
.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; vertical-align: middle; }
.badge-en_cours { background: var(--accent-soft); color: var(--accent); border-color: #f3d3ad; }
.badge-termine { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cb; }
.badge-archive { background: #eee; color: #666; }
.badge-manual { background: var(--warn-soft); color: var(--warn); border-color: #f2df9c; }
.badge-auto { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cb; }
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash-ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cb; }
.flash-err { background: var(--err-soft); color: var(--err); border-color: #f5c2c0; }
.flash-warn { background: var(--warn-soft); color: #7a4b00; border-color: #f2df9c; }
.toast { position: fixed; z-index: 60; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(92vw, 520px);
  padding: 12px 18px; border-radius: 10px; color: #fff; background: #23201c; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.toast-err { background: var(--err); }

/* ---------- Formulaires ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--ink-2); }
label small { font-weight: 400; color: var(--ink-3); }
input, select, textarea { font: inherit; font-size: 1rem; color: var(--ink); background: #fff; border: 1px solid var(--line-2); border-radius: 8px;
  padding: 9px 11px; min-height: 42px; width: 100%; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type="color"] { padding: 3px; height: 42px; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; }
legend { font-size: .85rem; font-weight: 600; color: var(--ink-2); padding: 0 4px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.span2 { grid-column: span 2; } .span4 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; grid-column: 1 / -1; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toolbar input { flex: 1 1 240px; width: auto; }
.toolbar select { width: auto; }
aside .grid { grid-template-columns: 1fr; } aside .span2 { grid-column: auto; }
aside .grid3 { grid-template-columns: repeat(3, 1fr); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .92rem;
  padding: 9px 15px; min-height: 40px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #9a4708; }
.btn-danger { color: var(--err); border-color: #f0c4c1; }
.btn-danger:hover { background: var(--err-soft); }
.btn-sm { padding: 6px 11px; min-height: 34px; font-size: .85rem; }
.btn-block { width: 100%; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
.table-wrap.card { padding: 0; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-2); background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.err td { background: var(--err-soft); }
table.mini { font-size: .88rem; }
table.mini th, table.mini td { padding: 6px 6px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0 0 12px; }
.kv dt { color: var(--ink-2); } .kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.kv .sub { padding-left: 12px; font-size: .86rem; }
.swatch, .lg { display: inline-block; width: 14px; height: 6px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.lg.none { background: repeating-linear-gradient(90deg, #9aa0a6 0 3px, transparent 3px 6px); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--ink-2); }
.chip { display: inline-block; border: 2px solid var(--line); border-radius: 6px; padding: 0 6px; margin: 1px 2px; font-size: .8rem; white-space: nowrap; }

/* ---------- Pièces et chants ---------- */
.pieces { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); gap: 14px; }
.piece-card { margin: 0; padding: 14px; }
.piece-card.is-manual { border-color: #ecd27f; }
.piece-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.piece-name { font-weight: 700; font-size: 1.02rem; border-color: transparent; background: transparent; padding-left: 4px; }
.piece-name:hover { border-color: var(--line); }
.piece-body-wrap { display: grid; grid-template-columns: 1fr; gap: 10px; }
.piece-drawing { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.piece-fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.piece-fields .span2 { grid-column: span 4; }
.chants-line { margin: 8px 0 0; }
.piece-svg { display: block; width: 100%; height: auto; max-height: 260px; touch-action: manipulation; user-select: none; }
.piece-svg .piece-body { fill: var(--wood); stroke: var(--wood-line); stroke-width: 1; }
.piece-svg .grain { stroke: var(--wood-line); stroke-width: 1.5; fill: none; }
.piece-svg text { font: 600 12px var(--font); fill: var(--ink-2); pointer-events: none; }
.piece-svg .edge { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.piece-svg .edge .hit { stroke: transparent; stroke-width: 28; stroke-linecap: round; }
.piece-svg .edge .vis { stroke-width: 7; stroke-linecap: round; transition: stroke-width .1s; }
.piece-svg .edge.none .vis { stroke: #9aa0a6; stroke-width: 3; stroke-dasharray: 6 5; }
.piece-svg .edge:hover .vis, .piece-svg .edge:focus .vis { stroke-width: 11; }
.piece-svg .edge.none:hover .vis, .piece-svg .edge.none:focus .vis { stroke: var(--accent); stroke-width: 5; }
.edge-menu { position: fixed; z-index: 50; min-width: 230px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18); padding: 6px; }
.edge-menu-title { font-size: .8rem; color: var(--ink-2); padding: 6px 10px 8px; font-weight: 600; }
.edge-menu button { display: flex; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 11px 10px; border-radius: 8px; font: inherit; cursor: pointer; color: var(--ink); }
.edge-menu button:hover, .edge-menu button:focus { background: var(--surface-2); outline: none; }
.edge-menu button.current { background: var(--accent-soft); font-weight: 700; }
.edge-menu .lg { width: 22px; height: 7px; }
.edge-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.edge-all { flex-direction: row; align-items: center; gap: 8px; padding: 8px 10px; font-weight: 500; color: var(--ink); }

/* ---------- Règles ---------- */
.rule-row { margin-bottom: 0; }
.rule-new { border-style: dashed; }
.rule-del { text-align: right; margin: 6px 0 16px; }
.help ul { padding-left: 18px; margin: 6px 0; }
.chant-row { margin-bottom: 12px; }

/* ---------- Connexion ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- Tablette ---------- */
@media (max-width: 1100px) {
  .two-col, .two-col.left-narrow { grid-template-columns: 1fr; }
  .sticky { position: static; }
}

/* ---------- Téléphone ---------- */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .menu-toggle { display: inline-flex; }
  .brand { font-size: .95rem; }
  .save-status .txt { max-width: 42vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar { position: fixed; z-index: 40; top: var(--top); left: 0; bottom: 0; height: auto; transform: translateX(-100%);
    transition: transform .2s; box-shadow: 4px 0 30px rgba(0,0,0,.15); }
  .menu-open .sidebar { transform: none; }
  .main { padding: 14px 16px 80px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .page-head .actions > * { width: 100%; }
  .page-head .actions form.inline, .page-head .actions form.inline button { display: block; width: 100%; }
  .btn { min-height: 46px; }
  .btn-sm { min-height: 40px; }
  .grid, .grid4, .two-col.even { grid-template-columns: 1fr; }
  .span2, .span4 { grid-column: auto; }
  .grid3 { grid-template-columns: repeat(3, 1fr); }
  .piece-fields { grid-template-columns: 1fr 1fr; }
  .piece-fields .span2 { grid-column: span 2; }
  .cards { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  .piece-svg text { font-size: 13px; }

  /* Tableaux -> cartes lisibles */
  table.debit thead, table.rules thead { display: none; }
  table.debit, table.debit tbody, table.debit tr, table.debit td,
  table.rules, table.rules tbody, table.rules tr, table.rules td { display: block; width: 100%; }
  table.debit tr, table.rules tr { border-bottom: 1px solid var(--line-2); padding: 10px 12px; }
  table.debit td, table.rules td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.debit td::before, table.rules td::before { content: attr(data-l); color: var(--ink-2); font-size: .82rem; text-align: left; flex: none; }
  table.debit td.chants-cell { flex-wrap: wrap; justify-content: flex-end; }
  .table-wrap { overflow: visible; }
}

/* ---------- Impression ---------- */
.print-only { display: none; }
@media print {
  .topbar, .sidebar, .no-print, .crumbs, .toast, .row-actions { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; font-size: 11px; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #bbb; break-inside: avoid; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .chip { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
