/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --bg:           #09090b;
  --surface:      #18181b;
  --surface-2:    #27272a;
  --border:       #3f3f46;
  --text:         #fafafa;
  --text-muted:   #a1a1aa;
  --text-subtle:  #52525b;

  --accent:       #f59e0b;
  --accent-dim:   #78350f;

  --green:        #4ade80;
  --green-dim:    #16a34a;
  --green-bg:     #052e16;
  --green-ring:   #166534;

  --red:          #f87171;
  --red-dim:      #b91c1c;
  --red-bg:       #1c0808;
  --red-ring:     #7f1d1d;

  --r-sm:  6px;
  --r:     10px;
  --r-lg:  14px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family:
    system-ui, -apple-system, BlinkMacSystemFont,
    'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding: 1rem 1rem env(safe-area-inset-bottom, 1.5rem);
}

/* ── App shell ──────────────────────────────────────────────────────────────── */
#app {
  max-width: 480px;
  margin: 0 auto;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.header {
  padding: 0.75rem 0 0.875rem;
  border-bottom: 1px solid var(--border);
}

.header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.header__title {
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1.2;
}

.header__accent {
  color: var(--accent);
}

.header__stats {
  margin-top: 0.3rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.header__stats strong {
  color: var(--text);
  font-weight: 600;
}

/* ── Search fields ──────────────────────────────────────────────────────────── */
.search {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.field__label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 0.375rem;
}

.field__wrap {
  position: relative;
}

.field__input {
  display: block;
  width: 100%;
  height: 52px;
  padding: 0 1rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 150ms ease;
}

.field__input::placeholder {
  color: var(--text-subtle);
}

.field__input:focus {
  border-color: var(--accent);
}

.field__input:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* number input — hide spinners, increase size */
.field__input--num {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.field__input--num::-webkit-inner-spin-button,
.field__input--num::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.field__input--num {
  -moz-appearance: textfield;
}

/* clear × button */
.field__clear {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 150ms, color 150ms;
}

.field__clear:hover {
  background: var(--border);
  color: var(--text);
}

/* ── Dropdown ───────────────────────────────────────────────────────────────── */
.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  list-style: none;
  overflow-y: auto;
  max-height: 244px;
  z-index: 200;
  box-shadow: 0 4px 24px rgb(0 0 0 / .5);
}

.dropdown--empty {
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
}

.dropdown__item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--surface-2);
  transition: background 100ms;
  min-height: 52px;
}

.dropdown__item:last-child {
  border-bottom: none;
}

.dropdown__item:hover {
  background: var(--surface-2);
}

.dropdown__item--hi {
  background: var(--surface-2);
  border-left: 2px solid var(--accent);
  padding-left: calc(1rem - 2px);
}

.dropdown__code {
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  min-width: 2.75rem;
}

.dropdown__name {
  flex: 1;
  font-size: 0.9375rem;
  color: var(--text);
}

.dropdown__page {
  font-size: 0.75rem;
  color: var(--text-subtle);
}

/* ── Result ─────────────────────────────────────────────────────────────────── */
@keyframes result-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)  scale(1); }
}

.result {
  border-radius: var(--r-lg);
  padding: 1.75rem 1.5rem;
  text-align: center;
  border: 2px solid transparent;
  animation: result-in 230ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.result--needed {
  background: var(--green-bg);
  border-color: var(--green-ring);
}

.result--have {
  background: var(--red-bg);
  border-color: var(--red-ring);
}

.result__label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.625rem;
}

.result--needed .result__label { color: var(--green-dim); }
.result--have   .result__label { color: var(--red-dim); }

.result__verdict {
  display: block;
  font-size: clamp(2.75rem, 14vw, 4rem);
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 1;
  margin-bottom: 0.625rem;
}

.result--needed .result__verdict { color: var(--green); }
.result--have   .result__verdict { color: var(--red); }

.result__sub {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── Team card ──────────────────────────────────────────────────────────────── */
.team-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1rem 1rem 1.125rem;
}

.team-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.team-card__id {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.team-card__code {
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
}

.team-card__name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.team-card__badge {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.2rem 0.625rem;
  white-space: nowrap;
}

.team-card__page {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-bottom: 0.875rem;
}

/* ── Chips ──────────────────────────────────────────────────────────────────── */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 0.25rem;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: background 150ms, color 150ms, border-color 150ms;
}

.chip--active {
  background: var(--green-bg);
  border-color: var(--green-ring);
  color: var(--green);
  font-weight: 800;
}

.chips__empty {
  font-size: 0.875rem;
  color: var(--text-subtle);
  font-style: italic;
}

/* ── Source badge ───────────────────────────────────────────────────────────── */
.badge {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge--loading {
  color: var(--text-subtle);
  border-color: var(--border);
}

.badge--cloud {
  color: var(--green-dim);
  border-color: var(--green-ring);
  background: var(--green-bg);
}

.badge--local {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: #1c1407;
}

/* ── Offline banner ─────────────────────────────────────────────────────────── */
.offline-banner {
  background: #1c1407;
  border: 1px solid var(--accent-dim);
  border-radius: var(--r);
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  color: var(--accent);
  margin-top: 0.875rem;
}

/* ── Loading state ──────────────────────────────────────────────────────────── */
.loading {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 3rem 0;
}

/* ── Chip as button ─────────────────────────────────────────────────────────── */
button.chip {
  font-family: inherit;
  cursor: pointer;
}

button.chip:active {
  opacity: 0.7;
  transform: scale(0.93);
}

.chips__hint {
  width: 100%;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-subtle);
  font-style: italic;
}

/* ── Recents panel ──────────────────────────────────────────────────────────── */
.recents {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.recents__toggle {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
  gap: 0.5rem;
  transition: color 150ms;
}

.recents__toggle:hover {
  color: var(--text);
}

.recents__list {
  list-style: none;
  border-top: 1px solid var(--surface-2);
}

.recents__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--surface-2);
}

.recents__item:last-child {
  border-bottom: none;
}

.recents__info {
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  flex-wrap: wrap;
  flex: 1;
}

.recents__code {
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
}

.recents__num {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text);
}

.recents__by {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.recents__time {
  font-size: 0.6875rem;
  color: var(--text-subtle);
}

.recents__undo {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: none;
  border: 1px solid var(--accent-dim);
  border-radius: 99px;
  padding: 0.2rem 0.625rem;
  cursor: pointer;
  transition: background 150ms, color 150ms;
  white-space: nowrap;
}

.recents__undo:hover {
  background: var(--accent-dim);
  color: var(--text);
}

.recents__empty {
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  color: var(--text-subtle);
  font-style: italic;
  border-top: 1px solid var(--surface-2);
}

/* ── Name prompt ────────────────────────────────────────────────────────────── */
.name-prompt {
  position: fixed;
  inset: 0;
  background: rgba(9, 9, 11, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 500;
}

.name-prompt__card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.75rem 1.5rem;
  width: 100%;
  max-width: 360px;
}

.name-prompt__title {
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 0.375rem;
}

.name-prompt__sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  line-height: 1.4;
}

.name-prompt__input {
  margin-bottom: 0.75rem;
}

.name-prompt__btn {
  display: block;
  width: 100%;
  height: 52px;
  background: var(--accent);
  color: #09090b;
  border: none;
  border-radius: var(--r);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 150ms;
}

.name-prompt__btn:hover {
  opacity: 0.88;
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

#toast {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.5rem 1.125rem;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  max-width: calc(100vw - 2rem);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  z-index: 400;
  transition: opacity 300ms;
}

#toast.toast--visible {
  opacity: 1;
  animation: toast-in 250ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ── Accessibility ──────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Ensure minimum 44px touch targets on chips */
.chip {
  min-width: 44px;
  height: 44px;
}

/* ── Nav tabs ───────────────────────────────────────────────────────────────── */
.nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-top: 0.625rem;
}

.nav__tab {
  flex: 1;
  height: 44px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 150ms, border-color 150ms;
}

.nav__tab--active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.nav__tab:hover:not(.nav__tab--active) {
  color: var(--text);
}

/* ── Quick check ────────────────────────────────────────────────────────────── */
.search-divider {
  height: 1px;
  background: var(--surface-2);
  margin: 0.25rem 0;
}

.quick-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  border-radius: var(--r);
  margin-top: 0.5rem;
  border: 1.5px solid transparent;
}

.quick-result--needed {
  background: var(--green-bg);
  border-color: var(--green-ring);
}

.quick-result--have {
  background: var(--red-bg);
  border-color: var(--red-ring);
}

.quick-result__code {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}

.quick-result__verdict {
  font-size: 0.9375rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.quick-result--needed .quick-result__verdict { color: var(--green); }
.quick-result--have   .quick-result__verdict { color: var(--red); }

.quick-result__hint {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: 0.375rem;
  padding-left: 0.25rem;
}

/* ── Progress view ──────────────────────────────────────────────────────────── */
.prog-summary {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1rem;
}

.prog-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.prog-stat__num {
  font-size: 1.875rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
}

.prog-stat__num--accent { color: var(--accent); }
.prog-stat__num--green  { color: var(--green); }

.prog-stat__label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.prog-bar-wrap {
  height: 10px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

.prog-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 600ms cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 2px;
}

.prog-bar__label {
  font-size: 0.75rem;
  color: var(--text-subtle);
  text-align: center;
}

.prog-section-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green-dim);
}

.prog-list {
  list-style: none;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.prog-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--surface-2);
  min-height: 44px;
}

.prog-item:last-child { border-bottom: none; }

.prog-item__code {
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  min-width: 2.75rem;
}

.prog-item__name {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text);
}

.prog-item__count {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 1.75rem;
  text-align: right;
}

.prog-item--done { opacity: 0.55; }

.prog-item__check {
  font-size: 0.875rem;
  color: var(--green);
  min-width: 1.75rem;
  text-align: right;
}

/* ── Export button ──────────────────────────────────────────────────────────── */
.export-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  height: 44px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 150ms, color 150ms, border-color 150ms;
}

.export-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent-dim);
}

/* ── Header right group ─────────────────────────────────────────────────────── */
.header__right {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

/* ── Lock button ────────────────────────────────────────────────────────────── */
.lock-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-subtle);
  cursor: pointer;
  transition: background 150ms, color 150ms, border-color 150ms;
  flex-shrink: 0;
}

.lock-btn:hover {
  background: var(--surface-2);
  color: var(--text-muted);
  border-color: var(--text-subtle);
}

.lock-btn--unlocked {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.lock-btn--unlocked:hover {
  background: var(--accent-dim);
  color: var(--text);
}

/* ── PIN prompt error ───────────────────────────────────────────────────────── */
.pin-error {
  font-size: 0.8125rem;
  color: var(--red);
  min-height: 1.25rem;
  margin-bottom: 0.5rem;
}

/* ── Name choice buttons ────────────────────────────────────────────────────── */
.name-choices {
  display: flex;
  gap: 0.75rem;
}

.name-choice-btn {
  flex: 1;
  height: 52px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 150ms, border-color 150ms;
}

.name-choice-btn:hover {
  background: var(--border);
  border-color: var(--accent);
  color: var(--text);
}

/* ── Cancel button variant ──────────────────────────────────────────────────── */
.name-prompt__btn--cancel {
  margin-top: 0.5rem;
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}

.name-prompt__btn--cancel:hover {
  background: var(--surface-2);
  color: var(--text);
  opacity: 1;
}

/* ── Desktop bump ───────────────────────────────────────────────────────────── */
@media (min-width: 480px) {
  body { padding: 2rem 1.5rem; }

  .result__verdict {
    font-size: 4rem;
  }
}
