:root {
  --bg: #0d0e11;
  --surface: #14161b;
  --surface-2: #1a1d23;
  --line: #262a32;
  --line-soft: #1f232a;
  --text: #e8e6e1;
  --muted: #8d9099;
  --gold: #d8b469;
  --gold-soft: rgba(216, 180, 105, .14);
  --green: #6fbf8a;
  --red: #e2726b;
  --amber: #e5b04f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); }
a { color: inherit; text-decoration: none; }
.grid-bg {
  position: fixed; inset: 0 0 auto 0; height: 420px; pointer-events: none; z-index: 0;
  background-image: linear-gradient(var(--line-soft) 1px, transparent 1px), linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.7), transparent);
}
header.top, main { position: relative; z-index: 1; }

/* ---------- En-tête ---------- */
header.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 28px 40px 18px; border-bottom: 1px solid var(--line); }
.brand { display: flex; flex-direction: column; gap: 4px; }
.kicker { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); }
.title { font-family: var(--serif); font-size: 34px; line-height: 1; }
.title em, h1 em { color: var(--gold); font-style: italic; }
nav { display: flex; align-items: center; gap: 22px; }
nav a { color: var(--muted); font-size: 14px; padding-bottom: 3px; border-bottom: 1px solid transparent; }
nav a.on, nav a:hover { color: var(--text); border-color: var(--gold); }
.save { font-size: 12px; color: var(--muted); min-width: 90px; text-align: right; font-family: var(--mono); }
.save.err { color: var(--red); }

main { padding: 28px 40px 80px; max-width: 1320px; }
h1 { font-family: var(--serif); font-weight: 400; font-size: 30px; margin: 0; }
h2 { font-family: var(--serif); font-weight: 400; font-size: 21px; margin: 0; }
h3 { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0 0 12px; }

/* ---------- Contrôles ---------- */
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 9px; font: inherit; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
input.bad { border-color: var(--red); }
input.num { text-align: right; font-family: var(--mono); font-size: 14px; }
button {
  font: inherit; cursor: pointer; border-radius: 7px; padding: 7px 14px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  transition: border-color .15s, color .15s, background .15s;
}
button:hover { border-color: var(--gold); color: var(--gold); }
button.gold { background: var(--gold); color: #17140d; border-color: var(--gold); font-weight: 600; }
button.gold:hover { filter: brightness(1.08); color: #17140d; }
button.ghost { background: transparent; }
button.icon { padding: 5px 9px; background: transparent; color: var(--muted); border-color: transparent; }
button.icon:hover { color: var(--red); border-color: var(--line); }
button.play { width: 34px; padding: 5px 0; font-family: var(--mono); }
button.play.on { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.pos { color: var(--green); } .neg { color: var(--red); }

/* ---------- Panneaux ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.hint { font-size: 12.5px; color: var(--muted); }
.warn { color: var(--amber); font-size: 13px; margin-top: 8px; }

/* ---------- Liste des sessions ---------- */
.list-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.sessions { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.sess {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  display: flex; flex-direction: column; gap: 10px; cursor: pointer; overflow: hidden; transition: border-color .15s, transform .15s;
}
.sess:hover { border-color: var(--gold); transform: translateY(-2px); }
.sess .date { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.sess .name { font-family: var(--serif); font-size: 20px; }
.sess .ships { font-size: 13px; color: var(--muted); }
.sess .net { font-family: var(--mono); font-size: 18px; margin-top: auto; }
.badge { display: inline-block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.badge.live { border-color: var(--gold); color: var(--gold); }
.badge.done { border-color: #3a5a45; color: var(--green); }
.empty { border: 1px dashed var(--line); border-radius: 12px; padding: 50px 20px; text-align: center; color: var(--muted); }
.empty .big { font-family: var(--serif); font-size: 22px; color: var(--text); margin-bottom: 6px; }

/* ---------- Éditeur ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 22px; align-items: start; }
.editor-side { position: sticky; top: 18px; }
.sess-head { display: grid; grid-template-columns: 1fr 160px 170px; gap: 12px; margin-bottom: 18px; }
.sess-head label, .field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.sess-head input.name { font-family: var(--serif); font-size: 22px; padding: 6px 10px; }

/* Équipage */
.crew-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface-2); font-size: 14px; }
.mono-av { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font: 600 11px var(--serif); background: var(--gold-soft); color: var(--gold); flex: none; vertical-align: middle; }
.chip .mono-av { margin-left: -6px; }
.chip button { padding: 0 6px; border: 0; background: transparent; color: var(--muted); }
.chip button:hover { color: var(--red); }
.crew-add { display: flex; gap: 6px; }
.crew-add input { width: 170px; }

/* Vaisseaux */
.ship-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.ship-card + .ship-card { margin-top: 16px; }
.ship-banner { position: relative; height: 128px; background: #0a0b0d center/cover no-repeat; display: flex; align-items: flex-end; }
.ship-banner::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10,11,13,.92) 0%, rgba(10,11,13,.55) 55%, rgba(10,11,13,.15) 100%); }
.ship-banner .inner { position: relative; z-index: 1; padding: 14px 18px; display: flex; align-items: flex-end; gap: 18px; width: 100%; }
.ship-banner .sname { font-family: var(--serif); font-size: 26px; line-height: 1.05; }
.ship-banner .smanu { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--gold); }
.ship-banner .srole { font-size: 13px; color: #c6c3bc; }
.ship-banner .remove { position: absolute; top: 10px; right: 10px; z-index: 2; background: rgba(13,14,17,.7); }
.monogram { font-family: var(--serif); font-size: 44px; color: var(--gold); opacity: .8; }
.stats { display: flex; gap: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat { flex: 1; padding: 9px 14px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat .l { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 15px; }
.stat .v.over { color: var(--amber); }
.ship-body { padding: 14px 16px 16px; }
.owner-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 5px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th.r, td.r { text-align: right; }
td.pts { font-family: var(--mono); color: var(--muted); white-space: nowrap; text-align: right; }
.slot-label { font-size: 13.5px; white-space: nowrap; }
.timecell { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.timecell input { width: 92px; }
tr.running td { background: rgba(216, 180, 105, .05); }
tr.running .timecell input { color: var(--gold); border-color: rgba(216,180,105,.5); }
.add-row { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Livres de comptes */
.ledgers { display: grid; grid-template-columns: 1fr; gap: 22px; }
.ledger + .ledger { padding-top: 18px; border-top: 1px solid var(--line-soft); }
.ledger td:has([data-f="amount"]) { width: 150px; }
.ledger td:has([data-f="member"]) { width: 160px; }
.ledger td:has([data-f="cat"]) { width: 190px; }
.wgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.wcell { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 6px 5px 12px; background: var(--surface-2); }
.wcell .wname { flex: 1; font-size: 14px; }
.wcell input { width: 64px; padding: 4px 6px; }
.ledger td input, .ledger td select { font-size: 14px; padding: 6px 8px; }
.ledger .total { font-family: var(--mono); text-align: right; padding-top: 10px; color: var(--muted); }
.ledger .total b { color: var(--text); }

/* Résultat */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.kpi { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.kpi .l { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.kpi .v { font-family: var(--mono); font-size: 18px; margin-top: 2px; }
.kpi.wide { grid-column: span 2; border-color: rgba(216,180,105,.45); background: linear-gradient(135deg, var(--gold-soft), transparent 70%); }
.kpi.wide .v { font-size: 26px; color: var(--gold); }
.payouts { display: flex; flex-direction: column; gap: 10px; }
.payout { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.payout .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.payout .who { font-family: var(--serif); font-size: 18px; }
.payout .due { font-family: var(--mono); font-size: 17px; }
.payout .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bar { height: 5px; background: var(--line-soft); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #a8843f, var(--gold)); border-radius: 3px; }
.breakdown { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; font-size: 12px; }
.breakdown span { color: var(--muted); display: block; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; }
.breakdown b { font-family: var(--mono); font-weight: 400; }
.transfers { list-style: none; margin: 0; padding: 0; }
.transfers li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.transfers li .arrow { color: var(--gold); }
.transfers li .amt { margin-left: auto; font-family: var(--mono); }
textarea.out { font: 12px/1.4 var(--mono); min-height: 140px; margin-top: 10px; resize: vertical; }

/* Réglages */
.settings { max-width: 640px; }
.settings td input { font-size: 14px; }

/* ---------- Sélecteur de vaisseau ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5,6,8,.78); backdrop-filter: blur(6px); display: flex; justify-content: center; padding: 4vh 3vw; }
.modal[hidden] { display: none; }
.modal-card { width: min(1200px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: flex-end; justify-content: space-between; padding: 20px 24px 14px; border-bottom: 1px solid var(--line); }
.picker-tools { padding: 14px 24px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.picker-tools input { font-size: 16px; padding: 10px 12px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button { border-radius: 99px; padding: 4px 12px; font-size: 13px; }
.chips button.on { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }
.ship-grid { overflow-y: auto; padding: 18px 24px 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); grid-auto-rows: max-content; align-content: start; gap: 14px; flex: 1; min-height: 0; }
.pick { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface-2); cursor: pointer; transition: border-color .15s, transform .15s; display: flex; flex-direction: column; min-height: 0; flex: none; }
.pick:hover { border-color: var(--gold); transform: translateY(-2px); }
.pick .img { flex: none; height: 112px; background: #0a0b0d center/cover no-repeat; display: grid; place-items: center; }
.pick .img { position: relative; overflow: hidden; }
.pick .img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.pick .body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.pick .m { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }
.pick .n { font-family: var(--serif); font-size: 17px; line-height: 1.15; }
.pick .r { font-size: 12px; color: var(--muted); flex: 1; }
.pick .s { display: flex; gap: 12px; font: 12px var(--mono); color: var(--muted); margin-top: 4px; }
.pick .s b { color: var(--text); font-weight: 400; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--surface-2); border: 1px solid var(--gold); color: var(--text); padding: 10px 18px; border-radius: 8px; font-size: 14px; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .editor-main, .editor-side { min-width: 0; }
  .editor-side { position: static; }
  .ledgers { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  header.top, main { padding-left: 16px; padding-right: 16px; }
  .sess-head { grid-template-columns: 1fr; }
  .owner-row { grid-template-columns: 1fr; }
  .stats { flex-wrap: wrap; }
  header.top { flex-wrap: wrap; align-items: center; padding-top: 18px; }
  nav { width: 100%; justify-content: space-between; }
  .ship-body, .ledger { overflow-x: auto; }
  .ship-body table { min-width: 470px; }
  .ledger table { min-width: 520px; }
  .panel-head { flex-wrap: wrap; gap: 8px; }
  .panel { padding: 16px; }
  .list-head { flex-wrap: wrap; gap: 12px; }
}

/* ---------- Accès, partage, vue équipage ---------- */
.auth { max-width: 460px; margin: 6vh auto 0; }
.auth .panel { padding: 30px 30px 24px; }
.auth h1 { margin: 6px 0 18px; }
.authf { display: flex; flex-direction: column; gap: 14px; margin-bottom: 14px; }
.authf .field input { width: 100%; }
.authf button { align-self: flex-start; }
.share { margin-top: 16px; padding: 12px 14px; border: 1px dashed var(--line, #2a2d35); border-radius: 10px; }
.share.on { border-style: solid; border-color: rgba(216,180,105,.35); background: rgba(216,180,105,.05); }
.share .l { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--gold, #d8b469); margin-bottom: 6px; }
.share input { width: 100%; font-size: 12px; }
.who-nav { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--muted, #9aa0aa); font-size: 13px; }
.who-nav .mono-av { width: 24px; height: 24px; font-size: 10px; }
.badge.shared { margin-right: 6px; color: var(--gold, #d8b469); border-color: rgba(216,180,105,.4); }
.editor.ro .ship-card .ship-banner .remove { display: none; }
.editor.ro td { padding-top: 9px; padding-bottom: 9px; }

input[type="checkbox"] { width: auto; flex: none; margin: 0; accent-color: var(--gold); box-shadow: none; }
label.row { flex-wrap: nowrap; cursor: pointer; }
