:root {
  --bg: #f7f3ee; --card: #fff; --ink: #2b211b; --muted: #8a7b70; --line: #e6ddd3;
  --accent: #8a5a36; --accent-ink: #fff; --soft: #f1e7dc; --danger: #b3412e; --ok: #3f7d4e; --warn: #a86a12;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45; }
a { color: var(--accent); }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; background: #3b2a20; color: #f3e9dc;
}
.top .brand { color: #f3e9dc; font-weight: 700; text-decoration: none; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { color: #e3d3c2; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.top nav a.active { background: #5a4233; color: #fff; }
main { max-width: 860px; margin: 0 auto; padding: 16px 14px 80px; }
h1 { font-size: 1.5rem; margin: 6px 0 14px; }
h2 { font-size: 1.15rem; margin: 22px 0 10px; }
h3 { font-size: 1rem; margin: 14px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; }
.grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .875rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 1rem; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #d9b896; border-color: var(--accent); }
button, .btn {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 8px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--danger); border-color: #e7c3bb; }
button.ghost { background: transparent; border-color: transparent; padding: 6px 8px; }
button:disabled { opacity: .5; cursor: default; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex-direction: row; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 12px; border-radius: 999px; color: var(--ink); cursor: pointer; font-size: .95rem; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #fff; }
.rating { display: flex; gap: 4px; flex-wrap: wrap; }
.rating button { width: 40px; padding: 8px 0; justify-content: center; }
.rating button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--soft); font-size: .8rem; }
.badge.score { background: var(--accent); color: #fff; font-weight: 700; }
.reco { background: var(--soft); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.reco ul { margin: 6px 0 0; padding-left: 18px; }
.warn { color: var(--warn); }
.err { color: var(--danger); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
td, th { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
dl.kv { display: grid; grid-template-columns: minmax(130px, 38%) 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; white-space: pre-wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; text-decoration: none; color: var(--ink); font-size: .9rem; }
.tabs a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.libitem { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.libitem input[type=text] { flex: 1 1 180px; width: auto; }
.libitem select, .libitem input[type=number] { width: auto; }
.timer { font-variant-numeric: tabular-nums; font-size: 2rem; font-weight: 700; }
.timer-box { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 16px 0 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #2b211b; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: 90vw; }
.toast.error { background: var(--danger); }
.login { max-width: 360px; margin: 10vh auto; }
details summary { cursor: pointer; color: var(--accent); }
@media (max-width: 560px) {
  main { padding: 12px 10px 80px; }
  .top { padding: 8px 10px; gap: 6px; }
  .top nav a { padding: 5px 8px; font-size: .9rem; }
  dl.kv { grid-template-columns: 1fr; gap: 0 0; }
  dl.kv dd { margin-bottom: 8px; }
}
.modal { position: fixed; inset: 0; background: rgba(30, 20, 14, .45); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.modal-box { max-width: 420px; width: 100%; margin: 0; }

/* Формы в одну строку: поля одинаковой высоты, кнопка на линии полей */
.card > h3:first-child { margin-top: 0; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; gap: 12px; align-items: end; }
.form-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) auto; }
.form-row input, .form-row select, .form-row button { height: 42px; }
.form-row button { padding-inline: 18px; }
table.users td { vertical-align: middle; }
table.users select { height: 42px; }
@media (max-width: 640px) {
  .form-row, .form-row.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .form-row button { width: 100%; justify-content: center; }
}
/* Шапка страницы: заголовок и кнопки действий, с отступом до первого блока */
#app > .spread:first-child { margin-bottom: 16px; row-gap: 4px; }
#app > .spread:first-child h1 { margin-bottom: 6px; }

/* Таблица рекомендованных рецептов: на телефоне каждая строка — карточка */
.reco-table td:not(.rname) { white-space: nowrap; }
@media (max-width: 600px) {
  .reco-table tr:first-child { display: none; }
  .reco-table tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .reco-table td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 2px 0; }
  .reco-table td.rname { font-weight: 600; }
  .reco-table td[data-l]::before { content: attr(data-l); color: var(--muted); }
}
/* Оценка рядом с заголовком: по центру строки, крупнее */
h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h1 .badge { font-size: 1rem; line-height: 1; padding: 6px 10px; }
.card > :last-child { margin-bottom: 0; }

/* Фильтры списка чашек */
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 8px; }
@media (max-width: 760px) { .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
#resetFilters { padding: 4px 0; color: var(--accent); font-size: .875rem; }

/* Цвета оценок */
.s-bad { background: #c8473a !important; border-color: #c8473a !important; color: #fff !important; }
.s-mid { background: #f2c94c !important; border-color: #f2c94c !important; color: #3a2a00 !important; }
.s-good { background: #5aa25f !important; border-color: #5aa25f !important; color: #fff !important; }
.s-top { background: #1f6b35 !important; border-color: #1f6b35 !important; color: #fff !important; }
[hidden] { display: none !important; }
/* Своя стрелка у выпадающих списков, с отступом от правого края */
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238a5a36' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}
/* Мобильная версия */
input, select, textarea { font-size: 16px; } /* меньше 16px — iPhone увеличивает страницу при фокусе */
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
label.check { min-height: 44px; }
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid > label { min-width: 0; }
  .rating button { width: calc((100% - 16px) / 5); height: 44px; }
  .sticky-actions button, .sticky-actions .btn { flex: 1; justify-content: center; }
  .top nav { width: 100%; justify-content: space-between; }
}
