/* Trotti World Manager — mobile d'abord */
:root {
  --primary: #0f3d3e;
  --primary-2: #165456;
  --accent: #d97706;
  --accent-soft: #fde68a;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --input: #ffffff;
  --green: #16a34a; --green-bg: #dcfce7;
  --orange: #ea580c; --orange-bg: #ffedd5;
  --red: #dc2626; --red-bg: #fee2e2;
  --blue: #2563eb; --blue-bg: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1416; --card: #132224; --text: #e2e8f0; --muted: #94a3b8; --line: #1f3436; --line-2: #2c4a4d;
    --input: #0f1c1e; --primary-2: #1d6b6e;
    --green-bg: #12301f; --orange-bg: #3a2210; --red-bg: #3b1515; --blue-bg: #13244a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-2); }
[hidden] { display: none !important; }
.noscript { padding: 24px; text-align: center; }

/* ---------- Écran de chargement / connexion */
.splash, .auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.splash-logo { font-size: 3rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px; padding: 24px 20px; box-shadow: var(--shadow); border-top: 5px solid var(--accent); }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand h1 { margin: 6px 0 0; color: var(--primary); font-size: 1.4rem; letter-spacing: .5px; }
.auth-brand small { color: var(--muted); }
@media (prefers-color-scheme: dark) { .auth-brand h1 { color: var(--accent-soft); } }

/* ---------- En-tête */
.topbar {
  position: sticky; top: 0; z-index: 50; background: var(--primary); color: #fff;
  border-bottom: 3px solid var(--accent); padding: 10px 16px; display: flex; align-items: center; gap: 10px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar .brand { flex: 1; min-width: 0; }
.topbar .brand b { display: block; font-size: 1.02rem; letter-spacing: .4px; }
.topbar .brand small { display: block; color: var(--accent-soft); font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar select { max-width: 150px; background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 8px; padding: 6px 8px; font-size: .82rem; }
.topbar select option { color: #111; }
.icon-btn { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 10px; min-width: 40px; height: 40px; font-size: 1.1rem; cursor: pointer; }

/* ---------- Navigation (bas sur mobile) */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; background: var(--card);
  border-top: 1px solid var(--line-2); padding-bottom: var(--safe-b); box-shadow: 0 -2px 8px rgba(0,0,0,.05);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--nav-h); text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; position: relative;
}
.nav a .ico { font-size: 1.3rem; line-height: 1; }
.nav a.active { color: var(--primary-2); }
.nav a.active::before { content: ""; position: absolute; top: 0; left: 20%; right: 20%; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px; }
.nav .badge { position: absolute; top: 6px; right: calc(50% - 22px); background: var(--red); color: #fff; border-radius: 10px; font-size: .65rem; padding: 1px 6px; }
@media (prefers-color-scheme: dark) { .nav a.active { color: var(--accent-soft); } }

main { max-width: 860px; margin: 0 auto; padding: 14px 16px calc(var(--nav-h) + var(--safe-b) + 24px); }

@media (min-width: 900px) {
  .nav { position: sticky; top: 63px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line-2); justify-content: center; box-shadow: none; }
  .nav a { flex: 0 0 auto; flex-direction: row; gap: 6px; padding: 0 18px; min-height: 48px; font-size: .86rem; }
  .nav a.active::before { top: auto; bottom: 0; left: 10%; right: 10%; border-radius: 3px 3px 0 0; }
  .nav .badge { position: static; }
  main { padding-bottom: 40px; }
}

/* ---------- Cartes & typographie */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card > h2, .section-title { margin: 0 0 12px; font-size: 1.04rem; color: var(--primary); border-left: 4px solid var(--accent); padding-left: 8px; }
@media (prefers-color-scheme: dark) { .card > h2, .section-title { color: var(--accent-soft); } }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.15rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.center { text-align: center; }
.right { text-align: right; }
.mt { margin-top: 12px; } .mb0 { margin-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .ico { font-size: 2rem; display: block; margin-bottom: 6px; }

/* ---------- Formulaires */
.field { margin-bottom: 12px; }
.field > label, .label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 5px; }
.field .hint { font-size: .74rem; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=tel], input[type=number], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--input); font-size: 16px; min-height: 46px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-2); outline-offset: 0; border-color: transparent; }
input[readonly] { background: var(--bg); font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 420px) { .grid2.stack-sm { grid-template-columns: 1fr; } .grid3 { grid-template-columns: 1fr 1fr; } }
.field.error input, .field.error select, .field.error textarea { border-color: var(--red); }
.form-error { background: var(--red-bg); color: var(--red); border-radius: 8px; padding: 10px 12px; font-size: .86rem; margin-bottom: 12px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; min-height: 40px; }
.check input { width: 20px; height: 20px; }

/* ---------- Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 10px; cursor: pointer;
  padding: 12px 16px; font-weight: 700; font-size: .95rem; min-height: 46px; text-decoration: none; background: var(--line); color: var(--text);
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--line-2); }
.btn-sm { padding: 7px 12px; min-height: 36px; font-size: .82rem; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }
.btn-row.stack { flex-direction: column; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 72px; padding: 9px 8px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--card); font-weight: 600; font-size: .84rem; cursor: pointer; min-height: 42px; }
.seg button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
#catSeg button { flex: 1 1 calc(50% - 6px); }

/* ---------- Puces engins */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid var(--line-2); background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: .9rem;
  cursor: pointer; min-height: 42px; font-variant-numeric: tabular-nums;
}
.chip.on { border-color: var(--primary-2); background: var(--primary); color: #fff; }
.chip:disabled { opacity: .45; cursor: not-allowed; text-decoration: line-through; }

/* ---------- Étiquettes */
.tag { display: inline-block; font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--line); color: var(--muted); vertical-align: middle; white-space: nowrap; }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.orange { background: var(--orange-bg); color: var(--orange); }
.tag.red { background: var(--red-bg); color: var(--red); }
.tag.blue { background: var(--blue-bg); color: var(--blue); }
.tag.dark { background: var(--primary); color: #fff; }

/* ---------- Locations en cours */
.legend { font-size: .78rem; color: var(--muted); font-weight: 600; }
.rental { border-left: 6px solid var(--green); padding: 14px; }
.rental.s-green { border-left-color: var(--green); }
.rental.s-orange { border-left-color: var(--orange); background: linear-gradient(90deg, var(--orange-bg), var(--card) 40%); }
.rental.s-red { border-left-color: var(--red); background: linear-gradient(90deg, var(--red-bg), var(--card) 40%); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(220,38,38,.35); } 70% { box-shadow: 0 0 0 8px rgba(220,38,38,0); } 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); } }
@media (prefers-reduced-motion: reduce) { .rental.s-red { animation: none; } }
.rental-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.rental h3 { margin: 4px 0 2px; font-size: 1.05rem; }
.rental .meta { font-size: .84rem; }
.timer { font-size: 1.35rem; font-weight: 800; padding: 4px 10px; border-radius: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; background: var(--green-bg); color: var(--green); }
.s-orange .timer { background: var(--orange-bg); color: var(--orange); }
.s-red .timer { background: var(--red-bg); color: var(--red); }
.rental-actions { display: flex; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.rental-actions .btn { flex: 1; min-width: 90px; }

/* ---------- Listes */
.list-item { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; align-items: center; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.toolbar > * { flex: 1 1 140px; }
.toolbar .btn { flex: 0 0 auto; }

/* ---------- Indicateurs */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.kpi .k { font-size: .7rem; text-transform: uppercase; color: var(--muted); font-weight: 700; letter-spacing: .3px; }
.kpi .v { font-size: 1.3rem; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi.main { grid-column: span 2; background: var(--primary); color: #fff; border-color: var(--primary); }
.kpi.main .k { color: var(--accent-soft); }
.stand-live { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stand-live .card { margin: 0; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .bar-cash { fill: var(--green); }
.chart .bar-momo { fill: var(--accent); }
.chart .bar { fill: var(--primary-2); }
.hbar { display: flex; align-items: center; gap: 8px; font-size: .84rem; margin: 6px 0; }
.hbar .name { flex: 0 0 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar svg { flex: 1; height: 14px; }
.hbar .val { flex: 0 0 auto; font-weight: 700; font-variant-numeric: tabular-nums; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .84rem; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { font-size: .72rem; text-transform: uppercase; color: var(--muted); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.notice { border-radius: 10px; padding: 10px 12px; font-size: .84rem; margin-bottom: 12px; border-left: 4px solid var(--accent); background: var(--orange-bg); }
.notice.info { border-left-color: var(--blue); background: var(--blue-bg); }
.notice.ok { border-left-color: var(--green); background: var(--green-bg); }
.notice.bad { border-left-color: var(--red); background: var(--red-bg); }

.photo-preview { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.photo-preview img { width: 96px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line-2); }
.photo-full { max-width: 100%; border-radius: 8px; display: block; margin: 0 auto; }

.menu-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .menu-grid { grid-template-columns: repeat(4, 1fr); } }
.menu-grid a { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); font-weight: 600; font-size: .84rem; text-align: center; }
.menu-grid a.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.menu-grid .ico { font-size: 1.4rem; }

.audit-entry { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .82rem; }
.audit-entry .details { color: var(--muted); margin-top: 3px; word-break: break-word; }

/* ---------- Fenêtres modales */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .6); z-index: 200; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--card); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b)); animation: up .18s ease-out;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; padding: 16px; } .modal { border-radius: 16px; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 1.08rem; color: var(--primary); }
@media (prefers-color-scheme: dark) { .modal-head h3 { color: var(--accent-soft); } }
.modal-close { background: var(--line); border: 0; border-radius: 50%; width: 36px; height: 36px; font-size: 1.1rem; cursor: pointer; }
.summary { background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: .88rem; margin-bottom: 12px; }

/* ---------- Notifications */
#toasts { position: fixed; left: 0; right: 0; top: 70px; z-index: 300; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: #1e293b; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: .9rem; font-weight: 600; max-width: 480px; box-shadow: 0 6px 18px rgba(0,0,0,.25); animation: up .18s ease-out; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.toast.warn { background: var(--orange); }
.offline { position: sticky; top: 0; z-index: 400; background: var(--red); color: #fff; text-align: center; font-size: .82rem; font-weight: 700; padding: 6px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; padding: 30px; color: var(--muted); }
