/* AI Hub — тёплая нейтральная тема, светлая и тёмная (prefers-color-scheme) */
:root {
    --bg: #faf9f5; --surface: #ffffff; --surface-2: #f3f1ea; --ink: #1f1e1d; --muted: #6b6963; --line: #e6e3d8;
    --accent: #c96442; --accent-hover: #b4563a; --accent-ink: #ffffff; --accent-soft: #f6e6df;
    --danger: #b3261e; --danger-soft: #fbe9e7; --ok: #2e7d4f; --ok-soft: #e4f3ea; --warn: #8a5a00; --warn-soft: #fcf0d6;
    --radius: 12px; --shadow: 0 1px 2px rgba(31, 30, 29, .06), 0 4px 16px rgba(31, 30, 29, .05);
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1f1e1d; --surface: #2a2927; --surface-2: #33312f; --ink: #f0eee6; --muted: #a5a29a; --line: #3d3b37;
        --accent: #d97757; --accent-hover: #e88d6f; --accent-ink: #1f1e1d; --accent-soft: #3d2c25;
        --danger: #f2877e; --danger-soft: #3d2523; --ok: #7bcf9c; --ok-soft: #1f3328; --warn: #e6b455; --warn-soft: #3a2f17;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
code, pre { font-family: var(--mono); font-size: .9em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* кнопки */
.btn { display: inline-flex; align-items: center; gap: .4em; padding: .5em .95em; border-radius: 9px; border: 1px solid var(--line);
    background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); } .btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .25em .6em; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.inline-form { display: inline; margin: 0; }

/* формы */
label { display: block; font-weight: 500; margin-bottom: .3em; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=date], select, textarea {
    width: 100%; padding: .55em .75em; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); font: inherit; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field { margin-bottom: 1.1rem; }
.field .hint { color: var(--muted); font-size: .85rem; margin-top: .3em; }
.check { display: flex; align-items: center; gap: .55em; font-weight: 500; }
.check input { width: 1.05em; height: 1.05em; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1.25rem; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: 1.25rem; }

/* карточки, таблицы, бейджи */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat b { display: block; font: 600 1.8rem/1.1 var(--serif); }
.stat span { color: var(--muted); font-size: .85rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6em .7em; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: .1em .55em; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge-ok { background: var(--ok-soft); color: var(--ok); } .badge-off { background: var(--surface-2); color: var(--muted); }
.badge-err { background: var(--danger-soft); color: var(--danger); } .badge-accent { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.alert-warn, .alert-info { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.code-block { position: relative; background: #1f1e1d; color: #f0eee6; border-radius: 10px; padding: .9rem 1rem; overflow-x: auto; margin: .6rem 0 1rem; }
.code-block pre { margin: 0; white-space: pre-wrap; word-break: break-all; }
.pager { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: center; margin-top: 1rem; }
.pager a, .pager span { padding: .3em .7em; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); }
.pager .current { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* оболочка админки */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 1.1rem .8rem; display: flex; flex-direction: column; gap: .15rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font: 600 1.25rem var(--serif); padding: .2rem .6rem 1rem; color: var(--ink); display: flex; align-items: center; gap: .5rem; }
.brand i { width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--accent); display: inline-block; }
.brand:hover { text-decoration: none; }
.nav a { display: block; padding: .5em .7em; border-radius: 8px; color: var(--ink); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .9rem .7rem .3rem; }
.sidebar-foot { margin-top: auto; padding: .8rem .6rem 0; border-top: 1px solid var(--line); font-size: .85rem; }
.main { padding: 1.75rem 2rem 3rem; min-width: 0; max-width: 1180px; width: 100%; }
.menu-toggle { display: none; }

/* публичные страницы */
.public { max-width: 1040px; margin: 0 auto; padding: 0 1.25rem; }
.public-head { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 0; }
.hero { padding: 4.5rem 0 3rem; text-align: center; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); max-width: 18ch; margin: 0 auto .5em; }
.hero p { font-size: 1.15rem; color: var(--muted); max-width: 56ch; margin: 0 auto 1.6rem; }
.features { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); padding-bottom: 3rem; }
.features .card { margin: 0; }
.public-foot { border-top: 1px solid var(--line); padding: 1.5rem 0; color: var(--muted); font-size: .85rem; text-align: center; }
.auth-box { max-width: 400px; margin: 5rem auto; }

/* чат */
.chat-shell { display: grid; grid-template-columns: 260px 1fr; gap: 0; height: calc(100vh - 3.5rem); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.chat-list { border-right: 1px solid var(--line); overflow-y: auto; padding: .7rem; background: var(--surface-2); }
.chat-list form { margin-bottom: .6rem; }
.chat-list a { display: block; padding: .5em .65em; border-radius: 8px; color: var(--ink); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list a:hover { background: var(--surface); text-decoration: none; }
.chat-list a.is-active { background: var(--accent-soft); font-weight: 600; }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-bar { display: flex; gap: .6rem; align-items: center; padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
.chat-bar h2 { margin: 0; font-size: 1rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-bar select { width: auto; max-width: 260px; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 1.25rem 1rem; scroll-behavior: smooth; }
.msg { max-width: 760px; margin: 0 auto 1.25rem; display: flex; flex-direction: column; }
.msg-user { align-items: flex-end; }
.msg-user .bubble { background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px 16px 4px 16px; padding: .65em .95em; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg-assistant .bubble { padding: 0 .2rem; width: 100%; word-wrap: break-word; }
.msg-meta { font-size: .75rem; color: var(--muted); margin-top: .25rem; }
.md { line-height: 1.65; } .md p { margin: 0 0 .85em; } .md h1, .md h2, .md h3 { font-size: 1.1rem; margin: 1.1em 0 .4em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 .85em; } .md a { text-decoration: underline; }
.md blockquote { margin: 0 0 .85em; padding-left: .9em; border-left: 3px solid var(--line); color: var(--muted); }
.md .code-block .copy { position: absolute; top: .4rem; right: .5rem; font-size: .75rem; background: #3a3936; color: #f0eee6; border: 0; border-radius: 6px; padding: .2em .6em; cursor: pointer; }
.md .code-block .lang { position: absolute; top: .45rem; left: .8rem; font-size: .7rem; color: #a5a29a; }
.md .code-block pre { margin-top: 1rem; white-space: pre; word-break: normal; }
.composer { padding: .8rem 1rem 1rem; border-top: 1px solid var(--line); }
.composer-inner { max-width: 760px; margin: 0 auto; display: flex; gap: .6rem; align-items: flex-end; }
.composer textarea { min-height: 48px; max-height: 220px; flex: 1; }
.typing { display: inline-flex; gap: 4px; padding: .5rem 0; } .typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
.msg-error { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: .6rem .8rem; }
.chat-empty { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); padding: 2rem; }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .6; } .chat-scroll { scroll-behavior: auto; } }

@media (max-width: 860px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
    .sidebar.open { transform: none; box-shadow: var(--shadow); }
    .menu-toggle { display: inline-flex; margin-bottom: 1rem; }
    .main { padding: 1.1rem 1rem 2.5rem; }
    .chat-shell { grid-template-columns: 1fr; height: calc(100vh - 6rem); } .chat-list { display: none; }
}
