:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --sidebar: #ffffff;
  --border: #e5e7f0;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --bubble-user: #e9eaf2;
  --bubble-ai: #ffffff;
  --danger: #e5484d;
  --ok: #2f9e44;
  --warn: #f08c00;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(30, 27, 75, .06), 0 6px 24px rgba(30, 27, 75, .05);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------- Кнопки ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent-grad);
  color: #fff;
  transition: transform .08s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn:hover { box-shadow: 0 6px 18px rgba(99, 102, 241, .35); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn.secondary { background: #eef0f8; color: var(--text); }
.btn.secondary:hover { background: #e3e6f4; box-shadow: none; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f0f1f8; color: var(--text); box-shadow: none; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { box-shadow: 0 6px 18px rgba(229, 72, 77, .35); }

/* ---------- Поля ввода ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }

.notice { font-size: 14px; padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }
.notice.error { background: #fdecec; color: var(--danger); }
.notice.ok { background: #e9f7ee; color: var(--ok); }
.notice.info { background: #eef0fb; color: var(--accent); }

/* ---------- Экран авторизации ---------- */
.auth-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(139,92,246,.18), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(99,102,241,.16), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 30px;
  border: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.brand .logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--accent-grad);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 20px;
}
.brand h1 { font-size: 19px; margin: 0; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 4px 0 22px; }
.tabs { display: flex; gap: 6px; background: #f0f1f8; padding: 4px; border-radius: 12px; margin-bottom: 20px; }
.tab { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); transition: all .15s; }
.tab.active { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--border); flex: 1; }
.google-btn {
  width: 100%; border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 10px; padding: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: background .15s;
}
.google-btn:hover { background: #f7f8fc; }
.hidden { display: none !important; }

/* ---------- Главный интерфейс чата (трёхзонная структура, Приложение А) ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }

/* Левая навигационная панель */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-width: 0;
}
.sidebar-head { padding: 16px; border-bottom: 1px solid var(--border); }
.sidebar-head .brand h1 { font-size: 16px; }
.new-chat {
  width: 100%; margin-top: 14px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.chat-list { flex: 1; overflow-y: auto; padding: 10px; }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  color: var(--text); font-size: 14px; margin-bottom: 3px;
  transition: background .12s ease;
  position: relative;
}
.chat-item:hover { background: #f3f4fb; }
.chat-item.active { background: var(--accent-grad); color: #fff; font-weight: 600; }
.chat-item .title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .del {
  opacity: 0; border: none; background: transparent; color: inherit;
  font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 6px; transition: opacity .12s;
}
.chat-item:hover .del { opacity: .7; }
.chat-item .del:hover { opacity: 1; background: rgba(0,0,0,.08); }
.chat-item.active .del:hover { background: rgba(255,255,255,.2); }

.profile {
  border-top: 1px solid var(--border); padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.avatar.user { background: #d7dae8; color: #424b66; }
.avatar.ai { background: #fff; border: 1px solid var(--border); color: var(--accent); }
.profile .meta { flex: 1; min-width: 0; }
.profile .meta .email { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile .meta .role { font-size: 11px; color: var(--muted); }
.icon-btn { border: none; background: transparent; color: var(--muted); border-radius: 8px; padding: 7px; transition: background .12s, color .12s; }
.icon-btn:hover { background: #f0f1f8; color: var(--text); }

/* Центральная область переписки */
.main { display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--bg); }
.messages { flex: 1; overflow-y: auto; padding: 28px clamp(16px, 6vw, 90px); scroll-behavior: smooth; }
.empty-state { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty-state .big { width: 64px; height: 64px; border-radius: 18px; background: var(--accent-grad); display: grid; place-items: center; color: #fff; font-size: 30px; margin: 0 auto 16px; }
.empty-state h2 { color: var(--text); margin: 0 0 6px; }

.msg { display: flex; gap: 12px; margin-bottom: 18px; max-width: 760px; animation: rise .18s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { margin-left: auto; flex-direction: row-reverse; }
.bubble { padding: 12px 16px; border-radius: 16px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--bubble-user); color: var(--text); border-bottom-right-radius: 5px; }
.msg.ai .bubble { background: var(--bubble-ai); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg .quote-ref { font-size: 12px; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 8px; margin-bottom: 6px; opacity: .85; }
.msg .quote-btn { align-self: flex-end; border: none; background: transparent; color: var(--muted); font-size: 12px; padding: 2px 6px; border-radius: 6px; opacity: 0; transition: opacity .12s; }
.msg:hover .quote-btn { opacity: .8; }
.msg .quote-btn:hover { background: #eef0fb; color: var(--accent); }

.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* Нижняя панель ввода */
.composer { padding: 14px clamp(16px, 6vw, 90px) 22px; }
.quote-chip {
  display: flex; align-items: center; gap: 10px; background: #eef0fb; color: var(--text);
  border-left: 3px solid var(--accent); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; font-size: 13px;
}
.quote-chip .txt { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.input-row { position: relative; display: flex; align-items: flex-end; }
.msg-input {
  width: 100%; border: 1px solid var(--border); border-radius: 22px; resize: none;
  padding: 14px 56px 14px 18px; font-size: 15px; line-height: 1.4; max-height: 180px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.msg-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.13); }
.send-btn {
  position: absolute; right: 8px; bottom: 8px;
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--accent-grad); color: #fff; font-size: 18px;
  display: grid; place-items: center; transition: transform .1s, opacity .15s;
}
.send-btn:hover { transform: scale(1.06); }
.send-btn:disabled { background: #c7cad9; cursor: not-allowed; transform: none; }
.hint { text-align: center; font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Кнопка поддержки «?» */
.support-fab {
  position: fixed; right: 20px; bottom: 20px;
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: #fff; border: 1px solid var(--border); color: var(--accent);
  font-size: 22px; font-weight: 700; box-shadow: var(--shadow);
  transition: transform .12s, background .12s;
}
.support-fab:hover { transform: translateY(-2px); background: #f7f8fc; }

/* Модальное окно */
.modal-overlay { position: fixed; inset: 0; background: rgba(20, 18, 40, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { width: 100%; max-width: 440px; background: #fff; border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 4px; }
.modal p.sub { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.modal textarea { width: 100%; min-height: 110px; border: 1px solid var(--border); border-radius: 12px; padding: 12px; font-size: 15px; resize: vertical; }
.modal textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.13); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2430; color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 100; animation: rise .2s ease;
}

/* ---------- Мобильная адаптация ---------- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 280px; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .mobile-bar { display: flex !important; }
}
.mobile-bar { display: none; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fff; }
.mobile-bar .burger { border: none; background: transparent; font-size: 22px; color: var(--text); }

/* ---------- Административная панель ---------- */
.admin-shell { display: flex; flex-direction: column; min-height: 100vh; }
.admin-top {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px clamp(16px, 5vw, 48px); display: flex; align-items: center; gap: 16px;
}
.admin-top .brand h1 { font-size: 17px; }
.admin-top .spacer { flex: 1; }
.admin-top .who { font-size: 13px; color: var(--muted); text-align: right; }
.admin-body { padding: 24px clamp(16px, 5vw, 48px) 60px; max-width: 1200px; width: 100%; margin: 0 auto; }

.admin-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 24px; }
.admin-tab {
  border: 1px solid var(--border); background: #fff; color: var(--muted);
  padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; transition: all .12s;
}
.admin-tab:hover { background: #f7f8fc; color: var(--text); }
.admin-tab.active { background: var(--accent-grad); color: #fff; border-color: transparent; }

.panel { display: none; }
.panel.active { display: block; animation: rise .18s ease; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.card .k { font-size: 13px; color: var(--muted); }
.card .v { font-size: 30px; font-weight: 800; margin-top: 6px; }
.card .v.warn { color: var(--warn); }

.section-title { font-size: 16px; font-weight: 700; margin: 0 0 14px; }
.chart { background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.bars { display: flex; align-items: flex-end; gap: 14px; height: 180px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; max-width: 46px; border-radius: 8px 8px 0 0; background: var(--accent-grad); min-height: 4px; transition: height .4s ease; position: relative; }
.bar .num { position: absolute; top: -20px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); }
.bar-label { font-size: 12px; color: var(--muted); }

.card-block { background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); }
table.data th { background: #fafbff; color: var(--muted); font-weight: 600; font-size: 13px; position: sticky; top: 0; }
table.data tr:last-child td { border-bottom: none; }
.table-scroll { max-height: 520px; overflow-y: auto; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.tag.ok { background: #e9f7ee; color: var(--ok); }
.tag.err { background: #fdecec; color: var(--danger); }
.tag.warn { background: #fff4e0; color: var(--warn); }
.tag.neutral { background: #eef0fb; color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 18px; }
.toolbar .field { margin: 0; }
.toolbar .input, .toolbar select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; background: #fff; }
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.health-item { background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; }
.dot { width: 14px; height: 14px; border-radius: 50%; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px rgba(47,158,68,.15); }
.dot.err { background: var(--danger); box-shadow: 0 0 0 4px rgba(229,72,77,.15); }
