/* UAV Tracker: visual base. Telegram Mini App conventions, no framework.
   Tokens first, then components in the order the inventory needs them. */

/* ─── Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Colours follow Telegram's theme when it is present (Mini App sets --tg-theme-*),
     and fall back to Telegram iOS light. */
  --bg:        var(--tg-theme-secondary-bg-color, #efeff4);  /* page behind groups */
  --card:      var(--tg-theme-section-bg-color, #ffffff);    /* a group of rows */
  --hdr-bg:    var(--tg-theme-header-bg-color, #f6f6f6);
  --text:      var(--tg-theme-text-color, #000000);
  --hint:      var(--tg-theme-hint-color, #8e8e93);
  --cap:       var(--tg-theme-section-header-text-color, #6d6d72);
  --accent:    var(--tg-theme-link-color, #007aff);
  --btn:       var(--tg-theme-button-color, #007aff);
  --btn-text:  var(--tg-theme-button-text-color, #ffffff);
  --danger:    var(--tg-theme-destructive-text-color, #ff3b30);
  --sep:       var(--tg-theme-section-separator-color, #c8c7cc);
  --fill:      rgba(120, 120, 128, 0.12);   /* inset field, chip, press */
  --fill-2:    rgba(120, 120, 128, 0.20);   /* segment track, pressed row */
  --scrim:     rgba(0, 0, 0, 0.4);
  --ok:        #34c759;
  --warn:      #b86e00;
  /* Two sides. The only two colours of our own; used for bars and 3-letter marks only. */
  --enemy:     #d9480f;
  --own:       #1c7ed6;

  --f-ui:   system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --f-mono: ui-monospace, "SF Mono", Menlo, "Cascadia Mono", "Roboto Mono", monospace;
  --fs-title: 17px;  /* header title */
  --fs-body:  17px;  /* rows, inputs, buttons */
  --fs-sub:   15px;  /* segments, chips, row subtitles */
  --fs-note:  13px;  /* captions, footers, counts under thumbs */
  --fs-mark:  11px;  /* side mark, uppercase 3-letter */

  --pad: 16px;       /* side gutter and row padding */
  --gap: 12px;       /* gap inside a row */
  --row-h: 44px;
  --r-group: 10px;   /* grouped section, button */
  --r-field: 8px;    /* inset search/segment */
  --r-thumb: 6px;
  --r-sheet: 12px;

  --t-enter: 240ms;
  --t-exit:  170ms;
  --t-press: 100ms;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-in:  cubic-bezier(.4, 0, 1, 1);

  --z-bulk: 20; --z-tabbar: 30; --z-scrim: 40; --z-sheet: 50; --z-dialog: 60; --z-toast: 70;
  --tabbar-h: 50px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg:       var(--tg-theme-secondary-bg-color, #000000);
  --card:     var(--tg-theme-section-bg-color, #1c1c1e);
  --hdr-bg:   var(--tg-theme-header-bg-color, #1c1c1e);
  --text:     var(--tg-theme-text-color, #ffffff);
  --hint:     var(--tg-theme-hint-color, #98989e);
  --cap:      var(--tg-theme-section-header-text-color, #8d8e93);
  --accent:   var(--tg-theme-link-color, #3e88f7);
  --btn:      var(--tg-theme-button-color, #3e88f7);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger:   var(--tg-theme-destructive-text-color, #ff453a);
  --sep:      var(--tg-theme-section-separator-color, #3d3d3f);
  --fill:     rgba(120, 120, 128, 0.18);
  --fill-2:   rgba(120, 120, 128, 0.28);
  --scrim:    rgba(0, 0, 0, 0.55);
  --ok:       #30d158;
  --warn:     #ffb340;
  --enemy:    #ff8a4c;
  --own:      #5aa9ff;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:       var(--tg-theme-secondary-bg-color, #000000);
    --card:     var(--tg-theme-section-bg-color, #1c1c1e);
    --hdr-bg:   var(--tg-theme-header-bg-color, #1c1c1e);
    --text:     var(--tg-theme-text-color, #ffffff);
    --hint:     var(--tg-theme-hint-color, #98989e);
    --cap:      var(--tg-theme-section-header-text-color, #8d8e93);
    --accent:   var(--tg-theme-link-color, #3e88f7);
    --btn:      var(--tg-theme-button-color, #3e88f7);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --danger:   var(--tg-theme-destructive-text-color, #ff453a);
    --sep:      var(--tg-theme-section-separator-color, #3d3d3f);
    --fill:     rgba(120, 120, 128, 0.18);
    --fill-2:   rgba(120, 120, 128, 0.28);
    --scrim:    rgba(0, 0, 0, 0.55);
    --ok:       #30d158;
    --warn:     #ffb340;
    --enemy:    #ff8a4c;
    --own:      #5aa9ff;
    color-scheme: dark;
  }
}
@media (prefers-reduced-motion: reduce) {
  :root { --t-enter: 1ms; --t-exit: 1ms; --t-press: 1ms; }
}

/* ─── Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--fs-body)/1.3 var(--f-ui);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.num  { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--f-mono); font-size: 16px; }
.muted { color: var(--hint); }
.danger { color: var(--danger); }
.ok { color: var(--ok); }

/* page = header + scrolling content + tab bar */
.page { min-height: 100dvh; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px); }
.page.no-tabbar { padding-bottom: 24px; }
@media (min-width: 700px) {
  .page { max-width: 640px; margin: 0 auto; }
}

/* ─── Header (44px, title centred, text actions) ────────────────── */
.hdr {
  position: sticky; top: 0; z-index: 10; height: var(--row-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 var(--pad); background: var(--hdr-bg);
  border-bottom: 0.5px solid var(--sep);
}
.hdr-title { grid-column: 2; font-weight: 600; font-size: var(--fs-title); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.hdr-l { grid-column: 1; justify-self: start; }
.hdr-r { grid-column: 3; justify-self: end; }
.hdr-btn { color: var(--accent); font-size: var(--fs-body); height: var(--row-h); display: inline-flex; align-items: center; gap: 2px; }
.hdr-btn:active { opacity: .4; }
.hdr-btn.back::before { content: ""; width: 12px; height: 20px; background: currentColor; -webkit-mask: var(--i-chevron-l) center/contain no-repeat; mask: var(--i-chevron-l) center/contain no-repeat; margin-left: -4px; }
.hdr-sub { grid-column: 2; grid-row: 2; font-size: var(--fs-note); color: var(--hint); line-height: 1; }
.hdr.has-sub { height: auto; min-height: var(--row-h); grid-template-rows: 24px 16px; padding-top: 2px; padding-bottom: 4px; }

/* ─── Segmented control (Telegram folder tabs / iOS segment) ─────── */
.seg {
  display: flex; margin: 10px var(--pad) 0; padding: 2px; background: var(--fill);
  border-radius: var(--r-field); font-size: var(--fs-sub);
}
.seg > button {
  flex: 1; height: 30px; border-radius: 6px; color: var(--text); white-space: nowrap;
  transition: background var(--t-press);
}
.seg > button[aria-selected="true"] { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
[data-theme="dark"] .seg > button[aria-selected="true"] { background: #3a3a3c; box-shadow: none; }
.seg.inline { margin: 0; flex: 1; }

/* ─── Search field (grey inset, glyph inside) ────────────────────── */
.search {
  display: flex; align-items: center; gap: 6px; margin: 10px var(--pad) 0;
  height: 36px; padding: 0 10px; background: var(--fill); border-radius: var(--r-field);
}
.search::before { content: ""; width: 18px; height: 18px; flex: none; background: var(--hint); -webkit-mask: var(--i-search) center/contain no-repeat; mask: var(--i-search) center/contain no-repeat; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: var(--fs-body); }
.search input::placeholder { color: var(--hint); }
/* the browser's own cancel cross of type=search would stand beside the designed one */
.search input::-webkit-search-cancel-button, .search input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.search .clear { width: 18px; height: 18px; background: var(--hint); -webkit-mask: var(--i-close-c) center/contain no-repeat; mask: var(--i-close-c) center/contain no-repeat; }

/* ─── Grouped sections ───────────────────────────────────────────── */
.sect { margin: 16px var(--pad) 0; }
.sect:first-child, .seg + .sect, .search + .sect { margin-top: 12px; }
.sect-cap { display: block; padding: 0 var(--pad) 6px; font-size: var(--fs-note); color: var(--cap); }
.sect-cap .right { float: right; color: var(--hint); }
.sect-body { background: var(--card); border-radius: var(--r-group); overflow: hidden; }
.sect-foot { padding: 6px var(--pad) 0; font-size: var(--fs-note); color: var(--cap); line-height: 1.33; }
.sect-foot:empty { display: none; }

/* ─── Row anatomy ────────────────────────────────────────────────── */
/* [thumb|check|mark] [main: title, sub] [val] [arrow]; separator starts at the text edge. */
.row {
  display: flex; align-items: center; gap: var(--gap); width: 100%;
  min-height: var(--row-h); padding: 8px var(--pad); position: relative;
  text-align: left; color: inherit; background: none;
  transition: background var(--t-press);
}
.row + .row::before, .row + .field::before, .field + .row::before, .field + .field::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--pad); height: 0.5px; background: var(--sep);
}
.row.has-thumb + .row::before, .row.has-thumb + .row.has-thumb::before { left: calc(var(--pad) + 56px + var(--gap)); }
.row.has-check + .row::before { left: calc(var(--pad) + 22px + var(--gap)); }
button.row:active, a.row:active, .row.pressable:active { background: var(--fill-2); transition: none; }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-title.wrap { white-space: normal; }
.row-sub { display: block; font-size: var(--fs-sub); color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row-sub.wrap { white-space: normal; }
.row-val { color: var(--hint); font-variant-numeric: tabular-nums; flex: none; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-val.accent { color: var(--accent); }
.row-val.text { color: var(--text); }
.row-arrow { flex: none; width: 8px; height: 14px; background: var(--sep); -webkit-mask: var(--i-chevron-r) center/contain no-repeat; mask: var(--i-chevron-r) center/contain no-repeat; margin-right: -2px; }
[data-theme="dark"] .row-arrow { background: #5a5a5e; }
.row-arrow.down { transform: rotate(90deg); transition: transform var(--t-enter) var(--ease-out); }
.row-arrow.down.open { transform: rotate(-90deg); }
.row.link { color: var(--accent); }
.row.danger { color: var(--danger); }
.row.center { justify-content: center; }
.row.indent { padding-left: calc(var(--pad) + 16px); }
.row.indent + .row::before { left: calc(var(--pad) + 16px); }
.row-thumb {
  flex: none; width: 56px; height: 56px; border-radius: var(--r-thumb); background: var(--fill);
  object-fit: cover; position: relative; overflow: hidden;
}
.row-thumb.video::after { content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; background: #fff; -webkit-mask: var(--i-play) center/contain no-repeat; mask: var(--i-play) center/contain no-repeat; filter: drop-shadow(0 0 2px rgba(0,0,0,.6)); }
.row-thumb .n { position: absolute; right: 3px; bottom: 3px; font-size: var(--fs-mark); line-height: 1; padding: 2px 4px; border-radius: 4px; background: rgba(0,0,0,.6); color: #fff; }
/* side mark: three letters, one colour. Never a flag, never a pill. */
.mark { font-size: var(--fs-mark); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; flex: none; width: 28px; text-align: center; line-height: 1; }
.mark.enemy { color: var(--enemy); }
.mark.own   { color: var(--own); }
.mark.inline { width: auto; display: inline; margin-right: 6px; vertical-align: 1px; }

/* checkbox (bulk select) */
.chk { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--sep); appearance: none; margin: 0; position: relative; transition: background var(--t-press), border-color var(--t-press); }
.chk:checked { background: var(--btn); border-color: var(--btn); }
.chk:checked::after { content: ""; position: absolute; inset: 0; background: var(--btn-text); -webkit-mask: var(--i-check) center/14px no-repeat; mask: var(--i-check) center/14px no-repeat; }
.row.selected { background: var(--fill); }

/* switch */
.tgl { appearance: none; margin: 0; flex: none; width: 51px; height: 31px; border-radius: 16px; background: var(--fill-2); position: relative; transition: background var(--t-enter) var(--ease-out); }
.tgl::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform var(--t-enter) var(--ease-out); }
.tgl:checked { background: var(--ok); }
.tgl:checked::after { transform: translateX(20px); }

/* ─── Fields (label left, value right; textarea below label) ────── */
.field { display: flex; align-items: center; gap: var(--gap); min-height: var(--row-h); padding: 8px var(--pad); position: relative; }
.field > label { flex: none; width: 128px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field > input, .field > select { flex: 1; min-width: 0; background: none; border: 0; outline: 0; padding: 0; text-align: right; }
.field > input::placeholder { color: var(--hint); }
.field > select { appearance: none; color: var(--hint); padding-right: 14px; background: var(--i-chevron-r) right center/8px no-repeat; }
.field > input[type="date"] { color: var(--text); }
.field.stack { flex-direction: column; align-items: stretch; gap: 4px; }
.field.stack > label { width: auto; font-size: var(--fs-note); color: var(--cap); }
.field.stack > textarea { background: none; border: 0; outline: 0; padding: 0; resize: none; min-height: 72px; line-height: 1.35; }
.field.stack > textarea::placeholder { color: var(--hint); }
.field.stack > input { text-align: left; }
.field.invalid > label { color: var(--danger); }
.field .unit { color: var(--hint); flex: none; }

/* picker row = field whose value opens a sheet (chevron) */
.row.picker .row-val { color: var(--text); }
.row.picker .row-val.empty { color: var(--hint); }

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; width: 100%; height: 50px;
  border-radius: var(--r-group); font-size: var(--fs-body); font-weight: 600;
  background: var(--btn); color: var(--btn-text); transition: opacity var(--t-press);
}
.btn:active { opacity: .7; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.secondary { background: var(--card); color: var(--accent); font-weight: 400; }
.btn.secondary.danger { color: var(--danger); }
.btn.plain { background: none; color: var(--accent); font-weight: 400; height: var(--row-h); }
.btn.plain.danger { color: var(--danger); }
.btn.busy { color: transparent; position: relative; }
.btn.busy::after { content: ""; position: absolute; width: 20px; height: 20px; border: 2px solid var(--btn-text); border-right-color: transparent; border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btns { margin: 16px var(--pad) 0; display: grid; gap: 8px; }
.btns.two { grid-template-columns: 1fr 1fr; }
/* small inline button (inside rows, chips bar) */
.btn-sm { height: 30px; padding: 0 12px; border-radius: 15px; font-size: var(--fs-sub); background: var(--fill); color: var(--accent); white-space: nowrap; }
.btn-sm.danger { color: var(--danger); }
.btn-sm:active { background: var(--fill-2); }

/* ─── Chips (tags only; grey; no colour) ─────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px var(--pad) 12px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 10px; border-radius: 14px; background: var(--fill); font-size: var(--fs-sub); color: var(--text); white-space: nowrap; }
.chip .x { width: 14px; height: 14px; background: var(--hint); -webkit-mask: var(--i-close) center/contain no-repeat; mask: var(--i-close) center/contain no-repeat; margin-right: -4px; }
.chip.add { color: var(--accent); background: none; border: 1px dashed var(--sep); }
.chip.excl { text-decoration: line-through; color: var(--hint); }

/* ─── Media ──────────────────────────────────────────────────────── */
.media { margin: 12px var(--pad) 0; }
.media-main { display: block; width: 100%; aspect-ratio: 4/3; border-radius: var(--r-group); background: var(--fill); object-fit: cover; position: relative; overflow: hidden; }
.media-main.video::after { content: ""; position: absolute; inset: 0; margin: auto; width: 44px; height: 44px; background: #fff; -webkit-mask: var(--i-play) center/contain no-repeat; mask: var(--i-play) center/contain no-repeat; filter: drop-shadow(0 0 3px rgba(0,0,0,.5)); }
.media-main .cnt { position: absolute; right: 8px; bottom: 8px; font-size: var(--fs-note); padding: 3px 7px; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; font-variant-numeric: tabular-nums; }
.strip { display: flex; gap: 6px; margin-top: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.strip::-webkit-scrollbar { display: none; }
.strip .thumb { flex: none; width: 64px; height: 64px; border-radius: var(--r-thumb); background: var(--fill); position: relative; overflow: hidden; }
.strip .thumb.current { outline: 2px solid var(--accent); outline-offset: -2px; }
.strip .thumb.video::after { content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; background: #fff; -webkit-mask: var(--i-play) center/contain no-repeat; mask: var(--i-play) center/contain no-repeat; }
/* placeholder art: two tones, no icon, no text */
.ph { background: linear-gradient(0deg, var(--fill), var(--fill)), var(--card); }
.ph-photo { background: repeating-linear-gradient(135deg, var(--fill-2) 0 10px, transparent 10px 20px), var(--fill); }
/* reorder list in edit form */
.media-list .row-thumb { width: 44px; height: 44px; }
.media-list .row.has-thumb + .row::before { left: calc(var(--pad) + 44px + var(--gap)); }
.handle { flex: none; width: 18px; height: 14px; background: var(--sep); -webkit-mask: var(--i-grip) center/contain no-repeat; mask: var(--i-grip) center/contain no-repeat; }
.media-list .row-title { font-size: var(--fs-sub); }

/* post text from Telegram: body size, hint colour for meta, left line like a quote */
.post { padding: 10px var(--pad) 12px; font-size: 16px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.post.clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; padding-bottom: 0; margin-bottom: 12px; }   /* the seventh line must not peek into the padding */
.post-more { padding: 0 var(--pad) 10px; color: var(--accent); font-size: var(--fs-sub); }

/* ─── Key/value rows in details ──────────────────────────────────── */
.kv { display: flex; gap: var(--gap); padding: 10px var(--pad); position: relative; }
.kv + .kv::before { content: ""; position: absolute; top: 0; right: 0; left: var(--pad); height: 0.5px; background: var(--sep); }
.kv > dt { flex: none; width: 112px; color: var(--hint); font-size: var(--fs-sub); padding-top: 1px; }
.kv > dd { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
.kv > dd .line { display: block; }
.kv > dd .line + .line { margin-top: 2px; }
dl.sect-body { margin: 0; }

/* ─── Statistics ─────────────────────────────────────────────────── */
/* summary: plain rows with right numbers. Charts: bar rows, one colour. */
.bars { padding: 4px 0 6px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; column-gap: var(--gap); align-items: center; padding: 6px var(--pad) 0; }
.bar-row .lbl { font-size: var(--fs-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .n { font-size: var(--fs-sub); color: var(--hint); font-variant-numeric: tabular-nums; }
.bar-row .bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--fill); margin-top: 3px; overflow: hidden; }
.bar-row .bar > i { display: block; height: 100%; width: var(--w, 0%); background: var(--accent); border-radius: 3px; }
.bar-row.enemy .bar > i { background: var(--enemy); }
.bar-row.own .bar > i { background: var(--own); }
button.bar-row { width: 100%; text-align: left; color: inherit; }
button.bar-row:active { background: var(--fill); }
/* monthly columns: 12 equal columns, number on top, month letter below */
.cols { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 120px; padding: 12px var(--pad) 0; }
.cols > button { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; color: inherit; }
.cols > button i { display: block; width: 100%; max-width: 22px; height: var(--h, 4%); min-height: 2px; background: var(--accent); border-radius: 2px 2px 0 0; }
.cols > button.enemy i { background: var(--enemy); }
.cols > button.own i { background: var(--own); }
.cols > button b { font-weight: 400; font-size: var(--fs-mark); color: var(--hint); font-variant-numeric: tabular-nums; }
.cols > button[aria-selected="true"] i { outline: 2px solid var(--text); outline-offset: 1px; }
.cols-x { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; padding: 4px var(--pad) 10px; font-size: var(--fs-mark); color: var(--hint); text-align: center; }
/* two-tone stacked bar for side share */
.share { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin: 10px var(--pad) 0; background: var(--fill); }
.share > i { display: block; height: 100%; width: var(--w); }
.share > .enemy { background: var(--enemy); } .share > .own { background: var(--own); }
.share-lbl { display: flex; justify-content: space-between; padding: 6px var(--pad) 12px; font-size: var(--fs-note); color: var(--hint); font-variant-numeric: tabular-nums; }

/* ─── Tab bar ────────────────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-tabbar);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: var(--hdr-bg); border-top: 0.5px solid var(--sep);
}
.tabbar > a, .tabbar > button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--hint); font-size: 10px; line-height: 1; padding-top: 2px;
}
.tabbar > [aria-current="page"] { color: var(--accent); }
.tabbar .icw { position: relative; display: block; }
.tabbar i { display: block; width: 24px; height: 24px; background: currentColor; -webkit-mask: var(--i) center/contain no-repeat; mask: var(--i) center/contain no-repeat; }
.tabbar .badge { position: absolute; top: -3px; right: -10px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff; font-size: var(--fs-mark); line-height: 16px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: center; }

/* ─── Bulk action bar (sticky above tab bar, appears when ≥1 selected) ── */
.bulkbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: var(--z-bulk);
  display: flex; align-items: center; gap: var(--gap); height: var(--row-h); padding: 0 var(--pad);
  background: var(--hdr-bg); border-top: 0.5px solid var(--sep);
  animation: up var(--t-enter) var(--ease-out);
}
.bulkbar .cnt { font-variant-numeric: tabular-nums; }
.bulkbar .sp { flex: 1; }
.bulkbar button { color: var(--accent); }
.bulkbar button.danger { color: var(--danger); }
@keyframes up { from { transform: translateY(100%); } }

/* ─── Pager ──────────────────────────────────────────────────────── */
.pager { display: flex; align-items: center; justify-content: space-between; margin: 12px var(--pad) 0; color: var(--hint); font-size: var(--fs-sub); font-variant-numeric: tabular-nums; }
.pager button { color: var(--accent); height: var(--row-h); padding: 0 4px; }
.pager button:disabled { color: var(--sep); cursor: default; }

/* ─── Sheet, dialog, toast ───────────────────────────────────────── */
.scrim { position: fixed; inset: 0; z-index: var(--z-scrim); background: var(--scrim); animation: fade var(--t-enter); }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sheet); max-height: 92dvh;
  display: flex; flex-direction: column; background: var(--bg);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0; padding-bottom: var(--safe-b);
  animation: up var(--t-enter) var(--ease-out);
}
.sheet.closing { animation: down var(--t-exit) var(--ease-in) forwards; }
@keyframes down { to { transform: translateY(100%); } }
.sheet-hdr { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 52px; padding: 0 var(--pad); flex: none; }
.sheet-hdr::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--sep); }
.sheet-hdr .t { grid-column: 2; font-weight: 600; }
.sheet-hdr .l { grid-column: 1; justify-self: start; color: var(--accent); }
.sheet-hdr .r { grid-column: 3; justify-self: end; color: var(--accent); font-weight: 600; }
.sheet-body { overflow-y: auto; padding-bottom: 16px; }
.sheet-body > .sect:first-child, .sheet-body > .search:first-child { margin-top: 0; }
.sheet-body > .search + .sect { margin-top: 12px; }

/* dialog: system-like, title, one line, two buttons */
.dialog {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: var(--z-dialog);
  width: 270px; background: var(--card); border-radius: 14px; text-align: center; overflow: hidden;
  animation: pop var(--t-enter) var(--ease-out);
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, -50%) scale(1.08); } }
.dialog .t { padding: 18px 16px 4px; font-weight: 600; }
.dialog .m { padding: 0 16px 16px; font-size: var(--fs-note); color: var(--text); }
.dialog .b { display: flex; border-top: 0.5px solid var(--sep); }
.dialog .b > button { flex: 1; height: 44px; color: var(--accent); }
.dialog .b > button + button { border-left: 0.5px solid var(--sep); }
.dialog .b > button.danger { color: var(--danger); }
.dialog .b > button.strong { font-weight: 600; }
/* toast: bottom, one line, optional action; disappears itself */
.toast {
  position: fixed; left: var(--pad); right: var(--pad); bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: var(--z-toast);
  display: flex; align-items: center; gap: var(--gap); min-height: 44px; padding: 10px 14px;
  border-radius: var(--r-group); background: #2c2c2e; color: #fff; font-size: var(--fs-sub);
  animation: up var(--t-enter) var(--ease-out);
}
[data-theme="dark"] .toast { background: #3a3a3c; }
.toast .sp { flex: 1; }
.toast button { color: #6fb1ff; font-weight: 600; }


/* ─── Empty state (one grey line, maybe one action) ──────────────── */
.blank { padding: 48px var(--pad); text-align: center; color: var(--hint); font-size: var(--fs-sub); }
.blank a { display: block; margin-top: 8px; }

/* ─── Inline status rows (serials duplicate, progress) ───────────── */
.note { padding: 8px var(--pad) 10px; font-size: var(--fs-note); color: var(--hint); }
.note.warn { color: var(--warn); }
.progress { height: 3px; background: var(--fill); }
.progress > i { display: block; height: 100%; width: var(--w, 0%); background: var(--accent); transition: width 150ms linear; }

/* ─── Icons (currentColor masks; the whole set) ──────────────────── */
:root {
  --i-chevron-r: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 14'><path d='M1 1l6 6-6 6' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  --i-chevron-l: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 20'><path d='M10 2L2 10l8 8' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  --i-search: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='10.5' cy='10.5' r='6.5' fill='none' stroke='black' stroke-width='2'/><path d='M15.5 15.5L21 21' stroke='black' stroke-width='2' stroke-linecap='round'/></svg>");
  --i-close: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 6l12 12M18 6L6 18' stroke='black' stroke-width='2.2' stroke-linecap='round'/></svg>");
  --i-close-c: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='11' fill='black'/><path d='M8 8l8 8M16 8l-8 8' stroke='white' stroke-width='2' stroke-linecap='round'/></svg>");
  --i-check: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 12.5l5 5L20 7' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  --i-play: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M7 4l13 8-13 8z' fill='black'/></svg>");
  --i-grip: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 14'><path d='M1 2h16M1 7h16M1 12h16' stroke='black' stroke-width='2' stroke-linecap='round'/></svg>");
  --i-tab-list: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 6h16M4 12h16M4 18h16' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'/></svg>");
  --i-tab-tray: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M3 13l2.5-8h13L21 13v6H3z' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'/><path d='M3 13h5l1.5 3h5L16 13h5' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'/></svg>");
  --i-tab-hash: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M9 4L7 20M17 4l-2 16M4 9h17M3 15h17' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'/></svg>");
  --i-tab-chart: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M5 20V10M12 20V4M19 20v-7' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'/></svg>");
  --i-tab-more: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='5' cy='12' r='2' fill='black'/><circle cx='12' cy='12' r='2' fill='black'/><circle cx='19' cy='12' r='2' fill='black'/></svg>");
  --i-lock: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><rect x='5' y='10' width='14' height='11' rx='2' fill='none' stroke='black' stroke-width='2'/><path d='M8 10V7a4 4 0 0 1 8 0v3' fill='none' stroke='black' stroke-width='2'/></svg>");
}
.ic { display: inline-block; width: 16px; height: 16px; vertical-align: -3px; background: currentColor; -webkit-mask: var(--i) center/contain no-repeat; mask: var(--i) center/contain no-repeat; }
.ic.lock { --i: var(--i-lock); color: var(--hint); }

/* ─── Page transition (one kind, both directions) ────────────────── */
.page.enter { animation: slide-in var(--t-enter) var(--ease-out); }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }

/* ─── Late additions after the first screenshot pass ─────────────── */
.side { font-weight: 600; }               /* side as a word in details: colour only */
.side.enemy { color: var(--enemy); } .side.own { color: var(--own); }
.row-val.sub { font-size: var(--fs-sub); }
.bulkbar { font-size: var(--fs-sub); gap: 14px; }
.bulkbar .cnt { white-space: nowrap; font-size: var(--fs-body); }
.cols > button b { white-space: nowrap; }
.sect-foot a { white-space: nowrap; }
/* Desktop: one phone-wide column in the middle; fixed bars follow it.
   `translate` (not transform) so the enter keyframes do not undo the centring. Last in file: wins by order. */
@media (min-width: 700px) {
  .tabbar, .bulkbar, .sheet { left: 50%; right: auto; width: 100%; max-width: 640px; translate: -50% 0; }
  .toast { left: 50%; right: auto; width: calc(100% - 32px); max-width: 608px; translate: -50% 0; }
}
.row-val.id { font-size: var(--fs-sub); }
.row-val.wrap { white-space: normal; text-align: right; max-width: 62%; }   /* «Змінено: хто, коли» — a name and a moment do not fit one line of a phone */
/* Serials: "серія + номер" in one mono title; 15px so a Supercam designation fits beside a thumb. */
.row-title.mono { font-size: 15px; letter-spacing: .01em; }
.row-val.mono { font-family: var(--f-mono); font-size: 15px; color: var(--text); }
.row-val.sub:empty { display: none; }
/* ─── Rebuild pieces (SPEC 1.2–2) ────────────────────────────────── */
.row-sub.mono { font-family: var(--f-mono); font-size: 15px; color: var(--text); }
.row-title .muted { font-size: var(--fs-sub); }
.hdr-title .mono { font-size: 16px; font-weight: 600; }
/* tree rows: indent by level, level type small and grey after the name */
.tree .row { padding-left: calc(var(--pad) + var(--lvl, 0) * 18px); }
.tree .row + .row::before { left: calc(var(--pad) + var(--lvl, 0) * 18px); }
.lvl { font-size: var(--fs-note); color: var(--hint); margin-left: 6px; }
.tree .row.picked { background: var(--fill); }
/* journal: old value struck, new value plain */
.diff { font-size: var(--fs-sub); }
.diff .old { text-decoration: line-through; color: var(--hint); margin-right: 6px; }
/* warning row (duplicate): amber title, plain body, still a link */
.row.warn .row-title { color: var(--warn); }
/* plate photo picking: thumbs with a check */
.strip .thumb.pick::after { content: ""; position: absolute; right: 4px; top: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--btn); -webkit-mask: none; mask: none; }
.strip .thumb.pick::before { content: ""; position: absolute; right: 4px; top: 4px; width: 20px; height: 20px; z-index: 1; background: var(--btn-text); -webkit-mask: var(--i-check) center/12px no-repeat; mask: var(--i-check) center/12px no-repeat; }
.strip.pad { padding: 10px var(--pad) 4px; }
/* dates pair in one field row */
.field .pair { display: flex; gap: 8px; flex: 1; justify-content: flex-end; }
.field .pair input { width: 46%; text-align: right; background: none; border: 0; outline: 0; }

/* ─── Blocks that appear or go inside a page (fold-outs, loaded lists): one rule for all ─── */
.appear { animation: appear var(--t-enter) var(--ease-out); }
.vanish { animation: vanish var(--t-exit) var(--ease-in) forwards; }
/* a fade alone: a block that moves while its words show reads as text falling in from above (owner, 11.11) */
@keyframes appear { from { opacity: 0; } }
@keyframes vanish { to { opacity: 0; } }
.scrim.closing { animation: fade-out var(--t-exit) var(--ease-in) forwards; }
@keyframes fade-out { to { opacity: 0; } }
/* A dictionary tree row that both opens its page and folds its children: the name is the link, the arrow is the fold button */
.row > a.row-main { color: inherit; }
.row > .fold { flex: none; align-self: stretch; display: flex; align-items: center; gap: var(--gap); margin: -8px calc(-1 * var(--pad)) -8px 0; padding: 0 var(--pad) 0 var(--gap); }
.row > .fold > .row-val { max-width: none; }   /* 50% of a button sized by its content would cut the number */
/* pressing the name or the arrow of such a row lights the whole row, as pressing a plain folder row does */
.row:has(> .row-main:active), .row:has(> .fold:active) { background: var(--fill-2); transition: none; }
/* The chip being typed («Написання») */
input.chip { border: 0; outline: 0; width: 140px; }
/* Real media inside the placeholders the mockups draw */
.row-thumb > img, .strip .thumb > img, .media-main > img, .media-main > video { display: block; width: 100%; height: 100%; object-fit: cover; }

/* ─── After the cutover (docs/briefs/bugs) ───────────────────────── */
/* Header actions: a button fills the header's height in both of its forms (with a subtitle the grid has two rows and
   the button used to sit in the first one, 24 px high, hanging over the line); its text never runs under the title;
   the tap area is wider than the word. */
.hdr { column-gap: 8px; }
.hdr-l, .hdr-r { min-width: 0; max-width: 100%; }
.hdr-btn { display: inline-block; height: auto; line-height: var(--row-h); padding: 0 var(--pad); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-l { margin-left: calc(-1 * var(--pad)); }
.hdr-r { margin-right: calc(-1 * var(--pad)); }
.hdr-btn.back::before { display: inline-block; vertical-align: -4px; margin: 0 2px 0 -4px; }
.hdr.has-sub .hdr-btn { grid-row: 1 / span 2; align-self: center; }
.hdr.has-sub .hdr-title { align-self: end; }
button.hdr-btn:disabled { opacity: .4; }
/* the same page motion mirrored: a page the user returns to and a tab to the left come from the left */
.page.enter.rev { animation-name: slide-in-rev; }
@keyframes slide-in-rev { from { transform: translateX(-24px); opacity: 0; } }

/* Media: a photo is shown whole at its own proportions, never cut to the frame */
.media-main { aspect-ratio: auto; min-height: 120px; display: flex; align-items: center; justify-content: center; }
.media-main > img, .media-main > video { width: 100%; height: auto; max-height: 72dvh; object-fit: contain; }
.media-main > img { cursor: zoom-in; }
.media-nav { position: absolute; top: 0; bottom: 0; width: 44px; display: flex; align-items: center; justify-content: center; }
.media-nav.prev { left: 0; } .media-nav.next { right: 0; }
.media-nav::before { content: ""; width: 12px; height: 20px; background: #fff; filter: drop-shadow(0 0 2px rgba(0,0,0,.7)); -webkit-mask: var(--i-chevron-l) center/contain no-repeat; mask: var(--i-chevron-l) center/contain no-repeat; }
.media-nav.next::before { transform: scaleX(-1); }
.media-main > video ~ .media-nav { bottom: 56px; }   /* a video keeps its own controls reachable */
/* full-screen viewer: black, text actions on top */
.viewer { position: fixed; inset: 0; z-index: 80; background: #000; color: #fff; display: flex; flex-direction: column; animation: fade var(--t-enter); }
.viewer.closing { animation: fade-out var(--t-exit) var(--ease-in) forwards; pointer-events: none; }
.viewer-hdr { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: var(--row-h); padding: 0 var(--pad); }
.viewer-hdr > button { justify-self: start; color: #fff; height: var(--row-h); }
.viewer-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; padding-bottom: var(--safe-b); }
.viewer-stage > img, .viewer-stage > video { max-width: 100%; max-height: 100%; user-select: none; -webkit-user-select: none; }
.viewer-stage > img { will-change: transform; }
.viewer .media-nav { top: var(--row-h); }
.viewer-stage > video ~ .media-nav, .viewer:has(video) .media-nav { bottom: 72px; }

/* Folders that open (types of UAV): the first row inside an opened folder keeps its separator */
.fold-body > .row:first-child::before, .fold-body + .row::before, .fold-body + .fold-body > .row:first-child::before {
  content: ""; position: absolute; top: 0; right: 0; left: calc(var(--pad) + var(--lvl, 0) * 18px); height: 0.5px; background: var(--sep);
}
/* the path over an opened level of a place is a button that goes one level up */
button.sect-cap { width: 100%; text-align: left; color: var(--accent); }
/* a tag that is on, in the sheet of all tags: heavier and checked, still grey */
.chip.on { background: var(--fill-2); font-weight: 600; }
.chip.on::before { content: ""; width: 12px; height: 12px; background: currentColor; -webkit-mask: var(--i-check) center/contain no-repeat; mask: var(--i-check) center/contain no-repeat; }
button.chip { cursor: pointer; }
/* the order handle of a media row: a tap area of its own, never a page scroll or a tab swipe */
.grip { touch-action: none; align-self: stretch; display: flex; align-items: center; padding: 0 10px; margin: -8px -6px -8px -10px; cursor: grab; }
.row.dragging { background: var(--fill); z-index: 1; }
/* a text of several lines in a details row keeps its line breaks */
.kv > dd.pre { white-space: pre-line; }
