:root {
  --bg: #0b0f1a; --panel: #121826; --panel2: #0f1420; --border: #223049;
  --text: #e8ecf5; --muted: #94a3b8; --accent: #4f7cff; --accent2: #22c55e;
  --danger: #ef4444; --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.5;
}
a { color: var(--accent); }
button {
  font: inherit; cursor: pointer; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; padding: 10px 16px; transition: filter .15s;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.danger { background: var(--danger); }
input, textarea, select {
  font: inherit; width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }

/* --- auth --- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 28px;
}
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-card .sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.msg { margin-top: 12px; font-size: 14px; min-height: 20px; }
.msg.err { color: var(--danger); }

/* --- app shell --- */
.shell { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.brand { padding: 18px 18px 12px; font-weight: 700; letter-spacing: .3px; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.nav { padding: 8px; flex: 1; }
.nav button { width: 100%; text-align: left; background: transparent; color: var(--muted); padding: 10px 12px; border-radius: 8px; }
.nav button.active { background: var(--panel2); color: var(--text); }
.side .foot { padding: 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.main { overflow: hidden; display: flex; flex-direction: column; }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }
.view h2 { margin: 0; padding: 18px 22px; border-bottom: 1px solid var(--border); font-size: 17px; }
.pad { padding: 22px; overflow: auto; }

/* --- chat --- */
.chat-log { flex: 1; overflow: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.bubble { max-width: 760px; padding: 12px 15px; border-radius: 12px; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--accent); }
.bubble.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); }
.chat-input { display: flex; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); }
.chat-input textarea { resize: none; height: 46px; max-height: 160px; }
.empty { color: var(--muted); text-align: center; margin: auto; }

/* --- lists --- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p { margin: 0; color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.row { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--panel2); border: 1px solid var(--border); color: var(--muted); }
.ok { color: var(--accent2); }
.hint { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* --- campaigns --- */
.campaigns-wrap { flex: 1; min-height: 0; display: grid; grid-template-columns: 360px 1fr; }
.camp-form { padding: 18px 20px; overflow: auto; border-right: 1px solid var(--border); }
.camp-form label { margin-top: 10px; }
.camp-output { padding: 22px 28px; overflow: auto; }
.camp-output .empty { max-width: 440px; line-height: 1.7; }
.gen { color: var(--muted); }
.hr { height: 1px; background: var(--border); margin: 16px 0; }
.hist-item { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 7px; }
.hist-item:hover { background: var(--panel2); }
.hist-title { flex: 1; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- rendered markdown (кампании + чат) --- */
.camp-output h2, .camp-output h3, .camp-output h4, .bubble h2, .bubble h3, .bubble h4 {
  color: #fff; line-height: 1.3; margin: 18px 0 8px;
}
.camp-output h2, .bubble h2 { font-size: 19px; padding-top: 6px; border-top: 1px solid var(--border); }
.camp-output h2:first-child, .bubble h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.camp-output h3, .bubble h3 { font-size: 16px; }
.camp-output h4, .bubble h4 { font-size: 14px; color: var(--muted); }
.camp-output p, .bubble p { margin: 8px 0; }
.camp-output ul, .camp-output ol, .bubble ul, .bubble ol { margin: 8px 0; padding-left: 22px; }
.camp-output li, .bubble li { margin: 4px 0; }
.camp-output code, .bubble code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.camp-output hr, .bubble hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.tw { overflow-x: auto; margin: 12px 0; }
.tw table { border-collapse: collapse; width: 100%; font-size: 13px; }
.tw th, .tw td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.tw th { background: var(--panel2); color: var(--text); font-weight: 600; }
.bubble.assistant { max-width: 820px; }
