:root {
  --ink: #1c1914;
  --muted: #6f6458;
  --paper: #efe4d2;
  --card: #fffaf3;
  --line: #e4d3bc;
  --sidebar: #141c19;
  --sidebar-soft: #1d2a26;
  --cream: #f6efe2;
  --teal: #1a6a61;
  --teal-soft: #e5f3f0;
  --clay: #b5522a;
  --clay-deep: #8c3d1c;
  --gold: #a68445;
  --good: #1d7a46;
  --bad: #9d2430;
  --shadow: 0 18px 50px rgba(48, 32, 12, 0.08);
  --serif: Fraunces, Georgia, "Times New Roman", serif;
  --sans: Outfit, "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(181, 82, 42, 0.08), transparent 50%),
    linear-gradient(180deg, #f6efe3 0%, var(--paper) 40%, #e7dcc8 100%);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  letter-spacing: 0.01em;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, .brand strong { font-family: var(--serif); font-weight: 560; letter-spacing: -0.02em; }
.booting { padding: 48px; color: var(--muted); }

.shell { display: grid; grid-template-columns: 272px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: #f3eadc;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.mark {
  width: 34px; height: 34px; border: 1px solid var(--gold); border-radius: 10px;
  display: grid; place-items: center; flex: none;
}
.mark i { width: 12px; height: 12px; background: var(--clay); border-radius: 3px; display: block; }
.brand strong { display: block; font-size: 22px; line-height: 1; }
.brand span { color: #cbbfa8; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; padding-right: 4px; }
.nav button {
  text-align: left; background: transparent; border: 0; color: #e7dccb;
  border-radius: 10px; padding: 8px 10px; font-size: 14px;
}
.nav button:hover, .nav button.on { background: var(--sidebar-soft); color: white; }
.nav button.on { box-shadow: inset 3px 0 0 var(--gold); }
.sidebar .foot { margin-top: auto; color: #b4a790; font-size: 12px; padding: 0 8px 8px; }

.workspace { min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  padding: 18px 28px 8px; flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 28px; }
.topbar p { margin: 2px 0 0; color: var(--muted); }
.top-actions, .pills, .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.view { padding: 8px 28px 48px; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.card-head, .split { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.card h2 { margin: 0 0 4px; font-size: 26px; }
.card p { margin: 0; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span, .sheet th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 640; }
.field small { color: var(--muted); }
.field.missing input { border-color: var(--clay); background: #fff6f2; }
.decl-actions { margin-top: 16px; }
input, select, textarea {
  background: white; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(26, 106, 97, 0.25); border-color: var(--teal); }
.sheet input, .sheet select { min-width: 110px; background: #fff; }

.primary, .secondary, .ghost, .danger, a.ghost {
  border-radius: 999px; padding: 10px 14px; border: 1px solid transparent; text-decoration: none;
}
a.ghost { display: inline-flex; align-items: center; }
.primary { background: var(--clay); color: white; }
.primary:hover, .primary.dirty { background: var(--clay-deep); }
.secondary { background: var(--teal); color: white; }
.ghost { background: transparent; border-color: var(--line); }
.danger { background: transparent; color: var(--bad); border-color: #ecc7c4; }
.pill { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 7px 12px; }
.pill.on { background: var(--ink); color: white; border-color: var(--ink); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { padding: 16px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.kpi strong { display: block; margin-top: 6px; font-family: var(--serif); font-size: 28px; font-variant-numeric: tabular-nums; }
.kpi em { font-style: normal; color: var(--teal); font-size: 13px; }

.scroll { overflow: auto; margin-top: 12px; }
.sheet { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.sheet th, .sheet td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; vertical-align: middle; }
.sheet th:first-child, .sheet td:first-child { text-align: left; white-space: normal; }
.sheet thead th { background: #f3ecdf; position: sticky; top: 0; }
.sheet tr.total td, .sheet tr.total th { background: var(--teal-soft); color: var(--teal-deep, #0e3f3a); font-weight: 640; }
.sheet td.strong { font-weight: 640; }
.neg { color: var(--bad); }
.src { font-style: normal; margin-left: 6px; color: var(--gold); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }
.calc { color: var(--teal); }

.banner { border-radius: 14px; padding: 12px 14px; background: #fff4e4; border: 1px solid #efd3a4; }
.banner.alert { background: #fdeceb; border-color: #f0c2c2; }
.banner.demo { background: var(--teal-soft); border-color: #b7ddd6; }
.banner.dirty { background: #fff; border-style: dashed; }
.list { margin: 8px 0 0; padding-left: 18px; }
.list li { margin: 6px 0; }

.lanes { display: flex; gap: 10px; flex-wrap: wrap; width: 100%; margin: 8px 0 4px; }
.lanes .drop { flex: 1 1 200px; }
.top-actions .lanes { width: auto; margin: 0; }
.drop {
  width: 100%; text-align: left; border: 1.5px dashed var(--gold); background: #fff8ee;
  border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 4px;
}
.drop strong { font-family: var(--serif); font-size: 22px; }
#dropmask {
  position: fixed; inset: 16px; border: 2px dashed var(--clay); border-radius: 24px;
  background: rgba(255, 250, 243, 0.92); display: grid; place-items: center;
  font-family: var(--serif); font-size: 32px; z-index: 20; pointer-events: none;
}
.lane { align-items: stretch; }
.lane .ghost { align-self: flex-start; }
.lane-compact { display: flex; gap: 6px; align-items: center; }
.hidden { display: none !important; }

.modal { position: fixed; inset: 0; background: rgba(20, 18, 14, 0.46); display: grid; place-items: center; z-index: 30; padding: 18px; }
.modal-card { width: min(720px, 100%); background: var(--card); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); }
.modal-card h2 { margin-top: 0; }
.files { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.files span, .status { border-radius: 999px; padding: 3px 8px; background: #f3ecdf; font-size: 12px; }
.status.doublon, .status.rejete { background: #fdeceb; color: var(--bad); }
.status.importe { background: var(--teal-soft); color: var(--teal); }
.status.a_qualifier, .status.non_lu, .status.devise { background: #fff4e4; }

.piece { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.piece pre { white-space: pre-wrap; font-family: var(--sans); color: var(--muted); margin: 6px 0 0; }
#toast {
  position: fixed; bottom: 16px; right: 16px; background: var(--ink); color: white;
  padding: 12px 14px; border-radius: 12px; opacity: 0; transform: translateY(8px); transition: 0.2s ease; z-index: 40;
}
#toast.on { opacity: 1; transform: none; }
.note { color: var(--muted); font-size: 13px; }

@media (max-width: 980px) {
  .shell { display: block; }
  .sidebar { position: sticky; top: 0; height: auto; z-index: 5; }
  .nav { flex-direction: row; }
  .sidebar .foot, .brand span { display: none; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .topbar, .view { padding-left: 16px; padding-right: 16px; }
}
@media print {
  .sidebar, .topbar, .no-print, #dropmask, #modal, #toast { display: none !important; }
  body { background: white; }
  .card, .kpi { box-shadow: none; }
}
