/* publicwww.ai (TASK-628): цвета и шрифт - как у publicwww.com (style.8.css), светлая и
 * тёмная тема: data-theme на <html>, без него - как у системы. Раскладка чата: слева
 * сессии, справа диалог; до первого вопроса - стартовая страница посередине. */
:root {
	--brand: #1a6fd4; --brand-hover: #1559ab; --page: #f4f6f9; --surface: #ffffff; --border: #e2e6ec;
	--text: #1f2933; --muted: #6b7784; --code: #0b4fa2; --user: #e8f0fb; --err: #b42318; --warn-bg: #fff3bf;
	--side-w: 272px; --top-h: 52px;
	color-scheme: light;
}
:root[data-theme="dark"] {
	--brand: #6ea8fe; --brand-hover: #8fbcff; --page: #11161d; --surface: #1a212b; --border: #2b3542;
	--text: #dfe6ef; --muted: #93a1b1; --code: #86b7ff; --user: #1f2d40; --err: #ff8a80; --warn-bg: #4a3f14;
	color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--brand: #6ea8fe; --brand-hover: #8fbcff; --page: #11161d; --surface: #1a212b; --border: #2b3542;
		--text: #dfe6ef; --muted: #93a1b1; --code: #86b7ff; --user: #1f2d40; --err: #ff8a80; --warn-bg: #4a3f14;
		color-scheme: dark;
	}
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
	background: var(--page); color: var(--text);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
	font-size: 16px; line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); text-decoration: underline; }
code { color: var(--code); font-family: SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; overflow-wrap: anywhere; }
button { font: inherit; color: inherit; }
.ai-muted { color: var(--muted); }
.ai-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- шапка */
.ai-top {
	position: sticky; top: 0; z-index: 20; height: var(--top-h);
	display: flex; align-items: center; gap: 12px; padding: 0 16px;
	background: var(--surface); border-bottom: 1px solid var(--border);
}
.ai-brand { font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: .01em; }
.ai-brand span { color: var(--brand); }
.ai-brand:hover { text-decoration: none; color: var(--text); }
.ai-based { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-top-gap { flex: 1; }
.ai-icon-btn { display: none; border: 0; background: none; padding: 6px; border-radius: 8px; cursor: pointer; }
.ai-icon-btn:hover { background: var(--page); }
.ai-lang { position: relative; }
.ai-lang summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; font-size: .9rem; }
.ai-lang summary::-webkit-details-marker { display: none; }
.ai-lang summary:hover { background: var(--page); }
.ai-lang-list {
	position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 180px; padding: 6px;
	background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
	display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
}
.ai-lang-list a { padding: 5px 8px; border-radius: 6px; color: var(--text); font-size: .9rem; white-space: nowrap; }
.ai-lang-list a:hover, .ai-lang-list a.ai-on { background: var(--page); text-decoration: none; }
.ai-lang-list a.ai-on { font-weight: 700; }
.ai-theme { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.ai-theme button { border: 0; background: none; padding: 5px 8px; cursor: pointer; color: var(--muted); display: flex; }
.ai-theme button.ai-on { background: var(--brand); color: #fff; }

/* ---- раскладка чата */
.ai-chat-page { overflow: hidden; }
.ai-app { display: grid; grid-template-columns: var(--side-w) 1fr; height: calc(100vh - var(--top-h)); height: calc(100dvh - var(--top-h)); }
.ai-side { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); padding: 12px; }
.ai-new {
	display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 12px; cursor: pointer;
	border: 1px solid var(--border); border-radius: 10px; background: var(--page); font-weight: 600;
}
.ai-new:hover { border-color: var(--brand); color: var(--brand); }
.ai-sessions { flex: 1; overflow-y: auto; margin: 12px -4px 8px; padding: 0 4px; }
.ai-group { color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin: 12px 8px 4px; }
.ai-sess { display: flex; align-items: center; border-radius: 8px; }
.ai-sess:hover, .ai-sess.ai-on { background: var(--page); }
.ai-sess.ai-on .ai-sess-open { font-weight: 600; }
.ai-sess-open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 7px 8px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .92rem; }
.ai-sess-act { border: 0; background: none; padding: 5px; cursor: pointer; color: var(--muted); display: none; border-radius: 6px; }
.ai-sess:hover .ai-sess-act, .ai-sess.ai-on .ai-sess-act { display: flex; }
.ai-sess-act:hover { color: var(--text); background: var(--surface); }
.ai-side-foot { color: var(--muted); font-size: .8rem; border-top: 1px solid var(--border); padding-top: 8px; }
.ai-side-foot p { margin: 4px 0; }
.ai-scrim { display: none; }

.ai-main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 0 16px 12px; }
.ai-log { flex: 1; overflow-y: auto; padding: 16px 0; display: none; }
.ai-start { display: none; }
.ai-examples { display: none; }
.ai-form, .ai-log > *, .ai-note, .ai-start, .ai-examples { width: 100%; max-width: 820px; margin-left: auto; margin-right: auto; }

/* до первого вопроса - всё посередине, как у chatgpt.com */
.ai-app:not(.ai-started) .ai-main { overflow-y: auto; }
/* посередине через auto-поля: при нехватке высоты верх не обрезается (justify-content: center обрезал бы) */
.ai-app:not(.ai-started) .ai-start { display: block; text-align: center; margin-top: auto; margin-bottom: 18px; padding-top: 16px; }
.ai-app:not(.ai-started) .ai-note { margin-bottom: auto; }
.ai-app:not(.ai-started) .ai-examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.ai-start h1 { font-size: 1.9rem; margin: 0 0 8px; letter-spacing: -.01em; }
.ai-start p { margin: 0 auto; max-width: 620px; }
.ai-app.ai-started .ai-log { display: block; }

.ai-example {
	border: 1px solid var(--border); background: var(--surface); border-radius: 18px; padding: 7px 14px; cursor: pointer;
	font-size: .9rem; text-align: left; max-width: 100%;
}
.ai-example:hover { border-color: var(--brand); color: var(--brand); }

.ai-form { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); padding: 10px 10px 8px 14px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.ai-form:focus-within { border-color: var(--brand); }
.ai-form textarea {
	width: 100%; border: 0; outline: none; resize: none; background: none; color: var(--text);
	font: inherit; line-height: 1.45; min-height: 44px; max-height: 220px; padding: 2px 0;
}
.ai-form-bar { display: flex; align-items: center; gap: 8px; }
.ai-model select {
	border: 1px solid var(--border); border-radius: 8px; background: var(--page); color: var(--text);
	font: inherit; font-size: .85rem; padding: 4px 8px; max-width: 220px;
}
.ai-count { margin-left: auto; font-size: .8rem; }
.ai-btn { margin-left: auto; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.ai-count:not([hidden]) + .ai-btn, .ai-count:not([hidden]) ~ .ai-btn { margin-left: 0; }
.ai-send { background: var(--brand); color: #fff; }
.ai-send:hover { background: var(--brand-hover); }
.ai-stop { background: var(--text); color: var(--surface); }
.ai-note { font-size: .8rem; margin-top: 8px; text-align: center; }
.ai-warn { background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; }

/* ---- сообщения */
.ai-msg { margin: 0 auto 18px; }
.ai-user { display: flex; justify-content: flex-end; }
.ai-user .ai-body { background: var(--user); border-radius: 14px; padding: 9px 14px; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-who { font-weight: 700; font-size: .85rem; color: var(--brand); margin-bottom: 4px; }
.ai-text p { margin: 0 0 10px; }
.ai-text ul, .ai-text ol { margin: 0 0 10px; padding-left: 22px; }
.ai-err { color: var(--err); }
.ai-pre { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; overflow-x: auto; margin: 0 0 10px; }
.ai-pre code { overflow-wrap: normal; white-space: pre; }
.ai-steps { margin-bottom: 6px; }
.ai-step { color: var(--muted); font-size: .85rem; padding-left: 18px; position: relative; overflow-wrap: anywhere; }
.ai-step::before { content: "✓"; position: absolute; left: 0; color: var(--brand); }
.ai-step-run::before { content: "•"; animation: ai-blink 1s infinite; }
@keyframes ai-blink { 50% { opacity: .2; } }
.ai-card { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 10px 12px; margin: 8px 0; }
.ai-card-error { color: var(--err); }
.ai-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; overflow-wrap: anywhere; }
.ai-open { margin-left: auto; }
.ai-chip { display: inline-block; border: 1px solid var(--border); border-radius: 8px; background: var(--page); padding: 3px 10px; font-size: .82rem; cursor: pointer; color: var(--text); }
.ai-chip:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.ai-card-bar { margin-top: 8px; }
.ai-table-wrap { max-height: 360px; overflow: auto; border-radius: 6px; }
.ai-table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.ai-table th, .ai-table td { border-bottom: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; white-space: pre-line; }
.ai-table th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 600; }
.ai-typing { display: flex; gap: 4px; padding: 6px 0; }
.ai-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: ai-dot 1.2s infinite; }
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes ai-dot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---- страницы-тексты */
.ai-doc { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }
.ai-doc h1 { font-size: 1.8rem; margin-top: 8px; }
.ai-doc h2 { font-size: 1.2rem; margin-top: 26px; }
.ai-doc-back { margin-top: 32px; }

/* ---- узкий экран: сессии - шторкой слева */
@media (max-width: 860px) {
	.ai-icon-btn { display: flex; }
	.ai-based { display: none; }
	.ai-app { grid-template-columns: 1fr; }
	.ai-side { position: fixed; z-index: 40; top: var(--top-h); bottom: 0; left: 0; width: min(86vw, var(--side-w)); transform: translateX(-100%); transition: transform .2s; }
	.ai-app.ai-side-open .ai-side { transform: none; }
	.ai-scrim { display: block; position: fixed; z-index: 35; inset: var(--top-h) 0 0 0; background: rgba(0,0,0,.35); }
	.ai-scrim[hidden] { display: none; }
	.ai-start h1 { font-size: 1.45rem; }
	/* на телефоне - три примера, иначе поле ввода уезжает из вида */
	.ai-example:nth-child(n+4) { display: none; }
	.ai-example { font-size: .85rem; }
	.ai-user .ai-body { max-width: 92%; }
	.ai-main { padding: 0 12px 10px; }
}
