:root {
  --bg: #f4f6f4;
  --card: #ffffff;
  --text: #0e0f0c;
  --muted: #6b7280;
  --line: #e5e7eb;
  --green: #9fe870;
  --green-dark: #163300;
  --green-hover: #85d65a;
  --blue: #3b82f6;
  --orange: #f59e0b;
  --red: #ef4444;
  --gray: #9ca3af;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--green); color: var(--green-dark);
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
}
.top h1 { margin: 0; font-size: 18px; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; flex-shrink: 0; }
main { padding: 16px 14px calc(24px + var(--safe-bottom)); max-width: 860px; margin: 0 auto; }
.loading, .empty { text-align: center; color: var(--muted); padding: 40px 12px; }

.station {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  border: 1px solid var(--line);
  margin-bottom: 16px;
  overflow: hidden;
}
.station-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.station-head h2 { margin: 0; font-size: 17px; }
.counts { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.counts span { background: #f3f4f6; padding: 3px 8px; border-radius: 999px; }
.counts .ok { background: #ecfdf5; color: #047857; }
.counts .busy { background: #eff6ff; color: #1d4ed8; }
.counts .dead { background: #f3f4f6; color: #6b7280; }

.card-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .15s;
}
.card-row:last-child { border-bottom: none; }
.card-row:active, .card-row:hover { background: #f9fafb; }
.card-row.used_up { opacity: .55; }
.seq {
  width: 40px; height: 40px; border-radius: 12px;
  background: #163300; color: #9fe870;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.card-row.used_up .seq { background: #9ca3af; color: #fff; }
.card-meta .last4 { font-weight: 700; font-size: 16px; letter-spacing: .04em; }
.card-meta .who { font-size: 13px; color: var(--muted); margin-top: 2px; }
.badge {
  font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px; white-space:nowrap;
}
.badge.available { background: #ecfdf5; color: #047857; }
.badge.in_use { background: #eff6ff; color: #1d4ed8; }
.badge.used_up { background: #f3f4f6; color: #6b7280; }
.badge.awaiting_replacement { background: #fff1f2; color: #9f1239; white-space: normal; max-width: 172px; line-height: 1.5; }
.badge.refunded { background: #ecfeff; color: #155e75; }
.card-meta { min-width: 0; overflow-wrap: anywhere; }
.card-row.awaiting_replacement, .card-row.refunded { cursor: pointer; }
.delete-warning { color: #991b1b; line-height: 1.6; overflow-wrap: anywhere; }
#addTitle { overflow-wrap: anywhere; min-width: 0; font-size: 18px; }
.modal-head { gap: 12px; }
.icon-close { flex-shrink: 0; }
@media (max-width: 420px) {
  .card-row { grid-template-columns: 40px minmax(0, 1fr); gap: 8px; }
  .card-row .badge { grid-column: 2; justify-self: start; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
}

.btn {
  border: none; border-radius: 999px; padding: 10px 16px;
  font-size: 14px; font-weight: 650; cursor: pointer;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--green); color: var(--green-dark); }
.btn.primary:hover { background: var(--green-hover); }
.btn.secondary { background: #eef2ff; color: #3730a3; }
.btn.ghost { background: #f3f4f6; color: #374151; }
.btn.danger { background: #fee2e2; color: #991b1b; }
.btn.warn { background: #ffedd5; color: #9a3412; }
.btn.block { width: 100%; margin-top: 10px; padding: 14px 16px; font-size: 16px; }
.btn.copy {
  background: var(--green); color: var(--green-dark);
  padding: 7px 14px; font-size: 13px; min-width: 64px;
}
.btn.sm { padding: 8px 12px; font-size: 13px; }

.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50; padding: 12px;
}
@media (min-width: 640px) {
  .overlay { align-items: center; }
}
.overlay.hidden { display: none; }
.modal {
  background: #fff; border-radius: 20px; width: min(440px, 100%);
  max-height: min(92vh, 720px); overflow: auto;
  box-shadow: var(--shadow); padding: 18px 18px 16px;
}
.modal.small { width: min(380px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.icon-close {
  border: none; background: #f3f4f6; width: 32px; height: 32px; border-radius: 50%;
  font-size: 20px; line-height: 1; cursor: pointer; color: #374151;
}
.detail-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.detail-row:last-child { border-bottom: none; }
.detail-row .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.detail-row .value { font-size: 16px; font-weight: 600; word-break: break-word; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.hint code { background: #f3f4f6; padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; font-family: inherit; outline: none; background: #fff;
}
.field input:focus, .field select:focus, textarea:focus { border-color: #86efac; box-shadow: 0 0 0 3px rgba(159,232,112,.35); }
textarea { resize: vertical; min-height: 140px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #163300; color: #9fe870;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 80; box-shadow: var(--shadow); max-width: 90vw;
}
.toast.hidden { display: none; }
.toast.err { background: #7f1d1d; color: #fecaca; }

.station-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.station-tax { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.station-tax-select { min-width: 76px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); padding: 4px 8px; font: inherit; }
.station-tax-select:focus-visible { outline: 2px solid #047857; outline-offset: 2px; }
.station-tax-select:disabled { opacity: .6; }

.modal.wide { width: min(720px, 100%); }
.paste-zone {
  border: 2px dashed #c5d4b8;
  border-radius: 16px;
  min-height: 120px;
  background: #f7fbf2;
  padding: 12px;
  outline: none;
  margin-bottom: 10px;
}
.paste-zone:focus, .paste-zone.dragover {
  border-color: #85d65a;
  box-shadow: 0 0 0 3px rgba(159,232,112,.35);
}
.paste-hint {
  text-align: center; color: var(--muted); font-size: 14px; padding: 28px 8px; line-height: 1.5;
}
.thumb-list { display: flex; flex-wrap: wrap; gap: 10px; }
.thumb {
  position: relative; width: 96px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); background: #fff;
}
.thumb img { display: block; width: 96px; height: 72px; object-fit: cover; }
.thumb .t-cap {
  font-size: 11px; padding: 4px 6px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb .t-del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: none;
  border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; font-size: 14px; line-height: 1;
}
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; margin: 0; }
.preview-title { margin: 10px 0 8px; font-size: 15px; }
.table-scroll { overflow: auto; max-height: 280px; border: 1px solid var(--line); border-radius: 12px; }
.preview-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
.preview-table th, .preview-table td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.preview-table th { background: #f3f4f6; position: sticky; top: 0; z-index: 1; }
.preview-table input {
  width: 100%; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px;
  font-size: 13px; font-family: inherit; background: #fafafa;
}
.preview-table input:focus { border-color: #86efac; background: #fff; outline: none; }
.preview-table tr.bad td { background: #fff7ed; }
.advanced { margin-top: 12px; color: var(--muted); font-size: 13px; }
.advanced summary { cursor: pointer; margin-bottom: 8px; }
.advanced textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 14px; font-family: inherit; }

.btn.danger-solid { background: #ef4444; color: #fff; }
.admin-on #btnAdmin { background: #163300; color: #9fe870; }

.hidden { display: none !important; }
.auth-gate { padding: 16px 14px; max-width: 440px; margin: 0 auto; }
.auth-card {
  background: #fff; border-radius: 20px; padding: 18px; border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.auth-card h2 { margin: 0 0 8px; }
.tabs { display: flex; gap: 6px; margin: 12px 0 14px; }
.tab {
  flex: 1; border: none; border-radius: 999px; padding: 10px 8px; font-weight: 650;
  background: #f3f4f6; color: #374151; cursor: pointer; font-size: 14px;
}
.tab.on { background: var(--green); color: var(--green-dark); }
.users-list { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow: auto; }
.user-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px;
  background: #fafafa;
}
.user-card .u-name { font-weight: 700; font-size: 16px; }
.user-card .u-meta { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.grant-checks { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; padding: 8px 0; }
.check input { width: 18px; height: 18px; }

.badge.cooldown { background: #ffedd5; color: #9a3412; }
.badge.void, .badge.used_up { background: #f3f4f6; color: #6b7280; }
.media-row { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.media-thumb {
  width: 72px; height: 72px; border-radius: 12px; object-fit: cover;
  border: 1px solid var(--line); background: #f3f4f6; cursor: pointer;
}
.media-meta { flex: 1; min-width: 140px; font-size: 13px; color: var(--muted); }
.media-meta b { color: var(--text); }
.media-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }


.filter-bar {
  margin: 0 0 14px;
  padding: 12px 14px;
  background: #fff;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
}
.filter-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.filter-row:last-child { margin-bottom: 0; }
.filter-label {
  flex: 0 0 40px;
  font-size: 13px;
  color: #6b7280;
  padding-top: 6px;
  font-weight: 600;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #374151;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip.on {
  background: #9FE870;
  border-color: #7ccf4a;
  color: #163300;
  font-weight: 600;
}
.country-tag, .tax-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #166534;
  background: #dcfce7;
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
}
.tax-tag { color: #374151; background: #f3f4f6; }

.filter-search {
  flex: 1;
  min-width: 0;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  background: #fff;
}
.filter-search:focus {
  outline: none;
  border-color: #7ccf4a;
  box-shadow: 0 0 0 3px rgba(159, 232, 112, 0.35);
}

.active-users {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 8px 0 10px;
  font-size: 13px;
  color: #9a3412;
  font-weight: 600;
}
.user-pill {
  display: inline-block;
  background: #ffedd5;
  color: #9a3412;
  border: 1px solid #fdba74;
  border-radius: 999px;
  padding: 2px 10px;
  font-weight: 600;
}
.card-row.in_use .who {
  color: #9a3412;
  font-weight: 600;
}
.card-row.in_use .who b {
  font-weight: 700;
}
.badge.in_use {
  background: #ffedd5;
  color: #9a3412;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ops-list { max-height: 60vh; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.ops-row { display: grid; grid-template-columns: 1.2fr 0.8fr 0.7fr 1.2fr; gap: 8px; font-size: 12px; padding: 8px 10px; background: rgba(255,255,255,0.04); border-radius: 8px; }
.ops-t { opacity: 0.7; }
.ops-act { color: #8ec7ff; }
@media (max-width: 640px) { .ops-row { grid-template-columns: 1fr 1fr; } }
