:root {
  --bg: #14171d;
  --surface: #1b2029;
  --surface-2: #222935;
  --line: #303948;
  --line-soft: #262e3a;
  --ink: #e4e8ef;
  --muted: #8b95a7;
  --brass: #c89b3c;
  --brass-dim: #8e6f2c;
  --silver: #aeb8c6;
  --verdigris: #4e9c87;
  --copper: #be6242;
  --radius: 4px;
  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --sans: "Karla", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: .01em; margin: 0 0 .4em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
a { color: inherit; text-decoration: none; }
p { margin: 0 0 .8em; max-width: 68ch; }
.muted { color: var(--muted); }
.error { color: var(--copper); }
.gain { color: var(--verdigris); }
.loss { color: var(--copper); }

button, input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .45em .7em;
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}
button { cursor: pointer; }
button:hover { border-color: var(--brass-dim); }
button.primary { background: var(--brass); color: #171412; border-color: var(--brass); font-weight: 600; }
button.primary:hover { background: #d9ac4c; }
button.ghost { background: transparent; }
button.link { background: none; border: none; color: var(--muted); padding: 0; text-decoration: underline; }
button.link:hover { color: var(--ink); }
button.danger { color: var(--copper); }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2em; }
.field { margin-bottom: .8rem; }
.field input, .field select, .field textarea { width: 100%; }

/* --- Marque : un flan de pièce --- */
.coin-mark {
  width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #e0bd68, #a9822b 58%, #6c521c);
  box-shadow: inset 0 0 0 3px rgba(20,18,12,.45), inset 0 -3px 8px rgba(0,0,0,.5);
}
.coin-mark.small { width: 22px; height: 22px; box-shadow: inset 0 0 0 2px rgba(20,18,12,.45); }

/* --- Connexion --- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(340px, 100%); text-align: center; }
.login-card .coin-mark { margin: 0 auto 1.2rem; }
.login-card h1 { font-size: 2rem; }
#login-form { display: flex; flex-direction: column; gap: .6rem; margin-top: 1.2rem; }
#login-form button { background: var(--brass); color: #171412; border-color: var(--brass); font-weight: 600; }

/* --- Structure --- */
#app { display: grid; grid-template-columns: 218px 1fr; min-height: 100dvh; }

.rail {
  border-right: 1px solid var(--line-soft);
  background: var(--surface);
  display: flex; flex-direction: column;
  padding: 1.1rem .9rem;
  position: sticky; top: 0; height: 100dvh;
}
.rail-head { display: flex; align-items: center; gap: .55rem; margin-bottom: 1.6rem; }
.rail-title { font-family: var(--serif); font-size: 1.05rem; }
#nav { display: flex; flex-direction: column; gap: 1px; }
#nav a {
  padding: .45rem .6rem; border-radius: var(--radius); color: var(--muted);
  border-left: 2px solid transparent;
}
#nav a:hover { color: var(--ink); background: var(--surface-2); }
#nav a.active { color: var(--brass); border-left-color: var(--brass); background: var(--surface-2); }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: .7rem; font-size: .8rem; }
.quota-bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: .3rem; }
.quota-bar span { display: block; height: 100%; background: var(--brass); width: 0; transition: width .4s; }
.quota small { color: var(--muted); }

main { padding: 1.8rem 2rem 4rem; min-width: 0; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* --- Chiffres du cabinet --- */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line-soft); border: 1px solid var(--line-soft); }
.figure { background: var(--surface); padding: 1rem 1.1rem; }
.figure .n { font-family: var(--serif); font-size: 1.85rem; line-height: 1.1; display: block; }
.figure .n.brass { color: var(--brass); }
.figure .k { color: var(--muted); font-size: .8rem; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.2rem; margin-top: 1.6rem; }
.panel { background: var(--surface); border: 1px solid var(--line-soft); padding: 1rem 1.1rem; }
.panel h3 { color: var(--silver); font-size: .95rem; margin-bottom: .8rem; }
.panel canvas { max-height: 230px; }

/* --- Grille de médaillons : l'élément signature --- */
.tray { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 1.4rem .9rem; margin-top: 1rem; }
.medal { text-align: center; background: none; border: none; padding: 0; display: block; width: 100%; }
.medal .disc {
  width: 100%; aspect-ratio: 1; border-radius: 50%; margin-bottom: .5rem;
  background: var(--surface-2) center/cover no-repeat;
  box-shadow: inset 0 0 0 1px var(--line), 0 2px 10px rgba(0,0,0,.35);
  position: relative; transition: box-shadow .18s, transform .18s;
}
.medal:hover .disc, .medal:focus-visible .disc { box-shadow: inset 0 0 0 1px var(--brass), 0 4px 16px rgba(0,0,0,.5); transform: translateY(-2px); }
.medal.selected .disc { box-shadow: inset 0 0 0 2px var(--brass), 0 4px 16px rgba(0,0,0,.5); }
.medal .disc.empty::after {
  content: "?"; font-family: var(--serif); color: var(--line);
  font-size: 2rem; position: absolute; inset: 0; display: grid; place-items: center;
}
.medal .qty {
  position: absolute; right: 2px; bottom: 2px; background: var(--bg); color: var(--brass);
  border: 1px solid var(--line); border-radius: 999px; font-size: .7rem; padding: 0 .4em;
}
.medal .t { font-size: .82rem; line-height: 1.3; display: block; }
.medal .s { font-size: .74rem; color: var(--muted); display: block; }
.medal .fav { position: absolute; left: 4px; top: 4px; color: var(--brass); font-size: .8rem; }

/* --- Tableau --- */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: .8rem; padding: .5rem .6rem; border-bottom: 1px solid var(--line); cursor: pointer; }
th:hover { color: var(--ink); }
td { padding: .5rem .6rem; border-bottom: 1px solid var(--line-soft); }
tbody tr:hover { background: var(--surface); }
td.num, th.num { text-align: right; }
.thumb-cell img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; vertical-align: middle; }

/* --- Filtres --- */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; padding: .8rem 0 1rem; border-bottom: 1px solid var(--line-soft); }
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 120px; }
.filters input[type=search] { min-width: 210px; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .6rem 0; }
.chip { font-size: .78rem; padding: .12em .6em; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: transparent; }
.chip.on { border-color: var(--brass); color: var(--brass); }

.bulkbar {
  position: sticky; bottom: 1rem; margin-top: 1rem; display: flex; gap: .6rem; align-items: center;
  background: var(--surface-2); border: 1px solid var(--brass-dim); padding: .6rem .9rem; flex-wrap: wrap;
}

/* --- Tiroir latéral (fiche pièce) --- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(8,10,14,.7); }
.drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100%);
  background: var(--surface); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 1.6rem 1.7rem 3rem;
}
@media (prefers-reduced-motion: no-preference) {
  .drawer-panel { animation: slide .22s ease-out; }
  @keyframes slide { from { transform: translateX(18px); opacity: .4; } }
}
.drawer-panel .close { position: absolute; right: 1rem; top: 1rem; background: none; border: none; color: var(--muted); font-size: 1.3rem; }

/* Avers / revers côte à côte, retournables */
.faces { display: flex; gap: 1rem; margin: 1rem 0 1.4rem; }
.face { flex: 1; }
.face img, .face .placeholder {
  width: 100%; aspect-ratio: 1; border-radius: 50%; object-fit: cover;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line);
  display: grid; place-items: center; color: var(--line);
}
.face small { display: block; text-align: center; color: var(--muted); margin-top: .35rem; font-size: .76rem; }

dl.specs { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1.2rem; font-size: .88rem; }
dl.specs dt { color: var(--muted); }
dl.specs dd { margin: 0; }

.section-rule { border: none; border-top: 1px solid var(--line-soft); margin: 1.4rem 0; }

/* --- Complétude --- */
.years { display: flex; flex-wrap: wrap; gap: .3rem; }
.year { font-size: .78rem; padding: .1em .5em; border: 1px solid var(--line); color: var(--muted); border-radius: 2px; }
.year.have { border-color: var(--brass); color: var(--brass); background: rgba(200,155,60,.1); }

/* --- Divers --- */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--brass-dim); padding: .6rem 1rem; z-index: 60;
}
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.loading { color: var(--muted); padding: 2rem 0; }
.badge { font-size: .72rem; border: 1px solid var(--line); padding: 0 .45em; border-radius: 2px; color: var(--muted); }
.badge.swap { border-color: var(--verdigris); color: var(--verdigris); }

@media (max-width: 780px) {
  #app { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; align-items: center; gap: 1rem; overflow-x: auto; padding: .6rem .8rem; }
  .rail-head { margin: 0; }
  #nav { flex-direction: row; gap: .2rem; }
  #nav a { white-space: nowrap; border-left: none; border-bottom: 2px solid transparent; }
  #nav a.active { border-left: none; border-bottom-color: var(--brass); }
  .rail-foot { margin: 0; }
  .quota { display: none; }
  main { padding: 1.2rem 1rem 3rem; }
}
