:root {
  --bg: #faf7f4;
  --surface: #ffffff;
  --text: #2b2118;
  --muted: #6b5d4f;
  --accent: #7b1e2b;
  --accent-contrast: #ffffff;
  --border: #e6ddd4;
  --radius: 10px;
  --max-width: 1080px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
}

a {
  color: var(--accent);
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
  color: var(--text);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.site-nav a {
  margin-left: 1rem;
  text-decoration: none;
  color: var(--muted);
}

.site-nav a:hover {
  color: var(--accent);
}

/* Hamburger button: hidden on desktop, shown on small screens. */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  position: relative;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.nav-toggle-bars::before {
  top: -6px;
}

.nav-toggle-bars::after {
  top: 6px;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bars {
  background: transparent;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bars::before {
  transform: translateY(6px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bars::after {
  transform: translateY(-6px) rotate(-45deg);
}

.site-main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3rem) clamp(1rem, 4vw, 2rem);
}

.hero h1 {
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  margin: 0 0 0.5rem;
}

.hero p {
  color: var(--muted);
  max-width: 60ch;
}

.button {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.7rem 1.4rem;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-top: 2.5rem;
}

.features article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.features h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
}

.skip-link {
  position: absolute;
  left: -999px;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  background: var(--surface);
  padding: 0.5rem 1rem;
  z-index: 10;
}

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

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

.auth-card {
  max-width: 460px;
}

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

.stack label,
.card label:not(.checkbox) {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.95rem;
}

input,
select,
textarea {
  font: inherit;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  width: 100%;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
}

.checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}

.checkbox input {
  width: auto;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.inline-form {
  display: inline;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.link-button.danger {
  color: #a11;
}

.search-form {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

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

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: #efe7df;
  color: var(--muted);
  font-size: 0.8rem;
}

.badge-public {
  background: #e2efe4;
  color: #2c6b3c;
}

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.flash {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.flash-success {
  background: #e2efe4;
  border-color: #b9dcc2;
}

.flash-error {
  background: #f6e0e0;
  border-color: #e6b4b4;
}

.address-list {
  list-style: none;
  padding: 0;
}

.address-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.detail-list {
  display: grid;
  grid-template-columns: minmax(100px, 200px) 1fr;
  gap: 0.4rem 1rem;
  margin: 0;
}

@media (max-width: 480px) {
  .detail-list {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }

  .detail-list dt {
    margin-top: 0.5rem;
  }
}

.detail-list dt {
  font-weight: 600;
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
}

.photo-grid {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}

.photo-grid img,
.avatar {
  width: 100%;
  max-width: 160px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

@media (max-width: 560px) {
  .search-form {
    flex-direction: column;
  }
}

/* Mobile navigation (hamburger) */
@media (max-width: 720px) {
  .nav-toggle {
    display: inline-flex;
  }

  .site-nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    order: 3;
    margin-top: 0.75rem;
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
    gap: 0.15rem;
  }

  .site-nav.is-open {
    display: flex;
  }

  .site-nav a,
  .site-nav .language-switch {
    margin-left: 0;
  }

  .site-nav a {
    padding: 0.6rem 0.25rem;
    border-bottom: 1px solid var(--border);
  }

  .site-nav .inline-form {
    padding: 0.6rem 0.25rem;
  }

  .site-nav .language-switch {
    padding: 0.6rem 0.25rem;
  }

  .site-nav .language-switch select {
    width: 100%;
  }

  /* Prevent background scroll while the menu is open. */
  body.nav-open {
    overflow: hidden;
  }
}

/* Responsive tables: allow horizontal scroll instead of breaking layout. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  .data-table thead,
  .data-table tbody {
    display: table;
    width: 100%;
  }
}

/* Branding and artwork */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.brand img {
  display: block;
  width: 32px;
  height: 32px;
}

.hero-split {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 2rem;
  align-items: center;
}

.hero-art {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.hero-logo {
  display: block;
  width: clamp(120px, 30vw, 180px);
  height: auto;
  margin-bottom: 0.5rem;
}

.feature-icon {
  width: 56px;
  height: 56px;
}

.features article {
  text-align: left;
}

@media (max-width: 720px) {
  .hero-split {
    grid-template-columns: 1fr;
  }
}

/* Buttons */
.button-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.card-list {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 1rem;
}

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

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.fieldset legend {
  font-weight: 600;
  padding: 0 0.35rem;
}

/* State badges */
.badge.state-active,
.badge.state-negotiating { background: #e6e3f5; color: #4a3f8f; }
.badge.state-agreed,
.badge.state-paid { background: #e2efe4; color: #2c6b3c; }
.badge.state-completed { background: #d9efe0; color: #1f5a30; }
.badge.state-disputed { background: #f6e0e0; color: #a11; }
.badge.state-cancelled,
.badge.state-expired { background: #efe7df; color: #6b5d4f; }

/* Thread and timeline */
.thread,
.timeline {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.thread li {
  border-left: 3px solid var(--border);
  padding-left: 0.75rem;
}

.thread-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.thread-head time,
.timeline time {
  color: var(--muted);
  font-size: 0.85rem;
}

.timeline li::before {
  content: "○";
  margin-right: 0.5rem;
  color: var(--muted);
}

.timeline li.done::before {
  content: "●";
  color: #2c6b3c;
}

.swap-parties {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.totals {
  margin-top: 1rem;
}

/* Admin */
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: capitalize;
}

.unread {
  border-left: 4px solid var(--accent);
}

.site-nav a {
  margin-left: 0.75rem;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  margin-left: 0.75rem;
}

.language-switch select {
  width: auto;
  padding: 0.25rem 0.5rem;
  font-size: 0.9rem;
}

.camera-capture {
  margin: 0.5rem 0;
}

.camera-preview video {
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #000;
}

.match-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.match-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.match-item img {
  width: 48px;
  border-radius: 6px;
}

.match-item > div {
  flex: 1;
}

.catalog-wine-head {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.catalog-bottle {
  width: 120px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
}

.thumb-col {
  width: 48px;
}

.catalog-thumb {
  display: block;
  width: 40px;
  height: 56px;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
}

.catalog-thumb-empty {
  border: 1px dashed var(--border);
}

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