/* Ticket Scanner - web demo. Same look as the real door console:
   simple red / white / blue, black text, colour always paired with an icon + words. */

:root {
  --red: #b22234;
  --red-dark: #7a1620;
  --blue: #1b4bab;
  --blue-dark: #12357d;
  --green: #137333;
  --black: #111111;
  --paper: #f4f5f7;
  --muted: #555b63;
  --line: #d9dde4;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--black);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

button {
  font: inherit; cursor: pointer; font-weight: 700;
  border-radius: 10px; border: 2px solid var(--black);
  background: #fff; color: var(--black);
  padding: 12px 16px; min-height: 46px;
  box-shadow: inset -2px -2px 0 rgba(0,0,0,.18), inset 2px 2px 0 rgba(255,255,255,.9);
  transition: transform .05s linear, box-shadow .05s linear;
  -webkit-tap-highlight-color: transparent;
}
button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: inset 2px 2px 0 rgba(0,0,0,.22), inset -2px -2px 0 rgba(255,255,255,.4);
}
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.danger { border-color: var(--red); color: var(--red); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

input, select {
  font: inherit; width: 100%; min-width: 0;
  border: 2px solid var(--line); border-radius: 10px;
  padding: 12px 14px; background: #fff; color: var(--black);
}
label { display: block; font-weight: 700; font-size: .9rem; margin: 12px 0 6px; }

/* ---------- app frame: fills the iframe / phone screen ---------- */
#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; max-height: 100%; min-height: 0; position: relative; }
#main { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
#view-tickets, #view-door { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 14px 16px 20px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* ---------- top bar + hamburger ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px;
  background: var(--blue); color: #fff; flex: none;
}
.flag {
  width: 36px; height: 24px; border-radius: 3px; flex: none;
  background: repeating-linear-gradient(var(--red) 0 3.4px, #fff 3.4px 6.8px);
  position: relative; overflow: hidden; border: 1px solid rgba(255,255,255,.6);
}
.flag::before { content: ""; position: absolute; left: 0; top: 0; width: 42%; height: 53%; background: var(--blue-dark); }
.tb-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.tb-title .evt { font-weight: 800; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-title .door { font-size: .8rem; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.count {
  font-weight: 800; font-size: 1rem; white-space: nowrap;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.5); border-radius: 999px; padding: 4px 12px;
}
.menu-btn {
  width: 46px; height: 42px; min-height: 0; padding: 0; flex: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  background: transparent; border-color: rgba(255,255,255,.75); box-shadow: none;
}
.menu-btn span { display: block; width: 22px; height: 3px; background: #fff; border-radius: 2px; }
.menu {
  position: absolute; top: 58px; right: 10px; z-index: 50;
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
  background: #fff; border: 2px solid var(--black); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); min-width: 220px;
}
.menu button { text-align: left; }

/* ---------- tabs ---------- */
.tabs { display: flex; flex: none; background: #fff; border-bottom: 2px solid var(--line); }
.tabs button {
  flex: 1; border: 0; border-radius: 0; box-shadow: none; background: #fff;
  padding: 10px 6px; min-height: 44px; font-size: 1rem; color: var(--muted);
  border-bottom: 4px solid transparent; margin-bottom: -2px;
}
.tabs button[aria-selected="true"] { color: var(--blue); border-bottom-color: var(--blue); }

/* ---------- scan ---------- */
.camera-wrap {
  position: relative; flex: 1; min-height: 170px; background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#video { width: 100%; height: 100%; object-fit: cover; }
.reticle {
  position: absolute; width: min(64%, 62vh, 300px); aspect-ratio: 1;
  border: 5px solid rgba(255,255,255,.95); border-radius: 22px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none;
}
.hint {
  position: absolute; bottom: 12px; left: 0; right: 0; text-align: center;
  color: #fff; font-weight: 700; text-shadow: 0 1px 6px rgba(0,0,0,.8); pointer-events: none;
}
.cam-idle {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 16px;
  background: var(--blue-dark); color: #fff; text-align: center; overflow-y: auto;
}
.cam-idle strong { font-size: 1.15rem; }
.cam-idle .small { max-width: 44ch; opacity: .95; }
.cam-idle button { min-width: 240px; max-width: 100%; }
.cam-idle button.primary { background: #fff; color: var(--blue-dark); border-color: #fff; }
.cam-idle button:not(.primary) { background: transparent; color: #fff; border-color: rgba(255,255,255,.8); box-shadow: none; }

.controls { flex: none; background: #fff; border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; min-width: 0; }
.manual-row { display: flex; gap: 8px; }
.manual-row input { flex: 1; text-transform: uppercase; letter-spacing: 2px; font-weight: 700; }
.manual-row button { flex: none; }
.stat-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .95rem; }
.stat-row b { font-size: 1.1rem; }
.small-btn { padding: 6px 12px; min-height: 38px; font-size: .88rem; }

/* result overlay: covers the whole scan view */
#result {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  text-align: center; padding: 18px; color: #fff; overflow-y: auto;
}
#result > :first-child { margin-top: auto; }
#result > :last-child { margin-bottom: auto; }
#result.green { background: var(--green); }
#result.red   { background: var(--red); }
#result.used  { background: var(--red-dark); }
#result.dark  { background: #1c1c1c; }
#result svg { width: min(120px, 22vh); height: min(120px, 22vh); flex: none; }
#result .title { font-size: clamp(2.2rem, 11vw, 4.8rem); font-weight: 900; letter-spacing: 1px; margin: 4px 0 2px; line-height: 1.05; }
#result .msg { font-size: 1.2rem; max-width: 30ch; }
#result .admission { font-size: 1.5rem; font-weight: 900; text-transform: uppercase; margin-top: 8px; }
#result .detail { margin-top: 8px; font-size: 1.05rem; opacity: .97; }
#result .actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#result button { background: #fff; color: var(--black); border-color: #fff; min-width: 140px; }

/* ---------- wallet ---------- */
.note { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--blue); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; font-size: .95rem; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.row-actions > button { flex: 1 1 180px; }
.wallet { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tkt {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  background: #fff; border: 2px solid var(--black); border-radius: 12px; padding: 10px 8px 8px;
  font-weight: 400; min-height: 0; box-shadow: none; position: relative;
}
.tkt .qr { width: 100%; max-width: 150px; aspect-ratio: 1; }
.tkt .qr svg { width: 100%; height: 100%; display: block; }
.tkt .no { font-weight: 900; font-size: 1.05rem; letter-spacing: .5px; }
.tkt .type { font-size: .85rem; }
.tkt .st { font-size: .75rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.tkt .st.ok { color: var(--green); border-color: var(--green); }
.tkt .st.in { color: var(--red-dark); border-color: var(--red-dark); }
.tkt .st.other { color: var(--black); border-color: var(--black); }
.tkt.other { border-style: dashed; }

/* ---------- door ---------- */
.door-card { background: #fff; border: 2px solid var(--black); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; text-align: center; }
.big-count { font-size: 3.4rem; font-weight: 900; line-height: 1; }
.big-count small { font-size: 1.6rem; color: var(--muted); margin-left: 4px; }
.bar { height: 14px; background: #e5e8ee; border-radius: 999px; overflow: hidden; margin: 10px 0 8px; border: 1px solid var(--line); }
.bar span { display: block; height: 100%; width: 0; background: var(--green); }
.by-type { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; font-size: .92rem; }
.by-type span { border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.h2 { font-size: 1.05rem; margin: 6px 0 8px; }
.recent { list-style: none; margin: 0; padding: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.recent li { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid #eef1f6; font-size: .92rem; flex-wrap: wrap; }
.recent li:last-child { border-bottom: 0; }
.recent .t { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 5.5em; }
.recent .n { font-weight: 800; flex: 1; min-width: 6em; overflow-wrap: anywhere; }
.recent .d { color: var(--muted); font-size: .82rem; }
.pill { padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 800; border: 1.5px solid currentColor; white-space: nowrap; }
.pill.admit { color: var(--green); }
.pill.used { color: var(--red-dark); }
.pill.bad { color: var(--red); }
.pill.undo { color: var(--black); }

/* ---------- footer ---------- */
.foot { flex: none; text-align: center; font-size: .78rem; color: var(--muted); padding: 6px 12px; background: var(--paper); border-top: 1px solid var(--line); }

/* ---------- dialogs ---------- */
.dlg-back {
  position: fixed; inset: 0; z-index: 80; background: rgba(17,17,17,.6);
  display: flex; align-items: center; justify-content: center; padding: 12px;
}
.dlg {
  position: relative; background: #fff; border: 2px solid var(--black); border-radius: 14px;
  width: min(520px, 100%); max-height: 100%; overflow-y: auto; padding: 16px 16px 18px;
}
.dlg h2 { margin: 0 44px 10px 0; font-size: 1.15rem; }
.dlg-x {
  position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; min-height: 0; padding: 0;
  font-size: 1.6rem; line-height: 1; border-width: 2px; box-shadow: none;
}
.dlg p { margin: 0 0 10px; }
.dlg .big-qr { width: min(100%, 320px, 52vh); aspect-ratio: 1; margin: 6px auto 8px; }
.dlg .big-qr svg { width: 100%; height: 100%; display: block; }
.dlg .center { text-align: center; }
.dlg .tno { font-size: 1.6rem; font-weight: 900; letter-spacing: 1px; }
.sim-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.sim-list button { display: flex; flex-direction: column; align-items: flex-start; text-align: left; padding: 8px 10px; }
.sim-list button small { font-weight: 400; font-size: .8rem; }
.sim-list button.used { border-color: var(--red-dark); }
.sim-list button.used small { color: var(--red-dark); font-weight: 700; }
.sim-list button.odd { border-style: dashed; }
.dlg .actions { display: flex; gap: 8px; margin-top: 12px; }
.dlg .actions button { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 90;
  background: var(--black); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 700;
  max-width: calc(100% - 32px); text-align: center;
}

#printSheet { display: none; }

/* ---------- phones held sideways: camera left, controls right ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  .topbar { padding-top: 4px; padding-bottom: 4px; }
  .menu-btn { height: 36px; }
  .menu { top: 46px; }
  .tabs button { min-height: 36px; padding: 6px; }
  #view-scan { flex-direction: row; }
  .camera-wrap { min-height: 0; }
  .controls { width: min(46%, 380px); border-top: 0; border-left: 1px solid var(--line); justify-content: center; overflow-y: auto; }
  .btn-row { flex-wrap: wrap; }
  .btn-row > * { flex: 1 1 130px; }
  .foot { padding: 3px 12px; }
  .cam-idle { gap: 6px; padding: 10px; }
  .cam-idle button { min-width: 0; }
  #result { padding: 10px 18px; }
  #result svg { width: 56px; height: 56px; }
  #result .title { font-size: clamp(2rem, 13vh, 3.6rem); }
  #result .msg { font-size: 1.05rem; max-width: 40ch; }
  #result .admission { font-size: 1.2rem; margin-top: 4px; }
  #result .detail { margin-top: 4px; }
  #result .actions { margin-top: 10px; }
}

@media (max-width: 360px) {
  .count { font-size: .9rem; padding: 3px 8px; }
  .btn-row { flex-wrap: wrap; }
}

/* ---------- print: only the ticket sheet ---------- */
@media print {
  @page { margin: 12mm; }
  html, body { height: auto; overflow: visible; background: #fff; }
  #app, #dlgBack, #toast { display: none !important; }
  #printSheet { display: block !important; }
  .ps-head { font: 700 14pt "Segoe UI", Arial, sans-serif; margin-bottom: 6mm; }
  .ps-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5mm; }
  .ps-t {
    border: 1.5pt dashed #000; border-radius: 3mm; padding: 4mm; text-align: center;
    break-inside: avoid; page-break-inside: avoid; font-family: "Segoe UI", Arial, sans-serif;
  }
  .ps-t .ev { font-weight: 800; font-size: 11pt; }
  .ps-t .qr { width: 42mm; height: 42mm; margin: 2mm auto; }
  .ps-t .qr svg { width: 100%; height: 100%; display: block; }
  .ps-t .no { font-weight: 900; font-size: 13pt; letter-spacing: .5pt; }
  .ps-t .ty { font-size: 10pt; }
  .ps-t .fine { font-size: 7.5pt; color: #333; margin-top: 1.5mm; }
}
