/* ============================================================================
   MiamWise · Administration
   Palette alignée sur le thème Android (ui/theme/Color.kt) pour que le back-office
   et l'application racontent la même histoire visuelle.

   Disposition : trois volets côte à côte, comme une messagerie.
     rail    · les catégories et leurs compteurs
     list    · les demandes, une ligne chacune
     detail  · la demande choisie, en grand, avec la réponse
   Une seule demande à la fois est développée : l'ancien flux empilait un
   formulaire complet sous chaque carte, et vingt demandes faisaient vingt
   champs de réponse à faire défiler.
   ========================================================================= */

:root {
  --herb: #2F6B4F;
  --herb-dark: #1D4633;
  --herb-light: #DCEBE1;
  --terracotta: #C4703F;
  --terracotta-light: #F7E3D6;
  --amber: #D9930D;
  --amber-light: #FBEBCB;
  --berry: #A8432F;
  --berry-light: #F8E2DD;
  --olive: #8C914F;
  --olive-light: #EDEFD9;

  --cream: #FBF8F3;
  --surface: #FFFFFF;
  --muted-surface: #F1EDE5;
  --ink: #1F1D1A;
  --ink-soft: #4A453E;
  --ink-muted: #6B655C;
  --line: #E4DED2;

  --radius-lg: 18px;
  --radius-md: 13px;
  --radius-sm: 9px;
  --shadow-card: 0 1px 2px rgba(31, 29, 26, .04), 0 8px 24px rgba(31, 29, 26, .06);
  --shadow-lift: 0 4px 10px rgba(31, 29, 26, .07), 0 16px 40px rgba(31, 29, 26, .1);

  --topbar-h: 61px;
  --rail-w: 236px;
  --list-w: 380px;

  color-scheme: light;
  font-family: 'Segoe UI', Inter, ui-sans-serif, system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    --herb: #7FC29B;
    --herb-dark: #8FCFAA;
    --herb-light: #23342B;
    --terracotta: #E8A47B;
    --terracotta-light: #33261E;
    --amber: #F0C46B;
    --amber-light: #352C16;
    --berry: #FF8A73;
    --berry-light: #38211C;
    --olive: #C3C97B;
    --olive-light: #2C2E1D;

    --cream: #141715;
    --surface: #1E221F;
    --muted-surface: #2A2F2B;
    --ink: #EDEAE4;
    --ink-soft: #C9C4BB;
    --ink-muted: #A8A399;
    --line: #333A35;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
    --shadow-lift: 0 4px 10px rgba(0, 0, 0, .34), 0 16px 40px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* Les `display` explicites plus bas (inline-flex, grid…) l'emporteraient sinon sur
   la valeur par défaut de [hidden], laissant apparaître les contrôles réservés aux
   sessions authentifiées. */
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }

/* Teintes par famille de demande : posées une fois, lues partout. */
[data-type="report"]      { --tone: var(--berry);      --tone-bg: var(--berry-light); }
[data-type="appeal"]      { --tone: var(--amber);      --tone-bg: var(--amber-light); }
[data-type="bug"]         { --tone: var(--terracotta); --tone-bg: var(--terracotta-light); }
[data-type="improvement"] { --tone: var(--olive);      --tone-bg: var(--olive-light); }
[data-filter="all"]         { --tone: var(--herb);       --tone-bg: var(--herb-light); }
[data-filter="report"]      { --tone: var(--berry);      --tone-bg: var(--berry-light); }
[data-filter="appeal"]      { --tone: var(--amber);      --tone-bg: var(--amber-light); }
[data-filter="bug"]         { --tone: var(--terracotta); --tone-bg: var(--terracotta-light); }
[data-filter="improvement"] { --tone: var(--olive);      --tone-bg: var(--olive-light); }
[data-filter="answered"]    { --tone: var(--ink-muted);  --tone-bg: var(--muted-surface); }

/* ── Barre supérieure ─────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 clamp(14px, 3vw, 28px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand img { border-radius: 9px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15px; letter-spacing: -.02em; }
.brand-text small { font-size: 11.5px; color: var(--ink-muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.who {
  font-size: 12.5px; color: var(--ink-muted);
  padding: 5px 11px; border-radius: 999px; background: var(--muted-surface);
  max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Boutons ──────────────────────────────────────────────────────────── */

.btn {
  border: 0; border-radius: 999px; padding: 9px 16px;
  font: inherit; font-size: 14px; font-weight: 650; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  transition: transform .14s ease, background .14s ease, box-shadow .14s ease, opacity .14s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--herb) 45%, transparent); outline-offset: 2px; }

.btn-primary { background: var(--herb); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--herb) 32%, transparent); }
.btn-primary:hover:not(:disabled) { background: var(--herb-dark); }
.btn-ghost { background: var(--herb-light); color: var(--herb-dark); }
.btn-quiet { background: transparent; color: var(--ink-muted); }
.btn-quiet:hover:not(:disabled) { background: var(--muted-surface); }
.btn-danger { background: var(--berry-light); color: var(--berry); }
.btn-wide { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.ico { font-size: 15px; line-height: 1; }

@media (prefers-color-scheme: dark) {
  .btn-primary { background: var(--herb); color: #10231A; }
  .btn-primary:hover:not(:disabled) { background: var(--herb-dark); }
}

/* ── Coquille ─────────────────────────────────────────────────────────── */

.shell { flex: 1; display: flex; flex-direction: column; width: 100%; min-height: 0; }

/* ── Écran de connexion ───────────────────────────────────────────────── */

.gate {
  max-width: 430px; margin: clamp(24px, 10vh, 100px) auto;
  padding: 38px 34px; text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
}
.gate-logo { border-radius: 18px; margin-bottom: 18px; }
.gate h1 { font-size: 27px; letter-spacing: -.03em; margin: 0 0 10px; }
.gate p { color: var(--ink-muted); line-height: 1.55; margin: 0 0 26px; font-size: 14.5px; }
.gate-error { color: var(--berry); font-size: 13.5px; min-height: 20px; margin: 14px 0 0; }
.gate-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 20px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 13px; }
.gate-links a { color: var(--ink-muted); text-decoration: none; }
.gate-links a:hover { color: var(--herb); text-decoration: underline; }

/* ── Les trois volets ─────────────────────────────────────────────────── */

.workspace {
  flex: 1; min-height: 0;
  height: calc(100dvh - var(--topbar-h));
  display: grid;
  grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr);
}
.workspace > * { min-height: 0; }

/* ── Rail des catégories ──────────────────────────────────────────────── */

.rail {
  display: flex; flex-direction: column;
  padding: 22px 14px 18px;
  border-right: 1px solid var(--line);
  background: var(--cream);
  overflow-y: auto;
}
.rail-title { margin: 0 0 3px 10px; font-size: 16px; font-weight: 800; letter-spacing: -.02em; }
.rail-sub { margin: 0 0 16px 10px; font-size: 12.5px; color: var(--ink-muted); line-height: 1.4; }
.rail-help { margin: auto 0 0 10px; padding-top: 18px; font-size: 11.5px; color: var(--ink-muted); line-height: 1.6; }

#filters { display: flex; flex-direction: column; gap: 2px; }
.tab {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink-soft);
  font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer;
  transition: background .12s ease;
}
.tab:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.tab:focus-visible { outline: 3px solid color-mix(in srgb, var(--herb) 45%, transparent); outline-offset: -3px; }
.tab-ico { font-size: 16px; line-height: 1; width: 20px; text-align: center; }
.tab b {
  margin-left: auto; min-width: 26px; text-align: center;
  padding: 2px 8px; border-radius: 999px;
  background: var(--muted-surface); color: var(--ink-muted);
  font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.tab.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card); }
.tab.is-active b { background: var(--tone-bg); color: var(--tone); }
.rail-sep { display: block; height: 1px; background: var(--line); margin: 8px 6px; }

/* ── Liste des demandes ───────────────────────────────────────────────── */

.list { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); }
.list-head { padding: 12px 12px 10px; border-bottom: 1px solid var(--line); }
.list-head input {
  width: 100%; padding: 9px 14px;
  border: 1.5px solid var(--line); border-radius: 999px;
  font: inherit; font-size: 13.5px; color: var(--ink); background: var(--cream);
}
.list-head input:focus { outline: 0; border-color: var(--herb); box-shadow: 0 0 0 3px color-mix(in srgb, var(--herb) 18%, transparent); }
.list-head input::placeholder { color: var(--ink-muted); }
.rows { flex: 1; overflow-y: auto; }

.row {
  display: grid; grid-template-columns: 4px minmax(0, 1fr); gap: 0 12px;
  width: 100%; padding: 12px 14px 12px 10px;
  border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
  transition: background .12s ease;
}
.row:hover { background: var(--cream); }
.row:focus-visible { outline: 3px solid color-mix(in srgb, var(--herb) 45%, transparent); outline-offset: -3px; }
.row.is-selected { background: var(--tone-bg); }
.row-rail { grid-row: 1 / span 4; align-self: stretch; border-radius: 2px; background: var(--tone); }
.row-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-muted); }
.row-kind { font-weight: 750; color: var(--tone); }
.row-who { margin: 3px 0 2px; font-size: 14px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-excerpt {
  font-size: 13px; line-height: 1.45; color: var(--ink-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.row-excerpt.is-empty { color: var(--ink-muted); font-style: italic; }
.row-tags { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; font-size: 11.5px; color: var(--ink-muted); }
.row-tags span { display: inline-flex; align-items: center; gap: 4px; }

/* ── Détail ───────────────────────────────────────────────────────────── */

.detail { overflow-y: auto; background: var(--cream); }
.detail-inner { max-width: 1060px; margin: 0 auto; padding: 24px clamp(18px, 3vw, 40px) 64px; }

.back { display: none; margin: 0 0 14px -6px; }

.detail-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px 5px 9px; border-radius: 999px;
  background: var(--tone-bg); color: var(--tone);
  font-size: 12.5px; font-weight: 750; white-space: nowrap;
}
.when { font-size: 13px; color: var(--ink-muted); }
.detail h2 { margin: 12px 0 8px; font-size: 24px; letter-spacing: -.025em; line-height: 1.2; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; margin: 0 0 20px; font-size: 13.5px; color: var(--ink-muted); }
.meta b { font-weight: 600; color: var(--ink-soft); }
.meta code { font: inherit; color: var(--ink-soft); }

.body-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: start; margin-bottom: 22px; }
.message {
  margin: 0; padding: 18px 22px;
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--tone);
  border-radius: var(--radius-md);
  font-size: 16px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere;
}
.message.is-empty { color: var(--ink-muted); font-style: italic; }

/*
 * La capture jointe, à côté du message et non plus dessous.
 *
 * Une capture de téléphone est deux fois plus haute que large : mise sous le message, elle
 * poussait la zone de réponse hors de l'écran. À droite, bornée en hauteur, elle se lit d'un
 * coup d'œil avec le texte, et s'ouvre en grand d'un clic.
 *
 * Le lien est signé et expire au bout de 24 h : passé ce délai la vignette casse, et c'est le bon
 * comportement. La capture appartient à quelqu'un, elle n'a pas à rester visible indéfiniment.
 */
.shot {
  display: block; width: fit-content; max-width: 260px;
  border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden;
  background: var(--muted-surface); text-decoration: none; color: inherit;
  transition: box-shadow .14s ease, transform .14s ease;
}
.shot:hover { box-shadow: var(--shadow-card); transform: translateY(-1px); }
/* Hauteur fixe, largeur qui suit : une capture de téléphone reste une colonne fine, et la zone de
   réponse reste visible sans faire défiler. */
.shot img { display: block; height: 340px; width: auto; max-width: 260px; object-fit: contain; background: var(--muted-surface); }
.shot figcaption { padding: 8px 12px; font-size: 12px; color: var(--ink-muted); border-top: 1px solid var(--line); background: var(--surface); }
.shot-missing {
  width: 220px; padding: 14px; font-size: 12.5px; color: var(--ink-muted); line-height: 1.45;
  border: 1px dashed var(--line); border-radius: var(--radius-md);
}

.sent {
  margin: 0 0 22px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--herb);
  border-radius: var(--radius-md);
  font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere;
}
.sent-label {
  display: block; margin-bottom: 6px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--herb);
}

.compose {
  padding: 18px 20px 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
}
.reply-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.reply-head label { font-size: 14px; font-weight: 700; }
.counter { font-size: 11.5px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.counter.is-near { color: var(--terracotta); }

.compose textarea {
  width: 100%; min-height: 120px; resize: vertical;
  padding: 12px 14px; font: inherit; font-size: 15px; line-height: 1.55;
  color: var(--ink); background: var(--cream);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .14s ease, box-shadow .14s ease;
}
.compose textarea::placeholder { color: var(--ink-muted); }
.compose textarea:focus {
  outline: 0; border-color: var(--tone, var(--herb));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone, var(--herb)) 20%, transparent);
}

.snippets { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 10px 0 16px; }
.snippets-label { font-size: 12px; color: var(--ink-muted); margin-right: 4px; }
.snippet {
  border: 1px dashed color-mix(in srgb, var(--tone, var(--herb)) 40%, var(--line));
  background: transparent; color: var(--ink-soft);
  border-radius: 999px; padding: 6px 12px;
  font: inherit; font-size: 12.5px; cursor: pointer;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.snippet:hover { background: var(--tone-bg, var(--herb-light)); color: var(--tone, var(--herb-dark)); border-style: solid; }

.actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.hint { font-size: 11.5px; color: var(--ink-muted); margin-left: auto; }

/* ── États vides ──────────────────────────────────────────────────────── */

.empty { padding: 54px 28px; text-align: center; }
.empty-ico { font-size: 40px; line-height: 1; display: block; margin-bottom: 12px; }
.empty strong { display: block; font-size: 18px; letter-spacing: -.02em; margin-bottom: 6px; }
.empty span { color: var(--ink-muted); font-size: 14px; line-height: 1.5; }
.rows .empty { padding: 44px 22px; }
.detail .empty { margin-top: clamp(20px, 18vh, 140px); }

.skeleton { height: 84px; border-bottom: 1px solid var(--line); position: relative; overflow: hidden; }
.skeleton::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--muted-surface) 90%, transparent), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ── Capture en grand ─────────────────────────────────────────────────── */

.lightbox {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(15, 14, 12, .82); cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: var(--shadow-lift); background: #fff; }
.lightbox-close {
  position: absolute; top: 18px; right: 18px;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .14); color: #fff; font-size: 18px; cursor: pointer;
}

/* ── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 60;
  transform: translate(-50%, 20px);
  max-width: min(92vw, 460px);
  padding: 13px 20px; border-radius: 999px;
  background: var(--ink); color: var(--cream);
  font-size: 14px; font-weight: 600; text-align: center;
  box-shadow: var(--shadow-lift);
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--berry); color: #fff; }
@media (prefers-color-scheme: dark) { .toast { background: var(--muted-surface); color: var(--ink); } }

/* ── Écrans moyens : le rail passe en bandeau ─────────────────────────── */

@media (max-width: 1080px) {
  .workspace { grid-template-columns: var(--list-w) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .rail {
    grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 12px;
    padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line);
    overflow-x: auto; overflow-y: hidden;
  }
  .rail-title, .rail-sub, .rail-help { display: none; }
  #filters { flex-direction: row; gap: 4px; }
  .tab { width: auto; white-space: nowrap; padding: 7px 10px; }
  .rail-sep { width: 1px; height: 22px; margin: 0 4px; align-self: center; }
}

/* ── Téléphone : liste, puis détail, avec un retour ───────────────────── */

@media (max-width: 760px) {
  :root { --list-w: 1fr; }
  .workspace { grid-template-columns: 1fr; height: auto; min-height: calc(100dvh - var(--topbar-h)); }
  .list { border-right: 0; }
  body[data-view="list"] .detail { display: none; }
  body[data-view="detail"] .list, body[data-view="detail"] .rail { display: none; }
  .back { display: inline-flex; }
  .body-row { grid-template-columns: 1fr; }
  .shot, .shot-missing { width: 100%; max-width: none; }
  .shot img { height: auto; width: 100%; max-height: 320px; }
  .hint { display: none; }
  .who { display: none; }
  /* Sur téléphone, la barre garde l'icône ↻ seule : le mot ne tient pas à côté de « Se déconnecter ». */
  #refresh { font-size: 0; gap: 0; padding: 9px 12px; }
  #refresh .ico { font-size: 17px; }
  .detail-inner { padding: 16px 16px 48px; }
  .detail h2 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .row, .tab, .shot { transition: none; }
  .skeleton::after { animation: none; }
}
