:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #15171c; --muted: #6b7280; --line: #e3e6eb;
  --accent: #6d4aff; --accent-text: #ffffff; --mine: #6d4aff; --mine-text: #ffffff; --error: #c62828;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #181b21; --text: #eceef2; --muted: #9aa1ad; --line: #2a2f38;
          --accent: #8b6dff; --mine: #5b3df5; --error: #ff6b6b; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--error); }
#app { height: 100%; }
.screen { height: 100%; display: flex; flex-direction: column; }

/* вход */
#login { align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; padding: 28px 20px; }
.logo { width: 64px; height: 64px; }
.brand { margin: 8px 0 4px; font-size: 26px; }
#tg-login { min-height: 48px; margin: 18px 0 6px; display: flex; justify-content: center; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; margin: 14px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
#email-form input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); margin-bottom: 10px; }
.primary { width: 100%; padding: 12px; border: 0; border-radius: 12px; background: var(--accent);
  color: var(--accent-text); font-weight: 600; cursor: pointer; }

/* чат */
.topbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); }
#view-title { flex: 1; margin: 0; font-size: 18px; }
select { padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); width: 100%; min-width: 0; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 8px 12px; cursor: pointer; white-space: nowrap; }
.icon { border: 0; background: none; font-size: 20px; padding: 6px 8px; cursor: pointer; line-height: 1; }
.menu { position: absolute; right: 12px; top: 58px; z-index: 5; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 6px; min-width: 240px; box-shadow: 0 8px 30px rgba(0,0,0,.18); display: flex; flex-direction: column; }
.menu-head { padding: 8px 10px; display: flex; flex-direction: column; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button, .menu a { text-align: left; border: 0; background: none; padding: 10px; border-radius: 10px; cursor: pointer;
  text-decoration: none; color: inherit; }
.menu button:hover, .menu a:hover { background: var(--bg); }
#messages { flex: 1; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; text-align: center; max-width: 320px; }
.msg { max-width: min(760px, 88%); padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.error { align-self: center; background: none; color: var(--error); font-size: 14px; text-align: center; }
.msg img { max-width: 220px; border-radius: 10px; display: block; margin-bottom: 6px; }
.msg pre { background: var(--bg); padding: 10px; border-radius: 10px; overflow-x: auto; white-space: pre; }
.msg code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.typing::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
#composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom)); }
#composer .row { display: flex; gap: 6px; align-items: flex-end; }
#input { flex: 1; resize: none; max-height: 40vh; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); }
.send { border: 0; background: var(--accent); color: var(--accent-text); width: 42px; height: 42px; border-radius: 50%;
  font-size: 18px; cursor: pointer; flex: none; }
.send:disabled { opacity: .5; cursor: default; }
.attachment { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.attachment img { height: 56px; border-radius: 8px; }

/* разделы и вкладки */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view.scroll { overflow-y: auto; padding: 12px; gap: 10px; }
.bar { padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; border: 0; background: none; padding: 7px 0 6px; display: flex; flex-direction: column; align-items: center;
  font-size: 19px; color: var(--muted); cursor: pointer; }
.tabs button span { font-size: 11px; margin-top: 2px; }
.tabs button.active { color: var(--accent); }
#view-chat #composer { border-top: 1px solid var(--line); }
.small { font-size: 14px; margin: 0; }
.center { text-align: center; }
.section { margin: 8px 0 0; font-size: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.field select { color: var(--text); font-size: 16px; }
#gen-prompt { width: 100%; resize: vertical; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.row.wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button, .opt { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.chips button.on, .opt.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.setting { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.setting > span { font-size: 14px; color: var(--muted); }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.toggle input { margin: 0; }
label.chip { font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: start; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column;
  text-decoration: none; color: inherit; }
.tile .media { aspect-ratio: 9 / 16; background: var(--bg); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.tile.square .media { aspect-ratio: 1; }
.tile .media img, .tile .media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .info { padding: 8px 10px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.tile .info b { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.72); color: #fff; border-radius: 8px; padding: 3px 8px; font-size: 13px; font-weight: 600; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.idea { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 10px; }
.idea h4 { margin: 0 0 6px; font-size: 17px; }
.idea p { margin: 6px 0; font-size: 15px; }
.idea .refs { font-size: 14px; color: var(--muted); }
.idea .refs a { color: var(--accent); font-weight: 600; }
.idea .primary { margin-top: 8px; }
.helper { border: 1px solid var(--accent); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px;
  background: color-mix(in srgb, var(--accent) 8%, var(--panel)); font-size: 15px; }
.helper p, .helper ul { margin: 0; }
.helper ul { padding-left: 18px; }
.helper code { display: block; white-space: pre-wrap; background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.helper .actions { display: flex; flex-direction: column; gap: 6px; }
.secondary { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); cursor: pointer; }
button.chip { font-size: 14px; }
.secondary-link { display: inline-block; margin: 6px 0 4px; font-size: 14px; color: var(--accent); text-decoration: none; }
