:root {
  --bg: var(--tg-bg-color, #ffffff);
  --bg2: var(--tg-secondary-bg-color, #f1f3f5);
  --text: var(--tg-text-color, #111418);
  --hint: var(--tg-hint-color, #6b7280);
  --link: var(--tg-link-color, #2563eb);
  --btn: var(--tg-button-color, #2563eb);
  --btn-text: var(--tg-button-text-color, #ffffff);
  --danger: var(--tg-destructive-text-color, #d64545);
  --ok: #2e9e5b;
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --r: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.boot, .empty { color: var(--hint); text-align: center; padding: 40px 16px; }
header.top { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center;
  gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
header.top h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { border: 0; background: var(--bg2); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip.on { background: var(--btn); color: var(--btn-text); }
main { padding: 12px 16px 24px; max-width: 720px; margin: 0 auto; }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg); border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
nav.tabs button { flex: 1; border: 0; background: none; color: var(--hint); padding: 8px 0 10px; font-size: 12px; }
nav.tabs button b { display: block; font-size: 20px; font-weight: normal; }
nav.tabs button.on { color: var(--btn); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.scroll { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.scroll::-webkit-scrollbar { display: none; }
.card { background: var(--bg2); border-radius: var(--r); padding: 12px 14px; margin: 0 0 10px; display: block; width: 100%;
  text-align: left; border: 0; color: inherit; font: inherit; }
button.card { cursor: pointer; }
.card .t { font-weight: 600; }
.card .s { color: var(--hint); font-size: 14px; margin-top: 2px; }
.card .v { float: right; font-weight: 600; }
.flag-high { color: var(--danger); } .flag-low { color: #d98a00; } .flag-ok { color: var(--ok); }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; }
textarea { min-height: 110px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--hint); margin: 10px 0 4px; }
.btn { border: 0; background: var(--btn); color: var(--btn-text); border-radius: 10px; padding: 11px 16px; font: inherit;
  font-weight: 600; cursor: pointer; }
.btn.sec { background: var(--bg2); color: var(--text); }
.btn.danger { background: none; color: var(--danger); }
.btn.block { width: 100%; margin-top: 12px; }
.btn[disabled] { opacity: .5; }
.fab { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: var(--btn); color: var(--btn-text); font-size: 28px; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 7; }
h2 { font-size: 15px; color: var(--hint); font-weight: 600; margin: 18px 0 8px; text-transform: none; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv span:first-child { color: var(--hint); }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumbs .th { position: relative; aspect-ratio: 1; background: var(--bg2); border-radius: 10px; overflow: hidden; border: 0; padding: 0; }
.thumbs img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumbs .pdf { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 13px; color: var(--hint); padding: 6px; text-align: center; }
.err { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin: 10px 0; }
.note { background: color-mix(in srgb, var(--btn) 10%, transparent); padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-size: 14px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: 90%; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal .box { background: var(--bg); width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.modal .box p { margin: 0 0 14px; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 25; display: flex; flex-direction: column; }
.viewer img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.viewer .bar { display: flex; gap: 8px; padding: 10px 16px; background: #111; }
table.items { width: 100%; border-collapse: collapse; font-size: 14px; }
table.items td { padding: 4px 2px; vertical-align: middle; }
table.items input[type=text], table.items input[type=number] { padding: 6px 8px; }
table.items input[type=checkbox] { width: 20px; height: 20px; }
.ocrtext { white-space: pre-wrap; font-size: 13px; background: var(--bg2); padding: 10px; border-radius: 10px; max-height: 260px; overflow: auto; }
svg.chart { width: 100%; height: auto; background: var(--bg2); border-radius: var(--r); touch-action: manipulation; }
svg.chart text { fill: var(--hint); font-size: 17px; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--hint); }
