:root {
  --bg: #faf7f5;
  --surface: #ffffff;
  --text: #2a1f22;
  --muted: #7a6b6f;
  --border: #e8e0dc;
  --accent: #7b1e3a;
  --accent-text: #ffffff;
  --warning-bg: #fff4d6;
  --warning-text: #6b4e00;
  --error-bg: #fde8e8;
  --error-text: #8a1c1c;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1517;
    --surface: #241d20;
    --text: #f1e9eb;
    --muted: #a8979c;
    --border: #3a2f33;
    --accent: #c0506f;
    --warning-bg: #3d3216;
    --warning-text: #f3d98b;
    --error-bg: #3f1d1d;
    --error-text: #f5b5b5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

h1 { font-size: 1.5rem; margin: 8px 0 16px; }

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

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

.button {
  display: inline-block;
  padding: 10px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button:disabled { opacity: 0.6; cursor: wait; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.count { color: var(--muted); margin: 0 0 8px; }

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

.error {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 12px;
  border-radius: var(--radius);
}

.warning {
  display: inline-block;
  background: var(--warning-bg);
  color: var(--warning-text);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.875rem;
}

.empty { text-align: center; padding: 48px 0; }

/* Forms */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-weight: 600; margin-bottom: 4px; }
input, textarea {
  width: 100%;
  padding: 10px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input[type=file] { padding: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Candidate list */
.search-again { display: flex; gap: 8px; margin-bottom: 16px; }
.search-again input { flex: 1; min-width: 0; }

.candidates { list-style: none; padding: 0; margin: 0; }
.candidate { display: flex; gap: 12px; }
.candidate img, .candidate .noimg { width: 64px; height: 120px; object-fit: contain; flex-shrink: 0; }
.candidate .info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.choose { display: flex; align-items: flex-end; gap: 8px; margin-top: 8px; }
.choose label { font-size: 0.875rem; color: var(--muted); }
.choose input { width: 6.5em; display: block; }

/* Wine list: cards on phones, table on wider screens */
.wines { width: 100%; border-collapse: collapse; }
.wines thead { display: none; }
.wines tr {
  display: grid;
  grid-template-columns: 56px 1fr;
  column-gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}
.wines td { padding: 1px 0; grid-column: 2; }
.wines td.thumb { grid-column: 1; grid-row: 1 / span 8; }
.wines td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); }
.wines .name strong { display: block; }
.wines .name .muted { font-size: 0.875rem; }
.wines .links a { margin-right: 12px; font-size: 0.875rem; }
.thumb img { width: 56px; height: 96px; object-fit: contain; }

@media (min-width: 900px) {
  .wines thead { display: table-header-group; }
  .wines tr { display: table-row; border: 0; padding: 0; margin: 0; background: none; }
  .wines th, .wines td {
    display: table-cell;
    padding: 8px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
  }
  .wines th { font-size: 0.875rem; color: var(--muted); font-weight: 600; }
  .wines td[data-label]::before { content: none; }
  .wines .num { text-align: right; white-space: nowrap; }
  .wines .links a { display: block; margin: 0; }
  .wines tbody tr:hover { background: var(--surface); }
  .thumb img { width: 40px; height: 72px; }
}
