:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2a7de1);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --ok: #2fb36b;
  --warn: #f2a33a;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }

.app { min-height: 100vh; }
.view { padding: 12px 12px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

/* Header */
.page-title { font-size: 22px; font-weight: 700; margin: 6px 4px 12px; display: flex; align-items: center; gap: 8px; }
.page-title .grow { flex: 1; }
.subtitle { color: var(--hint); margin: -8px 4px 12px; font-size: 14px; }

/* Cards and lists */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.section-label { color: var(--header); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin: 18px 6px 6px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--sep); }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--soft); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--hint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .wrap { white-space: normal; }
.row .icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; background: var(--soft); flex: none; }
.row .chev { color: var(--hint); font-size: 18px; }
.thumb { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; background: var(--soft); flex: none; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.stat .num { font-size: 24px; font-weight: 700; }
.stat .lbl { color: var(--hint); font-size: 13px; }
.stat.tap:active { background: var(--soft); }

/* Hero */
.hero { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #7b5cff)); color: var(--accent-text); border-radius: 18px; padding: 18px; margin-bottom: 12px; }
.hero h1 { margin: 0 0 4px; font-size: 22px; }
.hero p { margin: 0; opacity: .9; }
.hero .chip { background: rgba(255,255,255,.2); color: inherit; }

/* Chips, badges */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--soft); color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.chip.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.chip.muted { background: var(--sep); color: var(--hint); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip.select { cursor: pointer; border: 1px solid transparent; background: var(--card); color: var(--text); }
.chip.select.on { background: var(--accent); color: var(--accent-text); }

/* Banner */
.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { background: color-mix(in srgb, var(--warn) 16%, var(--card)); }
.banner.info { background: var(--soft); }

/* Buttons */
.btn { appearance: none; border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer; background: var(--accent); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--soft); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--accent); padding: 8px 10px; min-height: 0; }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.98); }
.btns { display: grid; gap: 8px; }
.btns.two { grid-template-columns: 1fr 1fr; }
.btns.three { grid-template-columns: 1fr 1fr 1fr; }
.fab { position: fixed; right: 16px; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); font-size: 28px; box-shadow: 0 6px 18px rgba(0,0,0,.18); cursor: pointer; z-index: 5; }

/* Forms */
.field { padding: 10px 14px; position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--sep); }
.field label { display: block; color: var(--hint); font-size: 13px; margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; border: 0; outline: 0; background: transparent; padding: 4px 0; font-size: 16px; }
.field textarea { resize: vertical; min-height: 64px; }
.field .help { color: var(--hint); font-size: 12px; margin-top: 4px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.picker { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 30px; }
.picker .value { flex: 1; font-size: 16px; }
.picker .value.empty { color: var(--hint); }

/* Switch */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--sep); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

/* Tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--sep); display: flex; z-index: 10; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--hint); font-size: 11px; border: 0; background: none; cursor: pointer; position: relative; }
.tab .ico { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .75; }
.tab.on { color: var(--accent); }
.tab.on .ico { filter: none; opacity: 1; }
.tab .dot { position: absolute; top: 8px; left: calc(50% + 8px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 10px; display: grid; place-items: center; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s; }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 12px calc(16px + env(safe-area-inset-bottom)); animation: up .22s ease-out; }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--sep); margin: 4px auto 10px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* Toast */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 20px + env(safe-area-inset-bottom)); background: rgba(20,20,24,.92); color: #fff; padding: 10px 16px; border-radius: 12px; max-width: 90vw; z-index: 30; font-size: 14px; text-align: center; animation: fade .2s; }

/* Misc */
.empty { text-align: center; color: var(--hint); padding: 36px 16px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.loading { display: grid; place-items: center; padding: 60px 0; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--sep); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.pre { white-space: pre-wrap; }
.shot { width: 100%; border-radius: 12px; background: var(--soft); min-height: 120px; display: block; }
.spacer { height: 8px; }
.right { margin-left: auto; }
.search-input { width: 100%; border: 0; outline: 0; background: var(--card); border-radius: 12px; padding: 12px 14px; font-size: 16px; margin-bottom: 10px; }
