:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #000);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --ok: #1eaa5c;
  --danger: #d7393c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---- top bar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--secondary-bg);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.conn {
  font-size: 12px;
  padding: 3px 9px 3px 20px;
  border-radius: 999px;
  position: relative;
  color: var(--hint);
  background: var(--secondary-bg);
}
.conn::before {
  content: "";
  position: absolute;
  left: 8px; top: 50%;
  width: 8px; height: 8px; margin-top: -4px;
  border-radius: 50%;
  background: var(--hint);
}
.conn--on { color: var(--ok); }
.conn--on::before { background: var(--ok); box-shadow: 0 0 0 0 rgba(30,170,92,.5); animation: pulse 2s infinite; }
.conn--off { color: var(--danger); }
.conn--off::before { background: var(--danger); }

/* ---- transcript ------------------------------------------------------- */
.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  max-width: 86%;
  padding: 8px 12px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.user {
  align-self: flex-end;
  background: var(--btn);
  color: var(--btn-text);
  border-bottom-right-radius: 5px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--secondary-bg);
  color: var(--text);
  border-bottom-left-radius: 5px;
}
.msg.error {
  align-self: center;
  background: #ffe5e5;
  color: #b00020;
  font-size: 13px;
  border-radius: 10px;
}

/* ---- empty state ------------------------------------------------------ */
.empty {
  margin: auto;
  text-align: center;
  color: var(--hint);
  padding: 24px;
  max-width: 280px;
}
.empty-emoji { font-size: 40px; }
.empty-title { font-weight: 700; color: var(--text); margin-top: 8px; font-size: 17px; }
.empty-sub { margin-top: 6px; font-size: 14px; }

/* ---- activity zone (ephemeral tech status + permissions) -------------- */
.activity {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 12px;
}
.activity:not(:empty) { padding: 4px 12px 8px; }

.act {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--secondary-bg);
  border-radius: 12px;
  padding: 8px 11px;
  font-size: 13.5px;
  color: var(--text);
}
.act .dot {
  flex: none;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--link);
  animation: pulse 1.4s infinite;
}
.act.act--think .dot { background: #f0a020; }
.act.act--work .dot { background: var(--link); }
.act.act--tool .dot { background: var(--ok); }
.act .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act .timer {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  color: var(--hint);
  font-size: 12px;
}

/* ---- permission card -------------------------------------------------- */
.perm {
  background: var(--bg);
  border: 1.5px solid var(--btn);
  border-radius: 14px;
  padding: 11px 12px;
}
.perm .q { font-weight: 600; margin-bottom: 2px; }
.perm .det {
  font-size: 12px;
  color: var(--hint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-bottom: 9px;
  max-height: 64px;
  overflow: hidden;
}
.perm .btns { display: flex; gap: 8px; }
.perm button { flex: 1; padding: 10px; border: 0; border-radius: 11px; font-size: 14px; font-weight: 600; }
.perm .allow { background: var(--btn); color: var(--btn-text); }
.perm .deny { background: var(--secondary-bg); color: var(--danger); }
.perm button:disabled { opacity: 0.5; }

/* ---- composer --------------------------------------------------------- */
.composer {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--secondary-bg);
}
.input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--secondary-bg);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
}
.input:focus { outline: none; border-color: var(--btn); background: var(--bg); }
.send {
  width: 44px; height: 44px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 17px;
}
.send:disabled { opacity: 0.5; }
.notice { padding: 6px 12px; color: var(--hint); font-size: 13px; text-align: center; }
.notice:empty { display: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(36,129,204,.45); }
  70% { box-shadow: 0 0 0 7px rgba(36,129,204,0); }
  100% { box-shadow: 0 0 0 0 rgba(36,129,204,0); }
}
