* {
  box-sizing: border-box;
}

body {
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  margin: 0;
  padding: 32px;
  min-height: 100vh;
}

h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 32px 0;
  color: white;
}

h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #94a3b8;
  text-transform: uppercase;
  margin: 40px 0 16px 0;
}

/* --- Stats --- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat-card {
  background: #1e293b;
  border: 1px solid #334155;
  padding: 20px;
  border-radius: 8px;
}

.stat-label {
  font-size: 11px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.stat-value {
  font-family: "JetBrains Mono", monospace;
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
  color: white;
}

.stat-value.positive { color: #10b981; }
.stat-value.negative { color: #ef4444; }

/* --- By-set list --- */
.by-set {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  overflow: hidden;
}

.by-set-row {
  display: flex;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #334155;
  font-size: 14px;
}

.by-set-row:last-child { border-bottom: none; }

.by-set-row .set-name {
  font-weight: 500;
  color: #e2e8f0;
}

.by-set-row .value {
  font-family: "JetBrains Mono", monospace;
  color: #10b981;
  font-weight: 700;
  font-size: 14px;
}

/* --- Card grid --- */
#cards-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px;
  transition: border-color 0.15s ease, transform 0.15s ease;
  cursor: pointer;
}

.card:hover {
  border-color: #38bdf8;
  transform: translateY(-2px);
}

.card img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  display: block;
}

.card-name {
  font-weight: 600;
  margin-top: 12px;
  color: white;
  font-size: 14px;
}

.card-set {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
}

.card-price {
  font-family: "JetBrains Mono", monospace;
  margin-top: 10px;
  color: #10b981;
  font-weight: 700;
  font-size: 16px;
}

/* --- Search results grid --- */
#search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

#search-results:empty { display: none; }

.search-result {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.search-result img {
  width: 100%;
  border-radius: 4px;
}

.search-result .card-name {
  font-weight: 600;
  color: white;
  margin-top: 8px;
  font-size: 14px;
}

.search-result .card-set {
  font-size: 12px;
  color: #94a3b8;
}

.add-button {
  margin-top: 10px;
  width: 100%;
  background: #10b981;
  color: white;
  border: none;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 13px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
}

.add-button:hover { background: #059669; }

/* --- Modal --- */
#modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#modal-overlay.open { display: flex; }

#modal-panel {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  position: relative;
}

#modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 6px;
}

#modal-close:hover {
  background: #334155;
  color: white;
}

#modal-card-preview {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #334155;
}

#modal-card-preview img {
  width: 80px;
  border-radius: 4px;
}

#modal-card-preview .preview-name {
  font-weight: 600;
  color: white;
  font-size: 16px;
}

#modal-card-preview .preview-set {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
}

#acquire-form label {
  display: block;
  font-size: 12px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 16px;
}

#acquire-form input,
#acquire-form select {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}

#acquire-form input:focus,
#acquire-form select:focus { border-color: #38bdf8; }

#form-submit {
  width: 100%;
  background: #10b981;
  color: white;
  border: none;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 14px;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 8px;
}

#form-submit:hover { background: #059669; }

#form-submit:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* --- Pagination --- */
.pagination {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
  font-size: 14px;
  color: #94a3b8;
}

.pagination.visible { display: flex; }

.pagination button {
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
}

.pagination button:hover:not(:disabled) {
  border-color: #38bdf8;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination .page-info {
  font-variant-numeric: tabular-nums;
}

/* --- Search panel --- */
.search-panel {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 24px;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-narrow {
  max-width: 110px;
}

.filter label {
  font-size: 11px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.filter input[type="text"],
.filter input[type="number"] {
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
}

.filter input:focus { border-color: #38bdf8; }

.advanced-toggle {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-family: "Inter", sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.advanced-toggle:hover { color: #e2e8f0; }

#advanced-toggle-icon {
  display: inline-block;
  transition: transform 0.15s ease;
}

#advanced-toggle-icon.open { transform: rotate(90deg); }

.advanced-filters {
  display: none;
}

.advanced-filters.open {
  display: grid;
}

.search-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding-top: 16px;
  border-top: 1px solid #334155;
}

#page-size-select {
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}

#page-size-select:focus { border-color: #38bdf8; }

#clear-filters {
  background: transparent;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
}

#clear-filters:hover { border-color: #38bdf8; }

#search-button {
  background: #38bdf8;
  color: #0f172a;
  border: none;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 24px;
  border-radius: 6px;
  cursor: pointer;
  margin-left: auto;
}

#search-button:hover { background: #0ea5e9; }

/* --- Searchable dropdown --- */
.searchable-dropdown {
  position: relative;
}

.dropdown-input {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}

.dropdown-input:focus { border-color: #38bdf8; }

.dropdown-input::placeholder { color: #64748b; }

.dropdown-panel {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.dropdown-panel.open { display: block; }

.dropdown-option {
  padding: 8px 12px;
  font-size: 14px;
  color: #e2e8f0;
  cursor: pointer;
}

.dropdown-option:hover {
  background: #1e293b;
}

.dropdown-option.empty {
  color: #64748b;
  cursor: default;
  font-style: italic;
}

.dropdown-clear {
  padding: 8px 12px;
  font-size: 12px;
  color: #94a3b8;
  cursor: pointer;
  border-bottom: 1px solid #334155;
  font-weight: 600;
}

.dropdown-clear:hover {
  background: #1e293b;
  color: white;
}

/* --- Price status bar --- */
.price-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px 20px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #94a3b8;
}

.price-status-label #price-status-date {
  color: #e2e8f0;
  font-weight: 600;
}

#refresh-prices-button {
  background: transparent;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
}

#refresh-prices-button:hover:not(:disabled) {
  border-color: #38bdf8;
}

#refresh-prices-button:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* --- Detail modal --- */
#detail-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#detail-overlay.open { display: flex; }

#detail-panel {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

#detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 6px;
}

#detail-close:hover {
  background: #334155;
  color: white;
}

/* Card info section at the top of the detail modal */
#detail-card-info {
  display: flex;
  gap: 20px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid #334155;
}

#detail-card-info img {
  width: 140px;
  border-radius: 6px;
  flex-shrink: 0;
}

#detail-card-info .info {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#detail-card-info .name {
  font-size: 22px;
  font-weight: 700;
  color: white;
  margin-bottom: 4px;
}

#detail-card-info .set {
  font-size: 14px;
  color: #94a3b8;
  margin-bottom: 16px;
}

#detail-card-info .market-value {
  font-family: "JetBrains Mono", monospace;
  font-size: 24px;
  font-weight: 700;
  color: #10b981;
}

#detail-card-info .market-label {
  font-size: 11px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 4px;
}

#detail-card-info img,
#modal-card-preview img {
  width: 100%;
  max-width: 280px;
  height: auto;
  display: block;
}

/* Ownership rows list */
#detail-ownership-header {
  font-size: 11px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin: 0 0 12px 0;
}

.ownership-row {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.ownership-row .left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ownership-row .condition {
  font-weight: 600;
  color: white;
}

.ownership-row .meta {
  color: #94a3b8;
  font-size: 12px;
}

.ownership-row .price {
  font-family: "JetBrains Mono", monospace;
  color: #10b981;
  font-weight: 700;
  font-size: 16px;
}

.ownership-row .actions {
  display: flex;
  gap: 6px;
}

.ownership-row .icon-btn {
  background: transparent;
  border: 1px solid #334155;
  color: #94a3b8;
  font-family: "Inter", sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.ownership-row .icon-btn:hover {
  border-color: #38bdf8;
  color: #e2e8f0;
}

.ownership-row .icon-btn.danger:hover {
  border-color: #ef4444;
  color: #ef4444;
}

/* Inline delete confirmation */
.ownership-row .confirm-delete {
  display: none;
  align-items: center;
  gap: 8px;
}

.ownership-row.confirming .actions {
  display: none;
}

.ownership-row.confirming .confirm-delete {
  display: flex;
}

.ownership-row .confirm-text {
  font-size: 12px;
  color: #ef4444;
  font-weight: 600;
  margin-right: 4px;
}

/* Inline edit form */
.ownership-row .edit-form {
  display: none;
  flex: 1;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.ownership-row.editing .left,
.ownership-row.editing .price,
.ownership-row.editing .actions {
  display: none;
}

.ownership-row.editing .edit-form {
  display: flex;
}

.edit-form input,
.edit-form select {
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 5px;
  outline: none;
}

.edit-form input:focus,
.edit-form select:focus { border-color: #38bdf8; }

.edit-quantity { width: 60px; }
.edit-price { width: 90px; }
.edit-date { width: 140px; }
.edit-condition { width: 150px; }

/* --- Empty state --- */
#empty-state {
  display: none;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 60px 32px;
  text-align: center;
  margin-top: 16px;
}

#empty-state.visible { display: block; }

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-title {
  font-size: 22px;
  font-weight: 700;
  color: white;
  margin-bottom: 8px;
}

.empty-subtitle {
  font-size: 14px;
  color: #94a3b8;
  max-width: 400px;
  margin: 0 auto;
}

/* --- Skeleton loaders --- */
@keyframes skeleton-pulse {
  0% { opacity: 0.4; }
  50% { opacity: 0.7; }
  100% { opacity: 0.4; }
}

.skeleton {
  background: #334155;
  border-radius: 4px;
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}

.skeleton-stat-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 20px;
}

.skeleton-stat-card .skeleton-label {
  height: 11px;
  width: 80px;
  margin-bottom: 12px;
}

.skeleton-stat-card .skeleton-value {
  height: 28px;
  width: 140px;
}

.skeleton-row {
  display: flex;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #334155;
}

.skeleton-row:last-child { border-bottom: none; }

.skeleton-row .skeleton-text-l { height: 14px; width: 140px; }
.skeleton-row .skeleton-text-r { height: 14px; width: 70px; }

.skeleton-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px;
}

.skeleton-card .skeleton-image {
  width: 100%;
  aspect-ratio: 0.72; /* matches Pokémon card proportions */
  margin-bottom: 12px;
}

.skeleton-card .skeleton-name {
  height: 14px;
  width: 70%;
  margin-bottom: 6px;
}

.skeleton-card .skeleton-set {
  height: 12px;
  width: 50%;
  margin-bottom: 10px;
}

.skeleton-card .skeleton-price {
  height: 16px;
  width: 60px;
}

.load-error {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: #94a3b8;
}

.load-error-message {
  display: flex;
  align-items: center;
  gap: 10px;
}

.load-error-icon {
  color: #ef4444;
  font-size: 18px;
  font-weight: 700;
}

.load-error-retry {
  background: transparent;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}

.load-error-retry:hover {
  border-color: #38bdf8;
}

.title-icon {
  height: 36px;
  width: 36px;
  vertical-align: middle;
  margin-right: 8px;
  margin-bottom: 4px;
}

/* --- Auth --- */
.auth-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: -16px 0 24px 0;
  font-size: 13px;
  color: #94a3b8;
}

.auth-bar-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.auth-link {
  background: transparent;
  border: none;
  color: #38bdf8;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.auth-link:hover { color: #7dd3fc; }

body:not(.authed) .auth-required { display: none !important; }
body.authed .auth-only-loggedout { display: none !important; }

#login-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#login-overlay.open { display: flex; }

#login-panel {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  position: relative;
}

#login-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 6px;
}

#login-close:hover {
  background: #334155;
  color: white;
}

.login-title {
  margin: 0 0 6px 0;
  font-size: 18px;
  font-weight: 700;
  color: white;
  text-transform: none;
  letter-spacing: -0.01em;
}

.login-subtitle {
  margin: 0 0 20px 0;
  font-size: 13px;
  color: #94a3b8;
}

#login-form label {
  display: block;
  font-size: 12px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 16px;
}

#login-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Inter", sans-serif;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}

#login-form input:focus { border-color: #38bdf8; }

.login-error {
  font-size: 13px;
  color: #ef4444;
  margin-bottom: 12px;
  min-height: 18px;
}

#login-submit {
  width: 100%;
  background: #38bdf8;
  color: #0f172a;
  border: none;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 14px;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
}

#login-submit:hover { background: #0ea5e9; }

#login-submit:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* --- Mobile responsiveness --- */
@media (max-width: 600px) {
  body {
    padding: 16px;
  }

  h1 {
    font-size: 24px;
    margin-bottom: 20px;
  }

  /* Detail modal: stack image above info on narrow screens */
  #detail-card-info {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  #detail-card-info img {
    width: 60%;
    max-width: 200px;
  }

  /* Ownership rows: stack columns instead of fighting for horizontal space */
  .ownership-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .ownership-row .price {
    text-align: left;
  }

  .ownership-row .actions {
    justify-content: flex-end;
  }

  /* Inline edit form: stack inputs vertically on phones */
  .ownership-row .edit-form {
    flex-direction: column;
    align-items: stretch;
  }

  .edit-form input,
  .edit-form select {
    width: 100% !important;  /* override the fixed widths from desktop styles */
  }

  /* Cap the cards grid card width so a single card doesn't stretch full-width */
  #cards-container {
    grid-template-columns: repeat(auto-fill, minmax(140px, 200px));
    justify-content: start;
  }

  /* Confirm-delete: also stack to give the buttons room */
  .ownership-row .confirm-delete {
    flex-wrap: wrap;
  }

  /* Error UI: don't squash the Retry button */
  .load-error {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .load-error-retry {
    width: 100%;
  }
}