:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --btn: var(--tg-theme-button-color, #2a7ae2);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: var(--tg-theme-section-separator-color, rgba(127,127,127,.18));
  --ok: #2fa65a;
  --warn: #d98b0b;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.center { display: flex; align-items: center; justify-content: center; min-height: 70vh; padding: 24px; text-align: center; }
.hint { color: var(--hint); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.danger { color: var(--danger); }
.ok { color: var(--ok); }

/* ---------- головний екран ---------- */
.home { padding: 18px 16px 32px; max-width: 640px; margin: 0 auto; }
.home-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 18px; }
.home-head h1 { font-size: 22px; margin: 0; }
.icon-btn { border: 0; background: var(--section); width: 40px; height: 40px; border-radius: 12px; font-size: 19px; }
.tile {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  border: 0; text-align: left; background: var(--section); border-radius: var(--radius);
  padding: 22px 20px; margin-bottom: 12px; min-height: 88px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.tile:active { transform: scale(.985); }
.tile .t-name { font-size: 19px; font-weight: 650; }
.tile .t-sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.tile .t-count { font-size: 26px; font-weight: 700; color: var(--btn); }
.tile.all { background: var(--btn); color: var(--btn-text); }
.tile.all .t-count, .tile.all .t-sub { color: var(--btn-text); opacity: .95; }
.bell { display: inline-block; background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: 12px; font-weight: 600; margin-left: 8px; vertical-align: 2px; }

/* ---------- робочий екран ---------- */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--sep); }
.top-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; }
.top-row .back { border: 0; background: none; color: var(--link); padding: 6px 4px; font-size: 15px; white-space: nowrap; }
.top-row .title { font-weight: 650; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 12px 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: var(--bg2); border-radius: 18px; padding: 7px 13px; white-space: nowrap; font-size: 14px; }
.tab.on { background: var(--btn); color: var(--btn-text); font-weight: 600; }
.tab .bell { margin-left: 5px; vertical-align: 0; }
.content { padding: 10px 12px 96px; max-width: 760px; margin: 0 auto; }

.search { display: flex; gap: 8px; margin-bottom: 8px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--sep); background: var(--section); border-radius: 12px;
  padding: 10px 12px; outline: none; min-height: 42px;
}
.input:focus { border-color: var(--btn); }
textarea.input { min-height: 84px; resize: vertical; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--sep); background: var(--section); border-radius: 16px; padding: 5px 11px; font-size: 13px; white-space: nowrap; }
.chip.on { border-color: var(--btn); color: var(--btn); font-weight: 600; }

.list { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--sep); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--bg2); }
.row .num { min-width: 52px; font-weight: 700; color: var(--btn); font-variant-numeric: tabular-nums; }
.row .main { flex: 1; min-width: 0; }
.row .l1 { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .l1.fx { display: flex; align-items: center; min-width: 0; }
.row .l1 .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row .l1 .badge { flex: 0 0 auto; }
.row .l2 { color: var(--hint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .side { color: var(--hint); font-size: 13px; text-align: right; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 6px; padding: 1px 6px; margin-left: 4px; vertical-align: 1px; }
.b-transit { background: rgba(217,139,11,.15); color: var(--warn); }
.b-repair { background: rgba(229,72,77,.13); color: var(--danger); }
.b-off { background: var(--bg2); color: var(--hint); }
.empty { text-align: center; color: var(--hint); padding: 36px 12px; }
.count-line { color: var(--hint); font-size: 13px; margin: 2px 4px 8px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--hint); margin: 18px 6px 6px; }
.section-title:first-child { margin-top: 4px; }

.fab {
  position: fixed; right: 18px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 6;
  border: 0; background: var(--btn); color: var(--btn-text); border-radius: 28px; height: 52px; padding: 0 20px;
  font-size: 16px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.18);
}

/* журнал */
.log-entry { padding: 11px 14px; border-bottom: 1px solid var(--sep); }
.log-entry:last-child { border-bottom: 0; }
.log-entry .lh { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--hint); }
.log-entry .la { font-weight: 600; margin-top: 2px; }
.log-entry .li { margin-top: 1px; }
.log-entry .ld { color: var(--hint); font-size: 13px; margin-top: 2px; }
.log-entry .lr { font-size: 13px; margin-top: 4px; padding: 6px 9px; background: var(--bg2); border-radius: 8px; }

/* передачі */
.card { background: var(--section); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.card .ct { font-weight: 600; }
.card .cs { color: var(--hint); font-size: 13px; margin-top: 2px; }
.card .cr { font-size: 13px; margin-top: 6px; padding: 6px 9px; background: var(--bg2); border-radius: 8px; }
.btns { display: flex; gap: 8px; margin-top: 10px; }

.btn { border: 0; border-radius: 12px; padding: 11px 14px; font-weight: 600; background: var(--btn); color: var(--btn-text); width: 100%; min-height: 44px; }
.btn.sec { background: var(--bg2); color: var(--text); }
.sheet .btn.sec { background: var(--section); border: 1px solid var(--sep); }
.btn.dng { background: rgba(229,72,77,.12); color: var(--danger); }
.btn.okb { background: var(--ok); color: #fff; }
.btn:disabled { opacity: .45; }

/* ---------- аркуш (модальне вікно) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.38); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg2); width: 100%; max-width: 760px; max-height: 94vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 0 0 calc(18px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; background: var(--bg2); }
.sheet-head .st { flex: 1; font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-head .x { border: 0; background: var(--section); border-radius: 50%; width: 32px; height: 32px; font-size: 16px; color: var(--hint); }
.sheet-body { padding: 0 14px; }

.kv { background: var(--section); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--sep); }
.kv-row:last-child { border-bottom: 0; }
.kv-row .k { color: var(--hint); }
.kv-row .v { text-align: right; font-weight: 550; word-break: break-word; }
.big-num { font-size: 28px; font-weight: 750; color: var(--btn); margin: 2px 2px 10px; }
.actions { display: grid; gap: 8px; margin: 6px 0 14px; }
.actions.two { grid-template-columns: 1fr 1fr; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 5px; }
.field .req { color: var(--danger); }
.inline { display: flex; gap: 8px; }
.inline > * { flex: 1; }
.inline .btn { flex: 0 0 auto; width: auto; }
.seg { display: flex; background: var(--section); border: 1px solid var(--sep); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 6px; font-size: 14px; }
.seg button.on { background: var(--btn); color: var(--btn-text); font-weight: 600; }
.note { font-size: 13px; color: var(--hint); margin: -4px 4px 12px; }
.warn-box { background: rgba(217,139,11,.12); color: var(--warn); border-radius: 10px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }
.link-box { word-break: break-all; font-size: 13px; background: var(--section); border-radius: 10px; padding: 10px 12px; margin: 8px 0; user-select: all; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 40;
  background: rgba(20,22,26,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; text-align: center;
}
.toast.err { background: var(--danger); }
.toast[hidden] { display: none; }
.more { margin: 12px 0; }
