:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #111);
  --hint: var(--tg-theme-hint-color, #707579);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #fff);
  --secbg: var(--tg-theme-secondary-bg-color, #f4f4f5);
  --border: rgba(0, 0, 0, 0.08);
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  padding-bottom: 20px;
}
#root {
  max-width: 560px;
  margin: 0 auto;
}

/* HEADER */
.hdr {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.hdr-title {
  font-size: 20px;
  font-weight: 700;
}
.hdr-sub {
  font-size: 13px;
  color: var(--hint);
  margin-top: 2px;
}

/* TABS */
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  overflow-x: auto;
}
.tab {
  flex: 1;
  min-width: fit-content;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: none;
  color: var(--hint);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active {
  background: var(--secbg);
  color: var(--text);
}

/* PAGE */
.page {
  display: none;
  padding: 16px 20px;
}
.page.active {
  display: block;
}
h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.muted {
  color: var(--hint);
  font-size: 13px;
  margin: 8px 0;
}
.loader {
  padding: 24px;
  text-align: center;
  color: var(--hint);
}

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.kpi {
  background: var(--secbg);
  border-radius: 12px;
  padding: 12px;
}
.kpi-label {
  font-size: 11px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 4px;
}
.kpi-sub {
  font-size: 12px;
  color: var(--hint);
  margin-top: 2px;
}
.kpi-sub.up {
  color: #22c55e;
}
.kpi-sub.down {
  color: #ef4444;
}

/* QUICK BUTTONS */
.quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.qbtn {
  padding: 14px 12px;
  border: none;
  border-radius: 10px;
  background: var(--secbg);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition:
    background 0.2s,
    color 0.2s;
}
.qbtn:active {
  opacity: 0.7;
}
.qbtn.loading {
  background: #fef3c7;
  color: #b45309;
}
.qbtn.success {
  background: #d1fae5;
  color: #065f46;
}
.qbtn.error {
  background: #fee2e2;
  color: #b91c1c;
}
.qbtn:disabled {
  cursor: default;
}

/* SOURCE LIST */
.src-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.src-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  background: var(--secbg);
  border-radius: 10px;
  align-items: center;
}
.src-name {
  font-weight: 500;
  font-size: 14px;
}
.src-meta {
  font-size: 11px;
  color: var(--hint);
  margin-top: 2px;
}
.src-rev {
  font-weight: 600;
  text-align: right;
  font-size: 14px;
}
.src-conv {
  font-size: 11px;
  color: var(--hint);
  text-align: right;
}

/* COMMANDS */
.cmd-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cmd-item {
  background: var(--secbg);
  border-radius: 12px;
  padding: 12px;
}
.cmd-name {
  font-weight: 600;
  font-size: 14px;
}
.cmd-desc {
  font-size: 13px;
  color: var(--hint);
  margin-top: 4px;
}
.cmd-examples {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cmd-example {
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--link);
}
.cmd-example:active {
  opacity: 0.6;
}

/* ARCH */
#arch-diagram {
  background: var(--secbg);
  border-radius: 12px;
  padding: 16px;
  font-family: ui-monospace, Menlo, Monaco, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
  overflow-x: auto;
}
.arch-status {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.arch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--secbg);
  border-radius: 10px;
}
.arch-row .left {
  font-weight: 500;
}
.arch-row .right {
  font-size: 13px;
  color: var(--hint);
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  background: #22c55e;
}
.dot.warn {
  background: #f59e0b;
}
.dot.err {
  background: #ef4444;
}

/* HELP */
#help-content h3 {
  font-size: 14px;
  margin: 16px 0 8px;
  font-weight: 600;
}
#help-content p {
  font-size: 13px;
  color: var(--hint);
  margin: 6px 0;
  line-height: 1.5;
}
#help-content ul {
  margin: 6px 0 6px 20px;
  font-size: 13px;
}
#help-content li {
  margin: 4px 0;
}
#help-content code {
  background: var(--secbg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--button);
  color: var(--button-text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  max-width: 300px;
  text-align: center;
}
.toast.show {
  opacity: 1;
}
