:root {
  --bg: #f7f7f5; --panel: #ffffff; --side: #efeee9; --text: #1f1f1d; --muted: #6b6a65;
  --line: #e2e0d9; --accent: #c2410c; --accent-text: #ffffff; --user: #e9e6dd; --note: #ecf5ea;
  --warn: #fff4d6; --err: #fde8e4; --code: #f1efe8; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a; --panel: #242423; --side: #1f1f1e; --text: #ecebe6; --muted: #a3a29c;
    --line: #36352f; --accent: #f97316; --accent-text: #1b1b1a; --user: #33322d; --note: #1f3320;
    --warn: #3a3218; --err: #3d2320; --code: #2e2d29;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}

/* вхід */
.center { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.card h1 { font-size: 22px; margin: 0 0 4px; }
.card p.sub { color: var(--muted); margin: 0 0 20px; }
.card label { display: block; margin: 14px 0 6px; font-size: 14px; }
.card button { width: 100%; margin-top: 20px; padding: 10px; }
.msg { padding: 9px 12px; border-radius: 8px; margin-top: 12px; font-size: 14px; }
.msg.err { background: var(--err); } .msg.ok { background: var(--note); }

/* чат */
.layout { display: grid; grid-template-columns: 270px 1fr; height: 100%; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side header { padding: 14px; display: flex; gap: 8px; align-items: center; }
.side header b { flex: 1; font-size: 16px; }
.side .new { margin: 0 14px 10px; }
.chats { flex: 1; overflow-y: auto; padding: 0 8px; }
.chats a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chats a.active, .chats a:hover { background: var(--user); }
.side footer { padding: 12px 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.side footer form { margin: 0; }
.side footer button { padding: 4px 10px; font-size: 13px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.topbar { display: none; padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: center; gap: 10px; }
.topbar b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed { flex: 1; overflow-y: auto; padding: 24px 16px; }
.feed-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.bubble { padding: 10px 14px; border-radius: var(--radius); max-width: 100%; overflow-wrap: anywhere; }
.bubble.user { background: var(--user); align-self: flex-end; max-width: 85%; white-space: pre-wrap; }
.bubble.assistant { background: transparent; padding-left: 0; padding-right: 0; }
.bubble.note { background: var(--note); font-size: 14px; align-self: center; }
.bubble.error { background: var(--err); }
.bubble p { margin: 0 0 10px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble h3, .bubble h4 { margin: 12px 0 6px; font-size: 16px; }
.bubble code { background: var(--code); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.bubble pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; }
.bubble table { border-collapse: collapse; margin: 6px 0 10px; font-size: 14px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.files { display: flex; flex-direction: column; gap: 6px; }
.file { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); text-decoration: none; color: var(--text); font-size: 14px; }
.file::before { content: "📄"; }
.file.gone { color: var(--muted); text-decoration: line-through; }
.approval { padding: 12px 14px; background: var(--warn); border-radius: 10px; font-size: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.status { color: var(--muted); font-size: 14px; font-style: italic; }
.empty { color: var(--muted); text-align: center; margin-top: 15vh; }
.empty h2 { color: var(--text); margin-bottom: 6px; }

.composer { border-top: 1px solid var(--line); padding: 12px 16px 16px; background: var(--bg); }
.composer-inner { max-width: 820px; margin: 0 auto; }
.attached { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.attached span { font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.attached button { border: 0; background: none; padding: 0 0 0 6px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row textarea { resize: none; max-height: 220px; min-height: 44px; }
.row label.clip { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); cursor: pointer; font-size: 18px; }
.row button { height: 44px; flex: none; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* адмінка */
.admin { max-width: 960px; margin: 0 auto; padding: 20px 16px 60px; }
.admin h1 { font-size: 22px; } .admin h2 { font-size: 18px; margin-top: 32px; }
.admin table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.admin th, .admin td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
.admin .inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.admin .inline input[type=text] { width: 220px; }
.link-box { background: var(--warn); padding: 10px 12px; border-radius: 8px; word-break: break-all; font-size: 14px; margin: 10px 0; }
.table-wrap { overflow-x: auto; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 25% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar { display: flex; }
  .feed { padding: 16px 12px; }
  .bubble.user { max-width: 92%; }
}
