:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #efede8;
  --border: #dedbd3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7873;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #1a7f37;
  --mid: #9a6700;
  --bad: #c2312f;
  --good-bg: #e3f4e8;
  --mid-bg: #fbf0d5;
  --bad-bg: #fbe4e3;
  --series-price: #2a78d6;
  --series-taste: #eb6834;
  --series-value: #1baf7a;
  --grid: #e7e5df;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 8px rgba(0, 0, 0, .04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #34332f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --good: #5cc97a;
    --mid: #e3b341;
    --bad: #f07a78;
    --good-bg: #1d3324;
    --mid-bg: #3a2f13;
    --bad-bg: #3d1f1e;
    --series-price: #3987e5;
    --series-taste: #d95926;
    --series-value: #199e70;
    --grid: #2c2c29;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- Layout ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .inner {
  max-width: 1100px; margin: 0 auto; padding: .6rem 16px;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--text-2); padding: .3rem .6rem; border-radius: 6px;
}
.nav a.active, .nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.user { color: var(--muted); font-size: .875rem; }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card + .card { margin-top: 1rem; }
.grid > .card + .card { margin-top: 0; }

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

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: .5rem .9rem; border-radius: 8px; font: inherit; cursor: pointer;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.small { padding: .25rem .6rem; font-size: .875rem; }

label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; }

input[type=text], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.inline-check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }

.taste-picker { display: grid; grid-template-columns: repeat(11, 1fr); gap: .3rem; }
.taste-picker input { position: absolute; opacity: 0; pointer-events: none; }
.taste-picker label {
  margin: 0; text-align: center; padding: .5rem 0; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.taste-picker input:checked + label { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.taste-picker input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (max-width: 480px) {
  .taste-picker { grid-template-columns: repeat(6, 1fr); }
}

/* ---------- Autocomplete ---------- */
.ac { position: relative; }
.ac-list {
  list-style: none; margin: .25rem 0 0; padding: .25rem; border: 1px solid var(--border);
  background: var(--surface); border-radius: 8px; box-shadow: var(--shadow);
}
.ac-list[hidden] { display: none; }
.ac-list li {
  padding: .5rem .6rem; border-radius: 6px; cursor: pointer;
  display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap;
}
.ac-list li[aria-selected=true], .ac-list li:hover { background: var(--surface-2); }
.ac-list .ac-name { font-weight: 600; flex: 1; min-width: 12rem; }
.ac-list .ac-meta { color: var(--muted); font-size: .85rem; }
.ac-list .ac-new { color: var(--accent); font-weight: 600; }
.ac-heading { padding: .3rem .6rem; font-size: .8rem; color: var(--muted); cursor: default !important; }
.ac-heading:hover { background: none !important; }
.chosen {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .5rem .7rem; border-radius: 8px; background: var(--surface-2); margin-top: .4rem;
}
.chosen[hidden] { display: none; }
.warn-box {
  border: 1px solid var(--mid); background: var(--mid-bg); border-radius: 8px;
  padding: .5rem .7rem; margin-top: .4rem;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block; min-width: 2.2rem; text-align: center; padding: .05rem .45rem;
  border-radius: 999px; font-weight: 700; font-variant-numeric: tabular-nums; font-size: .9rem;
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.mid { background: var(--mid-bg); color: var(--mid); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.na { background: var(--surface-2); color: var(--muted); }
.tag {
  display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.up { color: var(--bad); }
.down { color: var(--good); }

/* ---------- Flash ---------- */
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.success { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.flash.error { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: .85rem; color: var(--text-2); font-weight: 600; white-space: nowrap; }
th a { color: inherit; }
th.sorted a { color: var(--text); }
tbody tr:hover { background: var(--surface-2); }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; }
.tile { background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; }
.tile .k { font-size: .8rem; color: var(--text-2); }
.tile .v { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Entries ---------- */
.entries { list-style: none; padding: 0; margin: 0; }
.entries > li { padding: .7rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .8rem; }
.entries > li:last-child { border-bottom: 0; }
.entries .body { flex: 1; min-width: 0; }
.entries .comment { margin: .3rem 0 0; white-space: pre-wrap; color: var(--text-2); }
.thumb { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.photo-preview { max-width: 220px; border-radius: 8px; display: block; margin-top: .5rem; }

.chart-box { position: relative; height: 220px; }
.chart-table summary { cursor: pointer; color: var(--muted); font-size: .85rem; margin-top: .5rem; }

.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--series-value); border-radius: 4px; }

.empty { color: var(--muted); padding: 1rem 0; }
.flash.notice { background: var(--mid-bg); color: var(--text); border-color: var(--mid); }
.photo-preview[hidden] { display: none; }

@media (max-width: 640px) {
  .topbar .inner { gap: .4rem .75rem; }
  .user { margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .nav a { white-space: nowrap; }
}

.gratin-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; width: 100%;
  padding: .75rem 1rem; border-radius: var(--radius); cursor: pointer; text-align: left; font: inherit;
  color: var(--text); background: var(--mid-bg); border: 1px solid var(--mid);
}
.gratin-option:hover { filter: brightness(.98); }
.gratin-option .gratin-title { font-weight: 700; font-size: 1.05rem; }
#dish-select[hidden], #chosen-heading[hidden], #gratin-contents-field[hidden] { display: none; }
.contents { margin: .3rem 0 0; }

/* ---------- Fotos (Nextcloud) ---------- */
.photo-link { flex-shrink: 0; display: block; }
.photo-link.broken {
  width: 84px; height: 84px; border-radius: 8px; background: var(--surface-2);
  display: grid; place-items: center;
}
.photo-link.broken img { display: none; }
.photo-link.broken::after { content: "📷"; font-size: 1.5rem; opacity: .5; }
.error-text { color: var(--bad) !important; }

.lightbox {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  border-radius: var(--radius); width: min(96vw, 1200px); max-height: 94vh;
}
.lightbox::backdrop { background: rgba(0, 0, 0, .75); }
.lightbox-bar {
  display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
  padding: .5rem .75rem; border-bottom: 1px solid var(--border);
}
.lightbox-body { display: grid; place-items: center; padding: .5rem; min-height: 200px; }
.lightbox-body img { max-width: 100%; max-height: calc(94vh - 80px); object-fit: contain; border-radius: 6px; }
.lightbox-body img[hidden], .lightbox-body p[hidden] { display: none; }
