:root {
  color-scheme: light;
  --text: #18212f;
  --muted: #637083;
  --border: #dce2e9;
  --border-strong: #b8c3d1;
  --surface: #ffffff;
  --surface-soft: #f5f7fa;
  --primary: #175cd3;
  --primary-dark: #124aa9;
  --primary-soft: #edf4ff;
  --success: #087a55;
  --success-soft: #ebfaf4;
  --error: #b42318;
  --error-soft: #fff1f0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
}

.header-content {
  display: flex;
  width: min(1120px, calc(100% - 40px));
  min-height: 68px;
  margin: auto;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.brand-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 9px;
  color: white;
  background: var(--primary);
}

.brand-icon svg {
  width: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.mode-badge {
  display: inline-flex;
  padding: 7px 11px;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: #475467;
  background: white;
  font-size: 13px;
  font-weight: 600;
}

.mode-badge > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #12a474;
}

main {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 80px;
}

.intro {
  padding: 62px 0 48px;
  text-align: center;
}

.kicker {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 13px;
  font-size: clamp(32px, 5vw, 46px);
  line-height: 1.16;
  letter-spacing: -.035em;
}

.intro > p:not(.kicker) {
  max-width: 620px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 17px;
}

.progress {
  display: grid;
  max-width: 720px;
  margin: 38px auto 0;
  padding: 0;
  grid-template-columns: repeat(3, 1fr);
  list-style: none;
}

.progress li {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 7px;
  color: #8a96a6;
  font-size: 13px;
  text-align: center;
}

.progress li:not(:last-child)::after {
  content: "";
  position: absolute;
  z-index: 0;
  top: 14px;
  left: calc(50% + 20px);
  width: calc(100% - 40px);
  height: 2px;
  background: var(--border);
}

.progress li > span {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  z-index: 1;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--surface-soft);
  font-weight: 700;
}

.progress li.active { color: var(--primary); }
.progress li.active > span { border-color: var(--primary); color: var(--primary); background: white; }
.progress li.complete { color: var(--success); }
.progress li.complete > span { border-color: var(--success); color: white; background: var(--success); }
.progress li.complete:not(:last-child)::after { background: #84d6bb; }

.workflow-step { margin-bottom: 54px; scroll-margin-top: 90px; }

.step-heading {
  display: flex;
  margin-bottom: 20px;
  align-items: flex-start;
  gap: 14px;
}

.step-heading.compact { margin-bottom: 18px; }

.step-number, .success-check {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 14px;
  font-weight: 800;
}

.success-check { color: white; background: var(--success); }

.step-heading h2 {
  margin-bottom: 3px;
  font-size: 22px;
  line-height: 1.35;
  letter-spacing: -.015em;
}

.step-heading p { margin-bottom: 0; color: var(--muted); font-size: 14px; }

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

.catalog-status { color: var(--muted); margin-bottom: 10px; }
#reload-catalog { margin-bottom: 16px; }

.ticket-card {
  position: relative;
  min-height: 248px;
  padding: 22px 19px 18px;
  overflow: hidden;
  text-align: left;
  border: 2px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.ticket-card:hover:not(:disabled) {
  border-color: var(--border-strong);
  box-shadow: 0 7px 22px rgba(24, 33, 47, .08);
  transform: translateY(-2px);
}

.ticket-card:focus-visible { outline: 3px solid rgba(23, 92, 211, .25); outline-offset: 2px; }

.ticket-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 92, 211, .1);
}

.ticket-card:disabled { cursor: wait; opacity: .7; }

.ticket-accent {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 6px;
}

.blue { background: #4b7bec; }
.green { background: #20a779; }
.violet { background: #8659d4; }
.orange { background: #e68a2e; }
.gray { background: #8b96a5; }

.ticket-check {
  position: absolute;
  top: 16px;
  right: 16px;
  display: none;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

.ticket-card.selected .ticket-check { display: grid; }

.ticket-category {
  display: block;
  margin: 4px 35px 9px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.ticket-card > strong {
  display: block;
  margin-bottom: 22px;
  font-size: 22px;
  letter-spacing: -.02em;
}

.ticket-detail { display: grid; gap: 11px; color: #566477; font-size: 13px; }

.ticket-detail > span { display: flex; align-items: flex-start; gap: 8px; }

.ticket-detail svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: #7b8797;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.45;
}

.choose-label {
  position: absolute;
  right: 19px;
  bottom: 17px;
  left: 19px;
  display: flex;
  justify-content: space-between;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

.form-card {
  max-width: 850px;
  margin-left: 46px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(24, 33, 47, .05);
}

.selected-ticket {
  display: flex;
  margin-bottom: 26px;
  padding: 14px 16px;
  align-items: center;
  gap: 12px;
  border: 1px solid #b6dfd1;
  border-radius: 10px;
  background: var(--success-soft);
}

.selected-ticket.empty { border-color: var(--border); background: var(--surface-soft); }

.selected-icon {
  display: grid;
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--success);
  font-size: 13px;
  font-weight: 800;
}

.selected-ticket.empty .selected-icon { color: #8995a5; background: #e3e7ec; }

.selected-ticket > div { display: grid; min-width: 0; }
.selected-ticket > div span { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.selected-ticket > div strong { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.selected-ticket > button { margin-left: auto; border: 0; color: var(--primary); background: transparent; font-size: 13px; font-weight: 700; cursor: pointer; }
.selected-ticket > button:hover { text-decoration: underline; }

.android-reader {
  margin-bottom: 26px;
  padding: 20px;
  border: 1px solid #bfd1ef;
  border-radius: 11px;
  background: #f7faff;
}

.reader-heading {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
}

.phone-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 9px;
  color: var(--primary);
  background: var(--primary-soft);
}

.phone-icon svg { width: 22px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.7; }
.reader-heading h3 { margin: 0 0 3px; font-size: 16px; }
.reader-heading p { margin: 0; color: var(--muted); font-size: 12px; }

.reader-state {
  display: inline-flex;
  padding: 5px 9px;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: white;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.reader-state > span { width: 7px; height: 7px; border-radius: 50%; background: #98a2b3; }
.reader-state.connected { border-color: #b6dfd1; color: var(--success); }
.reader-state.connected > span, .reader-state.received > span { background: #12a474; }
.reader-state.received { border-color: #84d6bb; color: var(--success); background: var(--success-soft); }
.reader-state.error, .reader-state.disconnected { color: var(--error); }
.reader-state.error > span, .reader-state.disconnected > span { background: var(--error); }
.reader-state.connecting > span { animation: blink .7s alternate infinite; }

.pairing-area {
  display: flex;
  margin-top: 17px;
  padding: 14px 16px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid #d6e1f3;
  border-radius: 9px;
  background: white;
}

.pairing-area > div:first-child { display: grid; gap: 2px; }
.pairing-label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.pairing-code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 27px; line-height: 1.15; letter-spacing: .16em; }
.pairing-actions { display: flex; gap: 7px; }

.small-button {
  min-height: 35px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: #344054;
  background: white;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.small-button:hover { border-color: #8996a7; background: var(--surface-soft); }
.small-button:focus-visible { outline: 3px solid rgba(23, 92, 211, .2); outline-offset: 2px; }

.reader-steps {
  display: grid;
  margin: 14px 0 0;
  padding: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  list-style: none;
}

.reader-steps li { display: flex; align-items: center; gap: 7px; color: #475467; font-size: 11px; }
.reader-steps li span { display: grid; width: 21px; height: 21px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: var(--primary); background: var(--primary-soft); font-size: 10px; font-weight: 800; }
.reader-network-hint { margin: 11px 0 0; color: var(--muted); font-size: 11px; }
.reader-network-hint.warning { padding-left: 9px; border-left: 3px solid #e6a02e; color: #795313; }

.label-row { display: flex; margin-bottom: 8px; align-items: center; justify-content: space-between; }
.label-row label { font-size: 14px; font-weight: 700; }
.label-row span { color: var(--muted); font-size: 12px; }
.label-row span.complete { color: var(--success); font-weight: 700; }

.token-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }

.token-actions { display: flex; gap: 8px; }

input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background: white;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  letter-spacing: .01em;
}

input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23, 92, 211, .12); }
input[aria-invalid="true"] { border-color: var(--error); }
input:disabled { background: var(--surface-soft); }

.secondary-button {
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: #344054;
  background: white;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.secondary-button:hover:not(:disabled) { border-color: #8996a7; background: var(--surface-soft); }
.secondary-button:focus-visible, .primary-button:focus-visible { outline: 3px solid rgba(23, 92, 211, .25); outline-offset: 2px; }
.secondary-button:disabled { cursor: not-allowed; opacity: .55; }

.field-help, .field-error { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.field-error { color: var(--error); font-weight: 600; }

.issuance-controls { margin: 24px 0; padding: 20px; border: 1px solid var(--border, #d6dce5); border-radius: 12px; }
.issuance-controls h3 { margin: 0 0 8px; }
.issuance-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.issuance-fields label { display: grid; gap: 6px; font-weight: 600; }
.issuance-fields input, .issuance-fields select { width: 100%; min-width: 0; padding: 10px; border: 1px solid #b9c3d0; border-radius: 8px; font: inherit; }
@media (max-width: 700px) { .issuance-fields { grid-template-columns: 1fr; } }

.unissued-warning { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; padding: 16px; border: 1px solid #e5b45c; border-radius: 10px; background: #fff8e9; }
.unissued-warning p { margin: 0; line-height: 1.5; }
.unissued-warning .secondary-button { flex: none; }
@media (max-width: 700px) { .unissued-warning { align-items: stretch; flex-direction: column; } }

.save-area {
  display: grid;
  margin-top: 27px;
  padding-top: 22px;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  border-top: 1px solid var(--border);
}

.primary-button {
  display: inline-flex;
  min-width: 190px;
  min-height: 48px;
  padding: 0 20px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 8px;
  color: white;
  background: var(--primary);
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}

.primary-button:hover:not(:disabled) { background: var(--primary-dark); }
.primary-button:disabled { color: #8b96a5; background: #e2e6eb; cursor: not-allowed; }
.primary-button svg { width: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.primary-button.loading svg { animation: blink .7s alternate infinite; }

.save-area p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }

.status {
  display: none;
  margin-top: 18px;
  padding: 14px 16px;
  align-items: flex-start;
  gap: 11px;
  border: 1px solid;
  border-radius: 9px;
  font-size: 13px;
}

.status.visible { display: flex; }
.status.success { border-color: #adddcd; color: #075d42; background: var(--success-soft); }
.status.error { border-color: #fac5c1; color: #8d1b13; background: var(--error-soft); }
.status-icon { display: grid; width: 21px; height: 21px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: white; background: currentColor; font-size: 11px; font-weight: 800; }
.status.success .status-icon { background: var(--success); }
.status.error .status-icon { background: var(--error); }
.status > span:last-child { display: grid; }
.status strong { color: inherit; font-size: 14px; }

.nfc-controls p { margin-bottom: 0; color: var(--muted); font-size: 13px; }

.saved-section {
  max-width: 850px;
  margin: 0 0 0 46px;
  padding: 26px 28px;
  border: 1px solid #b9dfd2;
  border-radius: 14px;
  background: #f7fffb;
}

.saved-list { display: grid; gap: 8px; }

.saved-item {
  display: grid;
  padding: 12px 14px;
  grid-template-columns: 9px minmax(130px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  border: 1px solid #d5ebe3;
  border-radius: 9px;
  background: white;
}

.assignments-message {
  margin: 0;
  padding: 16px;
  border: 1px dashed #b9d8cd;
  border-radius: 9px;
  color: var(--muted);
  background: white;
  font-size: 13px;
  text-align: center;
}

.assignments-message.error { border-color: #fac5c1; color: var(--error); background: var(--error-soft); }

.saved-dot { width: 9px; height: 35px; border-radius: 5px; }
.saved-item > div { display: grid; }
.saved-item > div strong { font-size: 14px; }
.saved-item > div span { color: var(--muted); font-size: 12px; }
.saved-item code { color: #475467; font-size: 12px; }

.remove-button {
  padding: 7px 10px;
  border: 1px solid #efb2ad;
  border-radius: 7px;
  color: var(--error);
  background: white;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.remove-button:hover:not(:disabled) { border-color: var(--error); background: var(--error-soft); }
.remove-button:focus-visible { outline: 3px solid rgba(180, 35, 24, .15); outline-offset: 2px; }
.remove-button:disabled { cursor: wait; opacity: .6; }

footer {
  display: flex;
  width: min(1120px, calc(100% - 40px));
  margin: auto;
  padding: 23px 0 30px;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

@keyframes blink { to { opacity: .3; } }

@media (max-width: 920px) {
  .ticket-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ticket-card { min-height: 230px; }
}

@media (max-width: 650px) {
  .header-content, main, footer { width: min(100% - 28px, 1120px); }
  .app-header { position: static; }
  .mode-badge { padding: 6px 8px; font-size: 11px; }
  .intro { padding: 42px 0 38px; text-align: left; }
  .intro > p:not(.kicker) { margin: 0; font-size: 15px; }
  .progress { margin-top: 28px; }
  .progress li { gap: 5px; font-size: 11px; }
  .ticket-grid { grid-template-columns: 1fr; }
  .ticket-card { min-height: 225px; }
  .form-card, .saved-section { margin-left: 0; padding: 20px 16px; }
  .token-input-row { grid-template-columns: 1fr; }
  .reader-heading { grid-template-columns: 38px 1fr; }
  .reader-state { grid-column: 2; justify-self: start; }
  .pairing-area { align-items: flex-start; flex-direction: column; }
  .pairing-actions { width: 100%; }
  .pairing-actions .small-button { flex: 1; }
  .reader-steps { grid-template-columns: 1fr; }
  .token-actions { display: grid; grid-template-columns: 1fr; }
  .save-area { grid-template-columns: 1fr; }
  .primary-button { width: 100%; }
  .saved-item { grid-template-columns: 8px 1fr auto; }
  .saved-item code { grid-column: 2; }
  .remove-button { grid-column: 3; grid-row: 1 / span 2; }
  footer span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
