/* Накладная → Excel. Ledger-paper palette: pale green accounting sheet, green ink, red margin rule. */
:root {
  --bg: #E9EDE4;            /* = theme-color = manifest background_color, byte for byte */
  --paper: #F7F8F3;
  --ink: #1E2620;
  --ink-2: #4A574D;
  --muted: #66746A;
  --rule: #C9D2C3;
  --rule-strong: #A9B6A6;
  --green: #1F3A2E;
  --green-hi: #2B4D3E;
  --red: #B23A26;
  --err-bg: #F4E2DC;
  --err-ink: #8E2B1B;
  --warn-bg: #F1EAD3;
  --warn-ink: #6B4E0E;
  --ok-ink: #2C5E3F;
  --display: "Iowan Old Style", "Charter", "Georgia", "Times New Roman", serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --tap: 48px;
  --radius: 10px;
  --dock-pad-b: max(calc(env(safe-area-inset-bottom) - 14px), 10px);
}

* { box-sizing: border-box; }
html { height: 100%; overscroll-behavior-y: contain; -webkit-text-size-adjust: 100%; }
body {
  height: 100%; margin: 0; overflow: hidden; overscroll-behavior-y: none;
  background: var(--bg); color: var(--ink); font: 16px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
}
button, input, a { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ── App shell: the dock lives in the flex column, never position:fixed ── */
#shell {
  position: fixed; top: 0; left: 0; right: 0; height: 100%;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto;
}
.top {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 18px 10px;
  border-bottom: 1px solid var(--rule);
}
.brand { margin: 0; font: 600 21px/1.2 var(--display); letter-spacing: .005em; }
.brand span { color: var(--red); }
.icon-btn {
  width: var(--tap); height: var(--tap); margin-right: -10px; border: 0; background: none;
  display: grid; place-items: center; color: var(--ink-2); border-radius: 50%; cursor: pointer;
}
#main {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch; padding: 18px 16px 24px;
}
.dock {
  flex: 0 0 auto; position: relative; z-index: 35;
  background: var(--bg); border-top: 1px solid var(--rule);
  padding: 10px 16px var(--dock-pad-b);
}
.dock-action { padding-bottom: 8px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; }
.tab {
  min-height: var(--tap); border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; font-weight: 500;
}
.tab[aria-selected="true"] { color: var(--green); }
.tab[aria-selected="true"] span { text-decoration: underline; text-decoration-color: var(--red); text-decoration-thickness: 2px; text-underline-offset: 4px; }

/* ── Buttons ── */
.btn {
  min-height: 52px; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 18px; font-weight: 600; font-size: 17px; text-decoration: none;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--green); color: var(--paper); }
.btn-primary:active { background: var(--green-hi); }
.btn-primary:disabled { background: var(--rule); color: var(--muted); cursor: default; }
.btn-secondary { background: var(--paper); border-color: var(--rule-strong); color: var(--green); }
.btn-ghost { background: none; color: var(--ink-2); font-weight: 500; }
.btn-small { min-height: 44px; font-size: 15px; padding: 0 14px; }

/* ── Picker ── */
.picker {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 18px 16px; min-height: 84px; cursor: pointer;
  background: var(--paper); border: 1.5px dashed var(--rule-strong); border-radius: var(--radius);
}
.picker input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.picker-sheet { color: var(--green); flex: 0 0 auto; }
.picker-text b { display: block; font: 600 19px/1.25 var(--display); }
.picker-text small { color: var(--muted); font-size: 14px; }
.picker.busy { opacity: .5; pointer-events: none; }

.form-error { color: var(--err-ink); font-size: 14px; margin: 8px 2px 0; min-height: 0; }
.form-error:empty { display: none; }

/* ── File list ── */
.files { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.file {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 12px; display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center;
}
.thumb {
  width: 52px; height: 64px; border-radius: 4px; background: var(--bg); border: 1px solid var(--rule);
  object-fit: cover; display: grid; place-items: center; color: var(--ink-2);
  font: 700 11px/1 var(--body); letter-spacing: .06em; overflow: hidden;
}
.file-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.file-meta.err { color: var(--err-ink); }
.file-meta.ok { color: var(--ok-ink); }
.remove {
  width: var(--tap); height: var(--tap); border: 0; background: none; color: var(--muted); cursor: pointer;
  display: grid; place-items: center; margin-right: -8px;
}
.status-line { display: flex; align-items: center; gap: 8px; }
.dots { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--rule-strong); border-top-color: var(--green); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result sheet (inside the file card) ── */
.result { grid-column: 1 / -1; border-top: 1px solid var(--rule); padding-top: 12px; margin-top: 2px; }
.doc-title { font: 600 18px/1.3 var(--display); margin: 0 0 2px; text-wrap: pretty; }
.doc-sub { color: var(--ink-2); font-size: 14px; margin: 0 0 10px; text-wrap: pretty; }
.figures { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0 0 12px; font-variant-numeric: tabular-nums; }
.figures dt { color: var(--muted); font-size: 14px; }
.figures dd { margin: 0; text-align: right; font-weight: 600; font-size: 16px; }
.figures dd.total { font: 700 20px/1.25 var(--display); border-bottom: 3px double var(--ink); justify-self: end; }
.warns { margin: 0 0 12px; padding: 10px 12px; background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; font-size: 14px; }
.warns b { display: block; margin-bottom: 4px; }
.warns ul { margin: 0; padding-left: 18px; }
.warns li + li { margin-top: 3px; }
.err-box { grid-column: 1 / -1; margin: 0; padding: 10px 12px; background: var(--err-bg); color: var(--err-ink); border-radius: 8px; font-size: 14px; }

.batch-actions { display: grid; gap: 4px; margin-top: 16px; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: var(--tap); margin-top: 14px; color: var(--ink-2); font-size: 15px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--green); }

/* ── History ── */
.section-title { font: 600 19px/1.3 var(--display); margin: 4px 2px 12px; }
.day { color: var(--muted); font-size: 13px; letter-spacing: .04em; text-transform: uppercase; margin: 18px 2px 8px; }
.day:first-child { margin-top: 0; }
.h-batch { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 10px; }
.h-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px; }
.h-row + .h-row { border-top: 1px solid var(--rule); }
.h-name { font-weight: 600; font-size: 15px; text-wrap: pretty; }
.h-meta { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.h-zip { padding: 0 12px 12px; }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }

/* ── Gate (no session, invite pages) ── */
.gate { text-align: center; padding: 48px 12px; }
.gate img { border-radius: 16px; }
.gate h1, .gate h2 { font: 600 24px/1.25 var(--display); margin: 18px 0 10px; }
.gate p { color: var(--ink-2); max-width: 32ch; margin: 0 auto 20px; }
body.plain { overflow: auto; height: auto; padding: calc(env(safe-area-inset-top) + 8px) 18px 40px; }
body.plain .btn-primary { min-height: 52px; min-width: 200px; border-radius: var(--radius); border: 0; font-weight: 600; font-size: 17px; cursor: pointer; }

/* ── Toast, PTR ── */
.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 1000; max-width: 88vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.ptr { position: fixed; top: env(safe-area-inset-top); left: 0; right: 0; height: 0; display: flex; justify-content: center; z-index: 90; pointer-events: none; opacity: 0; }
.ptr-ring { display: block; padding: 0; margin-top: 6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--rule-strong); border-top-color: var(--red); }
.ptr.spinning .ptr-ring { animation: spin .7s linear infinite; }

@media (prefers-reduced-motion: reduce) {
  .dots, .ptr.spinning .ptr-ring { animation-duration: 2.4s; }
  .toast { transition: none; }
}
