:root {
  --black: #1a2332;
  --white: #ffffff;
  --grey-1: #f5f3f0;
  --grey-2: #e2ddd7;
  --grey-3: #a8a29e;
  --grey-4: #57534e;
  --focus: #e5a100;
  --error: #c2410c;
  --success: #166534;
  --accent: #1e5c6b;

  /* Backward-compat aliases */
  --bg: var(--white);
  --surface: var(--grey-1);
  --border: var(--grey-2);
  --text: var(--black);
  --text-muted: var(--grey-4);
  --primary: var(--black);
  --primary-hover: #2d3f54;
  --danger: var(--error);
  --danger-hover: #9a3412;
  --badge-bg: #dfe8ea;
  --badge-text: #1e5c6b;
  --radius: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --black: #f0ece6;
    --white: #141a23;
    --grey-1: #1c2430;
    --grey-2: #2a3444;
    --grey-3: #4a5568;
    --grey-4: #a0aec0;
    --focus: #e5a100;
    --error: #fb923c;
    --success: #4ade80;
    --accent: #38b2ac;
    --badge-bg: #1e3a40;
    --badge-text: #81e6d9;
  }
}

[data-theme="dark"] {
  --black: #f0ece6;
  --white: #141a23;
  --grey-1: #1c2430;
  --grey-2: #2a3444;
  --grey-3: #4a5568;
  --grey-4: #a0aec0;
  --focus: #e5a100;
  --error: #fb923c;
  --success: #4ade80;
  --accent: #38b2ac;
  --badge-bg: #1e3a40;
  --badge-text: #81e6d9;
}

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

*:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

body {
  font-family:
    "Inter",
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--white);
  color: var(--black);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: var(--black);
  text-decoration: underline;
}

a:hover {
  text-decoration: none;
}

code {
  font-family: monospace;
  font-size: 0.9em;
}

/* Header */
header {
  background: #1a2332;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-weight: 700;
  font-size: 1.15rem;
  color: #f0ece6;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.logo:hover {
  text-decoration: underline;
  color: #f0ece6;
}

nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav-link {
  color: #f0ece6;
  font-size: 0.9rem;
  text-decoration: underline;
}

.nav-link:hover {
  text-decoration: none;
  color: #f0ece6;
}

nav .username {
  color: #f0ece6;
  font-weight: 500;
  font-size: 0.9rem;
}

/* Theme toggle */
.btn-theme-toggle {
  background: none;
  border: 1px solid rgba(240, 236, 230, 0.5);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  color: #f0ece6;
  display: flex;
  align-items: center;
}

.btn-theme-toggle:hover {
  background: var(--grey-3);
}

/* Show sun in dark mode, moon in light mode */
.theme-icon-sun {
  display: none;
}

.theme-icon-moon {
  display: inline;
}

[data-theme="dark"] .theme-icon-sun {
  display: inline;
}

[data-theme="dark"] .theme-icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :not([data-theme="light"]) .theme-icon-sun {
    display: inline;
  }

  :not([data-theme="light"]) .theme-icon-moon {
    display: none;
  }
}

/* Main */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.text-muted {
  color: var(--text-muted);
}

.hint {
  color: var(--text-muted);
  font-size: 0.85em;
  font-weight: normal;
}

/* Trade category cards */
.trade-cards {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 2rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  justify-content: center;
}

.trade-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-width: 88px;
  padding: 0.75rem 0.5rem;
  background: var(--grey-1);
  border: 1px solid var(--grey-2);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--black);
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    background 0.15s;
  flex-shrink: 0;
}

.trade-card:hover {
  border-color: var(--accent, var(--black));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  background: var(--white);
  text-decoration: none;
}

.trade-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.trade-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--grey-4);
  white-space: nowrap;
}

.trade-card:hover .trade-label {
  color: var(--black);
}

.trade-card.selected {
  border-color: var(--accent, var(--black));
  background: var(--white);
}

.trade-card.selected .trade-label {
  color: var(--black);
}

/* Search / filter bar */
.search-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.search-bar input,
.search-bar select {
  padding: 0.55rem 0.85rem;
  border: 2px solid var(--grey-2);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 0.95rem;
  color: var(--black);
  outline: none;
  transition: border-color 0.15s;
}

.search-bar input:focus,
.search-bar select:focus {
  border-color: var(--accent, var(--black));
}

.search-bar input {
  flex: 1;
  min-width: 160px;
}

.results-note {
  font-size: 0.9rem;
  color: var(--grey-4);
  margin-bottom: 1rem;
}

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--grey-1);
  border: 1px solid var(--grey-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.card:hover {
  border-color: var(--accent, var(--black));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.card-img {
  height: 160px;
  overflow: hidden;
}

.card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card > .card-header,
.card > h3,
.card > .stars,
.card > .description,
.card > .card-address,
.card > .card-footer {
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding-top: 1rem;
  padding-bottom: 0.3rem;
}

.card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  padding-top: 0.3rem;
}

.card h3 a {
  color: var(--black);
  text-decoration: none;
}

.card h3 a:hover {
  text-decoration: underline;
}

.card .description {
  color: var(--grey-4);
  font-size: 0.9rem;
  flex: 1;
  padding-top: 0.3rem;
}

.sponsor-card {
  border-color: var(--accent);
  background: var(--white);
  grid-column: 1 / -1;
  display: flex;
  flex-direction: row;
  min-height: 200px;
}

.sponsor-card .card-img {
  width: 40%;
  height: auto;
  min-height: 200px;
  aspect-ratio: 16 / 9;
}

.sponsor-card .card-content {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.sponsor-card h3 {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
  padding: 0;
}

.sponsor-card .description {
  font-size: 1rem;
  margin-bottom: 1.5rem;
  padding: 0;
}

.sponsor-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--white);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  width: fit-content;
}

@media (max-width: 600px) {
  .sponsor-card {
    flex-direction: column;
  }

  .sponsor-card .card-img {
    width: 100%;
    height: 160px;
    min-height: 160px;
  }
}

.card-address {
  font-size: 0.85rem;
  color: var(--grey-4);
  padding-top: 0.2rem;
}

.card-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding-top: 0.75rem;
  padding-bottom: 1rem;
  margin-top: auto;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Badge */
.badge {
  display: inline-block;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 2px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Verified badge */
.verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: #dcfce7;
  color: #15803d;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
}

@media (prefers-color-scheme: dark) {
  :not([data-theme="light"]) .verified-badge {
    background: #14532d;
    color: #86efac;
  }
}

[data-theme="dark"] .verified-badge {
  background: #14532d;
  color: #86efac;
}

/* Open now badge */
.open-badge {
  display: inline-block;
  background: #d1fae5;
  color: #065f46;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
}

@media (prefers-color-scheme: dark) {
  :not([data-theme="light"]) .open-badge {
    background: #064e3b;
    color: #6ee7b7;
  }
}

[data-theme="dark"] .open-badge {
  background: #064e3b;
  color: #6ee7b7;
}

/* Stars */
.stars {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  font-size: 0.9rem;
}

.star {
  color: #d1d5db;
}

.star.filled {
  color: #f59e0b;
}

.review-count {
  font-size: 0.8rem;
  color: var(--grey-4);
  margin-left: 0.2rem;
}

/* Heart / favorite button */
.btn-heart {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--grey-4);
  padding: 0 0.2rem;
  line-height: 1;
}

.btn-heart:hover {
  color: var(--black);
}

.btn-heart.favorited {
  color: #ef4444;
}

/* Detail page */
.detail-card {
  background: var(--grey-1);
  border: 1px solid var(--grey-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  max-width: 680px;
}

.hero-img {
  margin: -2rem -2rem 1.5rem;
  overflow: hidden;
  max-height: 300px;
}

.hero-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}

.detail-card h1 {
  margin-bottom: 0.35rem;
}

.detail-meta {
  color: var(--grey-4);
  font-size: 0.9rem;
  margin: 0.5rem 0 1.25rem;
}

.detail-row {
  margin-bottom: 0.6rem;
  font-size: 0.95rem;
}

.detail-row strong {
  display: inline-block;
  width: 90px;
  color: var(--grey-4);
}

/* Hours table */
.hours-table {
  margin: 1.25rem 0;
}

.hours-table strong {
  display: block;
  color: var(--grey-4);
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hours-table table {
  border-collapse: collapse;
  font-size: 0.9rem;
}

.hours-table td {
  padding: 0.2rem 0.6rem 0.2rem 0;
}

.hours-day {
  color: var(--grey-4);
  width: 90px;
}

/* Hours form */
.hours-section {
  border: 1px solid var(--grey-2);
  margin-top: 0.5rem;
}

.hours-section summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.95rem;
  user-select: none;
}

.hours-grid {
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.hours-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.hours-day-label {
  width: 85px;
  font-weight: 500;
  color: var(--grey-4);
}

.hours-row input[type="time"] {
  padding: 0.3rem 0.5rem;
  border: 2px solid var(--black);
  background: var(--white);
  color: var(--black);
  font-size: 0.9rem;
}

.hours-closed-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--grey-4);
  cursor: pointer;
}

/* Share section */
.share-section {
  margin-top: 1.5rem;
}

.share-section strong {
  display: block;
  color: var(--grey-4);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.share-links {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.share-url {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--grey-2);
  background: var(--white);
  color: var(--grey-4);
  font-size: 0.85rem;
  font-family: monospace;
  outline: none;
}

/* btn-fav-active */
.btn-fav-active {
  color: #ef4444;
  border-color: #fca5a5;
}

/* Reviews */
.reviews-section {
  max-width: 680px;
  margin-top: 2rem;
}

.reviews-section h2 {
  margin-bottom: 1rem;
}

.review-form {
  background: var(--grey-1);
  border: 1px solid var(--grey-2);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.review-card {
  background: var(--grey-1);
  border: 1px solid var(--grey-2);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}

.own-review {
  border-color: var(--black);
}

.review-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}

.review-author {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--black);
}

.review-date {
  font-size: 0.8rem;
  color: var(--grey-4);
  margin-left: auto;
}

.review-body {
  font-size: 0.9rem;
  color: var(--grey-4);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 2rem;
  justify-content: center;
}

.page-info {
  color: var(--grey-4);
  font-size: 0.9rem;
}

.btn.disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* My listings */
.my-listings-table {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.my-listing-row {
  background: var(--grey-1);
  border: 1px solid var(--grey-2);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.my-listing-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.my-listing-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  flex-shrink: 0;
}

.my-listing-name {
  font-weight: 600;
  color: var(--black);
  text-decoration: none;
}

.my-listing-name:hover {
  text-decoration: underline;
}

/* Admin */
.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  border-top: 2px solid var(--black);
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--grey-2);
}

.admin-table th {
  color: var(--black);
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--grey-1);
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-table td form {
  display: inline;
  margin-right: 0.3rem;
}

/* Settings / tokens */
.token-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--grey-2);
  flex-wrap: wrap;
}

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

.token-value {
  font-size: 0.82rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Form */
.form-wrapper {
  max-width: 520px;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.9rem;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  padding: 0.55rem 0.85rem;
  border: 2px solid var(--grey-2);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--black);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent, var(--black));
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group input[type="file"] {
  padding: 0.4rem 0.6rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-family: inherit;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.btn-primary {
  background: var(--accent, var(--black));
  color: var(--white);
  border-color: var(--accent, var(--black));
}

.btn-primary:hover {
  background: var(--white);
  color: var(--accent, var(--black));
  border-color: var(--accent, var(--black));
  text-decoration: none;
}

.btn-secondary {
  background: var(--white);
  color: var(--black);
  border-color: var(--black);
}

.btn-secondary:hover {
  background: var(--black);
  color: var(--white);
  text-decoration: none;
}

.btn-danger {
  background: var(--white);
  color: var(--error);
  border-color: var(--error);
}

.btn-danger:hover {
  background: var(--error);
  color: var(--white);
  text-decoration: none;
}

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

/* Alert / error */
.alert {
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border-radius: var(--radius);
}

.alert-error {
  border-left: 4px solid var(--error);
  background: #fff2f0;
  color: #1a2332;
}

.alert-success {
  border-left: 4px solid var(--success);
  background: #f0fff4;
  color: #1a2332;
}

.alert-info {
  border-left: 4px solid var(--accent, #3b82f6);
  background: #eff6ff;
  color: #1a2332;
}

@media (prefers-color-scheme: dark) {
  :not([data-theme="light"]) .alert-error {
    background: #2d1010;
    color: #f0ece6;
    border-left-color: var(--error);
  }

  :not([data-theme="light"]) .alert-success {
    background: #0d2010;
    color: #f0ece6;
    border-left-color: var(--success);
  }

  :not([data-theme="light"]) .alert-info {
    background: #0d1a2d;
    color: #f0ece6;
    border-left-color: #3b82f6;
  }
}

[data-theme="dark"] .alert-error {
  background: #2d1010;
  color: #f0ece6;
  border-left-color: var(--error);
}

[data-theme="dark"] .alert-success {
  background: #0d2010;
  color: #f0ece6;
  border-left-color: var(--success);
}

[data-theme="dark"] .alert-info {
  background: #0d1a2d;
  color: #f0ece6;
  border-left-color: #3b82f6;
}

/* Empty state */
.empty {
  padding: 4rem 0;
  color: var(--grey-4);
}

.empty p {
  font-size: 1.05rem;
}

/* Auth pages */
.auth-wrapper {
  max-width: 400px;
  margin: 3rem auto;
}

.auth-wrapper h1 {
  margin-bottom: 1.5rem;
}

/* Back link */
.back {
  display: inline-block;
  margin-bottom: 1.5rem;
  color: var(--grey-4);
  font-size: 0.9rem;
}

.back:hover {
  color: var(--black);
}

/* Footer */
footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 1.5rem;
  border-top: 1px solid var(--grey-2);
  font-size: 0.85rem;
  color: var(--grey-4);
  text-align: center;
}

@media (max-width: 600px) {
  header {
    padding: 0 1rem;
  }

  main {
    padding: 1.25rem 1rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  nav {
    gap: 0.5rem;
  }

  .search-bar {
    flex-direction: column;
  }

  .search-bar input {
    width: 100%;
  }

  .hours-row {
    flex-wrap: wrap;
  }

  .hours-day-label {
    width: 100%;
  }
}
