[hidden] { display: none !important; }
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f4);
  --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, #7c8591);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d93a3a);
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  --tabs-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #0f1216);
    --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1a1f26));
    --text: var(--tg-theme-text-color, #eef1f4);
    --hint: var(--tg-theme-hint-color, #8a94a1);
    --link: var(--tg-theme-link-color, #6ab3f3);
    --btn: var(--tg-theme-button-color, #3e92dd);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; overflow-wrap: anywhere;
}
#view { padding: 16px 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 20px 4px 8px; }
.hint { color: var(--hint); font-size: 14px; }
.error { color: var(--danger); }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
#tabs[hidden] { display: none; }
#tabs button {
  flex: 1; height: var(--tabs-h); border: 0; background: none; color: var(--hint);
  font: inherit; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#tabs button span { font-size: 20px; line-height: 1; }
#tabs button.on { color: var(--link); font-weight: 600; }

.list { background: var(--card); border-radius: 14px; overflow: hidden; }
.row {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 12px 14px; border: 0; background: none;
  color: inherit; font: inherit; text-align: left; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--line); }
.row .ico { font-size: 24px; width: 32px; text-align: center; flex: none; }
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { color: var(--hint); font-size: 13px; }
.row.off { opacity: .55; }
.badge { font-size: 11px; color: var(--hint); border: 1px solid var(--line); border-radius: 20px; padding: 2px 8px; flex: none; }

.back { border: 0; background: none; color: var(--link); font: inherit; padding: 6px 0; margin-bottom: 4px; }
form.card, .card { background: var(--card); border-radius: 14px; padding: 14px; }
label { display: block; font-size: 13px; color: var(--hint); margin: 12px 0 4px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 11px 12px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--btn); }
textarea { min-height: 120px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 16px; }
.btn {
  display: block; width: 100%; margin-top: 16px; padding: 13px; border: 0; border-radius: 12px;
  background: var(--btn); color: var(--btn-text); font: inherit; font-weight: 600;
}
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; }
.btn.small { display: inline-block; width: auto; margin: 8px 8px 0 0; padding: 7px 14px; font-size: 14px; border-radius: 9px; }
.btn.ghost { background: none; color: var(--link); border: 1px solid var(--line); }

.result { margin-top: 16px; }
.status { font-size: 13px; margin: 0 4px 8px; color: var(--hint); }
.status.bad { color: var(--danger); }
.item { background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.item .title { font-weight: 600; }
.item .sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.item .text { margin-top: 8px; white-space: pre-wrap; font-size: 15px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--btn); margin-right: 6px; }
table.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
table.kv td { padding: 6px 0; vertical-align: top; border-bottom: 1px solid var(--line); }
table.kv tr:last-child td { border-bottom: 0; }
table.kv td:first-child { color: var(--hint); width: 35%; padding-right: 10px; }
table.kv td:last-child { white-space: pre-wrap; }
details { margin-top: 10px; font-size: 13px; color: var(--hint); }
pre { white-space: pre-wrap; background: var(--card); color: var(--text); padding: 12px; border-radius: 12px; font-size: 12px; margin: 8px 0 0; max-height: 50vh; overflow: auto; }

.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 80px; }
.msg { max-width: 86%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; background: var(--card); align-self: flex-start; border-bottom-left-radius: 5px; }
.msg.user { align-self: flex-end; background: var(--btn); color: var(--btn-text); border-radius: 16px; border-bottom-right-radius: 5px; }
.msg.wait { color: var(--hint); }
.msg.fail { color: var(--danger); }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  display: flex; gap: 8px; padding: 8px 12px; background: var(--bg); border-top: 1px solid var(--line); align-items: flex-end;
}
.composer textarea { min-height: 44px; max-height: 140px; height: 44px; resize: none; background: var(--card); }
.composer textarea { flex: 1; min-width: 0; }
.composer .btn { width: auto; flex: none; white-space: nowrap; margin: 0; padding: 11px 16px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; }
.toolbar h1 { margin-bottom: 8px; }
.toolbar .back { margin: 0; font-size: 14px; }

/* composer with files and voice */
.composer { flex-direction: column; align-items: stretch; gap: 6px; }
.composer .bar { display: flex; gap: 6px; align-items: flex-end; }
.icon-btn {
  flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 12px; background: none;
  font-size: 22px; line-height: 1; color: var(--hint); display: flex; align-items: center; justify-content: center;
}
.icon-btn.send { background: var(--btn); color: var(--btn-text); font-size: 18px; }
.icon-btn.stop { background: var(--danger); color: #fff; font-size: 16px; }
.icon-btn:disabled { opacity: .4; }
.tray { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 4px 4px 4px 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; font-size: 13px;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.note { padding-right: 10px; }
.chip.error { color: var(--danger); }
.chip button { border: 0; background: none; color: var(--hint); font-size: 14px; padding: 2px 6px; }
.recbar {
  flex: 1; min-width: 0; height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.recbar .grow { flex: 1; font-variant-numeric: tabular-nums; }
.recbar button { border: 0; background: none; color: var(--link); font: inherit; padding: 0; }
.recdot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.chat { padding-bottom: 120px; }
.atts { display: flex; flex-direction: column; gap: 6px; }
.atts + .msg-text { margin-top: 6px; }
.att-img img { display: block; max-width: min(240px, 100%); max-height: 240px; border-radius: 10px; }
.att-audio { width: 240px; max-width: 100%; height: 40px; }
.att { color: inherit; font-size: 14px; }
.att.gone { opacity: .6; }

/* function cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.fn-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-height: 140px; padding: 14px;
  background: var(--card); color: inherit; font: inherit; text-align: left; border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04); transition: transform .12s ease, box-shadow .12s ease;
}
.fn-card:active { transform: scale(.97); }
@media (hover: hover) { .fn-card:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, .08); } }
.fn-top { display: flex; width: 100%; justify-content: space-between; align-items: flex-start; gap: 6px; }
.fn-ico {
  width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 24px; background: color-mix(in srgb, var(--btn) 12%, transparent);
}
.fn-card.danger .fn-ico { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.fn-title { font-weight: 600; margin-top: 4px; }
.fn-sub {
  color: var(--hint); font-size: 13px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.fn-card.off { opacity: .6; }

/* AI writer */
.label-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 12px 0 4px; }
.label-row label { margin: 0; }
.ai-btn {
  border: 0; border-radius: 20px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap;
  color: #fff; background: linear-gradient(135deg, #7b5cff, #3e92dd);
}
.ai-btn:disabled { opacity: .55; }
.btn.small.ai { color: #fff; background: linear-gradient(135deg, #7b5cff, #3e92dd); }
.ai-note { margin: 6px 2px 0; font-size: 12px; }
textarea.ai-busy { opacity: .5; }
textarea#f-reply { min-height: 180px; }
