/* Главная страница хаба. Светлая тема в стиле исходного Corp Hub (React + Tailwind).
   admin.html по-прежнему использует style.css. */
:root {
  --bg: #ffffff;
  --side: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --soft: #f3f4f6;
  --dark: #111827;
  --accent: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --side-w: 270px;
  font-family: Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- кнопки ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 999px; border: none; background: none;
  color: #374151; cursor: pointer; transition: background .15s; flex-shrink: 0;
}
.icon-btn:hover { background: var(--soft); }
.icon-btn.filled { background: var(--soft); }
.icon-btn.filled:hover { background: #e5e7eb; }
.btn-dark {
  background: var(--dark); color: #fff; border: none; border-radius: 999px;
  padding: 9px 20px; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn-dark:hover { background: #000; }
.btn-dark:disabled { opacity: .55; cursor: default; }
.btn-block { width: 100%; border-radius: 12px; padding: 12px; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 0; }
.link-btn:hover { color: var(--danger); }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; text-align: center; }

/* ---------- вход ---------- */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; background: var(--side); padding: 16px; }
.login-card { width: 100%; max-width: 420px; background: #fff; border-radius: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.08); padding: 32px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0 0 8px; font-size: 14px; }
.login-card input { padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border); font-size: 15px; outline: none; }
.login-card input:focus { border-color: var(--dark); box-shadow: 0 0 0 1px var(--dark); }

/* ---------- каркас ---------- */
.layout { display: flex; height: 100%; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }

/* история слева */
.sidebar {
  width: var(--side-w); flex-shrink: 0; background: var(--side); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100%;
}
.sidebar-head { padding: 14px 12px 8px; display: flex; gap: 6px; align-items: center; }
.new-chat {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border: 1px solid var(--border); background: #fff; border-radius: 12px; cursor: pointer; font-weight: 500; font-size: 14px;
}
.new-chat:hover { border-color: var(--border-strong); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.new-chat .ic { width: 18px; height: 18px; }
.sidebar-title { padding: 10px 16px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.history { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.history-group { padding: 10px 8px 4px; font-size: 12px; color: var(--muted); }
.history-item {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-radius: 10px; cursor: pointer;
  font-size: 14px; color: #374151;
}
.history-item:hover { background: #eef0f3; }
.history-item.active { background: #e5e7eb; color: var(--text); }
.history-item .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .del { visibility: hidden; border: none; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 6px; font-size: 13px; }
.history-item:hover .del { visibility: visible; }
.history-item .del:hover { color: var(--danger); background: #fff; }
.history-empty { padding: 8px 10px; font-size: 13px; color: var(--muted); }
.sidebar-foot { border-top: 1px solid var(--border); padding: 8px 16px; }

/* шапка */
.topbar { display: flex; align-items: center; gap: 8px; padding: 14px 20px; min-height: 68px; }
.topbar-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #374151; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
#sidebar-open { display: none; }
.profile-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 46px; background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,.08); min-width: 230px; padding: 6px; z-index: 40;
}
.dropdown a, .dropdown button {
  display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: 8px; border: none; background: none;
  color: var(--text); text-decoration: none; font-size: 14px; cursor: pointer;
}
.dropdown a:hover, .dropdown button:hover { background: var(--soft); }

/* ---------- центр ---------- */
.scroll { flex: 1; overflow-y: auto; padding: 0 16px; }
.hero {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 0 0 12vh;
}
.hero h1 { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 8px; }
.hero > p { margin: 0 0 28px; }
.frequent { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; width: 100%; max-width: 760px; margin-bottom: 28px; }
.tool-tile {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border: 1px solid var(--border);
  border-radius: 14px; color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500; transition: .15s;
}
.tool-tile:hover { border-color: var(--border-strong); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.tool-tile .ic { width: 22px; height: 22px; flex-shrink: 0; }
.composer-slot { width: 100%; max-width: 760px; }

/* поисковая строка (одна и та же форма: в центре, затем внизу) */
.composer { width: 100%; }
.composer-box {
  display: flex; align-items: flex-end; gap: 8px; background: #fff; border: 1px solid var(--border);
  border-radius: 28px; box-shadow: 0 4px 14px rgba(0,0,0,.07); padding: 8px 8px 8px 10px; transition: border-color .15s;
}
.composer-box:focus-within { border-color: var(--border-strong); }
.composer.dragging .composer-box { border-color: var(--accent); background: #eff6ff; }
.composer textarea {
  flex: 1; min-width: 0; border: none; outline: none; resize: none; background: transparent;
  font: inherit; font-size: 15px; line-height: 22px; padding: 9px 4px; max-height: 200px; color: var(--text); overflow-y: hidden;
}
.composer .attach { cursor: pointer; color: var(--muted); }
.composer .attach:hover { color: var(--text); }
.composer .send { align-self: flex-end; margin-bottom: 1px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; margin: 10px 0 0 14px; padding: 6px 12px; border-radius: 999px;
  background: var(--soft); font-size: 13px; color: #374151; max-width: calc(100% - 14px);
}
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: none; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; font-size: 14px; }
.chip button:hover { color: var(--danger); }
.chip.error { background: #fef2f2; color: var(--danger); }
.hint { font-size: 12px; margin-top: 8px; text-align: center; display: none; }

.bottom-slot { padding: 6px 16px 14px; }
.bottom-slot .composer { max-width: 820px; margin: 0 auto; }
.bottom-slot .hint { display: block; }

/* ---------- диалог ---------- */
.messages { max-width: 820px; margin: 0 auto; padding: 8px 0 24px; display: flex; flex-direction: column; gap: 22px; }
.msg-user { align-self: flex-end; max-width: 80%; background: var(--soft); padding: 11px 16px; border-radius: 20px 20px 6px 20px; white-space: pre-wrap; word-wrap: break-word; }
.msg-ai { display: flex; gap: 12px; align-items: flex-start; }
.ai-avatar {
  width: 30px; height: 30px; border-radius: 999px; background: var(--dark); color: #fff; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; margin-top: 2px;
}
.ai-body { flex: 1; min-width: 0; line-height: 1.6; color: #1f2937; }
.ai-body p { margin: 0 0 10px; }
.ai-body ul, .ai-body ol { margin: 0 0 10px; padding-left: 22px; }
.ai-body h3, .ai-body h4 { margin: 14px 0 6px; font-size: 16px; }
.ai-body code { background: var(--soft); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.ai-body .table-wrap { overflow-x: auto; margin: 0 0 10px; }
.ai-body table { border-collapse: collapse; font-size: 14px; }
.ai-body th, .ai-body td { border: 1px solid var(--border-strong); padding: 6px 10px; text-align: left; vertical-align: top; }
.ai-body th { background: var(--side); }
.tool-tag { display: inline-block; font-size: 11px; color: var(--muted); background: var(--soft); border-radius: 6px; padding: 2px 8px; margin-bottom: 8px; }
.thinking { display: flex; align-items: center; gap: 10px; color: var(--accent); font-size: 14px; padding-top: 4px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 999px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.msg-error { color: var(--danger); background: #fef2f2; padding: 8px 12px; border-radius: 10px; display: inline-block; }

.sources-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin: 14px 0 8px; }
.sources { display: flex; flex-wrap: wrap; gap: 8px; }
.source-card {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-size: 12px;
  background: #fff; border: 1px solid var(--border); color: #4b5563; box-shadow: 0 1px 2px rgba(0,0,0,.04); max-width: 100%;
}
.source-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-card.clickable { cursor: pointer; }
.source-card.clickable:hover { border-color: var(--accent); color: var(--text); }
.candidates { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.candidate-btn { text-align: left; padding: 9px 14px; border-radius: 12px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 14px; }
.candidate-btn:hover { border-color: var(--accent); }
.feedback { margin-top: 10px; display: flex; gap: 4px; }
.feedback button { border: 1px solid transparent; background: none; border-radius: 8px; padding: 3px 7px; cursor: pointer; color: var(--muted); font-size: 14px; }
.feedback button:hover { background: var(--soft); }
.feedback button.on-up { border-color: var(--ok); }
.feedback button.on-down { border-color: var(--danger); }

/* ---------- все сервисы (справа) ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.2); backdrop-filter: blur(2px); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 33%; min-width: 320px; max-width: 100%; background: #fff;
  border-left: 1px solid var(--border); z-index: 30; visibility: hidden;
  transform: translateX(100%); transition: transform .2s ease, visibility .2s;
}
.drawer.open { transform: translateX(0); visibility: visible; box-shadow: -10px 0 30px rgba(0,0,0,.08); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; font-size: 16px; }
.tools-grid { padding: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tool-card { display: block; border: 1px solid var(--border); border-radius: 14px; padding: 14px; text-decoration: none; color: var(--text); transition: .15s; }
.tool-card:hover { border-color: var(--border-strong); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.tool-card .ic { width: 20px; height: 20px; margin-bottom: 8px; }
.tool-card .n { font-size: 14px; font-weight: 500; }

/* превью страницы */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 16px; cursor: zoom-out; }
.modal img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; }
.modal .msg { color: #fff; }

.mobile-only { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 35; transform: translateX(-100%); transition: transform .2s ease, visibility .2s; visibility: hidden; }
  .sidebar.open { transform: translateX(0); visibility: visible; box-shadow: 10px 0 30px rgba(0,0,0,.08); }
  .mobile-only { display: inline-flex; }
  .backdrop.mobile-only { display: block; }
  .backdrop.mobile-only.hidden { display: none !important; }
  #sidebar-open { display: inline-flex; }
  .frequent { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero h1 { font-size: 24px; }
  .topbar { padding: 10px 12px; min-height: 60px; }
  .send { padding: 9px 14px; }
}
