:root {
  --bg: #0a0a0a;
  --panel: #141414;
  --panel-2: #1c1c1c;
  --border: #2a2a2a;
  --text: #f4f4f4;
  --muted: #888;
  --accent: #ED1B24;
  --accent-2: #ff3b42;
  --accent-dark: #b8141a;
  --user: #2a1416;
  --assistant: #181818;
  --gold: #d4a946;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-display: "Bebas Neue", "Inter", -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-columns: 280px 1fr;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 56px; height: 40px;
  background: url("/static/img/spartak-crest.svg") center/contain no-repeat;
}
.brand-mark > span { display: none; }
.brand-name { font-weight: 800; font-family: var(--font-display); font-size: 22px; letter-spacing: 0.06em; line-height: 1; }
.brand-sub { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; letter-spacing: 0; font-family: var(--font); }

.new-chat {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}
.new-chat:hover { background: var(--panel-2); }

.picker label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.picker select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
}

.hint {
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.hint code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.log {
  flex: 1;
  overflow-y: auto;
  padding: 28px 0 12px;
}

.empty {
  max-width: 880px;
  margin: 4vh auto 40px;
  text-align: center;
  padding: 0 24px;
}
.empty h1 {
  font-family: var(--font-display);
  font-size: 38px;
  color: var(--text);
  margin: 0 0 8px;
  letter-spacing: 0.02em;
}
.empty-sub {
  color: var(--muted);
  max-width: 560px;
  margin: 0 auto 28px;
  line-height: 1.55;
}
.empty-emblem {
  width: 180px; height: 130px;
  background: url("/static/img/spartak-crest.svg") center/contain no-repeat;
  margin: 0 auto 18px;
  filter: drop-shadow(0 10px 24px rgba(237,28,36,0.35));
}
.empty-emblem > span { display: none; }

.templates {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 0 auto 24px;
  text-align: left;
}
.tpl {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: all 0.15s;
  text-align: left;
}
.tpl:hover {
  border-color: var(--accent);
  background: var(--panel-2);
  transform: translateY(-2px);
}
.tpl-emoji { font-size: 26px; margin-bottom: 6px; }
.tpl-title { font-weight: 700; margin-bottom: 4px; color: var(--text); }
.tpl-desc { font-size: 12px; color: var(--muted); line-height: 1.45; }

.empty-explain {
  margin-top: 16px;
  text-align: left;
}
.empty-explain details {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.empty-explain summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}
.empty-explain summary::-webkit-details-marker { display: none; }
.empty-explain summary::before { content: "▸ "; }
.empty-explain details[open] summary::before { content: "▾ "; }
.explain-body { padding-top: 10px; color: var(--muted); }
.explain-body p { margin: 8px 0; }
.explain-body ul { margin: 8px 0; padding-left: 0; list-style: none; }
.explain-body ul li { margin: 6px 0; }
.explain-body b { color: var(--text); }

@media (max-width: 900px) {
  .templates { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .templates { grid-template-columns: 1fr; }
}

/* подсказки рядом с лейблом */
.help-icon {
  display: inline-grid;
  place-items: center;
  width: 14px; height: 14px;
  background: var(--border);
  border-radius: 50%;
  font-size: 10px;
  color: var(--muted);
  margin-left: 4px;
  cursor: help;
}
.picker-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}
.help-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  padding: 8px 0;
}
.help-link:hover { text-decoration: underline; }

.kag-card {
  margin-top: 8px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #1f0608, #141414);
  border: 1px solid var(--accent);
  border-radius: 10px;
}
.kag-link { text-decoration: none; color: var(--text); display: block; }
.kag-link:hover { color: var(--accent); }
.kag-title { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.kag-sub { font-size: 11px; color: var(--muted); line-height: 1.4; }
.kag-creds {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.kag-creds summary { cursor: pointer; outline: none; }
.kag-creds summary:hover { color: var(--text); }
.kag-creds div { padding: 3px 0; }
.kag-creds code {
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: #fff;
  user-select: all;
}

/* modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: grid;
  place-items: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 640px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}
.modal-card h2 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0 0 16px;
  letter-spacing: 0.02em;
}
.modal-card h3 {
  font-size: 15px;
  margin: 24px 0 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 50%;
}
.modal-close:hover { background: var(--panel-2); color: var(--text); }
.howto, .model-help, .examples {
  padding-left: 20px;
  color: var(--text);
  line-height: 1.65;
}
.howto li, .model-help li { margin: 8px 0; }
.examples li {
  margin: 10px 0;
  color: var(--muted);
  font-style: italic;
}

.msg {
  max-width: 760px;
  margin: 0 auto 18px;
  padding: 14px 18px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user {
  background: var(--user);
  border: 1px solid #4a2024;
}
.msg.assistant {
  background: var(--assistant);
  border: 1px solid var(--border);
}
.msg.error {
  background: #3a1d22;
  border: 1px solid #6b2c33;
  color: #ffb4b8;
}
.msg .role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.msg .body .text { white-space: pre-wrap; }
.msg .body .text + .diagram,
.msg .body .diagram + .text,
.msg .body .diagram + .diagram { margin-top: 12px; }

.diagram {
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 12px;
  overflow: auto;
}
.diagram-bpmn { height: 460px; padding: 0; }
.diagram-bpmn .bjs-container { background: #fff; }
.diagram-mermaid svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.diagram-warn {
  background: #3a2a08;
  color: #ffd47a;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 8px;
}
.diagram-error {
  background: #3a1d22;
  color: #ffb4b8;
  padding: 10px 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  margin: 0 0 8px;
}
.diagram-source {
  background: #0e0f12;
  color: #cbd1de;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  overflow: auto;
}

.empty-hint {
  margin-top: 16px;
  font-size: 13px;
  opacity: 0.7;
}

.wizard-open-btn {
  display: block;
  width: 100%;
  max-width: 720px;
  margin: 0 auto 20px;
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  border: none;
  border-radius: 12px;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 8px 24px rgba(237,27,36,0.25);
  transition: all 0.15s;
}
.wizard-open-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(237,27,36,0.4);
}

/* --- me block --- */
.me-block {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.me-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.me-name { font-weight: 600; font-size: 14px; }
.me-role { font-size: 11px; }
.muted { color: var(--muted); }

.ghost-mini {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.ghost-mini:hover { background: var(--bg); }

.usage { font-size: 12px; }
.usage-line {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.bar {
  height: 6px;
  background: #2a2e38;
  border-radius: 3px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}

.admin-link {
  display: inline-block;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  padding-top: 4px;
}
.admin-link:hover { text-decoration: underline; }

.logout-btn {
  margin-top: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  transition: all 0.15s;
}
.logout-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.usage-tag {
  font-size: 11px;
  color: var(--muted);
  padding: 4px 18px 0;
  max-width: 760px;
  margin: -10px auto 18px;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

/* --- login page --- */
.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  grid-template-columns: none !important;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
}
.user-btn:hover { border-color: var(--accent); }
.user-name { font-weight: 600; }
.user-role {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* --- admin page --- */
.admin-body {
  display: block;
  grid-template-columns: none;
  min-height: 100vh;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar .brand { text-decoration: none; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.ghost:hover { background: var(--panel-2); }

.admin-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px;
}
.admin-main h1 { margin: 0 0 6px; }
.table-wrap { margin-top: 24px; overflow-x: auto; }
.team-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.team-table th, .team-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.team-table th {
  background: var(--panel-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.team-table tr:last-child td { border-bottom: none; }
.team-table .bar { width: 140px; margin-top: 6px; }
.limit-input {
  width: 110px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
}
.save-btn {
  background: var(--accent);
  color: #0e0f12;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.save-btn:hover { filter: brightness(1.1); }

.ghost-sm {
  padding: 4px 10px;
  font-size: 13px;
}

.models-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin: 16px 0 20px;
  max-height: 360px;
  overflow-y: auto;
}
.model-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.1s;
}
.model-check:has(input:checked) {
  border-color: var(--accent);
}
.model-check input { cursor: pointer; accent-color: var(--accent); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.section-title {
  margin: 48px 0 4px;
  font-family: var(--font-display);
  font-size: 28px;
  letter-spacing: 0.04em;
}

.model-usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.usage-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.usage-card.empty { border-color: #4a2024; opacity: 0.7; }
.usage-name { font-weight: 700; margin-bottom: 12px; }
.usage-bar { margin-bottom: 10px; }
.usage-bar:last-child { margin-bottom: 0; }
.usage-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
}

.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-top: 16px;
}
.chart-meta {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 12px;
}
.chart-meta b { color: var(--text); }

.brand-voice-wrap {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.brand-voice-wrap textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
  resize: vertical;
}
.brand-voice-wrap textarea:focus { outline: none; border-color: var(--accent); }
.brand-voice-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 18px 20px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 200px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.composer button {
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.composer button:hover:not(:disabled) { background: var(--accent-dark); }

.attach-btn {
  background: var(--panel-2) !important;
  border: 1px solid var(--border) !important;
  color: var(--muted) !important;
  font-size: 18px !important;
  font-weight: 400 !important;
}
.attach-btn:hover:not(:disabled) {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--accent) !important;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
  padding: 8px 18px 0;
  width: 100%;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 6px 8px 6px 12px;
  font-size: 13px;
  max-width: 280px;
}
.attach-icon { font-size: 16px; }
.attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}
.attach-size { color: var(--muted); font-size: 11px; }
.attach-remove {
  background: transparent !important;
  border: none !important;
  color: var(--muted) !important;
  width: 22px !important;
  height: 22px !important;
  border-radius: 50% !important;
  font-size: 16px !important;
  font-weight: 400 !important;
  padding: 0 !important;
  cursor: pointer;
  display: grid !important;
  place-items: center;
}
.attach-remove:hover {
  background: var(--bg) !important;
  color: var(--accent) !important;
}

main.chat.drop-hover {
  outline: 2px dashed var(--accent);
  outline-offset: -16px;
  background: rgba(237,27,36,0.04);
}
.composer button:disabled { opacity: 0.4; cursor: not-allowed; }

@media (max-width: 720px) {
  body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
