:root {
  --bg: #f8f5ff;
  --panel: #ffffff;
  --panel-strong: #f1eaff;
  --ink: #22162f;
  --muted: #6b5d7d;
  --line: #ddd1ef;
  --brand: #6d28d9;
  --brand-dark: #4c1d95;
  --accent: #c084fc;
  --info: #5b5bd6;
  --danger: #b42318;
  --warning: #99640f;
  --success: #147a4a;
  --shadow: 0 12px 36px rgba(34, 22, 47, 0.1);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.logo-stack {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.logo-slot {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  overflow: hidden;
}

.logo-slot.secondary {
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #2d1648;
}

.logo-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 2px;
  font-size: clamp(1.2rem, 2vw, 1.75rem);
  line-height: 1.15;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

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

.small {
  font-size: 0.9rem;
}

.status-pill,
.quota-chip,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--brand-dark);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.closed,
.badge.danger {
  color: var(--danger);
  background: #fff2ef;
  border-color: #f4c7c0;
}

.badge.warning {
  color: var(--warning);
  background: #fff7e7;
  border-color: #f1d49a;
}

.badge.success {
  color: var(--success);
  background: #ecfdf3;
  border-color: #b9e6c9;
}

.connection-panel,
.view,
.form-panel,
.scan-result,
.ticket-result,
.admin-login,
.admin-area {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.connection-panel {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 16px;
  align-items: end;
  margin-top: 14px;
  padding: 16px;
}

.main-nav,
.switcher,
.admin-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 6px;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eee7fa;
}

.nav-btn,
.switch-btn,
.admin-tab {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.nav-btn.active,
.switch-btn.active,
.admin-tab.active {
  background: var(--panel);
  color: var(--brand-dark);
  box-shadow: 0 3px 14px rgba(34, 22, 47, 0.1);
}

.identity-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4edff;
}

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

.identity-choice {
  display: grid;
  gap: 6px;
  min-height: 104px;
  padding: 14px;
  border: 1px solid #cec0e6;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.identity-choice strong {
  color: var(--brand-dark);
  font-size: 1.05rem;
}

.identity-choice span {
  color: var(--muted);
  font-size: 0.92rem;
}

.identity-choice.active {
  border-color: var(--brand);
  background: #efe5ff;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.12);
}

.guest-mode .main-nav,
.guest-mode .staff-nav,
.guest-mode .staff-only {
  display: none !important;
}

.access-links {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
}

.link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.link-row input {
  margin-top: 6px;
  font-size: 0.9rem;
}

.view {
  display: none;
  padding: 16px;
}

.view.active {
  display: block;
}

.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.summary-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.form-panel {
  padding: 16px;
  margin-top: 12px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

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

label {
  color: #332344;
  font-size: 0.92rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #cec0e6;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(47, 109, 181, 0.25);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
}

input[readonly] {
  background: #f4f0fb;
  color: var(--muted);
}

.inline-form {
  display: flex;
  gap: 8px;
}

.inline-form input {
  min-width: 0;
}

.btn {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--brand-dark);
  font-weight: 850;
}

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

.btn.warning {
  border-color: var(--accent);
  background: var(--accent);
  color: #2d1648;
}

.btn.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.btn.ghost {
  background: #f6f1ff;
}

.btn.wide {
  width: 100%;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 4px 0 6px;
}

.check-row input {
  width: 20px;
  height: 20px;
  min-height: 20px;
}

.rules-box {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid #d8c8ef;
  border-radius: 8px;
  background: #fbf8ff;
  color: var(--ink);
}

.rules-box strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.rules-box ul {
  margin: 0;
  padding-left: 18px;
}

.rules-box li {
  margin: 4px 0;
  line-height: 1.45;
}

.combo {
  position: relative;
}

.combo-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.combo-option {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #efe8fa;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.combo-option:hover,
.combo-option:focus {
  background: #f7f1ff;
}

.combo-option:disabled {
  background: #fafafa;
  color: #8f8499;
}

.combo-name {
  font-weight: 800;
}

.combo-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.ticket-card {
  width: min(480px, 100%);
  margin: 0 auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ticket-card.exporting .ticket-actions {
  display: none;
}

.ticket-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed #d6c7ec;
}

.ticket-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 900;
}

.ticket-person {
  margin: 14px 0 10px;
  font-size: 1.2rem;
  font-weight: 900;
}

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

.detail-item {
  padding: 10px;
  border: 1px solid #e7dff4;
  border-radius: 6px;
  background: #fdfcff;
}

.detail-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-value {
  display: block;
  margin-top: 2px;
  font-weight: 900;
  word-break: break-word;
}

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

.qr-box {
  display: grid;
  place-items: center;
  margin: 16px auto 8px;
  width: 208px;
  min-height: 208px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.qr-image,
.qr-box canvas {
  width: 190px;
  height: 190px;
}

.ticket-note {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px dashed #d6c7ec;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: center;
}

.ticket-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.ticket-png-preview {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed #d6c7ec;
}

.ticket-png-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.ticket-png-preview img {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  border: 1px solid #d8c8ef;
  border-radius: 8px;
  background: #fff;
}

.ticket-png-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

#qr-reader {
  width: min(460px, 100%);
  min-height: 260px;
  margin: 0 auto 12px;
  border: 1px dashed #cab9e6;
  border-radius: 8px;
  overflow: hidden;
  background: #f7f2ff;
}

.result-list,
.admin-list,
.guest-checklist {
  display: grid;
  gap: 8px;
}

.result-item,
.admin-item,
.student-item,
.guest-check-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-item {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.guest-check-item {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.guest-check-actions {
  display: grid;
  gap: 8px;
  min-width: 104px;
}

.quick-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #d8c8ef;
  border-radius: 8px;
  background: #f7f2ff;
  font-weight: 850;
}

.scan-result {
  padding: 16px;
  margin-top: 12px;
}

.scan-alert {
  padding: 12px;
  border-radius: 8px;
  background: #fff7e7;
  border: 1px solid #f1d49a;
  color: var(--warning);
  font-weight: 850;
}

.scan-loading {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f2ff;
  color: var(--brand-dark);
  font-weight: 850;
}

.admin-login {
  display: flex;
  gap: 10px;
  align-items: end;
  padding: 16px;
}

.admin-login .field {
  flex: 1;
  margin-bottom: 0;
}

.admin-area {
  padding: 14px;
}

.admin-panel {
  display: none;
}

.admin-panel.active {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.summary-card {
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.85rem;
  line-height: 1;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 170px 170px;
  gap: 8px;
  margin-bottom: 12px;
}

.admin-item-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.admin-item-title {
  font-weight: 900;
}

.admin-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.item-actions .btn {
  min-height: 36px;
  padding: 7px 10px;
  font-size: 0.9rem;
}

.student-form,
.settings-form {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fdfcff;
}

.import-summary {
  margin-top: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 100;
  transform: translateX(-50%) translateY(20px);
  min-width: min(92vw, 420px);
  padding: 12px 14px;
  border-radius: 8px;
  background: #22162f;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(19, 32, 26, 0.46);
}

.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 1.2rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 840px) {
  .connection-panel,
  .operator-panel,
  .field-grid,
  .toolbar,
  .summary-grid,
  .identity-options,
  .link-row {
    grid-template-columns: 1fr;
  }

  .topbar,
  .view-head,
  .admin-login {
    align-items: stretch;
    flex-direction: column;
  }

  .main-nav,
  .switcher,
  .admin-tabs {
    grid-auto-flow: row;
  }

  .inline-form {
    flex-direction: column;
  }

  .result-item {
    grid-template-columns: 1fr;
  }

  .guest-check-item {
    grid-template-columns: 1fr;
  }

  .guest-check-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 10px;
  }

  .brand {
    align-items: flex-start;
  }

  .logo-stack {
    flex-direction: column;
    gap: 5px;
  }

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

  .logo-slot.secondary {
    width: 38px;
    height: 38px;
  }

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

@media print {
  @page {
    margin: 12mm;
  }

  body {
    background: #fff;
  }

  body * {
    visibility: hidden !important;
  }

  .ticket-card,
  .ticket-card * {
    visibility: visible !important;
  }

  .ticket-actions,
  .ticket-png-preview,
  .toast {
    display: none !important;
  }

  .ticket-card {
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    max-width: 480px;
    margin: 0;
    padding: 14px;
    box-shadow: none;
  }

  .qr-image,
  .qr-box canvas {
    width: 190px !important;
    height: 190px !important;
  }
}
