:root {
  color-scheme: dark;
  --bg: #090909;
  --surface: #111111;
  --surface-2: #171717;
  --line: rgba(241, 237, 231, 0.09);
  --line-strong: rgba(241, 237, 231, 0.2);
  --red: #c92b35;
  --red-bright: #e2434d;
  --burgundy: #861f27;
  --cream: #f1ede7;
  --cream-dim: rgba(241, 237, 231, 0.66);
  --cream-faint: rgba(241, 237, 231, 0.42);
  --ok: #6fcf97;
  --radius: 12px;
  --display: "Fraunces", Georgia, serif;
  --sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--cream);
  font: 500 15px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}

h1, h2, p { margin: 0; }
h2 { font: 560 20px/1.2 var(--display); }
ul { list-style: none; margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

.muted { color: var(--cream-dim); }
.brand { font: 560 34px/1 var(--display); letter-spacing: 0.08em; }
.brand-small { font-size: 20px; }

/* Кнопки */
.btn {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-bright); }
.btn-ghost { border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--burgundy); color: #fff; }
.btn-danger-ghost { color: var(--red-bright); padding: 0 8px; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-wide { width: 100%; }
.icon-btn {
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: none;
  font-size: 26px; line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
:focus-visible { outline: 2px solid var(--red-bright); outline-offset: 2px; }

/* Поля */
.input, .field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 16px; /* менше 16px змушує iPhone масштабувати сторінку */
}
.field textarea { resize: vertical; }
.field { display: block; margin-bottom: 14px; min-width: 0; flex: 1; }
.field > span { display: block; margin-bottom: 5px; color: var(--cream-dim); font-size: 13px; }
.field-row { display: flex; gap: 12px; }
.form-error { margin-bottom: 12px; color: var(--red-bright); font-size: 14px; }

/* Вхід */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  padding: 28px 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
}
.login-card .muted { margin: 8px 0 22px; }

/* Верхня панель */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 9, 9, 0.94);
}
.tabs { display: flex; gap: 4px; }
.tab {
  min-height: 36px; padding: 0 12px;
  border: 0; border-radius: 10px;
  background: none;
  color: var(--cream-dim);
  font-weight: 600;
  cursor: pointer;
}
.tab.is-active { background: var(--surface-2); color: var(--cream); }
.topbar-actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }

.banner {
  max-width: 1040px;
  margin: 14px auto 0;
  padding: 11px 14px;
  border: 1px solid rgba(226, 67, 77, 0.45);
  border-radius: var(--radius);
  background: rgba(134, 31, 39, 0.22);
  font-size: 14px;
}
@media (max-width: 1072px) { .banner { margin-inline: 16px; } }

.page { max-width: 1040px; margin: 0 auto; padding: 16px 16px 60px; }
.toolbar { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; }
.summary { margin: 12px 0; font-size: 13px; }

/* Список позицій */
.item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 104px auto auto;
  align-items: center;
  gap: 12px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
}
.item.is-hidden .item-text, .item.is-hidden .thumb { opacity: 0.45; }
.thumb {
  width: 56px; height: 56px;
  border-radius: 10px;
  background: var(--surface-2);
  object-fit: cover;
  display: block;
}
.item-name { font-weight: 600; overflow-wrap: anywhere; }
.item-meta { color: var(--cream-faint); font-size: 12.5px; }
.price-wrap { position: relative; }
.price-input {
  width: 100%; min-height: 40px;
  padding: 6px 24px 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 16px; font-weight: 700;
  text-align: right;
}
.price-wrap::after {
  content: "₴";
  position: absolute; right: 9px; top: 50%;
  transform: translateY(-50%);
  color: var(--cream-faint);
  pointer-events: none;
}
.price-input.is-saved { border-color: var(--ok); }
.price-input::-webkit-outer-spin-button,
.price-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.price-input { -moz-appearance: textfield; appearance: textfield; }

.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--cream-dim); cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--red); margin: 0; }

@media (max-width: 720px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  #searchInput, #addBtn { grid-column: 1 / -1; }
  .item {
    grid-template-columns: 56px minmax(0, 1fr) auto;
    grid-template-areas: "thumb text text" "thumb price actions" "switch switch switch";
    row-gap: 8px;
  }
  .item .thumb { grid-area: thumb; }
  .item-text { grid-area: text; }
  .price-wrap { grid-area: price; max-width: 130px; }
  .item-edit { grid-area: actions; }
  .switch { grid-area: switch; }
}

/* Журнал */
.history-item {
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.history-main { min-width: 0; }
.history-title { font-weight: 600; overflow-wrap: anywhere; }
.history-changes { margin-top: 3px; color: var(--cream-dim); font-size: 13.5px; overflow-wrap: anywhere; }
.history-meta { margin-top: 3px; color: var(--cream-faint); font-size: 12.5px; }

/* Вікна */
.dialog {
  width: min(600px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--surface);
  color: var(--cream);
}
.dialog-small { width: min(420px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.spacer { flex: 1; }
#confirmText { margin-top: 8px; }

.photo-row { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.photo-preview {
  flex: 0 0 110px; height: 110px;
  border-radius: 12px;
  background: var(--surface-2) center / cover no-repeat;
  overflow: hidden;
  display: grid; place-items: center;
  color: var(--cream-faint); font-size: 12px;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.file-btn:focus-within { outline: 2px solid var(--red-bright); outline-offset: 2px; }
.hint { flex-basis: 100%; font-size: 12.5px; }

.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 6px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--red); margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  width: max-content; max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #1f1f1f;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
}
.toast.is-error { border-color: var(--red-bright); }

.empty { padding: 30px 8px; color: var(--cream-dim); text-align: center; }
