:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #17212b; --bg2: #0e1621; --text: #f5f5f5; --hint: #7f8b99; --link: #6ab3f3; --accent: #5288c1;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: 4px; padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 25%, transparent);
}
.tab {
  flex: 1; padding: 8px; border: 0; border-radius: 10px;
  background: transparent; color: var(--hint); font: inherit; font-weight: 600;
}
.tab.active { background: var(--bg2); color: var(--text); }

main { padding: 12px 16px 24px; }
.panel { display: flex; flex-direction: column; gap: 12px; }

form { display: flex; flex-direction: column; gap: 10px; background: var(--bg); padding: 14px; border-radius: var(--radius); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--hint); }
.field small { font-size: 12px; }
input, select {
  width: 100%; min-width: 0; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg2); border: 1px solid transparent; border-radius: 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.actions { display: flex; gap: 8px; }
.btn {
  flex: 1; padding: 11px 12px; border: 0; border-radius: 10px; font: inherit; font-weight: 600;
  background: var(--bg2); color: var(--accent); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; }
.btn.danger { color: var(--danger); }

.status { padding: 10px 14px; border-radius: var(--radius); background: var(--bg); color: var(--hint); }
.status.error { color: var(--danger); }

.cards, .subs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.card {
  display: grid; grid-template-columns: 96px 1fr; gap: 10px; padding: 10px;
  background: var(--bg); border-radius: var(--radius); color: inherit; text-decoration: none;
}
.card img, .card .noimg { width: 96px; height: 72px; border-radius: 8px; object-fit: cover; background: var(--bg2); }
.card .title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .price { font-weight: 700; margin-top: 2px; }
.card .meta { font-size: 13px; color: var(--hint); margin-top: 2px; }

.sub { background: var(--bg); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.sub .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sub .name { font-weight: 600; overflow-wrap: anywhere; }
.sub .desc, .sub .when { font-size: 13px; color: var(--hint); overflow-wrap: anywhere; }
.sub .err { font-size: 13px; color: var(--danger); }
.sub .actions .btn { padding: 8px; font-size: 14px; }
.switch { width: 44px; height: 26px; flex: none; accent-color: var(--accent); }
.hint { margin: 0; color: var(--hint); font-size: 13px; }

dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(92vw, 420px); background: var(--bg); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h3 { margin: 0 0 4px; }
