:root {
  --bg: #f3f4f6;
  --dark: #111827;
  --muted: #6b7280;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #f59e0b;
  --blue: #2563eb;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--dark);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 28px;
  box-shadow: 0 12px 40px rgba(17, 24, 39, .12);
}

.brand {
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--blue);
}
h1 { margin: 10px 0; font-size: 30px; }
.muted { color: var(--muted); }
label { display: block; margin: 18px 0 8px; font-weight: 700; }
.optional { font-weight: 400; color: var(--muted); }
input, select {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 15px 16px;
  font-size: 17px;
  background: #fff;
}
select:disabled, button:disabled {
  opacity: .55;
  cursor: not-allowed;
}
button {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 15px 18px;
  font-weight: 800;
  font-size: 16px;
  background: var(--dark);
  color: #fff;
  cursor: pointer;
}
form button { width: 100%; margin-top: 22px; }
.message { min-height: 24px; color: var(--muted); }
.message.error { color: var(--red); font-weight: 700; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top));
  background: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.topbar small { display: block; color: var(--muted); font-weight: 500; margin-top: 2px; }
.ghost, .secondary {
  background: #e5e7eb;
  color: var(--dark);
}
main { padding: 16px; max-width: 620px; margin: 0 auto; }
.result {
  border-radius: 22px;
  padding: 24px 18px;
  text-align: center;
  color: #fff;
  margin-bottom: 16px;
  min-height: 150px;
  display: grid;
  place-items: center;
  align-content: center;
}
.result-icon { font-size: 28px; }
#resultTitle { font-size: 28px; font-weight: 900; margin: 6px 0; }
#resultText { margin: 0; font-size: 16px; opacity: .95; word-break: break-word; }
.result.waiting { background: #374151; }
.result.checking { background: var(--blue); }
.result.valid { background: var(--green); }
.result.invalid { background: var(--red); }
.result.warning { background: var(--orange); }
.scanner-wrap {
  background: #111;
  border-radius: 22px;
  overflow: hidden;
  min-height: 280px;
}
#reader { width: 100%; }
.manual-box {
  margin-top: 16px;
  background: #fff;
  border-radius: 22px;
  padding: 16px;
}
.manual-box button { width: 100%; margin-top: 12px; }
.secondary { width: 100%; margin-top: 14px; }

.sound-btn {
  margin-top: 10px;
  background: #eef2ff;
  color: #1e3a8a;
}

.sound-btn.sound-enabled {
  background: #dcfce7;
  color: #166534;
}

.debug-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f9fafb;
  color: var(--dark);
  font-weight: 700;
}
.debug-toggle input {
  width: auto;
  transform: scale(1.2);
}
.scan-debug-toggle {
  background: #fff;
}
.debug-panel {
  margin-top: 16px;
  background: #0f172a;
  color: #e5e7eb;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(15, 23, 42, .18);
}
.debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #111827;
  color: #fff;
}
.mini-btn {
  width: auto;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  background: #374151;
  color: #fff;
}
.debug-panel pre {
  margin: 0;
  padding: 14px;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.45;
}

/* V7 - Debug vraiment visible à côté */
.login-page {
  display: block;
  padding: 20px;
}

.page-layout {
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(360px, 1fr);
  gap: 18px;
  align-items: start;
}

.main-card {
  width: 100%;
}

.scan-page main.page-layout {
  max-width: 1180px;
  padding: 16px;
}

.scan-main-panel {
  min-width: 0;
}

.debug-side-panel {
  display: block !important;
  position: sticky;
  top: 84px;
  margin-top: 0;
  min-height: 520px;
  max-height: calc(100vh - 110px);
}

.debug-side-panel .debug-head small {
  display: block;
  margin-top: 3px;
  color: #cbd5e1;
  font-weight: 600;
}

.debug-side-panel pre {
  max-height: calc(100vh - 190px);
  min-height: 455px;
}

.debug-panel.debug-disabled {
  background: #1f2937;
}

.debug-panel.debug-disabled pre {
  color: #9ca3af;
}

@media (max-width: 900px) {
  .page-layout {
    grid-template-columns: 1fr;
  }

  .debug-side-panel {
    position: static;
    min-height: 300px;
    max-height: none;
  }

  .debug-side-panel pre {
    min-height: 260px;
    max-height: 420px;
  }
}

.access-form {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 16px;
  background: rgba(249, 250, 251, 0.9);
}

.access-form input {
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  font-size: 20px;
  letter-spacing: 0.18em;
  text-align: center;
}

.ticket-details {
  margin: 14px 0;
  border-radius: 18px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(17, 24, 39, 0.08);
  overflow: hidden;
}

.ticket-details-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  background: #111827;
  color: #ffffff;
}

.ticket-details-head span {
  font-size: 13px;
  opacity: 0.85;
}

.ticket-details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: #e5e7eb;
}

.ticket-kpi {
  min-width: 0;
  padding: 12px 14px;
  background: #ffffff;
}

.ticket-kpi span {
  display: block;
  color: #6b7280;
  font-size: 12px;
  margin-bottom: 4px;
}

.ticket-kpi strong {
  display: block;
  color: #111827;
  font-size: 15px;
  word-break: break-word;
}

.ticket-empty {
  grid-column: 1 / -1;
  background: #fff7ed;
  color: #9a3412;
  padding: 14px 16px;
  font-weight: 700;
}

@media (max-width: 640px) {
  .ticket-details-grid {
    grid-template-columns: 1fr;
  }
}
