/* ── Global Resets & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
}

main {
  padding: 1.5rem 2rem;
  max-width: 1100px;
}

@media (max-width: 600px) {
  main { padding: 1rem 0.75rem; }
}

/* ── Header & Navigation ── */
header {
  background: #16213e;
  border-bottom: 2px solid #e94560;
  padding: 1.25rem 2rem 0; /* Padding bottom 0 for tabs */
}

/* Adjust padding for index which has no tabs */
header.no-tabs {
  padding-bottom: 1.25rem;
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

header h1 {
  font-size: 1.6rem;
  color: #e94560;
  letter-spacing: 1px;
}

.list-sub {
  font-size: 0.82rem;
  color: #aaa;
  margin-top: 0.2rem;
}

.user-bar {
  font-size: 0.82rem;
  color: #aaa;
  text-align: right;
  line-height: 1.7;
}

.user-bar strong { color: #e0e0e0; }
.user-bar a { color: #e94560; text-decoration: none; }
.user-bar a:hover { text-decoration: underline; }

.header-tabs { display: flex; margin-top: 0.25rem; margin-bottom: 0.85rem; }

.tab {
  padding: 0.55rem 1rem;
  color: #aaa;
  text-decoration: none;
  font-size: 0.88rem;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover  { color: #e0e0e0; }
.tab.active { color: #e94560; border-bottom-color: #e94560; }
.tab-home {
  margin-right: 0.5rem;
  padding-right: 0.75rem;
  border-right: 1px solid #333;
}

@media (max-width: 600px) {
  header { padding: 0.75rem 1rem 0; }
  .tab   { padding: 0.5rem 0.65rem; font-size: 0.8rem; }
}

/* ── Buttons ── */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  text-decoration: none;
  display: inline-block;
}

.btn-primary { background: #e94560; color: #fff; }
.btn-primary:hover { background: #c73652; }
.btn-primary:disabled { background: #555; color: #999; cursor: default; }

.btn-ghost { background: #0f3460; color: #ccc; }
.btn-ghost:hover { background: #1a4a8a; }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; border-radius: 5px; }

.btn-danger { background: transparent; color: #e94560; border: 1px solid #3d1a22; }
.btn-danger:hover { background: #e94560; color: #fff; border-color: #e94560; }

.btn-delete {
  background: transparent;
  color: #e94560;
  border: 1px solid #3d1a22;
}
.btn-delete:hover { background: #e94560; color: #fff; border-color: #e94560; }

/* ── Status & Spinners ── */
#status {
  color: #aaa;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  min-height: 1.2em;
}
#status.error { color: #e94560; }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid #555;
  border-top-color: #e94560;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Common Tables ── */
.lists-table, .cards-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.lists-table th, .cards-table th {
  text-align: left;
  padding: 0.55rem 0.85rem;
  border-bottom: 2px solid #333;
  color: #aaa;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.71rem;
  letter-spacing: 0.07em;
}

.lists-table th.right, .lists-table td.right,
.cards-table th.right, .cards-table td.right { text-align: right; }

.lists-table td, .cards-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid #222;
  color: #ddd;
  vertical-align: middle;
}

.lists-table tbody tr:hover td, .cards-table tbody tr:hover td { background: #16213e; }

/* ── Modal Base ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
  background: #16213e;
  border: 1px solid #333;
  border-radius: 12px;
  width: 100%;
  max-width: 1160px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #333;
  background: #0f3460;
}

.modal-header h2 { font-size: 1.1rem; color: #e0e0e0; }

.modal-header button, .modal-header .close-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.2rem;
}
.modal-header button:hover, .modal-header .close-btn:hover { color: #e94560; }

.modal-body {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
}

.modal-table-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem 1rem 0.75rem;
}

.modal-body table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.modal-body th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #333;
  color: #aaa;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
}
.modal-body td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #222;
  color: #ddd;
}
.modal-body tr:last-child td { border-bottom: none; }
.modal-body tr:hover td { background: #0f3460; }

.modal-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid #333;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  align-items: center;
}

/* ── Helper Classes ── */
.price, .price-green { color: #7bed9f; font-variant-numeric: tabular-nums; }
.price-foil { color: #a29bfe; font-variant-numeric: tabular-nums; }
.price-na { color: #555; }
.stat { font-variant-numeric: tabular-nums; }

.set-code {
  font-family: monospace;
  font-size: 0.8rem;
  background: #0f3460;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: #74b9ff;
}

.mana-icons { display: inline-flex; align-items: center; gap: 0.2rem; vertical-align: middle; }
.mana-icon { width: 15px; height: 15px; display: inline-block; }

.empty-state {
  background: #16213e;
  border: 1px dashed #333;
  border-radius: 10px;
  padding: 3rem 2rem;
  text-align: center;
  color: #666;
}
.empty-state p { margin-bottom: 1.25rem; font-size: 0.95rem; line-height: 1.6; }

/* ── Search Page Specific ── */
.search-area {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.search-group { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; min-width: 220px; }
.search-group label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: #aaa; }
.search-group .input-row { display: flex; gap: 0.5rem; }
.search-group input {
  flex: 1; padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid #333;
  background: #0f3460; color: #e0e0e0; font-size: 0.95rem; outline: none; transition: border-color 0.2s;
}
.search-group input:focus { border-color: #e94560; }
.divider { display: flex; align-items: center; color: #555; font-size: 0.85rem; padding: 0 0.25rem; align-self: flex-end; padding-bottom: 0.45rem; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 1rem; }
.card-tile {
  background: #16213e; border-radius: 10px; overflow: hidden; cursor: pointer; border: 2px solid transparent; transition: border-color 0.2s, transform 0.15s;
}
.card-tile:hover { border-color: #e94560; transform: translateY(-3px); }
.card-tile img { width: 100%; display: block; }
.card-tile .card-label { padding: 0.5rem 0.6rem; font-size: 0.8rem; color: #ccc; text-align: center; background: #0f3460; }
.card-tile .no-image { height: 120px; display: flex; align-items: center; justify-content: center; color: #555; font-size: 0.85rem; background: #0f3460; }

/* ── List/Report Specific ── */
.card-thumb { height: 44px; width: auto; border-radius: 3px; display: block; }
.card-name { font-weight: 500; color: #e0e0e0; }
.card-name-wrap { display: inline-flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }

.modal-image-panel {
  flex-shrink: 0; width: 336px; padding: 1rem 0.75rem 1rem 1.25rem; display: flex; align-items: flex-start; justify-content: center;
}
.modal-image-panel img { width: 100%; border-radius: 8px; display: block; }
.modal-image-panel.empty { display: none; }

@media (max-width: 600px) {
  .modal-body { flex-direction: column; overflow-y: auto; }
  .modal-image-panel { width: 100%; padding: 0.75rem 1rem 0; justify-content: center; }
  .modal-image-panel img { width: 60%; max-width: 220px; }
  .modal-table-panel { overflow-y: unset; padding: 0.75rem 1rem 1rem; }
}

/* ── Home Page (Auth/Lists) Specific ── */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; gap: 1rem; }
.toolbar h2 { font-size: 1.2rem; color: #e0e0e0; font-weight: 600; }
.list-name-link { color: #74b9ff; font-weight: 600; cursor: pointer; text-decoration: none; font-size: 0.92rem; }
.list-name-link:hover { text-decoration: underline; }
.actions-cell { display: flex; gap: 0.35rem; align-items: center; flex-wrap: nowrap; }
.row-actions { display: none; }
@media (max-width: 640px) {
  .lists-table th.col-actions, .lists-table td.col-actions  { display: none; }
  .row-actions { display: table-row; }
  .row-actions td { padding: 0 0.85rem 0.6rem; border-bottom: 1px solid #222; }
  .row-actions .actions-cell { flex-wrap: wrap; }
}
.rename-input {
  background: #0f3460; border: 1px solid #e94560; border-radius: 4px; color: #e0e0e0; font-size: 0.875rem; padding: 0.25rem 0.5rem; width: 200px; outline: none;
}

/* Generic Modal Box (Auth / New List) */
.modal-box {
  background: #16213e; border: 1px solid #333; border-radius: 12px; padding: 1.75rem 2rem; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 1rem;
}
.modal-box h2 { color: #e94560; font-size: 1.1rem; }
.modal-box input {
  padding: 0.6rem 0.85rem; border-radius: 6px; border: 1px solid #333; background: #0f3460; color: #e0e0e0; font-size: 0.95rem; outline: none; transition: border-color 0.2s;
}
.modal-box input:focus { border-color: #e94560; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.field-error { color: #e94560; font-size: 0.82rem; min-height: 1em; }

/* Auth Overlay */
.name-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 200; align-items: center; justify-content: center;
}
.name-overlay.open { display: flex; }
.name-box {
  background: #16213e; border: 1px solid #e94560; border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 1rem;
}
.name-box h2 { color: #e94560; font-size: 1.2rem; }
.name-box p { color: #aaa; font-size: 0.875rem; }
.name-box input {
  padding: 0.6rem 0.85rem; border-radius: 6px; border: 1px solid #333; background: #0f3460; color: #e0e0e0; font-size: 1rem; outline: none; transition: border-color 0.2s;
}
.name-box input:focus { border-color: #e94560; }
.name-box button { padding: 0.6rem 1rem; border: none; border-radius: 6px; background: #e94560; color: #fff; font-size: 0.95rem; cursor: pointer; }
.name-box button:hover { background: #c73652; }
.name-error { color: #e94560; font-size: 0.82rem; min-height: 1em; }
.auth-toggle { font-size: 0.82rem; color: #aaa; text-align: center; }
.auth-toggle a { color: #e94560; text-decoration: none; cursor: pointer; }
.auth-toggle a:hover { text-decoration: underline; }

/* ── Shopping Buddy (Report) Specific ── */
.summary { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.summary-chip { background: #16213e; border: 1px solid #333; border-radius: 8px; padding: 0.6rem 1rem; font-size: 0.85rem; color: #ccc; }
.summary-chip strong { display: block; font-size: 1.3rem; color: #e94560; line-height: 1.2; }

.sets-list { display: flex; flex-direction: column; gap: 1.25rem; }
.set-card { background: #16213e; border: 1px solid #333; border-radius: 10px; overflow: hidden; }
.set-header { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; background: #0f3460; cursor: pointer; user-select: none; gap: 0.75rem; }
.set-header:hover { background: #1a4a8a; }
.set-header-left { display: flex; align-items: center; gap: 0.75rem; }
.set-name { font-size: 0.95rem; font-weight: 600; color: #e0e0e0; }
.set-released { font-size: 0.78rem; color: #888; }
.set-badge { background: #e94560; color: #fff; font-size: 0.75rem; font-weight: 700; padding: 0.2rem 0.55rem; border-radius: 999px; flex-shrink: 0; }
.set-chevron { color: #555; font-size: 0.9rem; transition: transform 0.2s; flex-shrink: 0; }
.set-card.open .set-chevron { transform: rotate(180deg); }
.set-body { display: none; padding: 0; }
.set-card.open .set-body { display: block; }
.set-body th { background: #16213e; }

.rarity-chip {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.15rem; height: 1.15rem; margin-left: 0.35rem; border: 1px solid #4b5d7a; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700; line-height: 1; color: #d7dfef; background: #23395d; vertical-align: middle;
}

.cheapest-badge {
  display: inline-block; background: #f9ca24; color: #1a1a2e; font-size: 0.68rem; font-weight: 700; padding: 0.1rem 0.4rem; border-radius: 4px; margin-left: 0.4rem; vertical-align: middle; letter-spacing: 0.03em;
}
.found-badge {
  display: inline-block; background: #27ae60; color: #fff; font-size: 0.68rem; font-weight: 700; padding: 0.1rem 0.4rem; border-radius: 4px; margin-left: 0.4rem; vertical-align: middle; letter-spacing: 0.03em;
}
.set-body tr.is-found td { opacity: 0.4; }
.set-body tr.is-found td:first-child { text-decoration: line-through; }
.set-body tr.row-hidden { display: none; }
.set-body tr { cursor: pointer; }

/* Shopping Buddy Card Detail Overrides */
.modal-card-image { flex-shrink: 0; width: 200px; }
.modal-card-image img { width: 100%; border-radius: 10px; display: block; }
.modal-card-image.hidden { display: none; }
.modal-table-wrap { flex: 1; min-width: 0; overflow-x: auto; }
.current-set td { background: #1a3a6a; }

#btn-found { background: #27ae60; color: #fff; transition: background 0.2s; }
#btn-found:hover { background: #1e8449; }
#btn-found.is-found { background: #555; }
#btn-found.is-found:hover { background: #e94560; }

#modal-status { flex: 1; font-size: 0.85rem; color: #7bed9f; }

/* ── Import Page Specific ── */
.drop-zone {
  border: 2px dashed #334; border-radius: 12px; padding: 3.5rem 2rem; text-align: center; cursor: pointer;
  transition: border-color 0.2s, background 0.2s; margin-bottom: 1.5rem;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: #e94560; background: rgba(233,69,96,0.05); }
.drop-icon { font-size: 2.5rem; margin-bottom: 0.75rem; color: #555; }
.drop-zone p { color: #888; font-size: 0.95rem; margin-bottom: 0.5rem; }
.drop-zone .or { color: #555; font-size: 0.8rem; margin: 0.5rem 0; }
.file-label { cursor: pointer; }
#file-input { display: none; }

.progress-wrap { margin-bottom: 1.25rem; }
.progress-track { height: 6px; background: #222; border-radius: 3px; overflow: hidden; margin-bottom: 0.5rem; }
.progress-fill { height: 100%; background: #e94560; border-radius: 3px; transition: width 0.3s ease; width: 0%; }
.progress-label { font-size: 0.82rem; color: #888; }

.table-toolbar { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.85rem; flex-wrap: wrap; }
.table-summary { font-size: 0.82rem; color: #aaa; flex: 1; }

.import-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.import-table th {
  text-align: left; padding: 0.5rem 0.75rem; border-bottom: 2px solid #333; color: #aaa; font-weight: 600;
  text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.07em; white-space: nowrap;
}
.import-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid #1e1e3a; vertical-align: middle; }
.import-table tbody tr:hover td { background: #16213e; }

.import-table .col-check { width: 36px; }
.import-table .col-img   { width: 44px; padding-right: 0.25rem; }
.import-table .col-set   { white-space: nowrap; color: #aaa; }
.import-table .col-price { white-space: nowrap; text-align: right; }
.import-table .col-status { white-space: nowrap; width: 130px; }

.import-table input[type="checkbox"] { width: 15px; height: 15px; accent-color: #e94560; cursor: pointer; }

.badge-foil {
  display: inline-block; background: #6c5ce7; color: #fff; font-size: 0.62rem; font-weight: 700;
  padding: 0.08rem 0.35rem; border-radius: 3px; margin-left: 0.4rem; vertical-align: middle;
  letter-spacing: 0.04em; text-transform: uppercase;
}

.price-val { color: #7bed9f; font-variant-numeric: tabular-nums; }
tr.row-warn td { opacity: 0.55; }

.status-badge {
  display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; font-weight: 600;
  padding: 0.2rem 0.55rem; border-radius: 4px; letter-spacing: 0.03em;
}
.status-queued   { background: #2a2a3e; color: #666; }
.status-loading  { background: #0f3460; color: #74b9ff; }
.status-found    { background: #1a3a1a; color: #7bed9f; }
.status-notfound { background: #3a1a1a; color: #e94560; }
.status-error    { background: #3a2a0a; color: #fdcb6e; }

.mini-spin {
  display: inline-block; width: 10px; height: 10px; border: 1.5px solid #335;
  border-top-color: #74b9ff; border-radius: 50%; animation: spin 0.6s linear infinite; flex-shrink: 0;
}

.save-area { margin-top: 1.5rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.save-ok    { color: #7bed9f; font-size: 0.9rem; }
.save-error { color: #e94560; font-size: 0.9rem; }