/* Цвета те же, что в программе (Themes/Light.xaml и Dark.xaml). Основа — телефон, планшет и ПК надстраиваются над ним. */
:root,
[data-theme="light"] {
  --bg: #F1F5F0;
  --panel: #FFFFFF;
  --panel2: #EEF3ED;
  --sub: #F5F9F4;
  --border: #DAE3D8;
  --border-strong: #C5D2C3;
  --text: #16261A;
  --muted: #5A6B5D;
  --accent: #1D7A3A;
  --primary: #1D7A3A;
  --primary-press: #17632F;
  --on-accent: #FFFFFF;
  --input: #FFFFFF;
  --sel: #BFD8F9;
  --sel-border: #1F6FD1;
  --hover: #E1ECFB;
  --ok: #1F8A4C;
  --warn: #B06A00;
  --err: #C83A3A;
  --ok-bg: #E2F3E9;
  --warn-bg: #FCEFD9;
  --err-bg: #FBE4E4;
  --info-bg: #E4EEFB;
  --muted-bg: #EAEEF3;
  --top: #0B3D1A;
  --top-text: #FFFFFF;
  --top-muted: rgba(255, 255, 255, .78);
  --top-mark: #8BD12C;
  --shadow: 0 1px 2px rgba(22, 38, 26, .06);
  --shadow-up: 0 -8px 30px rgba(22, 38, 26, .16);
  --scrim: rgba(10, 25, 14, .42);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #12151B;
  --panel: #1A1F27;
  --panel2: #212834;
  --sub: #161B22;
  --border: #2D3644;
  --border-strong: #3D4858;
  --text: #DFE5EE;
  --muted: #8A96A8;
  --accent: #4F9DFF;
  --primary: #2A5EA8;
  --primary-press: #234E8C;
  --on-accent: #FFFFFF;
  --input: #0F1217;
  --sel: #274A78;
  --sel-border: #4F9DFF;
  --hover: #2A3342;
  --ok: #46C37B;
  --warn: #E8A33D;
  --err: #E86A6A;
  --ok-bg: #183A28;
  --warn-bg: #3D2E14;
  --err-bg: #3D1C1C;
  --info-bg: #172A44;
  --muted-bg: #252B35;
  --top: #1A1F27;
  --top-text: #DFE5EE;
  --top-muted: #8A96A8;
  --top-mark: #4F9DFF;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-up: 0 -8px 30px rgba(0, 0, 0, .5);
  --scrim: rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body { overflow: hidden; overscroll-behavior: none; }

button, a, [role="button"], label.tappable, summary {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); }

/* iOS приближает страницу, если шрифт в поле меньше 16px */
input, textarea, select { font: inherit; font-size: 16px; color: var(--text); }

:focus-visible { outline: 2px solid var(--sel-border); outline-offset: 1px; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.err { color: var(--err); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---- Каркас: на телефоне шапка сверху и вкладки снизу ---- */

#app { height: 100dvh; }

.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "main" "nav";
}

.topbar {
  grid-area: top;
  background: var(--top);
  color: var(--top-text);
  padding: env(safe-area-inset-top, 0) max(12px, env(safe-area-inset-right, 0)) 0 max(12px, env(safe-area-inset-left, 0));
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  box-sizing: content-box;
}

.topbar-title { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
.topbar-title .mark { width: 22px; height: 22px; flex: none; }
.topbar-sub { color: var(--top-muted); font-size: 12px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { color: var(--top-text); }

.main { grid-area: main; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.main > .main { flex: 1; }

.nav {
  grid-area: nav;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 0 env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

.nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  color: var(--muted);
  font-size: 11px;
  transition: transform 100ms ease-out;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item:active { transform: scale(.95); }
/* Открытая вкладка светится ровно: без жирного шрифта и смены цвета при наведении */
.nav-item.active { color: var(--accent); }
.nav-badge {
  position: absolute;
  top: 5px;
  left: calc(50% + 5px);
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--err);
  color: #fff;
  font-size: 11px;
  line-height: 17px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: var(--text);
  transition: transform 100ms ease-out, background 100ms ease-out, opacity 100ms;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(.92); background: rgba(127, 127, 127, .18); }
.icon-btn:disabled { opacity: .35; }

/* ---- Панель поиска и фильтры над списком ---- */

.toolbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 8px max(12px, env(safe-area-inset-right, 0)) 8px max(12px, env(safe-area-inset-left, 0));
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: none;
}

.search { position: relative; flex: 1; min-width: 0; }
.search input {
  width: 100%;
  height: 42px;
  padding: 0 38px 0 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--sub);
  -webkit-appearance: none;
  appearance: none;
}
.search input:focus { outline: none; border-color: var(--accent); background: var(--input); }
.search input::-webkit-search-cancel-button { display: none; }
.search .search-icon { position: absolute; left: 10px; top: 10px; width: 22px; height: 22px; color: var(--muted); pointer-events: none; }
.search .search-icon svg { display: block; width: 22px; height: 22px; }
.search .search-clear { position: absolute; right: 0; top: 0; width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.search .search-clear svg { width: 18px; height: 18px; }

.toolbar-row { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* Ряд кнопок прокручивается пальцем */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  margin: 0 -12px;
  padding: 0 12px;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  height: 34px;
  padding: 0 12px;
  border-radius: 17px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: transform 100ms ease-out, background 100ms ease-out;
}
.chip:active { transform: scale(.96); }
.chip:disabled { opacity: .45; }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--on-accent); }
.chip .count { opacity: .75; font-variant-numeric: tabular-nums; }
.chip svg { width: 16px; height: 16px; }
.chip.warn-chip:not(.active) { background: var(--warn-bg); border-color: transparent; color: var(--warn); }

.segments {
  display: flex;
  background: var(--panel2);
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
}
.segment {
  flex: 1;
  min-width: 0;
  height: 36px;
  border-radius: 9px;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.segment.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.segment .count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- Список ---- */

.scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.summary {
  padding: 8px max(12px, env(safe-area-inset-right, 0)) 8px max(12px, env(safe-area-inset-left, 0));
  font-size: 13px;
  color: var(--muted);
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 max(12px, env(safe-area-inset-right, 0)) 16px max(12px, env(safe-area-inset-left, 0));
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 100ms ease-out, background 100ms ease-out;
  min-width: 0;
}
.card:active { transform: scale(.985); background: var(--sub); }
.card.selected { background: var(--hover); border-color: var(--sel-border); }
.card-body { flex: 1; min-width: 0; }
.card-title {
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.card-meta { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-row { display: flex; align-items: baseline; gap: 4px 12px; margin-top: 8px; flex-wrap: wrap; }
.card-price { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-price small { font-size: 13px; font-weight: 400; color: var(--muted); }
.stat { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat b { color: var(--text); font-weight: 600; }
.stat.ok { color: var(--ok); }
.stat.err { color: var(--err); }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 7px;
  font-size: 12px;
  line-height: 18px;
  background: var(--muted-bg);
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.info { background: var(--info-bg); color: var(--sel-border); }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }

/* Подсветка строки с изменившейся закупкой, как в программе */
.pending-box {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  background: var(--warn-bg);
  color: var(--text);
  display: flex;
  gap: 8px;
  align-items: center;
}
.pending-box.up { background: var(--err-bg); }
.pending-box.down { background: var(--ok-bg); }
.pending-box.noOffer { background: var(--muted-bg); }
.pending-box > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.card-action {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: var(--on-accent);
  transition: transform 100ms ease-out, background 100ms ease-out;
}
.card-action svg { width: 22px; height: 22px; }
.card-action:active { transform: scale(.9); }
.card-action.done { background: var(--ok-bg); color: var(--ok); }
td .card-action { width: 34px; height: 34px; }
td .card-action svg { width: 18px; height: 18px; }

.check {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 8px;
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  margin-top: 1px;
}
.check svg { width: 18px; height: 18px; }
.selected > .check, .check.on { background: var(--sel-border); border-color: var(--sel-border); color: #fff; }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

.more { padding: 12px; text-align: center; color: var(--muted); font-size: 13px; min-height: 40px; }

.skeleton { height: 92px; border-radius: 14px; background: var(--panel2); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---- Таблица: от ширины планшета ---- */

.table-wrap { padding: 0 12px 16px; }

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
}
table.grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel2);
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.grid th:first-child { border-top-left-radius: 11px; }
table.grid th:last-child { border-top-right-radius: 11px; }
table.grid th.sortable { cursor: pointer; }
table.grid th .arrow { color: var(--accent); }
table.grid td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:active { background: var(--hover); }
table.grid tbody tr.selected { background: var(--sel); }
table.grid tr.row-up { background: var(--err-bg); }
table.grid tr.row-down { background: var(--ok-bg); }
table.grid tr.row-supplier { background: var(--warn-bg); }
table.grid tr.row-noOffer { background: var(--muted-bg); }
table.grid .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid .c { text-align: center; }
/* Название остаётся на месте, пока таблица прокручивается вбок */
table.grid tbody tr { background: var(--panel); }
table.grid .name { min-width: 240px; max-width: 360px; overflow-wrap: anywhere; position: sticky; left: 0; background: inherit; }
table.grid th.name { background: var(--panel2); z-index: 2; }
table.grid .check { width: 22px; height: 22px; border-radius: 6px; margin: 0; }
.cell-edit { border-bottom: 1px dotted var(--muted); cursor: text; }
.cell-input { width: 86px; height: 32px; padding: 0 6px; border: 1px solid var(--accent); border-radius: 6px; background: var(--input); text-align: right; font-size: 14px; }
.cell-input.wide { width: 100%; min-width: 200px; text-align: left; }

/* ---- Кнопки и поля ---- */

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--panel2);
  color: var(--text);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  transition: transform 100ms ease-out, background 100ms ease-out, opacity 100ms;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--primary); color: var(--on-accent); }
.btn.primary:active { background: var(--primary-press); }
.btn.danger { background: var(--err-bg); color: var(--err); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.apply { min-height: 34px; padding: 0 10px; font-size: 13px; background: var(--panel); flex: none; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; min-width: 120px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--input);
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.field input:disabled, .field select:disabled, .field textarea:disabled { background: var(--panel2); color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }

.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.fields .wide { grid-column: 1 / -1; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; cursor: pointer; }
.toggle input { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--border-strong); position: relative; flex: none; margin: 0; transition: background 150ms ease-out; cursor: pointer; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform 150ms ease-out; }
.toggle input:checked { background: var(--primary); }
.toggle input:checked::after { transform: translateX(18px); }

/* Большие кнопки шага для наценки на телефоне */
.stepper { display: flex; align-items: stretch; gap: 6px; }
.stepper input { flex: 1; min-width: 0; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; padding-left: 4px; padding-right: 4px; }
.stepper button { width: 40px; flex: none; border-radius: 10px; background: var(--panel2); font-size: 20px; line-height: 1; transition: transform 100ms ease-out; }
.stepper button:active { transform: scale(.92); }

/* ---- Шторка снизу; от планшета панель справа ---- */

.scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity 200ms ease-out;
  z-index: 20;
}
.scrim.open { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow-up);
  transform: translateY(100%);
  transition: transform 240ms cubic-bezier(.32, .72, 0, 1);
  will-change: transform;
}
.sheet.open { transform: none; }
.sheet.tall { height: 92dvh; }
.sheet.dragging { transition: none; }

.sheet-handle { flex: none; padding: 8px 0 4px; touch-action: none; cursor: grab; }
.sheet-handle::before { content: ""; display: block; width: 40px; height: 5px; margin: 0 auto; border-radius: 3px; background: var(--border-strong); }

.sheet-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 2px 8px 8px 16px;
  touch-action: none;
}
.sheet-title { flex: 1; min-width: 0; font-size: 17px; font-weight: 600; padding-top: 10px; overflow-wrap: anywhere; line-height: 1.25; }
.sheet-sub { color: var(--muted); font-size: 13px; font-weight: 400; margin-top: 2px; }

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(16px + env(safe-area-inset-bottom, 0));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sheet-foot {
  flex: none;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.sheet-foot > .btn { flex: 1; }

.menu { display: flex; flex-direction: column; margin: 0 -16px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 16px;
  text-align: left;
  width: 100%;
  transition: background 100ms ease-out;
}
.menu-item svg { width: 22px; height: 22px; flex: none; color: var(--muted); }
.menu-item:active { background: var(--panel2); }
.menu-item.danger, .menu-item.danger svg { color: var(--err); }
.menu-item:disabled { opacity: .45; }
.menu-item .menu-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.menu-item .menu-note { display: block; font-size: 13px; color: var(--muted); margin-top: 1px; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 16px; }
.menu-title { font-size: 13px; color: var(--muted); padding: 12px 16px 4px; }

.panel { background: var(--sub); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.panel h4 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; }
.kv > :nth-child(odd) { color: var(--muted); }
.kv > :nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; overflow-wrap: anywhere; }

.offer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.offer:last-child { border-bottom: 0; }
.offer-name { font-weight: 500; overflow-wrap: anywhere; min-width: 0; }
.offer-price { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.offer-meta { color: var(--muted); font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.offer-diff { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.chart { width: 100%; height: 200px; display: block; touch-action: pan-y; }
.chart-tip { font-size: 13px; min-height: 18px; color: var(--muted); }
.chart-legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

.list-gap { display: flex; flex-direction: column; gap: 8px; }

/* Панель действий над выбранными строками */
.action-bar {
  flex: none;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 8px max(12px, env(safe-area-inset-right, 0)) 8px max(12px, env(safe-area-inset-left, 0));
  display: flex;
  align-items: center;
  gap: 8px;
}
.action-bar .count { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.action-bar .chips { flex: 1; margin: 0; padding: 0; }

/* ---- Экран «Ещё» ---- */

.page { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px max(12px, env(safe-area-inset-right, 0)) 24px max(12px, env(safe-area-inset-left, 0)); display: flex; flex-direction: column; gap: 12px; }
.page > * { flex: none; }
.page-group { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.page-group .menu { margin: 0; }
.page-group .menu-item + .menu-item { border-top: 1px solid var(--border); }
.page-title { font-size: 13px; color: var(--muted); padding: 0 4px; margin-bottom: -6px; }
.status-line { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; font-size: 14px; padding: 4px 0; min-width: 0; }
.status-line .muted { white-space: nowrap; }

/* ---- Вход ---- */

.login {
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top, 0)) 20px max(24px, env(safe-area-inset-bottom, 0));
  background: var(--top);
}
.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 20px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
  margin: auto;
}
.login-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-head img { width: 44px; height: 44px; }
.login-head h1 { margin: 0; font-size: 20px; line-height: 1.2; }
.login-head p { margin: 0; color: var(--muted); font-size: 13px; }
.form-error { background: var(--err-bg); color: var(--err); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.form-note { background: var(--info-bg); padding: 10px 12px; border-radius: 10px; font-size: 14px; }

.password-field { position: relative; }
.password-field input { padding-right: 48px; }
.password-field button { position: absolute; right: 0; bottom: 0; width: 46px; height: 44px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.password-field button svg { width: 20px; height: 20px; }

/* ---- Подсказки ---- */

#toasts {
  position: fixed;
  z-index: 40;
  left: 12px;
  right: 12px;
  bottom: calc(68px + env(safe-area-inset-bottom, 0));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 480px;
  background: #16261A;
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
  animation: toast-in 180ms ease-out;
  overflow-wrap: anywhere;
}
.toast.error { background: var(--err); }
.toast button { color: #A9E36B; font-weight: 600; white-space: nowrap; min-height: 28px; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.progress { height: 3px; background: var(--panel2); overflow: hidden; flex: none; }
.progress::after { content: ""; display: block; height: 100%; width: 30%; background: var(--accent); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(400%); } }

.pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.4; }

/* ---- Наведение только там, где есть мышь ---- */

@media (hover: hover) and (pointer: fine) {
  table.grid tbody tr:hover { background: var(--hover); }
  table.grid tbody tr.selected:hover { background: var(--sel); }
  .card:hover { border-color: var(--border-strong); }
  .btn:hover { filter: brightness(.97); }
  .menu-item:hover { background: var(--panel2); }
  .chip:hover:not(.active) { border-color: var(--border-strong); }
  .icon-btn:hover { background: rgba(127, 127, 127, .14); }
}

/* ---- Телефон лёжа: высота дороже ширины, вкладки уходят влево, шапка тоньше ---- */

@media (orientation: landscape) and (max-height: 520px) {
  .shell {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "nav top" "nav main";
  }
  .topbar { min-height: 42px; padding-left: 12px; }
  .topbar-title { font-size: 16px; }
  .topbar .icon-btn { height: 40px; }
  .nav {
    grid-auto-flow: row;
    grid-auto-rows: 1fr;
    width: calc(64px + env(safe-area-inset-left, 0));
    border-top: 0;
    border-right: 1px solid var(--border);
    padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  }
  .nav-item { min-height: 0; font-size: 10px; gap: 0; }
  .nav-item svg { width: 22px; height: 22px; }
  .nav-badge { top: 2px; }
  .toolbar { flex-direction: row; flex-wrap: wrap; align-items: center; padding-top: 6px; padding-bottom: 6px; }
  .toolbar .segments, .toolbar .chips { flex: 1 1 280px; min-width: 0; margin: 0; padding: 0; }
  .toolbar .toolbar-row { flex: 1 1 240px; }
  .search input { height: 38px; }
  .search .search-icon { top: 8px; }
  .search .search-clear { height: 38px; }
  .cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet, .sheet.tall { max-height: 100dvh; left: auto; top: 0; width: min(520px, 75vw); border-radius: 18px 0 0 18px; transform: translateX(100%); height: 100dvh; padding-top: env(safe-area-inset-top, 0); }
  .sheet.open { transform: none; }
  .sheet-handle { display: none; }
  .sheet-head { padding-top: 6px; }
  #toasts { bottom: 12px; left: 76px; }
}

/* ---- Планшет: вкладки слева с подписями, таблицы вместо карточек, панель справа ---- */

@media (min-width: 720px) and (min-height: 521px) {
  .shell {
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "nav top" "nav main";
  }
  .nav {
    grid-auto-flow: row;
    grid-auto-rows: 72px;
    align-content: start;
    border-top: 0;
    border-right: 1px solid var(--border);
    padding: 8px 0;
  }
  .nav-item { font-size: 12px; }
  .sheet, .sheet.tall {
    left: auto;
    top: 0;
    width: min(560px, 70vw);
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 18px 0 0 18px;
    transform: translateX(100%);
  }
  .sheet.open { transform: none; }
  .sheet.center {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    height: auto;
    max-height: 86dvh;
    width: min(460px, 90vw);
    border-radius: 18px;
    transform: translate(-50%, -46%);
    opacity: 0;
    transition: transform 180ms ease-out, opacity 180ms ease-out;
  }
  .sheet.center.open { transform: translate(-50%, -50%); opacity: 1; }
  .sheet-handle { display: none; }
  .sheet-head { padding-top: 10px; }
  #toasts { bottom: 20px; left: 96px; }
  .toolbar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .toolbar .search { flex: 1 1 280px; max-width: 480px; }
  .toolbar .segments { flex: 0 0 auto; }
  .toolbar .segment { padding: 0 14px; }
  .toolbar .chips { flex: 1 1 100%; margin: 0; padding: 0; flex-wrap: wrap; overflow: visible; }
  .toolbar .toolbar-row { flex: 1 1 280px; }
  .page { max-width: 760px; }
}

@media (min-width: 1200px) {
  .shell { grid-template-columns: 96px minmax(0, 1fr); }
  .toolbar .chips { flex: 1 1 auto; }
}

/* Лёжа маленькие окна тоже сбоку */
@media (orientation: landscape) and (max-height: 520px) {
  .sheet.center { width: min(460px, 75vw); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
