:root {
  --bg: #f6f5f2;
  --card: #fff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e5e2dc;
  --accent: #0d6e5a;
  --danger: #c62828;
  --pos: #0d6e5a;
  --neg: #b71c1c;
  --hdr-h: 0px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  /* Primary save button height; leave ~1.5× empty below so Android nav/gestures don't cover it */
  --save-btn-h: 48px;
  --save-bar-clear: calc((var(--save-btn-h) * 1.5) + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
}
button, input, select, textarea { font: inherit; }
a { color: var(--accent); }

#app { max-width: 480px; margin: 0 auto; min-height: 100vh; background: var(--bg); }
/* Trip expand: comfortable phone shell — never full-desktop stretch */
#app.wide-trip { max-width: 560px; width: 100%; margin: 0 auto; }
#app.wide-trip .trip-expand,
#app.wide-trip .people-tab,
#app.wide-trip .trip-feed,
#app.wide-trip .form {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.screen { display: none; padding-bottom: calc(88px + var(--save-bar-clear)); }
.screen.active { display: block; }
.screen.screen-detail {
  padding-bottom: calc(72px + var(--save-bar-clear));
}
html.is-android .screen,
html.is-capacitor .screen {
  padding-bottom: calc(88px + var(--save-bar-clear));
}
html.is-android .screen.screen-detail,
html.is-capacitor .screen.screen-detail {
  padding-bottom: calc(80px + var(--save-bar-clear));
}

.sticky-hdr {
  position: sticky;
  top: 0;
  z-index: 60;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: max(10px, env(safe-area-inset-top, 0px)) 14px 8px;
}
.sticky-hdr .btn {
  position: relative;
  z-index: 2;
  min-height: 40px;
  min-width: 44px;
  touch-action: manipulation;
}
.detail-save-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  /* ~1.5 button heights of empty space under Сохранить (clears Android gesture/nav) */
  padding-bottom: calc(12px + var(--save-bar-clear));
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 14px rgba(0,0,0,.06);
  pointer-events: auto;
}
#app.wide-trip .detail-save-bar { max-width: 560px; }
/* Space for fixed save bar: top pad + button + clearance under button */
#app.detail-route,
#app.form-route {
  padding-bottom: calc(22px + var(--save-btn-h) + var(--save-bar-clear));
  min-height: 100vh;
}
.detail-save-bar .btn {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: var(--save-btn-h);
  touch-action: manipulation;
}
.sticky-hdr h1, .sticky-hdr .title-edit {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  border: none;
  background: transparent;
  width: 100%;
  padding: 0;
}
.hdr-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
  flex-wrap: wrap;
}
.hdr-row .spacer { flex: 1; }
.bal-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 4px;
  -webkit-overflow-scrolling: touch;
}
.bal-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fafafa;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.bal-chip:hover { border-color: var(--accent); background: #f3faf7; }
.bal-chip:active { transform: scale(0.98); }
.bal-chip .n { font-weight: 650; }
.bal-chip.pos .n { color: var(--pos); }
.bal-chip.neg .n { color: var(--neg); }
.bal-view-seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.bal-view-seg .bal-view-btn {
  border: none;
  border-radius: 0;
  padding: 6px 10px;
  margin: 0;
  background: transparent;
  font-size: 0.82rem;
}
.bal-view-seg .bal-view-btn + .bal-view-btn {
  border-left: 1px solid var(--line);
}
.bal-view-seg .bal-view-btn.active {
  background: var(--accent);
  color: #fff;
}
.settle-spend-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 0;
}
.person-ops-modal { max-height: 90vh; }
.person-ops-list { max-height: 60vh; overflow: auto; padding-bottom: 4px; }
.person-ops-list .card { margin: 6px 0; }

.toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 14px;
}
.toolbar.trip-actions {
  flex-wrap: nowrap;
}
.toolbar.trip-actions > .btn {
  flex: 1 1 50%;
  min-width: 0;
  text-align: center;
}
.ops-amt-filter {
  padding: 4px 14px 10px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.ops-amt-filter label {
  display: grid;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}
.ops-amt-filter input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  width: 100%;
  font-variant-numeric: tabular-nums;
}
.ops-amt-filter input:focus {
  border-color: var(--accent);
  outline: none;
}
.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: #f0c0c0; background: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.fab {
  position: fixed;
  right: max(16px, calc(50% - 224px));
  bottom: max(20px, calc(12px + env(safe-area-inset-bottom, 0px)));
  z-index: 50;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.6rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
  cursor: pointer;
}
#app.wide-trip .fab {
  right: max(16px, calc(50% - 264px));
}

.list { padding: 0 12px 12px; }
.list.home-trips { padding: 0 8px 12px; }
/* Near-full width on phone; keep normal side padding on wide viewports */
@media (max-width: 600px) {
  #app.wide-trip .list.home-trips { padding: 0 0 12px; }
  #app.wide-trip .trip-card {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  #app.wide-trip .trip-expand { padding-left: 6px; padding-right: 6px; }
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.card:active { background: #fafafa; }
.exp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  font-size: 0.9rem;
}
.exp-grid .sum {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.exp-grid .muted { color: var(--muted); font-size: 0.8rem; }
.loc-status {
  font-weight: 650;
  font-size: 0.9rem;
}
.loc-status.loc-no {
  color: var(--danger);
  opacity: 0.9;
}
.loc-status.loc-yes {
  color: var(--accent);
  text-decoration: none;
}
.loc-status.loc-yes:hover { text-decoration: underline; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font-size: 0.72rem;
  background: #eee;
  border-radius: 999px;
  padding: 2px 8px;
}

.home-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.home-item .meta { color: var(--muted); font-size: 0.8rem; }
.trip-av {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  background: #e8e8e8;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.trip-av.sm { width: 40px; height: 40px; border-radius: 10px; }
.trip-av.lg { width: 56px; height: 56px; border-radius: 14px; }
.trip-av-ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--muted);
  background: #eee;
}
.trip-av-wrap {
  position: relative;
  flex: 0 0 auto;
  cursor: pointer;
}
.hdr-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.hdr-title-row .title-edit { flex: 1; }

.trip-card {
  padding: 0;
  overflow: hidden;
}
.trip-card .trip-head {
  padding: 12px;
  cursor: pointer;
}
.trip-card.open {
  border-color: var(--accent);
}
.trip-title-line {
  display: flex;
  align-items: center;
  gap: 6px;
}
.trip-title-text {
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trip-title-text:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chev {
  color: var(--muted);
  font-size: 0.85rem;
  flex: 0 0 auto;
  margin-left: 4px;
}
.trip-expand {
  border-top: 1px solid var(--line);
  padding: 8px 4px 12px;
  background: #fafafa;
}
.trip-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 0 2px 8px;
  width: 100%;
  min-width: 0;
}
.trip-badges .bal-view-seg {
  margin-left: auto;
  flex: 0 0 auto;
  display: inline-flex;
  visibility: visible;
  opacity: 1;
  max-width: none;
}
.trip-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-family: inherit;
}
button.trip-badge-cur {
  cursor: pointer;
  color: var(--accent);
  border-color: var(--accent);
  background: #fff;
}
.trip-badge.sync-ok { color: var(--pos, #1a5c3a); border-color: #b7d4c2; }
.trip-badge.sync-pending { color: #8a6a12; border-color: #e6d59a; }
.trip-badge.sync-conflict { color: #8a4b12; border-color: #e6c4a0; background: #f7eadc; }
.trip-badge.sync-error { color: #8b2e2e; border-color: #e6b0b0; background: #f6e6e6; }
.empty-hero {
  padding: 28px 16px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 8px 0;
}
.hdr-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.hdr-brand-row h1 { margin: 0; width: auto; flex: 1; min-width: 0; }
.bal-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 0 0 6px;
}
.bal-row .bal-scroll {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  margin: 0;
}
.trip-quick {
  display: flex;
  gap: 8px;
  padding: 0 4px 8px;
}
.trip-quick .btn {
  flex: 1 1 50%;
}
.trip-expand-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 0 4px 4px;
}
.cur-tool {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.fx-rates-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font-family: inherit;
}
.fx-rates-link:hover { color: var(--ink); }
.fx-modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.modal.modal-fx { max-height: 90vh; }
.fx-calc {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin: 0 0 12px;
  background: #fafafa;
}
.fx-calc-in {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
  margin-bottom: 8px;
}
.fx-calc-amt {
  display: grid;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1 1 120px;
  min-width: 110px;
}
.fx-calc-amt input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  font-variant-numeric: tabular-nums;
}
.fx-calc-from {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  padding-bottom: 8px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.fx-calc-from-lab {
  color: var(--muted);
  font-size: 0.8rem;
}
.fx-calc-from-sel {
  appearance: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 28px 8px 10px;
  background: #fff;
  font: inherit;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text, #1a1a1a);
  cursor: pointer;
  min-width: 7.5rem;
  max-width: 11rem;
}
.fx-calc-from-sel:focus {
  outline: 2px solid var(--accent, #2a6);
  outline-offset: 1px;
}
.fx-calc-from-sel:hover {
  border-color: #bbb;
}
.fx-calc-out {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.fx-calc-cell {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
  display: grid;
  gap: 2px;
}
.fx-calc-cell.fx-calc-same {
  background: #fff6e5;
  border-color: #e0c48a;
}
.fx-calc-cell.fx-calc-focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.fx-calc-ccy {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}
.fx-calc-val {
  font-size: 0.92rem;
  font-weight: 650;
}
.fx-calc-hint {
  margin: 8px 0 0;
  font-size: 0.75rem;
}
.fx-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -2px;
}
.fx-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}
.fx-table.fx-matrix {
  width: max-content;
  min-width: 100%;
  font-size: 0.78rem;
}
.fx-matrix-cap {
  caption-side: top;
  text-align: left;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 0 6px;
}
.fx-table th,
.fx-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: right;
}
.fx-table.fx-matrix th,
.fx-table.fx-matrix td {
  padding: 6px 7px;
  white-space: nowrap;
}
.fx-table th:first-child,
.fx-table td:first-child,
.fx-table.fx-matrix th[scope="row"],
.fx-table.fx-matrix .fx-corner {
  text-align: left;
}
.fx-table th {
  background: #f3f3f3;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
}
.fx-table.fx-matrix thead th {
  font-size: 0.72rem;
}
.fx-table.fx-matrix .fx-sym {
  font-weight: 500;
  opacity: 0.75;
}
.fx-table.fx-matrix .fx-diag {
  color: var(--muted);
  text-align: center;
}
.fx-table.fx-matrix th.fx-base,
.fx-table.fx-matrix td.fx-base,
.fx-table.fx-matrix tr.fx-base th[scope="row"] {
  background: #e6f4f0;
}
.fx-table.fx-matrix tr.fx-base td.fx-base {
  background: #d4ebe4;
  font-weight: 600;
}
.fx-table tbody tr:nth-child(even) td {
  background: #fafafa;
}
.fx-table.fx-matrix tbody tr:nth-child(even) td:not(.fx-base) {
  background: #fafafa;
}
.fx-table.fx-matrix tbody tr:nth-child(even) td.fx-base {
  background: #e6f4f0;
}
.fx-table.fx-matrix tbody tr.fx-base:nth-child(even) td.fx-base {
  background: #d4ebe4;
}
.fx-table.fx-matrix .fx-row-head {
  cursor: pointer;
  user-select: none;
  color: var(--ink);
}
.fx-table.fx-matrix .fx-row-head:hover,
.fx-table.fx-matrix .fx-row-head:focus {
  outline: none;
  background: #fff6e5;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.fx-table.fx-matrix .fx-col-head {
  cursor: pointer;
  user-select: none;
}
.fx-table.fx-matrix .fx-col-head:hover {
  background: #eef7f4;
}
.fx-table.fx-matrix tbody tr.fx-calc-src th[scope="row"],
.fx-table.fx-matrix tbody tr.fx-calc-src td,
.fx-table.fx-matrix tbody tr.fx-calc-src:nth-child(even) td,
.fx-table.fx-matrix tbody tr.fx-calc-src:nth-child(even) td:not(.fx-base) {
  background: #fff6e5;
}
.fx-table.fx-matrix tbody tr.fx-calc-src th[scope="row"] {
  font-weight: 700;
  box-shadow: inset 3px 0 0 #c9962a;
}
.fx-table.fx-matrix tbody tr.fx-calc-src td.fx-diag {
  background: #f5e6c8;
  font-weight: 600;
}
.fx-table.fx-matrix tbody tr.fx-base.fx-calc-src th[scope="row"],
.fx-table.fx-matrix tbody tr.fx-base.fx-calc-src td.fx-base,
.fx-table.fx-matrix tbody tr.fx-base.fx-calc-src:nth-child(even) td.fx-base {
  background: #f0edd8;
}
.fx-table.fx-matrix th.fx-calc-col,
.fx-table.fx-matrix td.fx-calc-col {
  box-shadow: inset 0 -2px 0 var(--accent);
}
.trip-feed .card { margin: 6px 4px; }
.admin-chip {
  background: #d8efe8;
  color: #0d6e5a;
}
.hdr-sum-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 6px 0 2px;
  align-items: baseline;
}
.hdr-sum {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  font-size: 0.82rem;
}
.hdr-sum strong {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.settle-fam {
  padding: 0;
  cursor: pointer;
}
.settle-fam-head {
  padding: 12px;
}
.settle-fam-body {
  border-top: 1px solid var(--line);
  padding: 8px 12px 12px;
  background: #fafafa;
}
.settle-fam.open {
  border-color: var(--accent);
}

.form { padding: 12px 14px; display: grid; gap: 10px; }
.people-tab {
  padding: 4px 2px 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}
.people-tab-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.people-tab-actions > .btn {
  flex: 1 1 40%;
  min-width: 0;
  text-align: center;
}
.people-tab .card {
  margin-bottom: 0;
  width: 100%;
}
.people-tab h3 { padding: 0 2px; }
.people-tab > .muted { padding: 0 2px; }
.person-name-edit {
  cursor: pointer;
  color: var(--accent);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
  font-weight: 650;
}
.person-name-edit:hover,
.person-name-edit:focus {
  color: var(--ink);
  text-decoration-style: solid;
  outline: none;
}
.person-name-edit:active { opacity: 0.75; }
.invite-people {
  display: grid;
  gap: 8px;
}
.invite-pick-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.invite-pick-btn:hover,
.invite-pick-btn:focus {
  border-color: var(--accent);
  outline: none;
}
.form label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.form input, .form select, .form textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
}
.curr-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.curr-chips .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.settle-cur {
  margin: 6px 0 4px;
  gap: 4px;
}
.settle-cur .btn {
  padding: 4px 8px;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.ocr-lang-chip {
  display: inline-block;
  font-size: 0.78rem;
  line-height: 1.35;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f3faf7;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.ocr-lang-chip.warn {
  background: #fff6e8;
  border-color: #e0b56a;
  color: #6a4a12;
}

.parts-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.parts-all-btn {
  padding: 2px 10px;
  font-size: 0.8rem;
  line-height: 1.3;
  flex-shrink: 0;
}
.check-list { display: grid; gap: 6px; }
.check-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.95rem;
}

.detail-rows { padding: 8px 16px; }
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.detail-row .k { color: var(--muted); }
.detail-row .v { text-align: right; font-variant-numeric: tabular-nums; }

.split-box {
  margin: 12px 14px;
  background: #ececec;
  border-radius: 12px;
  padding: 12px 14px;
}
.split-box.split-editable {
  cursor: pointer;
  outline: none;
}
.split-box.split-editable:active {
  background: #e4e4e4;
}
.split-box h3 { margin: 0 0 8px; font-size: 0.95rem; font-weight: 600; }
.split-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-variant-numeric: tabular-nums;
}

.receipt-lines-box .receipt-lines-sum b {
  font-variant-numeric: tabular-nums;
}
.receipt-line {
  display: grid;
  grid-template-columns: 1fr 88px minmax(90px, 1fr) 36px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.receipt-line input,
.receipt-line select {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.receipt-line-del {
  padding: 4px 6px !important;
  min-width: 0;
  color: var(--muted);
}
.receipt-rem-all {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}
.receipt-over-warn {
  color: var(--danger);
  font-size: 0.82rem;
  margin: 0 0 8px;
  padding: 6px 8px;
  border: 1px solid #f0c0c0;
  background: #fff5f5;
  border-radius: 6px;
}
.hdr-sum strong.neg { color: var(--neg); }
.hdr-sum strong.pos { color: var(--pos); }

@media (max-width: 420px) {
  .receipt-line {
    grid-template-columns: 1fr 1fr 36px;
    grid-template-areas:
      "name name del"
      "amt person del";
  }
  .receipt-line input[data-line-name],
  .receipt-line input:first-child { grid-area: name; }
  .receipt-line input[data-line-amt] { grid-area: amt; }
  .receipt-line select { grid-area: person; }
  .receipt-line-del { grid-area: del; align-self: stretch; }
}

.cancel-op {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--danger);
  background: none;
  border: none;
  width: 100%;
  padding: 20px;
  font-size: 1rem;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 0;
  align-items: stretch;
  padding: 0 8px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.tabs > button {
  flex: 1 1 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 8px;
  margin-bottom: -1px;
  cursor: pointer;
  font-family: inherit;
}
.tabs > button.active {
  color: var(--accent);
  font-weight: 650;
  border-bottom-color: var(--accent);
}
.tabs > button.tab-settings {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 8px 12px;
}
.tabs > button.tab-settings .tab-gear {
  display: block;
  opacity: 0.85;
}
.tabs > button.tab-settings.active .tab-gear {
  opacity: 1;
}

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 480px;
  border-radius: 14px 14px 0 0;
  padding: 16px;
  max-height: 85vh;
  overflow: auto;
}
.modal h2 { margin: 0 0 12px; font-size: 1.1rem; }

.modal.modal-map {
  max-height: 92vh;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.loc-map-wrap {
  height: min(52vh, 360px);
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin: 0 0 8px;
  background: #e8e6e1;
}
.loc-map-wrap .leaflet-container {
  height: 100%;
  width: 100%;
  font: inherit;
}
.loc-map-status {
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.25em;
  margin: 0 0 10px;
  font-variant-numeric: tabular-nums;
}
.loc-map-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.loc-map-actions .btn { flex: 1 1 auto; min-width: 88px; }
.assign-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--muted, #666);
}
.assign-field .assign-name,
.assign-field .assign-amt {
  width: 100%;
  max-width: none;
  text-align: left;
  font-size: 1.05rem;
  color: var(--text, #1a1a1a);
  box-sizing: border-box;
}
.ocr-total-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 14px;
  margin: 0 0 10px;
}
.ocr-total-label {
  flex: 1 1 140px;
  margin: 0;
}
.ocr-unalloc-hint {
  flex: 1 1 140px;
  margin: 0 0 6px;
  padding-bottom: 2px;
}
.assign-unalloc-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 0.85rem;
}
.assign-unalloc {
  flex: 1 1 auto;
  min-width: 140px;
  font-variant-numeric: tabular-nums;
}
.assign-unalloc b { font-size: 1rem; color: var(--text, #1a1a1a); }
.assign-all-lbl {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
}
.assign-people { margin-top: 4px; }
.assign-people-hint { margin: 0 0 6px; font-size: 0.8rem; }
.assign-amt-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted, #666);
}
.assign-amt-label .assign-amt {
  width: 100%;
  max-width: none;
  text-align: left;
  font-size: 1.05rem;
}

.rl-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 8px;
  flex-wrap: wrap;
}
.rl-toolbar .rl-hint { flex: 1; min-width: 140px; font-size: 0.8rem; }
.rl-toolbar #btnDelLines { display: none; }
.rl-wrap {
  position: relative;
  margin-bottom: 6px;
  border-radius: 8px;
  overflow: hidden;
  touch-action: pan-y;
}
.rl-actions {
  position: absolute;
  inset: 0 0 0 auto;
  width: 88px;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  background: var(--danger);
  z-index: 0;
}
.rl-del {
  flex: 1;
  border: 0;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0 8px;
}
.receipt-line {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  will-change: transform;
}
.receipt-line.selected { border-color: var(--accent); background: #eef8f5; }
.receipt-line .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.receipt-line .rl-main { min-width: 0; }
.amt-edit {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 88px;
}
.rl-amt {
  width: 96px;
  max-width: 28vw;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
  background: #fafaf8;
}
.rl-amt:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.rl-adj {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.rl-check {
  display: none;
  margin: 0;
  align-items: center;
  cursor: pointer;
}
.rl-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Desktop / fine pointer: checkboxes + bulk delete; no swipe affordance needed */
@media (pointer: fine), (min-width: 768px) {
  .rl-toolbar #btnDelLines { display: inline-flex; }
  .rl-toolbar .rl-hint::after { content: ' · отметьте строки'; }
  .rl-check { display: flex; }
  .rl-actions { display: none; }
  .rl-wrap { overflow: visible; }
  .receipt-line { grid-template-columns: auto 1fr auto; }
}
@media (hover: none) and (pointer: coarse) and (max-width: 767px) {
  .receipt-line { grid-template-columns: 1fr auto; }
  .rl-check { display: none !important; }
}
.badge {
  display: inline-block;
  font-size: 0.72rem;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  padding: 1px 6px;
  margin-top: 4px;
  margin-right: 4px;
}
.badge-row { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.badge-row .badge { margin-top: 0; }

.ocr-debug {
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 0.8rem;
}
.ocr-debug summary {
  cursor: pointer;
  padding: 8px 10px;
  color: var(--muted);
  user-select: none;
}
.ocr-debug-body { padding: 0 10px 10px; }
.ocr-debug code { font-size: 0.75rem; word-break: break-all; }
.ocr-raw {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f4f4f2;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  margin: 4px 0 0;
  max-height: 140px;
  overflow: auto;
  font-size: 0.72rem;
}

/* Receipt photo: button (.js-att-pick) + sibling file input.
   Open via programmatic input.click() in the same user gesture (see app.js).
   Do NOT use display:none/[hidden] (breaks .click() on iOS) or label→clipped
   sr-only (flaky in MAX/Android WebViews). pointer-events:none so the button
   receives the tap; input stays in DOM for gesture-synced .click(). */
.file-pick {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  justify-content: center;
  margin: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  min-height: 40px;
  min-width: 96px;
}
.file-pick > .js-att-pick {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 40px;
}
.file-pick > input.js-att-file,
.file-pick > input[type="file"] {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: 0 !important;
  font-size: 0 !important;
  cursor: pointer;
  pointer-events: none;
  /* never display:none / clip to 1px — keeps .click() working */
}
/* Legacy class kept harmless if old cached HTML briefly appears */
.sr-only,
.att-file-fallback {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
.att-webview-hint {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff6e8;
  border: 1px solid #f0d2a0;
  color: #5c4813;
  font-size: 0.85rem;
  line-height: 1.35;
}
.att-webview-hint a { color: #0d6e5a; font-weight: 600; }
.att-status {
  font-size: 0.8rem;
  color: var(--muted, #6b7c76);
  min-height: 1.2em;
  margin-top: 6px;
}
.att-status.is-busy { color: var(--accent, #0d6e5a); }
.att-status.is-err { color: #b42318; }

/* Capacitor: native camera / gallery / document chooser */
.att-source-modal {
  max-width: 320px;
  width: calc(100% - 32px);
}
.att-source-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.att-source-list .btn.block { width: 100%; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  -webkit-touch-callout: none;
  user-select: none;
}
.modal-bg.photo-lightbox {
  align-items: center;
  background: rgba(0, 0, 0, 0.88);
  padding: 12px;
  z-index: 100;
  cursor: zoom-out;
}
.photo-lightbox-img {
  max-width: min(100%, 960px);
  max-height: min(92vh, 100%);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  cursor: default;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

.day-label {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 12px 4px 6px;
  font-weight: 600;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.pay-amt-box { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.pay-amt-row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
}
.pay-amt-row .pay-amt-input { flex: 1; min-width: 0; }
.trip-focus-hdr .trip-focus-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.trip-focus-list .trip-focus-card {
  border: none;
  box-shadow: none;
  padding: 0;
  background: transparent;
}
.trip-focus-list .trip-focus-card > .expanded-body,
.trip-focus-card .trip-expand {
  margin-top: 0;
}

@media print {
  .sticky-hdr, .toolbar, .fab, .tabs, .cancel-op, .detail-save-bar, .btn, .no-print { display: none !important; }
  .screen { display: block !important; padding: 0; }
  body { background: #fff; }
}
