:root {
  --bg: #17212b; --text: #f5f5f5; --hint: #708499; --link: #6ab3f3;
  --btn: #5288c1; --btn-text: #fff; --secondary: #232e3c; --accent: #6ab2f2; --danger: #e5645c; --ok: #5cc07a;
  --line: rgba(127,127,127,.28); --nav-h: 56px;
  --top: calc(env(safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; min-height: 100dvh; }
[hidden] { display: none !important; }
#state { padding: calc(32px + var(--top)) 20px 32px; text-align: center; color: var(--hint); max-width: 520px; margin: 0 auto; }
#state strong { display: block; color: var(--text); font-size: 1.15rem; margin-bottom: 8px; }
#app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
#nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--secondary); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--line); }
#nav button { flex: 1 1 0; min-width: 0; min-height: var(--nav-h); border: 0; background: none; color: var(--hint); font: inherit; font-size: clamp(.6rem, 2.6vw, .8rem); cursor: pointer; padding: 6px 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav button[aria-current="page"] { color: var(--accent); font-weight: 600; }
#nav button:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#main { flex: 1; padding: calc(16px + var(--top)) max(16px, env(safe-area-inset-right)) calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); width: 100%; max-width: 920px; margin: 0 auto; outline: none; min-width: 0; }
h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 16px 0 8px; }
.card { background: var(--secondary); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; overflow-wrap: anywhere; }
.muted { color: var(--hint); }
.small { font-size: .85rem; }
.row { display: flex; align-items: center; gap: 10px; }
.row > .grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 12px; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; border: 1px solid var(--line); background: none; color: var(--text); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: .9rem; cursor: pointer; min-height: 36px; }
.tabs button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
button.btn, .btn, button.ghost, button.danger { border: 0; background: var(--btn); color: var(--btn-text); border-radius: 10px; padding: 9px 16px; font: inherit; cursor: pointer; min-height: 40px; }
button.ghost { background: none; color: var(--accent); border: 1px solid var(--line); }
button.danger { background: none; color: var(--danger); border: 1px solid var(--line); }
.card .row.wrap { margin-top: 8px; }
button:disabled { opacity: .5; cursor: default; }
label { display: block; font-size: .85rem; color: var(--hint); margin: 10px 0 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-height: 40px; }
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; flex: none; }
.item { cursor: pointer; }
.item .t { font-weight: 600; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: .78rem; background: rgba(127,127,127,.22); margin-right: 4px; }
.badge.ok { color: var(--ok); } .badge.warn { color: #e0b04a; } .badge.bad { color: var(--danger); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar select { width: auto; min-width: 0; flex: 0 1 200px; }
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); border-radius: 16px 16px 0 0; width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; padding: 16px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); border: 1px solid var(--line); }
.sheet h2 { margin-top: 0; }
.sheet .actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); background: var(--secondary); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; z-index: 20; max-width: 90vw; }
.msgs { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.msg { padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--btn); color: var(--btn-text); }
.msg.assistant { align-self: flex-start; background: var(--secondary); }
.composer { display: flex; gap: 8px; align-items: flex-end; position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--bg); padding: 8px 0; }
.composer textarea { min-height: 44px; max-height: 160px; }
.bar { height: 8px; border-radius: 4px; background: rgba(127,127,127,.25); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; }
.bar > i.p0 { width: 0; } .bar > i.p10 { width: 10%; } .bar > i.p20 { width: 20%; } .bar > i.p30 { width: 30%; } .bar > i.p40 { width: 40%; }
.bar > i.p50 { width: 50%; } .bar > i.p60 { width: 60%; } .bar > i.p70 { width: 70%; } .bar > i.p80 { width: 80%; } .bar > i.p90 { width: 90%; } .bar > i.p100 { width: 100%; }
.done .t { text-decoration: line-through; color: var(--hint); }
@media (min-width: 900px) {
  #app { flex-direction: row; }
  #nav { position: sticky; top: 0; align-self: flex-start; flex-direction: column; width: 220px; height: 100vh; padding: calc(16px + var(--top)) 8px 16px; border-top: 0; border-right: 1px solid var(--line); }
  #nav button { flex: none; min-height: 44px; text-align: left; padding: 8px 14px; font-size: 1rem; border-radius: 8px; }
  #nav button[aria-current="page"] { background: rgba(127,127,127,.18); }
  #main { padding: calc(28px + var(--top)) 32px 40px; margin: 0; max-width: 1000px; }
  .sheet-bg { align-items: center; }
  .sheet { border-radius: 16px; }
  #toast { bottom: 24px; }
  .composer { bottom: 0; }
}
@media (prefers-reduced-motion: no-preference) { #main { animation: fade .15s ease-out; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
