:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --text: #2a2522;
  --muted: #7a706a;
  --line: #e5ded7;
  --accent: #c2603a;
  --accent-text: #ffffff;
  --tile: #e9e3dc;
  --danger: #b3261e;
  --ok: #2e7d4f;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171514;
    --surface: #211e1c;
    --text: #eee8e3;
    --muted: #a39890;
    --line: #34302d;
    --accent: #e07a52;
    --tile: #2b2725;
    --danger: #f2867d;
    --ok: #6fcf97;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button { font: inherit; cursor: pointer; }

/* --- connexion ---------------------------------------------------------- */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; display: grid; gap: 14px; text-align: center;
}
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box img { margin: 0 auto; }
.login-box label { display: grid; gap: 4px; text-align: left; font-size: 13px; color: var(--muted); }
.login-box input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px;
}
.login-box input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-box button {
  background: var(--accent); color: var(--accent-text); border: 0;
  border-radius: 8px; padding: 11px; font-weight: 600; margin-top: 4px;
}
.error { color: var(--danger); margin: 0; }

/* --- en-tête ------------------------------------------------------------ */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; }
.top nav { display: flex; gap: 4px; }
.top nav a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--muted);
}
.top nav a.active { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.top form { margin-left: auto; }
.ghost { background: none; border: 0; color: var(--muted); padding: 6px 8px; }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.status.off { color: var(--danger); }
@media (max-width: 560px) {
  .brand span { display: none; }
  .top { gap: 8px; }
  .status { position: absolute; top: 100%; right: 16px; background: var(--surface);
            padding: 2px 8px; border-radius: 0 0 6px 6px; border: 1px solid var(--line); border-top: 0; }
}

/* --- contenu ------------------------------------------------------------ */
main { padding: 16px; max-width: 1600px; margin: 0 auto; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: baseline; margin: 4px 0 16px; }
.crumbs a { text-decoration: none; color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { color: var(--muted); }
.crumbs h1 { font-size: 22px; margin: 0; }
.count { color: var(--muted); font-size: 13px; margin-left: 8px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

.folders {
  display: grid; gap: 12px; margin-bottom: 24px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.folder {
  position: relative; aspect-ratio: 4 / 3; border-radius: var(--radius); overflow: hidden;
  background: var(--tile); text-decoration: none; display: block;
}
.folder img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.folder:hover img { transform: scale(1.04); }
.folder .label {
  position: absolute; inset: auto 0 0 0; padding: 28px 12px 10px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
}
.folder .label strong { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .label span { font-size: 12px; opacity: .85; }
.folder.nocover { display: grid; place-items: center; color: var(--muted); }

.grid {
  display: grid; gap: 4px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (max-width: 560px) {
  main { padding: 12px; }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 3px; }
  .folders { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}
.tile {
  position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 4px;
  overflow: hidden; background: var(--tile); display: block; width: 100%;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile .badge {
  position: absolute; right: 6px; bottom: 6px; font-size: 12px; color: #fff;
  background: rgba(0,0,0,.6); padding: 1px 6px; border-radius: 999px;
}
.tile .wait {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 8px;
  color: var(--muted); font-size: 11px; text-align: center; word-break: break-all;
}
.month { font-size: 17px; margin: 24px 0 10px; text-transform: capitalize; }
.month:first-child { margin-top: 4px; }
.years { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.years button {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 3px 10px; font-size: 13px;
}
.sentinel { height: 1px; }
.loading { color: var(--muted); text-align: center; padding: 20px; }

/* --- visionneuse -------------------------------------------------------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #000; color: #fff;
  display: grid; grid-template-rows: 1fr auto;
}
.viewer[hidden] { display: none; }
.stage { position: relative; display: grid; place-items: center; overflow: hidden; touch-action: pan-y; }
.stage img, .stage video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.stage .msg { color: #ccc; text-align: center; padding: 24px; }
.viewer .nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px;
  background: rgba(255,255,255,.08); color: #fff; border: 0; font-size: 36px; border-radius: 8px;
}
.viewer .prev { left: 8px; }
.viewer .next { right: 8px; }
@media (hover: none) { .viewer .nav { display: none; } }
.viewer .bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom)); background: #111;
}
.viewer .meta { min-width: 0; flex: 1; display: grid; }
.viewer .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .sub { color: #aaa; font-size: 13px; }
.viewer .actions { display: flex; gap: 6px; }
.btn {
  background: #2a2a2a; color: #fff; border: 0; border-radius: 8px; padding: 7px 12px;
  text-decoration: none; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: #3a3a3a; }
.btn[hidden] { display: none; }
.btn:disabled { opacity: .7; cursor: default; }
.seek { position: absolute; left: 16px; right: 16px; top: 10px; display: flex; gap: 10px; align-items: center; font-size: 13px; }
.seek input { flex: 1; accent-color: var(--accent); }
@media (max-width: 560px) {
  .viewer .folder-link { display: none; }
  .viewer .bar { flex-wrap: wrap; }
}
