:root {
  color-scheme: light;
  --navy: #061426;
  --navy-soft: #0b2d52;
  --blue: #1469d8;
  --cyan: #16bfc9;
  --gold: #f2bd58;
  --paper-bg: #f3f7fc;
  --white: #ffffff;
  --ink: #142033;
  --muted: #65748b;
  --line: #dbe3ef;
  --line-strong: #c7d3e3;
  --focus: 0 0 0 3px rgba(20,105,216,.14);
  --shadow: 0 20px 55px rgba(6,20,38,.12);
}

/* L'attribut HTML hidden doit toujours l'emporter sur les mises en page
   explicites comme display:grid utilisées par les formulaires. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--paper-bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
button, input, select { font: inherit; }
button, select, input { color: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 72px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  background: linear-gradient(90deg, rgba(6,20,38,.98), rgba(8,35,66,.97));
  color: white;
  box-shadow: 0 5px 24px rgba(6,20,38,.14);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; text-decoration: none; }
.brand-mark { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 12px; background: linear-gradient(135deg,var(--cyan),var(--blue)); box-shadow: 0 8px 24px rgba(28,200,210,.28); }
.brand-mark svg { width: 22px; height: 22px; }
.app-identity { display: grid; justify-items: center; line-height: 1.15; }
.app-kicker { margin-bottom: 4px; color: #95ecf1; font-size: .71rem; font-weight: 850; letter-spacing: .12em; }
.app-identity strong { font-size: .98rem; }
.back-link { justify-self: end; padding: 9px 13px; border-radius: 10px; color: #d9e5f6; font-size: .9rem; font-weight: 700; text-decoration: none; }
.back-link:hover, .back-link:focus-visible { background: rgba(255,255,255,.1); color: white; }

.workspace { display: grid; grid-template-columns: minmax(370px, 500px) minmax(0, 1fr); min-height: calc(100vh - 72px); }
.workspace.controls-collapsed { grid-template-columns: 76px minmax(0,1fr); }
.control-panel { z-index: 2; overflow-y: auto; max-height: calc(100vh - 72px); padding: 22px; border-right: 1px solid var(--line); background: #f8fbff; transition: padding .18s ease; }
.controls-collapsed .control-panel { overflow: hidden; padding: 16px 12px; }
.controls-collapsed .control-panel > :not(.panel-heading) { display: none; }
.controls-collapsed .panel-heading h1, .controls-collapsed .panel-heading .step-number { display: none; }
.controls-collapsed .panel-heading { justify-content: center; }
.controls-collapsed .icon-button { transform: rotate(180deg); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 2px 2px 18px; }
.panel-heading > div { display: flex; align-items: center; gap: 12px; }
.panel-heading h1 { margin: 0; font-size: 1.26rem; letter-spacing: -.025em; line-height: 1.15; }
.step-number { display: inline-grid; min-width: 36px; height: 30px; place-items: center; border-radius: 9px; background: #e6f1ff; color: var(--blue); font-size: .76rem; font-weight: 900; letter-spacing: .08em; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--blue); font-size: 1.45rem; }

.control-section { margin-bottom: 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: white; box-shadow: 0 6px 20px rgba(7,22,45,.035); }
.accent-section { position: relative; padding: 16px; }
.accent-section::before { position: absolute; inset: 0 0 auto; height: 4px; background: linear-gradient(90deg,var(--blue),var(--cyan)); content: ""; }
.section-toggle { display: flex; width: 100%; min-height: 47px; align-items: center; justify-content: space-between; padding: 0 16px; border: 0; background: white; font-size: .91rem; font-weight: 820; text-align: left; }
.section-toggle:hover { background: #f7faff; }
.section-toggle b { margin-right: 9px; color: #8ba0bc; font-size: .74rem; letter-spacing: .08em; }
.section-body { padding: 2px 16px 16px; border-top: 1px solid #edf1f6; }
.fields-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px 12px; }
.section-body.fields-grid { padding-top: 15px; }
.field { display: grid; min-width: 0; gap: 6px; }
.field > span:first-child { color: #4a5a71; font-size: .79rem; font-weight: 750; }
.full-field { grid-column: 1 / -1; }
input[type="text"], input[type="number"], select {
  width: 100%; min-width: 0; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line-strong); border-radius: 10px; outline: 0; background: #fbfdff;
}
input:focus, select:focus { border-color: var(--blue); box-shadow: var(--focus); }
input:disabled, select:disabled { cursor: not-allowed; opacity: .55; background: #eef2f7; }
.input-unit { position: relative; display: block; }
.input-unit input { padding-right: 46px; }
.input-unit i { position: absolute; top: 50%; right: 10px; color: #73839a; font-size: .8rem; font-style: normal; transform: translateY(-50%); pointer-events: none; }
.check-field { display: flex; align-items: center; gap: 9px; min-height: 34px; color: #3f5068; font-size: .84rem; font-weight: 690; }
.check-field input { width: 17px; height: 17px; accent-color: var(--blue); }
.model-note { margin: 11px 1px 0; color: var(--muted); font-size: .82rem; }
.live-result { margin: 0 16px 15px; padding: 10px 12px; border: 1px solid #cfe4fa; border-radius: 10px; background: #eff7ff; color: #14569f; font-size: .81rem; font-weight: 700; }
.live-result.warning { border-color: #f1d5a0; background: #fff8e8; color: #85560a; }
.compact-actions { padding-top: 14px; }
.help-text { margin: 9px 0 0; color: var(--muted); font-size: .78rem; }
.primary-actions { position: sticky; bottom: -1px; display: grid; gap: 9px; margin: 18px -4px -4px; padding: 13px 4px 4px; background: linear-gradient(transparent,#f8fbff 16%); }
.primary-button, .secondary-button { min-height: 43px; border-radius: 11px; font-weight: 800; }
.primary-button { border: 0; background: linear-gradient(125deg,#0d58b8,#1675dc); color: white; box-shadow: 0 10px 23px rgba(20,105,216,.22); }
.primary-button:hover { filter: brightness(1.05); transform: translateY(-1px); }
.secondary-button { padding: 0 13px; border: 1px solid var(--line-strong); background: white; color: #31506f; }
.secondary-button:hover { border-color: #98b4d8; background: #f7fbff; }
.export-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.batch-button { width: 100%; }

.preview-panel { min-width: 0; background: #eaf0f7; }
.preview-toolbar { position: sticky; z-index: 10; top: 72px; display: flex; min-height: 68px; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(14px); }
.preview-title { display: flex; align-items: center; gap: 11px; }
.preview-title > div { display: grid; }
.preview-title strong { font-size: .96rem; }
.preview-title span:last-child { color: var(--muted); font-size: .78rem; }
.tabs { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: #f1f5fa; }
.tab { min-height: 36px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent; color: #63748b; font-size: .84rem; font-weight: 800; }
.tab.active { background: white; color: var(--blue); box-shadow: 0 3px 10px rgba(7,22,45,.09); }
.preview-stage { display: grid; place-items: start center; min-height: calc(100vh - 140px); padding: 26px; }
.paper-shell { width: 100%; max-width: 980px; }
.paper-shell:not(.active) { display: none; }
.paper { overflow: hidden; width: 100%; border: 1px solid #cbd5e2; border-radius: 4px; background: white; box-shadow: var(--shadow); }
.paper svg { display: block; width: 100%; height: auto; touch-action: none; user-select: none; }
.paper svg.drag-enabled .motion-point { cursor: grab; }
.paper svg.drag-enabled .motion-point:active { cursor: grabbing; }
.values-card { margin-top: 18px; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: 0 12px 30px rgba(7,22,45,.07); }
.values-card h2 { margin: 0 0 12px; font-size: 1rem; }
.values-scroll { overflow-x: auto; }
.values-card table { width: 100%; border-collapse: collapse; font-size: .78rem; font-variant-numeric: tabular-nums; }
.values-card th, .values-card td { padding: 7px 9px; border-bottom: 1px solid #e6ecf4; text-align: right; white-space: nowrap; }
.values-card th:first-child, .values-card td:first-child { text-align: left; }
.values-card th { background: #f3f7fc; color: #496078; }
.toast { position: fixed; z-index: 50; right: 24px; bottom: 24px; max-width: 360px; padding: 12px 16px; border-radius: 12px; background: var(--navy); color: white; box-shadow: var(--shadow); opacity: 0; transform: translateY(14px); pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.batch-dialog { width: min(720px, calc(100vw - 30px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 20px; color: var(--ink); box-shadow: 0 30px 90px rgba(6,20,38,.3); }
.batch-dialog::backdrop { background: rgba(6,20,38,.58); backdrop-filter: blur(4px); }
.batch-form { padding: 22px; }
.batch-form > header { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.batch-form > header > div { display: flex; align-items: center; gap: 11px; }
.batch-form h2 { margin: 0; font-size: 1.25rem; }
.batch-form > p { margin: 12px 0 20px; color: var(--muted); }
.batch-ranges { margin: 20px 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #f8fbff; }
.batch-ranges h3 { margin: 0 0 12px; font-size: .92rem; }
.batch-range-row { display: grid; grid-template-columns: minmax(180px,1.5fr) auto minmax(80px,1fr) auto minmax(80px,1fr); align-items: center; gap: 8px; margin-top: 10px; }
.batch-range-row > span { color: var(--muted); font-size: .8rem; }
.batch-range-row .check-field { min-width: 0; }
.batch-output { padding-top: 3px; }
.batch-form > footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.batch-form > footer button { padding-inline: 18px; }

.project-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .35rem 1.25rem;
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--line);
  background: #f8fafc;
  color: #526579;
  font-size: .82rem;
  line-height: 1.45;
  text-align: center;
}
.project-footer b { color: var(--ink); }
.project-footer a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: .18em;
}

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .app-identity { display: none; }
  .workspace { grid-template-columns: minmax(330px,42vw) minmax(0,1fr); }
  .preview-stage { padding: 18px; }
}
@media (max-width: 760px) {
  .topbar { min-height: 64px; padding: 0 16px; }
  .back-link { font-size: 0; }
  .back-link::after { font-size: .85rem; content: "Site ↗"; }
  .workspace, .workspace.controls-collapsed { display: block; }
  .control-panel { overflow: visible; max-height: none; padding: 16px; border-right: 0; }
  .controls-collapsed .control-panel { padding: 12px 16px; }
  .controls-collapsed .panel-heading h1, .controls-collapsed .panel-heading .step-number { display: initial; }
  .controls-collapsed .control-panel > :not(.panel-heading) { display: none; }
  .preview-toolbar { top: 64px; padding: 10px 16px; }
  .preview-stage { min-height: auto; padding: 14px; }
}
@media (max-width: 480px) {
  .brand span:last-child { display: none; }
  .fields-grid { grid-template-columns: 1fr; }
  .full-field { grid-column: auto; }
  .preview-title .step-number { display: none; }
  .tab { padding-inline: 11px; }
}

@media print {
  @page { margin: 0; }
  body { background: white; }
  .topbar, .control-panel, .preview-toolbar, .project-footer, .toast { display: none !important; }
  .workspace { display: block; min-height: auto; }
  .preview-stage { display: block; min-height: auto; padding: 0; }
  .paper-shell { display: none !important; max-width: none; }
  .paper-shell.active { display: block !important; }
  .paper { border: 0; box-shadow: none; }
  .values-card { break-inside: avoid; border: 0; box-shadow: none; }
}
