/* Appa - feuille de style globale */

:root {
  --brand: #0d9488;
  --brand-dark: #0b3b38;
  --brand-soft: #d7f0ec;
  --accent: #f59e0b;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e3e8ef;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #ea580c;
  --warn-soft: #ffedd5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --gray-soft: #eef2f6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .18);
  --nav-h: 66px;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

/* ------------------------------------------------------------ En-tete */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(135deg, var(--brand-dark), #12564f 60%, #0d6e63);
  color: #fff;
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: 0 2px 12px rgba(11, 59, 56, .28);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  max-width: 1180px;
  margin: 0 auto;
}

.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { display: inline-flex; }
.topbar-text { display: flex; flex-direction: column; min-width: 0; }
.topbar-text strong { font-size: 1.02rem; }
.topbar-text small { font-size: .72rem; color: rgba(255, 255, 255, .7); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .16);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .2); }

/* -------------------------------------------------------------- Layout */

.app-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 28px);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 16px;
}
.page-head p { color: var(--muted); font-size: .88rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-head .muted { color: var(--muted); font-size: .82rem; }

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: 12px; grid-template-columns: 1fr; }

/* --------------------------------------------------------------- Stats */

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: center;
}
.stat-ico {
  width: 42px; height: 42px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-soft); color: var(--brand-dark); flex: none;
}
.stat-ico.ok { background: var(--ok-soft); color: #15803d; }
.stat-ico.warn { background: var(--warn-soft); color: #c2410c; }
.stat-ico.danger { background: var(--danger-soft); color: #b91c1c; }
.stat-ico.info { background: var(--info-soft); color: #1d4ed8; }
.stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ------------------------------------------------------------- Boutons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.btn:hover { background: #f8fafc; }
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #0b8578; }
.btn-dark { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-dark:hover { background: #0e4b47; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: .84rem; border-radius: 10px; }
.btn-lg { padding: 16px 20px; font-size: 1.02rem; border-radius: 14px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ------------------------------------------------------------ Formulaires */

.form { display: grid; gap: 12px; }
.field { display: block; }
.field-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 5px;
}
input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .16);
}
.field-row { display: grid; gap: 12px; grid-template-columns: 1fr; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }

/* -------------------------------------------------------------- Tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.dtable { width: 100%; border-collapse: collapse; font-size: .88rem; }
.dtable th {
  text-align: left;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.dtable td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dtable tr:last-child td { border-bottom: 0; }
.dtable .num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-strong { font-weight: 600; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

@media (max-width: 860px) {
  .dtable thead { display: none; }
  .dtable, .dtable tbody, .dtable tr, .dtable td { display: block; width: 100%; }
  .dtable tr {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    padding: 6px 12px;
    background: #fff;
  }
  .dtable td {
    border-bottom: 1px dashed var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    text-align: left !important;
    padding: 8px 0;
  }
  .dtable td:last-child { border-bottom: 0; }
  .dtable td::before {
    content: attr(data-label);
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    font-weight: 600;
    flex: none;
  }
  .dtable td .cell-value { text-align: right; }
  .dtable td.empty-row { text-align: center !important; }
  .dtable td.empty-row::before { content: none; }
}

/* ------------------------------------------------------------- Pastilles */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 700;
  background: var(--gray-soft);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: #15803d; }
.pill.warn { background: var(--warn-soft); color: #c2410c; }
.pill.danger { background: var(--danger-soft); color: #b91c1c; }
.pill.info { background: var(--info-soft); color: #1d4ed8; }
.pill.dark { background: #e2e8f0; color: #334155; }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: .88rem;
  margin-bottom: 12px;
  border: 1px solid;
}
.alert-error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.alert-ok { background: var(--ok-soft); border-color: #bbf7d0; color: #166534; }
.alert-warn { background: var(--warn-soft); border-color: #fed7aa; color: #9a3412; }
.alert-info { background: var(--info-soft); border-color: #bfdbfe; color: #1e40af; }

/* ------------------------------------------------------- Navigation basse */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  gap: 2px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px 9px;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 600;
  font-family: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.is-active { color: var(--brand); }
.nav-item.is-active .nav-ico { background: var(--brand-soft); }
.nav-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 28px;
  border-radius: 10px;
}
.nav-label { line-height: 1; }

/* -------------------------------------------------------------- Connexion */

.page-auth { background: linear-gradient(160deg, #0b3b38, #0f172a 70%); min-height: 100vh; }
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: calc(env(safe-area-inset-top, 0px) + 28px) 16px calc(env(safe-area-inset-bottom, 0px) + 28px);
}
.auth-panel {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, .5);
}
.auth-title { margin: 18px 0 4px; }
.auth-text { color: var(--muted); font-size: .88rem; margin-bottom: 16px; }
.auth-help { margin-top: 16px; font-size: .8rem; color: var(--muted); text-align: center; }
.auth-foot { color: rgba(255, 255, 255, .55); font-size: .78rem; }
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-name { font-size: 1.3rem; }
.brand-sub { font-size: .78rem; color: var(--muted); }

/* ---------------------------------------------------------------- Divers */

.hero-badge {
  background: linear-gradient(135deg, var(--brand-dark), #0f766e);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.hero-badge .who { font-size: .82rem; color: rgba(255, 255, 255, .72); }
.hero-badge .name { font-size: 1.3rem; font-weight: 800; }
.hero-badge .meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hero-badge .chip {
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: .78rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.punch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  border: 0;
  border-radius: 18px;
  padding: 22px 18px;
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #0d9488, #0f766e);
  box-shadow: 0 14px 30px -14px rgba(13, 148, 136, .8);
  cursor: pointer;
}
.punch-btn.is-out { background: linear-gradient(135deg, #d97706, #b45309); box-shadow: 0 14px 30px -14px rgba(180, 83, 9, .8); }
.punch-btn.is-done { background: #e2e8f0; color: var(--ink-2); box-shadow: none; cursor: not-allowed; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
}
.timeline li:last-child { border-bottom: 0; }
.timeline .t-ico {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--gray-soft); color: var(--ink-2);
}
.timeline .t-ico.ok { background: var(--ok-soft); color: #15803d; }
.timeline .t-ico.warn { background: var(--warn-soft); color: #c2410c; }
.timeline .t-ico.danger { background: var(--danger-soft); color: #b91c1c; }
.timeline .t-body { flex: 1 1 auto; min-width: 0; }
.timeline .t-title { font-weight: 600; }
.timeline .t-sub { font-size: .78rem; color: var(--muted); }
.timeline .t-right { font-variant-numeric: tabular-nums; font-weight: 700; }

.badge-card {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  background: #fff;
}
.qr-box { display: inline-flex; padding: 10px; background: #fff; border-radius: 12px; border: 1px solid var(--line); }
.qr-code-text { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; font-weight: 700; margin-top: 10px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 14px;
}
.toolbar .field { flex: 1 1 150px; min-width: 130px; }
.toolbar .btn { flex: 0 0 auto; }
.search-field { position: relative; }
.search-field svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-field input { padding-left: 38px; }

.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  font-size: .9rem;
}

/* ------------------------------------------------------------------ Borne */

.page-kiosk { background: #0b1720; color: #e2e8f0; }
.page-kiosk .app-main { max-width: 720px; }
.kiosk-frame {
  background: #12212b;
  border: 1px solid #1e3441;
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 16px;
}
.kiosk-title { text-align: center; color: #fff; }
.kiosk-sub { text-align: center; color: #93b0c0; font-size: .85rem; margin-bottom: 14px; }
#reader { border-radius: 14px; overflow: hidden; background: #000; }
#reader video { width: 100% !important; border-radius: 12px; }
.kiosk-result {
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  margin-bottom: 16px;
  border: 2px solid;
}
.kiosk-result.ok { background: rgba(22, 163, 74, .14); border-color: #16a34a; }
.kiosk-result.warn { background: rgba(234, 88, 12, .14); border-color: #ea580c; }
.kiosk-result.danger { background: rgba(220, 38, 38, .14); border-color: #dc2626; }
.kiosk-result .kr-name { font-size: 1.5rem; font-weight: 800; color: #fff; }
.kiosk-result .kr-msg { color: #cbd5e1; margin-top: 4px; }
.kiosk-result .kr-time { font-size: 2.2rem; font-weight: 800; margin-top: 6px; color: #fff; font-variant-numeric: tabular-nums; }
.kiosk-clock { font-size: 2rem; font-weight: 800; color: #fff; text-align: center; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.kiosk-hint { color: #7f9aab; font-size: .8rem; text-align: center; margin-top: 10px; }

.kiosk-form { display: grid; gap: 10px; grid-template-columns: 1fr; margin-top: 14px; }
.kiosk-form input {
  background: #0b1720; border-color: #24404f; color: #e2e8f0;
  text-align: center; letter-spacing: .12em; font-weight: 700; text-transform: uppercase;
}

/* --------------------------------------------------------------- Modales */

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-panel {
  background: #fff;
  width: 100%;
  max-width: 560px;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(env(safe-area-inset-bottom, 0px) + 22px);
  max-height: 92vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-head h2 { font-size: 1.08rem; }
.modal-actions { display: grid; gap: 10px; margin-top: 6px; }

/* ------------------------------------------------------------ Installation */

.install-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.install-bar .ib-text strong { display: block; }
.install-bar .ib-text span { font-size: .82rem; color: var(--muted); }
.store-logos { display: inline-flex; align-items: center; gap: 8px; }

/* ---------------------------------------------------- Espace administration */

.admin-shell { background: var(--bg); }
.admin-topbar {
  background: linear-gradient(135deg, #111827, #1f2937);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: env(safe-area-inset-top, 0px);
}
.admin-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 12px;
  background: rgba(255, 255, 255, .06);
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.admin-tabs button {
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, .72);
  font: inherit;
  font-weight: 600;
  font-size: .86rem;
  padding: 12px 10px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.admin-tabs button.is-active { color: #fff; border-bottom-color: var(--accent); }
.admin-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
  background: linear-gradient(160deg, #0f172a, #1f2937);
}
.admin-gate .auth-panel { max-width: 430px; }
.kv { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); font-size: .84rem; }
.kv span:last-child { font-weight: 600; text-align: right; }

/* ----------------------------------------------------------------- Toasts */

.toast-zone {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: #0f172a;
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: .88rem;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .6);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { background: #14532d; }
.toast.error { background: #7f1d1d; }
.toast.warn { background: #7c2d12; }

/* ------------------------------------------------------------ Impression */

.qr-sheet { display: grid; gap: 14px; grid-template-columns: 1fr; }

@media print {
  .topbar, .bottom-nav, .install-bar, .no-print, .toast-zone { display: none !important; }
  .app-main { padding: 0; }
  body { background: #fff; }
  .qr-sheet { grid-template-columns: repeat(2, 1fr); }
  .badge-card { break-inside: avoid; box-shadow: none; }
}

/* --------------------------------------------------------------- Desktop */

@media (min-width: 620px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .kiosk-form { grid-template-columns: 1fr auto; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid .field-full { grid-column: 1 / -1; }
  .field-row { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 768px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .qr-sheet { grid-template-columns: repeat(2, 1fr); }
  .modal { align-items: center; }
  .modal-panel { border-radius: 20px; margin: 16px; }
  .app-main { padding: 22px 22px 60px; }
  .bottom-nav { position: sticky; bottom: 0; }
}

@media (min-width: 1080px) {
  .qr-sheet { grid-template-columns: repeat(3, 1fr); }
}
