:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #697386;
  --line: #d9e0e8;
  --soft: #f4f7fb;
  --panel: #ffffff;
  --brand: #146c94;
  --brand-dark: #0f4c75;
  --ok: #16784f;
  --warn: #9a5b00;
  --bad: #a33737;
  --shadow: 0 18px 40px rgba(22, 32, 42, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px 1fr;
  background: var(--soft);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.validate-page {
  display: block;
  background: #102a43;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #102a43;
}

.login-screen.hidden {
  display: none;
}

.login-panel {
  width: min(100%, 420px);
  display: grid;
  gap: 18px;
  padding: 26px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
}

.login-brand {
  color: var(--ink);
}

.login-brand small {
  color: var(--muted);
}

.login-error {
  min-height: 22px;
  color: var(--bad);
  font-weight: 700;
}

.validate-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.validate-card {
  width: min(100%, 520px);
  display: grid;
  gap: 22px;
  padding: 26px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
}

.validate-brand small {
  color: var(--muted);
}

.validate-form {
  display: grid;
  gap: 14px;
}

.public-result {
  min-height: 128px;
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
}

.public-result.good {
  border-color: rgba(22, 120, 79, 0.35);
  background: #eefaf4;
  color: #124f36;
}

.public-result.warn {
  border-color: rgba(154, 91, 0, 0.35);
  background: #fff7e8;
  color: #6f4200;
}

.public-result.bad {
  border-color: rgba(163, 55, 55, 0.35);
  background: #fff1f1;
  color: #842424;
}

.public-result strong,
.public-result small,
.public-result span {
  display: block;
}

.public-result strong {
  color: var(--ink);
  font-size: 24px;
}

.public-status {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

.public-result dl {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
}

.public-result dl div {
  display: grid;
  gap: 2px;
}

.public-result dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.public-result dd {
  margin: 0;
  color: var(--ink);
  font-weight: 750;
}

button,
input,
select,
textarea {
  font: inherit;
}

.sidebar {
  min-height: 100vh;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: #102a43;
  color: #f7fbff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f5b84b;
  color: #102a43;
  font-weight: 800;
}

.brand-logo {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
  padding: 5px;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.sidebar-footer {
  color: #b9c8d8;
}

.sidebar-logout {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  cursor: pointer;
}

.sidebar-logout:hover {
  background: rgba(255, 255, 255, 0.16);
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  background: transparent;
  color: #dce8f3;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: #1f4568;
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.shell {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 22px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

h1 {
  margin: 0 0 4px;
  font-size: 30px;
  line-height: 1.2;
}

p {
  margin: 0;
  color: var(--muted);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  width: min(100%, 1080px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-weight: 650;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(20, 108, 148, 0.18);
  border-color: var(--brand);
}

input[readonly] {
  background: #edf2f7;
  color: #526173;
  cursor: not-allowed;
}

.wide {
  grid-column: 1 / -1;
}

.action-row,
.toolbar,
.dialog-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.check {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
}

.check input {
  width: 18px;
  height: 18px;
}

.primary-button,
.ghost-button,
.action-button {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ticket-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.action-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--brand);
  color: #fff;
}

.action-button:hover {
  background: var(--brand-dark);
}

.button-icon {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.18);
  line-height: 1;
}

.button-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar {
  margin-bottom: 18px;
}

.toolbar input {
  max-width: 560px;
}

.toolbar select {
  max-width: 190px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #526173;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.status {
  display: inline-flex;
  min-width: 78px;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 13px;
  font-weight: 800;
  text-transform: capitalize;
}

.status.valid {
  background: #e4f6ee;
  color: var(--ok);
}

.status.used {
  background: #fff0d4;
  color: var(--warn);
}

.status.cancelled {
  background: #ffe5e5;
  color: var(--bad);
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.mini-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.mini-button:hover {
  border-color: var(--brand);
}

.checkin-panel {
  display: grid;
  max-width: 640px;
  gap: 16px;
}

.scanner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.scanner-box {
  min-height: 260px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed #9aa8b7;
  border-radius: 8px;
  background: #f8fafc;
}

.scanner-box:empty::before {
  content: "Camera preview will appear here";
  color: var(--muted);
}

.scanner-box video {
  width: 100%;
  max-height: 420px;
  object-fit: cover;
}

.scanner-note {
  color: var(--muted);
}

.scanner-note.error {
  color: var(--bad);
  font-weight: 700;
}

.result {
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 16px;
  background: #f8fafc;
  line-height: 1.55;
}

.result.good {
  border-color: #9ad7bc;
  background: #ecfdf5;
}

.result.bad {
  border-color: #f0a4a4;
  background: #fff1f1;
}

dialog {
  width: min(860px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.ticket-preview {
  padding: 28px;
  background: #fff;
}

.ticket-card {
  border: 2px solid #102a43;
  border-radius: 8px;
  overflow: hidden;
}

.ticket-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 30px;
  background: #102a43;
  color: #fff;
}

.ticket-brand {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.ticket-logo {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
  padding: 7px;
}

.ticket-head h2 {
  margin: 0 0 12px;
  font-size: 32px;
  line-height: 1.15;
}

.ticket-head p {
  color: #d7e5f0;
  font-size: 17px;
}

.ticket-head strong {
  display: block;
  font-size: 18px;
  text-align: right;
}

.ticket-body {
  display: grid;
  grid-template-columns: 1fr 250px;
  gap: 34px;
  padding: 32px;
}

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

.ticket-details span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  text-transform: uppercase;
}

.ticket-details strong {
  display: block;
  margin-top: 6px;
  font-size: 21px;
}

.qr-box {
  display: grid;
  place-items: center;
  gap: 12px;
  text-align: center;
}

.qr-box img {
  width: 230px;
  height: 230px;
  border: 1px solid var(--line);
}

.qr-box strong {
  font-size: 18px;
}

.ticket-foot {
  border-top: 1px dashed #9aa8b7;
  padding: 20px 30px;
  color: var(--muted);
  font-size: 17px;
}

.dialog-topbar {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

@media (max-width: 860px) {
  body {
    grid-template-columns: 1fr;
  }

  .login-screen {
    min-height: 100dvh;
    padding: 18px;
  }

  .login-panel {
    width: min(100%, 390px);
    padding: 24px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    min-height: 0;
    height: auto;
    padding: 12px 14px;
    gap: 12px;
    box-shadow: 0 8px 20px rgba(15, 42, 67, 0.16);
  }

  .brand-logo {
    width: 40px;
    height: 40px;
  }

  .brand strong {
    font-size: 15px;
  }

  .brand small {
    font-size: 12px;
  }

  .sidebar-logout {
    width: auto;
    padding: 9px 12px;
    font-size: 14px;
    white-space: nowrap;
  }

  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    padding: 8px;
    background: #ffffff;
    border-top: 1px solid var(--line);
    box-shadow: 0 -12px 30px rgba(15, 23, 42, 0.12);
  }

  .nav-item {
    width: 100%;
    min-height: 44px;
    padding: 8px 6px;
    border-radius: 8px;
    color: #28445f;
    text-align: center;
    white-space: normal;
    line-height: 1.15;
  }

  .nav-item:hover,
  .nav-item.active {
    background: #e7f1f8;
    color: #102a43;
  }

  .sidebar-footer {
    margin-top: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    font-size: 12px;
  }

  .sidebar-footer span {
    border-radius: 8px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.08);
    text-align: center;
    white-space: nowrap;
  }

  .shell {
    padding: 16px 12px 92px;
  }

  .topbar,
  .action-row,
  .toolbar,
  .dialog-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .toolbar input,
  .toolbar select {
    max-width: none;
    min-height: 46px;
  }

  .ticket-actions {
    justify-content: stretch;
  }

  .action-button {
    justify-content: center;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  dialog {
    width: min(980px, calc(100vw - 16px));
  }

  .ticket-preview {
    overflow-x: hidden;
    padding: 10px;
  }

  .ticket-card {
    width: 100%;
    max-width: none;
  }

  .ticket-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(116px, auto);
    align-items: center;
    gap: 12px;
    padding: 16px;
  }

  .ticket-brand {
    align-items: center;
  }

  .ticket-logo {
    width: 44px;
    height: 44px;
  }

  .ticket-head h2 {
    font-size: 19px;
  }

  .ticket-head p {
    font-size: 13px;
  }

  .ticket-head strong {
    max-width: 126px;
    overflow-wrap: anywhere;
    font-size: 13px;
    line-height: 1.15;
    text-align: right;
  }

  .ticket-head > div:last-child {
    display: grid;
    justify-items: end;
    gap: 4px;
    min-width: 116px;
  }

  .ticket-head > div:last-child p {
    line-height: 1.15;
    text-align: right;
  }

  .ticket-body {
    grid-template-columns: minmax(0, 1fr) 150px;
    gap: 16px;
    padding: 16px;
  }

  .ticket-details {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 14px;
  }

  .ticket-details span {
    font-size: 10px;
  }

  .ticket-details strong {
    font-size: 14px;
  }

  .qr-box img {
    width: 140px;
    height: 140px;
  }

  .ticket-foot {
    padding: 12px 16px;
    font-size: 13px;
  }
}

@media (max-width: 520px) {
  .nav-item {
    font-size: 14px;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .sidebar-logout {
    width: 100%;
  }

  .sidebar-footer {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .ticket-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .ticket-head {
    grid-template-columns: minmax(0, 1fr) 104px;
    gap: 8px;
  }

  .ticket-brand {
    gap: 10px;
  }

  .ticket-head h2 {
    font-size: 17px;
  }

  .ticket-head strong {
    max-width: 104px;
    font-size: 12px;
  }

  .ticket-head > div:last-child {
    min-width: 104px;
  }

  .ticket-head > div:last-child p {
    font-size: 12px;
  }

  .ticket-card {
    width: 100%;
  }

  .ticket-body {
    grid-template-columns: minmax(0, 1fr) 112px;
    gap: 10px;
    padding: 12px;
  }

  .qr-box img {
    width: 104px;
    height: 104px;
  }

  .qr-box strong {
    font-size: 12px;
  }

  .ticket-details {
    gap: 10px;
  }

  .ticket-details strong {
    font-size: 13px;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  html,
  body {
    width: auto;
    min-height: 0;
    display: block;
    background: #fff;
  }

  body * {
    visibility: hidden !important;
  }

  #ticketDialog,
  #ticketDialog * {
    visibility: visible !important;
  }

  #ticketDialog {
    position: absolute;
    inset: auto;
    top: 0;
    left: 0;
    display: block !important;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    background: #fff;
  }

  .ticket-preview {
    width: 100%;
    padding: 0;
  }

  .ticket-card {
    width: 100%;
    max-width: 260mm;
    margin: 0 auto;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .ticket-head {
    padding: 12mm 10mm;
  }

  .ticket-body {
    grid-template-columns: 1fr 66mm;
    gap: 12mm;
    padding: 10mm;
  }

  .ticket-details {
    gap: 8mm 10mm;
  }

  .qr-box img {
    width: 60mm;
    height: 60mm;
  }

  .ticket-foot {
    padding: 7mm 10mm;
  }

  .dialog-topbar {
    display: none !important;
  }
}
