:root {
  --bg: #ffffff;
  --surface: #f6f6f7;
  --surface-hover: #efeff0;
  --border: #e9e9ea;
  --text: #1a1a1a;
  --text-muted: #767676;
  --accent: #2166f0;
  --accent-hover: #1a52c4;
  --accent-soft: #eaf1ff;
  --positive: #1aab55;
  --positive-soft: #eafaf1;
  --negative: #fc3f1d;
  --negative-soft: #fff0ed;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow-card: 0 2px 6px rgba(0,0,0,0.07), 0 12px 32px rgba(0,0,0,0.10);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Фиксированные цветовые схемы поездки — влияют только на акцентный цвет.
   Цвета положительного/отрицательного баланса остаются неизменными (зелёный/красный) —
   это смысловые цвета, а не декоративные. */
:root[data-theme="red"]    { --accent: #fc3f1d; --accent-hover: #e2380f; --accent-soft: #fff0ed; }
:root[data-theme="blue"]   { --accent: #2166f0; --accent-hover: #1a52c4; --accent-soft: #eaf1ff; }
:root[data-theme="green"]  { --accent: #1aab55; --accent-hover: #158f47; --accent-soft: #e9f9ef; }
:root[data-theme="purple"] { --accent: #7c3aed; --accent-hover: #6b2fd1; --accent-soft: #f3ecfe; }
:root[data-theme="orange"] { --accent: #ea7c1f; --accent-hover: #cc6a13; --accent-soft: #fef2e6; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.loading-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-mark {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: -0.02em;
}

/* ---------- Верхняя навигация ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.03em;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand .trip-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 12px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  transition: background .15s, color .15s;
}

.tab.active {
  background: var(--text);
  color: #fff;
}

.tab:not(.active):hover {
  background: var(--surface);
  color: var(--text);
}

.content {
  flex: 1;
  padding: 20px 20px 100px;
}

/* ---------- Нижняя панель вкладок (мобильная версия) ---------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 720px;
  margin: 0 auto;
  z-index: 50;
  display: flex;
  background: rgba(255,255,255,0.94);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}

.bottom-nav-item {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  padding: 6px 2px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .15s;
}

.bottom-nav-icon {
  font-size: 21px;
  line-height: 1;
}

.bottom-nav-item.active {
  color: var(--accent);
}

/* ---------- Карточки ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.card-white {
  background: #fff;
  border: 1px solid #dcdcdd;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 24px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ---------- Расходы ---------- */

.expense-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.expense-row:last-child { border-bottom: none; }

.expense-emoji {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.expense-main {
  flex: 1;
  min-width: 0;
}

.expense-title {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: normal;
  overflow-wrap: break-word;
}

.split-mode-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.expense-amount {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  text-align: right;
}

.expense-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  border: none;
  background: transparent;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .emoji { font-size: 36px; margin-bottom: 12px; }

/* ---------- Баланс ---------- */

.balance-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.balance-row:last-child { border-bottom: none; }

.balance-name { font-weight: 600; font-size: 15px; }

.balance-value {
  font-weight: 700;
  font-size: 15px;
  padding: 4px 10px;
  border-radius: 999px;
  text-align: right;
}
.balance-value.positive { color: var(--positive); background: var(--positive-soft); }
.balance-value.negative { color: var(--negative); background: var(--negative-soft); }
.balance-value.zero { color: var(--text-muted); background: var(--surface); }

.balance-value-member {
  font-weight: 500;
  font-size: 13px;
  padding: 3px 9px;
  border-radius: 999px;
  text-align: right;
}
.balance-value-member.positive { color: var(--positive); background: var(--positive-soft); }
.balance-value-member.negative { color: var(--negative); background: var(--negative-soft); }
.balance-value-member.zero { color: var(--text-muted); background: var(--surface); }

.balance-value-family {
  font-weight: 800;
  font-size: 17px;
  padding: 4px 12px;
  border-radius: 999px;
  text-align: right;
}
.balance-value-family.positive { color: var(--positive); background: var(--positive-soft); }
.balance-value-family.negative { color: var(--negative); background: var(--negative-soft); }
.balance-value-family.zero { color: var(--text-muted); background: var(--surface); }

.settled-highlight {
  background: var(--positive-soft);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 10px;
}

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--surface); border-radius: var(--radius-sm); }

.transfer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.transfer-row:last-child { border-bottom: none; }

.transfer-arrow {
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
}

.transfer-names {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.transfer-from {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  text-align: right;
  white-space: normal;
  overflow-wrap: break-word;
  line-height: 1.25;
  min-width: 0;
}

.transfer-to {
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
  white-space: normal;
  overflow-wrap: break-word;
  line-height: 1.25;
  min-width: 0;
}

.transfer-amount {
  font-weight: 700;
  color: var(--accent);
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
}

/* На узких экранах имена + сумма + кнопка «Выполнен» не помещаются в одну
   строку — переносим сумму и кнопку на вторую строку под именами, чтобы
   колонке с именами было где развернуться и не наезжать на соседей. */
@media (max-width: 899px) {
  .transfer-row {
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .transfer-names {
    flex-basis: 100%;
  }
}

/* ---------- Кнопки ---------- */

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .1s, background .15s;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--surface); color: var(--text); }
.btn-secondary:hover { background: var(--surface-hover); }

.btn-block { width: 100%; }

.btn-small { padding: 8px 14px; font-size: 13px; }

.fab {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  box-shadow: 0 8px 24px rgba(252,63,29,0.35);
}

/* ---------- Формы ---------- */

.field {
  margin-bottom: 16px;
}

.field-warning select,
.field-warning input {
  border-color: var(--negative) !important;
  background: var(--negative-soft) !important;
}
.field-warning .expense-sub { color: var(--negative); }

.field-row {
  display: flex;
  gap: 10px;
}
.field-row .field {
  flex: 1;
  min-width: 0;
}
.field-row .field select,
.field-row .field input {
  width: 100%;
}

.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
}
.emoji-picker-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  font-size: 18px;
  padding: 6px 0;
  line-height: 1;
}
.emoji-picker-btn:hover { background: var(--surface); border-color: var(--accent); }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}

.field input:disabled,
.field select:disabled,
.field textarea:disabled {
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  opacity: 1;
  background: var(--surface);
  cursor: not-allowed;
}

.field textarea { resize: vertical; min-height: 60px; }

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-group-scroll {
  max-height: 130px;
  overflow-y: auto;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip.selected {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.split-mode-group {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.split-mode-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}
.split-mode-btn.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Модальные окна ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal-sheet {
  background: #fff;
  width: 100%;
  max-width: 720px;
  border-radius: 24px 24px 0 0;
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px 20px 32px;
  animation: slideUp .2s ease;
}

@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
  .modal-sheet { border-radius: var(--radius-lg); max-height: 88vh; }
}

@keyframes slideUp { from { transform: translateY(24px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-title { font-size: 18px; font-weight: 800; }

.modal-drag {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 0 auto 16px;
}

/* ---------- Загрузка фото ---------- */

.photo-drop {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.photo-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-drop img { max-width: 100%; max-height: 160px; border-radius: var(--radius-sm); }

.ocr-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}
.ocr-hint.busy { color: var(--accent); }

/* ---------- Onboarding / вход ---------- */

.onboarding {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  max-width: 480px;
  margin: 0 auto;
}

.onboarding-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.onboarding-sub {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 32px;
  line-height: 1.5;
}

.onboarding-switch {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}
.onboarding-switch button {
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 700;
  padding: 0;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  animation: fadeIn .15s ease;
}

.member-row, .family-row, .category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.member-row:last-child, .family-row:last-child, .category-row:last-child { border-bottom: none; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  margin-left: 6px;
}
.badge.admin { background: var(--accent-soft); color: var(--accent); }
.badge.completed { background: var(--negative-soft); color: var(--negative); }

.count-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  margin-left: 6px;
  vertical-align: middle;
}

.invite-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
}
.invite-code {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

/* ---------- Аватары ---------- */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  overflow: hidden;
  flex-shrink: 0;
  object-fit: cover;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 24px; height: 24px; font-size: 11px; }
.avatar-lg { width: 56px; height: 56px; font-size: 20px; }

.name-with-avatar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.family-head { font-weight: 800; }

.avatar-upload {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.avatar-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- Обложка поездки ---------- */

.trip-cover-plate {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.trip-cover-image {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
}
.trip-cover-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.gear-btn {
  border: none;
  background: var(--surface);
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text);
}
.gear-btn:hover { background: var(--surface-hover); }

.theme-swatches {
  display: flex;
  gap: 10px;
}
.theme-swatch {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
}
.theme-swatch.selected { border-color: var(--text); }
.theme-swatch.selected::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}

/* ---------- Графики ---------- */

.chart-block { margin-bottom: 8px; }
.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.chart-bar-label {
  width: 130px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-bar-track {
  flex: 1;
  height: 10px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
}
.chart-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.chart-bar-fill.negative { background: var(--negative); }
.chart-bar-value {
  width: 84px;
  flex-shrink: 0;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
}
.chart-bar-total {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.chart-bar-total .chart-bar-label,
.chart-bar-total .chart-bar-value {
  font-size: 14px;
  font-weight: 800;
}

.current-balance-row {
  margin-top: 10px !important;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.family-toggle-arrow {
  display: inline-block;
  font-size: 11px;
  color: var(--text-muted);
  width: 12px;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* ---------- Разворачиваемая разбивка баланса ---------- */

.balance-row-wrap { border-bottom: 1px solid var(--border); }
.balance-row-wrap:last-child { border-bottom: none; }
.balance-row-wrap .balance-row { border-bottom: none; cursor: pointer; padding: 12px 0; }
.balance-breakdown {
  padding: 0 0 14px 0;
  display: none;
}
.balance-breakdown.open { display: block; }
.breakdown-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 0 6px 12px;
  border-left: 2px solid var(--border);
}
.breakdown-item b { color: var(--text); font-weight: 600; }

.breakdown-category-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 12px 0 4px 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.breakdown-category-title:first-child { margin-top: 4px; }

.family-group-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.01em;
  margin: 18px 0 8px;
}

.family-card {
  background: #fff;
  border: 1px solid #dcdcdd;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}
.family-card:last-child { margin-bottom: 0; }
.family-card.settled-highlight { background: var(--positive-soft); border-color: transparent; }
.family-card .family-group-title { margin: 0 0 8px; }
.family-group-title:first-child { margin-top: 0; }

/* ---------- Полноэкранный просмотр фото ---------- */

.fullscreen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  cursor: zoom-out;
}
.fullscreen-overlay img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
}

.receipt-preview-box {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  margin-bottom: 8px;
}
.receipt-preview-box img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: zoom-in;
  flex-shrink: 0;
}
.receipt-preview-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.warning-banner {
  background: var(--negative-soft);
  color: var(--negative);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}

.items-list {
  font-size: 13px;
  color: var(--text-muted);
  white-space: pre-line;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ---------- Десктоп: единая панель Траты + Баланс ---------- */

@media (min-width: 900px) {
  #app { max-width: min(96vw, 1800px); }
  .content { padding: 20px 28px 60px; }

  .desktop-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
    align-items: start;
  }
  .charts-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Узкая верхняя панель события ---------- */

.event-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 15;
  background: rgba(255,255,255,0.94);
  backdrop-filter: saturate(180%) blur(12px);
}

.event-bar-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--text-muted);
  cursor: pointer;
}
.event-bar-name {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.event-bar-dates {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-muted);
}

.event-switcher {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.event-switcher::-webkit-scrollbar { display: none; }

.event-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  color: var(--text-muted);
}
.event-pill.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.event-pill-avatar {
  width: 22px; height: 22px; border-radius: 999px; object-fit: cover; background: var(--surface); flex-shrink: 0;
}
.event-pill-delete {
  border: none; background: transparent; color: var(--text-muted); font-size: 12px; padding: 0 2px; margin-left: 2px;
}
.event-pill-delete:hover { color: var(--negative); }

.settings-btn-labeled {
  border: none;
  background: var(--surface);
  border-radius: 999px;
  padding: 9px 16px 9px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}
.settings-btn-labeled:hover { background: var(--surface-hover); }

.event-user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  padding: 0 4px;
}
.event-user-badge b { color: var(--text); font-weight: 700; }

/* ---------- Трёхколоночная десктоп-раскладка ---------- */

.three-col {
  display: grid;
  grid-template-columns: minmax(340px, 1.15fr) minmax(320px, 1fr) minmax(340px, 1.15fr);
  gap: 40px;
  align-items: start;
  padding: 20px 40px 28px;
}
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: start;
  padding: 20px 40px 28px;
}
.two-col .col-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - var(--topbar-h, 64px) - 40px);
  padding: 4px 36px;
  margin: -4px -36px;
}
.three-col .col-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - var(--topbar-h, 64px) - 40px);
  padding: 4px 36px;
  margin: -4px -36px;
}
.three-col .col-split {
  max-height: calc(100vh - var(--topbar-h, 64px) - 40px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.col-split-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.col-split-pane .pane-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  padding: 4px 36px;
  margin: -4px -36px;
}
.three-col .col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

/* Колонка с зафиксированным (не прокручивающимся) заголовком — используется
   на вкладке «Расчёты», чтобы заголовок оставался на месте при скролле. */
.col-fixed-header {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--topbar-h, 64px) - 40px);
}
.col-fixed-header > *:not(.col-scroll-inner) {
  flex-shrink: 0;
}
.col-fixed-header .col-header {
  margin: 0 0 14px;
  padding-top: 2px;
}
.col-scroll-inner {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  padding: 4px 36px;
  margin: -4px -36px;
}

@media (max-width: 1099px) {
  .three-col { grid-template-columns: 1fr 1fr; }
  .three-col .col-fixed-header:nth-child(2) { grid-column: 1 / -1; order: 3; }
}
@media (max-width: 899px) {
  .three-col { grid-template-columns: 1fr; padding: 16px; }
  .three-col .col-scroll { max-height: none; overflow-y: visible; }
}

/* ---------- Вход администратора ---------- */

.admin-login-toggle {
  text-align: center;
  margin-top: 28px;
  font-size: 13px;
  color: var(--text-muted);
}
.admin-login-toggle button { border: none; background: none; color: var(--text-muted); text-decoration: underline; padding: 0; font-size: 13px; }

.admin-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.admin-list-row:last-child { border-bottom: none; }

/* ---------- План закупок ---------- */

.shopping-toolbar {
  margin-bottom: 16px;
}
.shopping-toolbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.shopping-toolbar-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-right: 2px;
}

.collapse-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.01em;
}
.shopping-import .collapse-toggle { margin: -2px -2px 0; padding: 2px; }
.collapse-body { margin-top: 12px; }

.shopping-import {
  margin-bottom: 16px;
}
.shopping-import textarea {
  width: 100%;
  min-height: 70px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  font-family: var(--font);
  resize: vertical;
}

.shopping-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.shopping-table-wrap {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - var(--topbar-h, 64px) - 60px);
}
.shopping-summary {
  width: 260px;
  flex-shrink: 0;
}
@media (max-width: 899px) {
  .shopping-layout { flex-direction: column; }
  .shopping-summary { width: 100%; }
  /* В column-направлении flex align-items:flex-start (унаследованный) даёт
     элементу его "естественную" ширину по содержимому вместо ширины
     контейнера — у широкой таблицы (много столбцов, много строк) это
     сотни лишних пикселей, из-за которых всю страницу распирает вбок.
     Явно фиксируем ширину на весь контейнер. */
  .shopping-table-wrap { width: 100%; }
}

table.shopping-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #dcdcdd;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
/* Раньше углы скруглялись через overflow:hidden на самой таблице — но это
   ломает position:sticky у заголовка (overflow создаёt свой контекст обрезки,
   и sticky перестаёт держаться относительно окна). Вместо этого скругляем
   угловые ячейки напрямую. */
table.shopping-table thead tr:first-child th:first-child { border-top-left-radius: var(--radius-md); }
table.shopping-table thead tr:first-child th:last-child { border-top-right-radius: var(--radius-md); }
table.shopping-table tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius-md); }
table.shopping-table tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius-md); }
table.shopping-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 5;
}
/* Первый столбец (Наименование) закреплён при горизонтальной прокрутке —
   иначе у широкой таблицы название товара сразу уезжает за край экрана.
   Угловая ячейка (шапка + первый столбец одновременно) — сверху всех. */
table.shopping-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fff;
}
table.shopping-table th:first-child {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 6;
}
table.shopping-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.shopping-table tr:last-child td { border-bottom: none; }
table.shopping-table tr.bought-row td { background: var(--positive-soft); }
table.shopping-table tr.shopping-row-focused td { background: var(--accent-soft); }

.shopping-cell-input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
}
.shopping-cell-input:hover { border-color: var(--border); }
.shopping-cell-input:focus { border-color: var(--accent); background: #fff; outline: none; }
.shopping-cell-input.num { text-align: right; }
.shopping-cell-input.name { min-width: 160px; }

.shopping-cell-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: var(--font);
  background: #fff;
  min-width: 110px;
}

.shopping-row-delete {
  border: none;
  background: transparent;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 999px;
  flex-shrink: 0;
}
.shopping-row-delete:hover { background: var(--negative-soft); color: var(--negative); }

.shopping-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.shopping-summary-row:last-child { border-bottom: none; }
.shopping-summary-row.total-row { font-weight: 800; font-size: 15px; padding-top: 12px; }
