/* =============================================================================
   tiepdan.trolyaotoaan.vn — Giao diện kiosk tiếp dân
   Định hướng: trang nghiêm cơ quan toà án — đỏ thẫm + vàng kim + nền giấy ấm.
   Chữ lớn, tương phản cao, vùng chạm rộng cho người cao tuổi.
   ============================================================================= */

:root {
  /* Bảng màu */
  --crimson:      #8a1212;   /* đỏ thẫm chủ đạo */
  --crimson-deep: #5e0c0c;
  --gold:         #b8902f;   /* vàng kim viền */
  --gold-soft:    #d8b25a;
  --paper:        #f7f1e6;   /* nền giấy ấm */
  --paper-2:      #fffaf0;
  --card:         #fffdf8;
  --ink:          #241c16;   /* mực chữ */
  --ink-soft:     #5c5147;
  --line:         #e2d6c0;
  --ok:           #2f7d4f;
  --danger:       #b3261e;

  --r-lg: 18px;
  --r-md: 12px;
  --shadow: 0 14px 40px -18px rgba(94, 12, 12, .35), 0 2px 8px -4px rgba(0,0,0,.12);
  --shadow-soft: 0 6px 22px -14px rgba(36,28,22,.45);

  --font-display: 'Lora', Georgia, 'Times New Roman', serif;
  --font-body: 'Be Vietnam Pro', system-ui, sans-serif;

  --tap: 64px; /* chiều cao chạm tối thiểu */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  font-size: 19px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Họa tiết nền: lưới chấm rất nhạt + dải vàng trên/dưới */
.bg-ornament {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(circle at 1px 1px, rgba(138,18,18,.05) 1px, transparent 0) 0 0 / 26px 26px,
    linear-gradient(180deg, rgba(184,144,47,.10), transparent 220px),
    linear-gradient(0deg, rgba(184,144,47,.08), transparent 200px);
}

.kiosk {
  position: relative; z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 28px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================ HEADER ============================ */
.masthead {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--gold);
  position: relative;
}
.masthead::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px;
  height: 1px; background: var(--gold-soft); opacity: .5;
}
.crest {
  width: 86px; height: 86px; display: grid; place-items: center;
  color: var(--crimson);
  background: radial-gradient(circle at 50% 35%, var(--paper-2), var(--paper));
  border: 2px solid var(--gold); border-radius: 50%;
  box-shadow: var(--shadow-soft);
}
.court-name {
  font-family: var(--font-display);
  font-weight: 700; letter-spacing: .14em;
  color: var(--crimson); font-size: 15px; text-transform: uppercase;
}
.kiosk-title {
  font-family: var(--font-display);
  font-size: 30px; font-weight: 700; color: var(--ink); line-height: 1.15;
}
.kiosk-sub { color: var(--ink-soft); font-size: 16px; margin-top: 2px; }
.clock {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-size: 20px; color: var(--crimson-deep); text-align: right;
  white-space: nowrap; font-weight: 600;
}

/* ============================ TIẾN TRÌNH ============================ */
.steps {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; margin: 22px auto 6px; max-width: 460px;
}
.steps[aria-hidden="true"] { visibility: hidden; height: 0; margin: 0; overflow: hidden; }
.step-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--line); border: 2px solid var(--line);
  transition: all .35s ease;
}
.step-dot.active { background: var(--gold); border-color: var(--gold); transform: scale(1.15); }
.step-dot.done { background: var(--crimson); border-color: var(--crimson); }
.step-line { flex: 1; height: 2px; background: var(--line); max-width: 90px; }

/* ============================ SÂN KHẤU / MÀN HÌNH ============================ */
.stage { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding-top: 14px; }
.screen { display: none; width: 100%; max-width: 880px; animation: rise .45s cubic-bezier(.2,.7,.2,1); }
.screen.is-active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.screen-title {
  font-family: var(--font-display);
  font-size: 28px; font-weight: 600; color: var(--ink);
  text-align: center; margin-bottom: 8px; line-height: 1.25;
}
.screen-note { text-align: center; color: var(--ink-soft); max-width: 620px; margin: 0 auto 24px; }
.optional { color: var(--ink-soft); font-weight: 400; font-size: .8em; }
.reassure { text-align: center; color: var(--ink-soft); font-size: 15px; margin-top: 28px; }

/* ============================ CHỌN CHẾ ĐỘ ============================ */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 30px; }
.mode-card {
  cursor: pointer; text-align: center;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--r-lg);
  padding: 40px 28px; color: var(--ink);
  box-shadow: var(--shadow-soft); transition: transform .2s, border-color .2s, box-shadow .2s;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  font-family: var(--font-body);
}
.mode-card:hover, .mode-card:focus-visible {
  transform: translateY(-4px); border-color: var(--gold);
  box-shadow: var(--shadow); outline: none;
}
.mode-card:active { transform: translateY(-1px); }
.mode-art { color: var(--crimson); }
.mode-label { font-family: var(--font-display); font-size: 23px; font-weight: 600; }
.mode-desc { color: var(--ink-soft); font-size: 16px; line-height: 1.45; }

/* ============================ TRƯỜNG NHẬP ============================ */
.field { margin: 0 auto 22px; max-width: 600px; }
.field > label {
  display: block; font-weight: 600; margin-bottom: 8px; font-size: 17px; color: var(--ink);
}
.field > label em { color: var(--crimson); font-style: normal; }
input[type=text], input[type=tel] {
  width: 100%; min-height: var(--tap); padding: 0 18px;
  font-family: var(--font-body); font-size: 22px; color: var(--ink);
  background: var(--paper-2); border: 2px solid var(--line); border-radius: var(--r-md);
  transition: border-color .2s, box-shadow .2s;
}
input:focus { outline: none; border-color: var(--crimson); box-shadow: 0 0 0 4px rgba(138,18,18,.12); }
.input-voice { display: flex; gap: 10px; }
.input-voice input { flex: 1; }
.mic {
  flex: 0 0 var(--tap); width: var(--tap); height: var(--tap);
  display: grid; place-items: center; cursor: pointer;
  background: var(--card); color: var(--crimson);
  border: 2px solid var(--line); border-radius: var(--r-md);
  transition: all .2s;
}
.mic:hover { border-color: var(--gold); }
.mic.listening { background: var(--crimson); color: #fff; border-color: var(--crimson); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(138,18,18,.5); } 50% { box-shadow: 0 0 0 12px rgba(138,18,18,0); } }
.field-error { color: var(--danger); font-size: 15px; min-height: 20px; margin-top: 6px; text-align: center; }
.lookup-result { font-size: 16px; margin-top: 8px; min-height: 22px; }
.lookup-result.found { color: var(--ok); }
.lookup-result.miss { color: var(--ink-soft); }

/* ============================ TƯ CÁCH ĐƯƠNG SỰ ============================ */
.role-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; max-width: 760px; margin: 24px auto 0; }
.role-chip {
  cursor: pointer; text-align: center; padding: 22px 14px;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--r-md);
  font-family: var(--font-display); font-size: 19px; font-weight: 600; color: var(--ink);
  display: flex; flex-direction: column; gap: 4px; min-height: 96px; justify-content: center;
  transition: all .18s;
}
.role-chip small { font-family: var(--font-body); font-weight: 400; font-size: 13px; color: var(--ink-soft); }
.role-chip:hover { border-color: var(--gold); }
.role-chip.selected {
  background: var(--crimson); color: var(--paper-2); border-color: var(--crimson);
}
.role-chip.selected small { color: var(--gold-soft); }

/* ============================ CHỌN CÁN BỘ ============================ */
.search-box {
  display: flex; align-items: center; gap: 12px; max-width: 640px; margin: 0 auto 18px;
  background: var(--paper-2); border: 2px solid var(--line); border-radius: var(--r-md);
  padding: 0 16px; color: var(--ink-soft);
}
.search-box input {
  border: none; background: transparent; flex: 1; min-height: 56px; padding: 0;
  font-size: 19px; color: var(--ink);
}
.search-box input:focus { outline: none; box-shadow: none; }
.staff-list {
  max-width: 700px; margin: 0 auto; max-height: 360px; overflow-y: auto;
  display: grid; gap: 10px; padding: 4px;
}
.staff-loading { text-align: center; color: var(--ink-soft); padding: 30px; }
.staff-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px;
  cursor: pointer; text-align: left; width: 100%;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--r-md);
  padding: 16px 20px; min-height: var(--tap); transition: all .16s; font-family: var(--font-body);
}
.staff-item:hover { border-color: var(--gold); }
.staff-item.selected { border-color: var(--crimson); background: #fbf3ee; box-shadow: inset 0 0 0 1px var(--crimson); }
.staff-item .s-name { font-family: var(--font-display); font-size: 20px; font-weight: 600; color: var(--ink); }
.staff-item .s-meta { font-size: 14px; color: var(--ink-soft); margin-top: 2px; }
.staff-item .s-role-tag {
  font-size: 13px; font-weight: 600; padding: 4px 12px; border-radius: 999px;
  background: rgba(138,18,18,.08); color: var(--crimson); white-space: nowrap;
}
.staff-item .s-suggest { font-size: 12px; color: var(--gold); font-weight: 600; }
.no-zalo-note { font-size: 12px; color: var(--ink-soft); }

/* ============================ XÁC NHẬN ============================ */
.confirm-card {
  max-width: 600px; margin: 24px auto 0; background: var(--card);
  border: 2px solid var(--gold); border-radius: var(--r-lg); padding: 26px 30px;
  box-shadow: var(--shadow-soft);
}
.confirm-card div { display: flex; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px dashed var(--line); }
.confirm-card div:last-child { border-bottom: none; }
.confirm-card dt { color: var(--ink-soft); font-size: 16px; }
.confirm-card dd { font-weight: 600; text-align: right; font-size: 18px; }

/* ============================ KẾT QUẢ / PHIẾU ============================ */
.done-wrap { text-align: center; }
.done-mark { color: var(--ok); display: inline-grid; place-items: center; margin-bottom: 8px; animation: pop .5s cubic-bezier(.2,1.4,.4,1); }
.done-mark.fail { color: var(--danger); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.done-title { font-family: var(--font-display); font-size: 28px; color: var(--ink); margin-bottom: 18px; }

.ticket {
  max-width: 380px; margin: 0 auto; background: var(--paper-2);
  border: 2px solid var(--ink); border-radius: 4px; padding: 24px 26px;
  text-align: center; position: relative;
  background-image: linear-gradient(180deg, transparent 0, transparent 92%, rgba(0,0,0,.02) 100%);
}
.ticket::before, .ticket::after {
  content: ""; position: absolute; width: 22px; height: 22px; background: var(--paper);
  border-radius: 50%; top: 50%; transform: translateY(-50%);
}
.ticket::before { left: -13px; } .ticket::after { right: -13px; }
.ticket-court { font-family: var(--font-display); font-weight: 700; font-size: 13px; letter-spacing: .1em; color: var(--crimson); }
.ticket-label { font-size: 12px; letter-spacing: .28em; color: var(--ink-soft); margin: 4px 0 6px; }
.ticket-number { font-family: var(--font-display); font-size: 64px; font-weight: 700; color: var(--crimson-deep); line-height: 1; margin: 6px 0; }
.ticket-info { text-align: left; border-top: 1px dashed var(--ink); margin-top: 14px; padding-top: 12px; }
.ticket-info div { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 14px; }
.ticket-info dt { color: var(--ink-soft); } .ticket-info dd { font-weight: 600; text-align: right; }
.ticket-code { margin-top: 12px; font-size: 13px; color: var(--ink-soft); letter-spacing: .04em; }
.ticket-code strong { color: var(--ink); letter-spacing: .1em; }
.done-message { max-width: 480px; margin: 20px auto 0; color: var(--ink-soft); font-size: 16px; }

/* ============================ NÚT ============================ */
.row-actions { display: flex; gap: 16px; justify-content: space-between; margin-top: 34px; max-width: 600px; margin-left: auto; margin-right: auto; }
.row-actions.center { justify-content: center; }
.btn {
  cursor: pointer; font-family: var(--font-body); font-weight: 600; font-size: 19px;
  min-height: var(--tap); padding: 0 32px; border-radius: var(--r-md); border: 2px solid transparent;
  transition: transform .12s, filter .2s, background .2s; display: inline-flex; align-items: center; gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--crimson); color: var(--paper-2); box-shadow: var(--shadow-soft); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-lg { padding: 0 44px; font-size: 21px; }
.btn-outline { background: transparent; color: var(--crimson); border-color: var(--crimson); }
.btn-outline:hover { background: rgba(138,18,18,.06); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============================ CAMERA QUÉT ============================ */
.scanner {
  position: relative; max-width: 460px; margin: 16px auto; aspect-ratio: 4/3;
  background: #000; border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow);
  border: 3px solid var(--gold);
}
#scanVideo { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset: 18%; }
.scan-frame span { position: absolute; width: 38px; height: 38px; border: 4px solid var(--gold-soft); }
.scan-frame span:nth-child(1) { top: 0; left: 0; border-right: none; border-bottom: none; }
.scan-frame span:nth-child(2) { top: 0; right: 0; border-left: none; border-bottom: none; }
.scan-frame span:nth-child(3) { bottom: 0; left: 0; border-right: none; border-top: none; }
.scan-frame span:nth-child(4) { bottom: 0; right: 0; border-left: none; border-top: none; }
.scan-hint { text-align: center; color: var(--ink-soft); margin-bottom: 8px; }

/* ============================ FOOTER ============================ */
.kiosk-foot {
  margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 12px;
  color: var(--ink-soft); font-size: 14px;
}
.restart-link { background: none; border: none; color: var(--crimson); font-weight: 600; cursor: pointer; font-size: 14px; font-family: var(--font-body); }
.foot-sep { opacity: .5; }

/* ============================ LỚP PHỦ / IDLE ============================ */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; gap: 18px;
  background: rgba(36,28,22,.55); backdrop-filter: blur(3px); color: var(--paper-2);
  font-size: 19px; flex-direction: column;
}
.overlay { display: none; } .overlay:not([hidden]) { display: grid; }
.spinner {
  width: 56px; height: 56px; border: 5px solid rgba(255,255,255,.25);
  border-top-color: var(--gold-soft); border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.idle-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--crimson-deep); color: var(--paper-2); padding: 14px 24px; border-radius: 999px;
  box-shadow: var(--shadow); font-size: 16px;
}
.idle-toast[hidden] { display: none; }

/* ============================ RESPONSIVE (máy tính bảng dọc) ============================ */
@media (max-width: 720px) {
  body { font-size: 18px; }
  .kiosk { padding: 18px 16px 28px; }
  .masthead { grid-template-columns: auto 1fr; gap: 14px; }
  .clock { display: none; }
  .kiosk-title { font-size: 24px; }
  .mode-grid { grid-template-columns: 1fr; gap: 16px; }
  .role-grid { grid-template-columns: 1fr 1fr; }
  .screen-title { font-size: 23px; }
  .row-actions { flex-direction: column-reverse; }
  .btn { width: 100%; justify-content: center; }
}

/* ============================ IN PHIẾU ============================ */
@media print {
  body * { visibility: hidden !important; }
  .ticket, .ticket * { visibility: visible !important; }
  .ticket { position: absolute; left: 50%; top: 20mm; transform: translateX(-50%); border-color: #000; box-shadow: none; }
  .bg-ornament { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
