:root {
  --bg: var(--tg-theme-secondary-bg-color, #eef0f5);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #15171c);
  --hint: var(--tg-theme-hint-color, #5d6472);
  --accent: var(--tg-theme-button-color, #0a63c9);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --separator: var(--tg-theme-section-separator-color, rgba(20, 24, 32, 0.1));
  --destructive: var(--tg-theme-destructive-text-color, #c62828);
  --glass: color-mix(in srgb, var(--section) 70%, transparent);
  --glass-edge: color-mix(in srgb, var(--section) 75%, transparent);
  --ok: #1f9d55;
  --warn: #b26a00;
  --fail: var(--destructive);
  --card-radius: 22px;
  --control-radius: 14px;
  --touch: 44px;
  --tabbar-height: 68px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(var(--tabbar-height) + 40px + var(--tg-safe-area-inset-bottom, 0px)); }

main { padding: 0 16px; max-width: 640px; margin: 0 auto; }

.page-title { margin: 20px 4px 14px; }
.page-title h1 { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.subtitle { margin: 4px 0 0; font-size: 14px; color: var(--hint); }
.status-line { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-weight: 600; }

.heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 22px 4px 8px; }
h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--header);
}

.section {
  background: var(--section);
  border-radius: var(--card-radius);
  overflow: hidden;
  margin-bottom: 4px;
}
.section + .section { margin-top: 14px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  position: relative;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: 1px solid var(--separator);
}

.row.tappable { cursor: pointer; }
.row.tappable:active, .row.choice:active { background: var(--separator); }
.chevron { width: 8px; height: 14px; flex: none; border-right: 2px solid var(--hint); border-top: 2px solid var(--hint); transform: rotate(45deg) scale(0.7); opacity: 0.8; }

.grow { flex: 1; min-width: 0; }
.label { overflow-wrap: anywhere; }
.label.strong { font-weight: 600; }
.sub { font-size: 13px; color: var(--hint); margin-top: 2px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.trailing { flex: none; max-width: 45%; font-size: 14px; color: var(--hint); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trailing.completed, .trailing.ok { color: var(--ok); font-weight: 600; }
.trailing.running, .trailing.warn { color: var(--warn); font-weight: 600; }
.trailing.failed, .trailing.fail { color: var(--fail); font-weight: 600; }

.hint { font-size: 13px; line-height: 1.4; color: var(--hint); margin: 8px 4px 0; }
.center { text-align: center; margin-top: 40px; }
.warning { color: var(--destructive); }

.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--section); font-size: 14px; font-weight: 600; margin: 0 4px; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--hint); }
.dot.available, .dot.ok { background: var(--ok); }
.dot.auth_unverified, .dot.unauthenticated, .dot.warn { background: var(--warn); }
.dot.issue, .dot.not_installed, .dot.fail { background: var(--fail); }
.dot.disabled { background: transparent; border: 2px solid var(--hint); }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; z-index: 1; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 31px; background: var(--separator); transition: background 0.2s; }
.switch span::before {
  content: "";
  position: absolute;
  width: 27px;
  height: 27px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:disabled + span { opacity: 0.45; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.choice { align-items: flex-start; padding-top: 14px; padding-bottom: 14px; cursor: pointer; }
.choice.selected { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.radio { width: 22px; height: 22px; margin-top: 1px; flex: none; border-radius: 50%; border: 2px solid var(--hint); }
.choice.selected .radio { border: 7px solid var(--accent); }

select {
  font: inherit;
  font-size: 16px;
  color: var(--accent);
  background: transparent;
  border: 0;
  max-width: 55%;
  min-height: var(--touch);
  text-align: right;
}

.button {
  display: block;
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: var(--control-radius);
  padding: 13px;
  margin-top: 14px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
}
.button.plain { color: var(--accent); background: var(--section); }
.button.danger { color: var(--destructive); background: var(--section); }
.button.compact { margin-top: 0; min-height: var(--touch); padding: 10px; flex: 1; }

.link { border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 15px; font-weight: 600; min-height: var(--touch); padding: 0 4px; }
.pill { flex: none; min-height: 36px; border: 0; border-radius: 18px; padding: 0 14px; background: var(--bg); color: var(--accent); font: inherit; font-size: 14px; font-weight: 600; }

.icon-button { flex: none; min-width: var(--touch); min-height: var(--touch); border: 0; background: transparent; color: var(--accent); font-size: 20px; }
.icon-button.danger { color: var(--destructive); }
.icon-button:disabled { opacity: 0.3; }

.input {
  width: 100%;
  min-height: var(--touch);
  border: 1px solid var(--separator);
  border-radius: var(--control-radius);
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
}

.busy { opacity: 0.6; pointer-events: none; }

.tabbar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(16px + var(--tg-safe-area-inset-bottom, 0px));
  max-width: 616px;
  margin: 0 auto;
  height: var(--tabbar-height);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  padding: 0 6px;
  border-radius: 34px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(28px) saturate(1.8);
  backdrop-filter: blur(28px) saturate(1.8);
  box-shadow: 0 0 0 1px var(--glass-edge) inset, 0 10px 30px rgba(20, 24, 32, 0.16);
  z-index: 3;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 56px;
  border: 0;
  border-radius: 26px;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

@media (prefers-reduced-motion: reduce) {
  .switch span, .switch span::before { transition: none; }
}

.search { margin: 0 0 16px; }
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }

textarea.input { resize: vertical; min-height: 96px; }
.input.compact { width: auto; min-width: 140px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0; }
.chip.selected { background: var(--accent); color: var(--accent-text); }
.button.destructive { color: var(--destructive); }
.plain-button { background: none; border: 0; padding: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
