:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1d1c1a;
  --muted: #6f6b63;
  --line: #e7e3da;
  --accent: #27406b;       /* indigo japonais */
  --accent-soft: #e8edf6;
  --stain: #d23c2a;        /* vermillon */
  --pending: #d99a1e;
  --ok: #2f7d4f;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(30, 25, 15, .04), 0 8px 28px rgba(30, 25, 15, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px; background: rgba(245, 243, 238, .86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 15px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { text-decoration: none; color: var(--muted); padding: 8px 14px; border-radius: 999px; font-weight: 550; font-size: .95rem; }
.nav a.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .9rem; }
main { max-width: 1240px; margin: 0 auto; padding: 28px 24px 110px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.grid { display: grid; gap: 18px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 1.35fr 1fr; align-items: start; }
.stack > * + * { margin-top: 16px; }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .value { font-size: 2.4rem; font-weight: 700; letter-spacing: -.02em; }
.stat .label { color: var(--muted); font-weight: 550; }

/* ---------- controls */
button, .btn {
  font: inherit; font-weight: 600; border: 0; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 14px; background: var(--accent-soft); color: var(--accent);
  transition: transform .06s ease, background .15s ease, opacity .15s;
}
button:active, .btn:active { transform: scale(.98); }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-big { padding: 16px 22px; font-size: 1.05rem; border-radius: 16px; width: 100%; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: #fbe9e6; color: var(--stain); }
.btn-ok { background: #e5f3ea; color: var(--ok); }
.btn-sm { padding: 7px 11px; border-radius: 10px; font-size: .85rem; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search], input[type=date], select, textarea {
  font: inherit; width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: #fbfaf7; color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
textarea { resize: vertical; min-height: 64px; }

.segmented { display: flex; background: #efece5; border-radius: 14px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; background: transparent; color: var(--muted); padding: 11px 10px; border-radius: 11px; }
.segmented button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650; background: #efece5; color: var(--muted); }
.badge.ok { background: #e5f3ea; color: var(--ok); }
.badge.warn { background: #fdf1d9; color: #9a6a0b; }
.badge.red { background: #fbe9e6; color: var(--stain); }

.alert { padding: 12px 16px; border-radius: 14px; background: #fdf1d9; color: #7a5609; font-size: .92rem; }
.alert.error { background: #fbe9e6; color: #9d2a1c; }
.alert.success { background: #e5f3ea; color: #215a38; }

/* ---------- camera */
.camera { position: relative; border-radius: 18px; overflow: hidden; background: #191816; aspect-ratio: 16 / 10; }
.camera video, .camera img { width: 100%; height: 100%; object-fit: contain; display: block; }
.camera .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #bdb8ae; text-align: center; padding: 24px; }
.camera .live { position: absolute; top: 12px; left: 12px; background: rgba(0,0,0,.55); color: #fff; font-size: .78rem; font-weight: 650; padding: 4px 10px; border-radius: 999px; }
.camera .live::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #ff4d3d; margin-right: 6px; vertical-align: 1px; }
.cam-tools { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.cam-tools select { flex: 1; min-width: 160px; }

/* ---------- editor */
.editor { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; align-items: start; }
.stage { position: relative; border-radius: 18px; overflow: hidden; background: #191816; user-select: none; }
.stage img { display: block; width: 100%; height: auto; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage.drawing svg { cursor: crosshair; touch-action: none; }
.box { fill: transparent; stroke-width: 3; vector-effect: non-scaling-stroke; cursor: pointer; }
.box.suggested { stroke: var(--pending); stroke-dasharray: 8 5; fill: rgba(217, 154, 30, .10); }
.box.confirmed { stroke: var(--stain); fill: rgba(210, 60, 42, .10); }
.box.rejected { stroke: #9a968e; stroke-dasharray: 3 4; fill: rgba(0,0,0,.25); }
.box.selected { stroke-width: 5; }
.box-label { font-weight: 700; paint-order: stroke; stroke: rgba(0,0,0,.55); stroke-width: 3px; fill: #fff; pointer-events: none; }
.draft { fill: rgba(39, 64, 107, .15); stroke: #8fb0ff; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; }

.stain-list { max-height: 560px; overflow: auto; padding-right: 4px; }
.stain { border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin-bottom: 10px; background: #fcfbf8; }
.stain.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.stain.rejected { opacity: .55; }
.stain-head { display: flex; align-items: center; gap: 8px; }
.stain-num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem; color: #fff; background: var(--pending); flex: none; }
.stain.confirmed .stain-num { background: var(--stain); }
.stain.rejected .stain-num { background: #9a968e; }
.stain-head .spacer { flex: 1; }
.stain-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.stain-fields .full { grid-column: 1 / -1; }
.stain-fields input, .stain-fields select { padding: 9px 11px; border-radius: 11px; font-size: .9rem; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- lists */
.row-list { display: flex; flex-direction: column; }
.row-item { display: flex; align-items: center; gap: 14px; padding: 12px 6px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.row-item:last-child { border-bottom: 0; }
.row-item:hover { background: #faf9f5; }
.thumb { width: 64px; height: 48px; border-radius: 10px; object-fit: cover; background: #e9e5dc; flex: none; }
.row-item .grow { flex: 1; min-width: 0; }
.row-item .ref { font-weight: 650; }

.kimono-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.kimono-card { padding: 0; overflow: hidden; text-decoration: none; color: inherit; transition: transform .12s; }
.kimono-card:hover { transform: translateY(-2px); }
.kimono-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #e9e5dc; }
.kimono-card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; }

.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photos figure { margin: 0; }
.photos img { width: 100%; border-radius: 14px; display: block; background: #e9e5dc; }
.photos figcaption { font-size: .82rem; color: var(--muted); margin-top: 6px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; box-shadow: var(--shadow); z-index: 50; font-weight: 550; max-width: 90vw; }
.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { margin-bottom: 22px; font-size: 1.1rem; }

/* ---------- mobile */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2, .editor { grid-template-columns: 1fr; }
  .stain-list { max-height: none; }
}
@media (max-width: 720px) {
  /* backdrop-filter créerait un bloc conteneur : la barre « fixed » resterait dans l'en-tête */
  .topbar { padding: 12px 16px; backdrop-filter: none; background: var(--bg); }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; justify-content: space-around;
    background: rgba(255,255,255,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }
  .nav a { font-size: .8rem; padding: 8px 10px; }
  .user .who { display: none; }
  main { padding: 18px 16px 110px; }
  h1 { font-size: 1.4rem; }
  .card { padding: 16px; border-radius: 18px; }
  .photos { grid-template-columns: 1fr; }
  .stat .value { font-size: 2rem; }
  .table-scroll { overflow-x: auto; }
}
