/* ИИ-помощник УК — чистые тона. Фирменный цвет меняется в одной строке: --brand */
:root {
  --brand: #1d5c8a;          /* глубокий синий — основной */
  --brand-dark: #154467;
  --brand-soft: #e7f0f7;
  --ink: #1b2430;
  --ink-2: #4a5665;
  --ink-3: #7b8794;
  --line: #e1e6ec;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ext: #b45309;  --ext-bg: #fff4e5;  --ext-line: #f3d9b1;   /* внешний контур — янтарный */
  --dom: #1b7f4b;  --dom-bg: #eaf7ef;  --dom-line: #bfe5cd;   /* российский контур — зелёный */
  --danger: #b42318; --danger-bg: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 6px 20px -8px rgba(16,24,40,.12);
  --font: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--ink-3); } .small { font-size: 13px; }
.hidden { display: none !important; }

/* --- кнопки --- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-weight: 500; transition: .15s; }
.btn:hover { border-color: #c9d2dc; background: #fafbfc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--brand-soft); color: var(--brand); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { width: 18px; height: 18px; flex: none; }

/* --- формы --- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  outline: none; transition: .15s; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29,92,138,.15); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

/* --- бейджи контуров --- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.external { color: var(--ext); background: var(--ext-bg); }
.badge.domestic { color: var(--dom); background: var(--dom-bg); }
.badge.gray { color: var(--ink-3); background: #eef1f4; }
.badge.gray::before { display: none; }

/* ======================= вход ======================= */
.auth { min-height: 100%; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side { background: linear-gradient(160deg, var(--brand-dark) 0%, var(--brand) 55%, #2f7fb3 100%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side .org { font-size: 13px; letter-spacing: .14em; text-transform: uppercase; opacity: .8; }
.auth-side h1 { font-size: 40px; margin-top: 16px; font-weight: 700; max-width: 14em; }
.auth-side p { max-width: 36em; opacity: .9; font-size: 16px; }
.auth-side ul { padding: 0; margin: 24px 0 0; list-style: none; display: grid; gap: 12px; max-width: 34em; }
.auth-side li { display: flex; gap: 12px; align-items: flex-start; opacity: .95; }
.auth-side li .icon { margin-top: 3px; opacity: .9; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 32px; }
.auth-card h2 { font-size: 22px; margin-bottom: 4px; }
.auth-card .error { background: var(--danger-bg); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.auth-footer { margin-top: 22px; font-size: 12px; color: var(--ink-3); line-height: 1.5; }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth-side { padding: 32px 24px; } .auth-side h1 { font-size: 28px; } }

/* ======================= приложение ======================= */
.app { display: grid; grid-template-columns: 290px 1fr; height: 100vh; }
.side { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.brand { display: flex; align-items: center; gap: 12px; padding: 18px 18px 14px; }
.brand .mark { width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px; letter-spacing: .02em; flex: none; }
.brand .t1 { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand .t2 { font-size: 12px; color: var(--ink-3); }
.side-actions { padding: 0 14px 10px; }
.chat-list { flex: 1; overflow: auto; padding: 4px 10px; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px; cursor: pointer; color: var(--ink-2); font-size: 14px; }
.chat-item:hover { background: #f1f4f7; }
.chat-item.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 500; }
.chat-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del { opacity: 0; border: 0; background: none; color: var(--ink-3); padding: 2px; border-radius: 6px; }
.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { color: var(--danger); background: var(--danger-bg); }
.side-user { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.side-user .name { font-weight: 600; font-size: 14px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .role { font-size: 12px; color: var(--ink-3); }
.side-user form { margin-left: auto; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.model-select { display: flex; align-items: center; gap: 10px; }
.model-select select { padding: 8px 32px 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 500; max-width: 340px; }
.quota { margin-left: auto; font-size: 13px; color: var(--ink-3); }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 20px; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.notice.external { background: var(--ext-bg); border-color: var(--ext-line); color: #7a3e07; }
.notice.domestic { background: var(--dom-bg); border-color: var(--dom-line); color: #14532d; }
.notice .icon { margin-top: 2px; flex: none; }
.notice b { font-weight: 700; }
.notice .more { margin-left: auto; white-space: nowrap; }

.messages { flex: 1; overflow: auto; padding: 24px 20px 12px; }
.thread { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 12px; }
.msg .who { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.msg.user .who { background: var(--brand-soft); color: var(--brand-dark); }
.msg.assistant .who { background: #e8ecf1; color: var(--ink-2); }
.msg .bubble { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; min-width: 0; max-width: 100%; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.msg.user .bubble { background: #fbfcfd; white-space: pre-wrap; }
.msg .meta { font-size: 12px; color: var(--ink-3); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.msg .meta .ent { color: var(--ext); }
.md p { margin: 0 0 .7em; } .md p:last-child { margin-bottom: 0; }
.md pre { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 10px; overflow: auto; font-size: 13px; }
.md code { background: #eef2f6; padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md pre code { background: none; padding: 0; }
.md ul, .md ol { padding-left: 1.4em; margin: .3em 0 .7em; }
.md h1, .md h2, .md h3 { margin-top: .8em; }
.md table { border-collapse: collapse; margin: .5em 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md blockquote { margin: .4em 0; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--ink-2); }
.reasoning { font-size: 13px; color: var(--ink-3); border-left: 3px solid var(--line); padding: 4px 10px; margin-bottom: 8px; white-space: pre-wrap; max-height: 160px; overflow: auto; }
.blocked { background: var(--danger-bg); color: var(--danger); border: 1px solid #f5c2c0; border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.blocked b { display: block; margin-bottom: 4px; }
.empty { text-align: center; color: var(--ink-3); padding: 60px 20px; }
.empty h2 { color: var(--ink); }
.empty .hints { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; max-width: 760px; margin: 22px auto 0; }
.hint { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.hint:hover { border-color: var(--brand); color: var(--ink); }

.composer { padding: 12px 20px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer-box { max-width: 860px; margin: 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 10px 12px 8px; }
.composer textarea { width: 100%; border: 0; resize: none; outline: none; padding: 6px 4px; max-height: 240px; min-height: 44px; background: transparent; line-height: 1.5; }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.composer-bar .hintline { font-size: 12px; color: var(--ink-3); flex: 1; }
.preview-box { max-width: 860px; margin: 0 auto 10px; background: #fff; border: 1px dashed var(--ext-line); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; }
.preview-box .head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; font-weight: 600; color: var(--ext); }
.preview-box pre { white-space: pre-wrap; margin: 0; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; color: var(--ink-2); }
.tok { background: var(--ext-bg); color: var(--ext); border-radius: 5px; padding: 0 4px; font-weight: 600; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: b 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes b { 0%, 80%, 100% { opacity: .3 } 40% { opacity: 1 } }

/* ======================= админка ======================= */
.admin { max-width: 1240px; margin: 0 auto; padding: 20px 20px 40px; }
.admin-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.admin-head h1 { margin: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 10px 14px; border: 0; background: none; color: var(--ink-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--brand); border-color: var(--brand); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 2px rgba(16,24,40,.03); }
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } .app { grid-template-columns: 1fr; } .side { display: none; } }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:hover td { background: #fafbfc; }
.tbl .actions { white-space: nowrap; text-align: right; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: 13px; color: var(--ink-3); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; }
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--card); border-radius: 16px; width: 100%; max-width: 560px; padding: 22px; box-shadow: 0 20px 60px -20px rgba(0,0,0,.4); max-height: 92vh; overflow: auto; }
.modal h2 { margin-bottom: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.models-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }
.bar-row { display: grid; grid-template-columns: 1fr 60px; gap: 10px; align-items: center; font-size: 13px; margin: 4px 0; }
.bar { height: 8px; background: #eef1f4; border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); }
.law { font-size: 13.5px; color: var(--ink-2); line-height: 1.55; }
.law li { margin-bottom: 6px; }
