:root {
  --bg: #212121;
  --side: #171717;
  --panel: #2f2f2f;
  --border: #3a3a3a;
  --text: #ececec;
  --muted: #9b9b9b;
  --accent: #10a37f;
  --danger: #ef4444;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; margin-top: 6px; }
.error { color: var(--danger); min-height: 1em; margin: 6px 0 0; }

/* ---------- logowanie ---------- */
.auth { height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; display: flex; flex-direction: column; gap: 12px;
}
.auth-card h1 { margin: 0; font-size: 24px; }
.auth-card p { margin: 0; }
.auth-card input, .add-user input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; outline: none;
}
.auth-card input:focus, .add-user input:focus { border-color: var(--accent); }
.auth-card button, .add-user button {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 11px; font-weight: 600;
}

/* ---------- układ ---------- */
.app { display: flex; height: 100%; }
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--side); display: flex; flex-direction: column;
  padding: 10px; gap: 8px;
}
.new-chat {
  background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; text-align: left;
}
.new-chat:hover { background: var(--panel); }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 8px; cursor: pointer;
  font-size: 14px;
}
.chat-item:hover, .chat-item.active { background: var(--panel); }
.chat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-actions { display: none; gap: 2px; }
.chat-item:hover .chat-actions, .chat-item.active .chat-actions { display: flex; }
.chat-actions button { background: none; border: 0; color: var(--muted); padding: 0 3px; font-size: 13px; }
.chat-actions button:hover { color: var(--text); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 10px; font-size: 13px; display: flex; flex-direction: column; gap: 8px; }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #666; flex-shrink: 0; }
.dot.on { background: #22c55e; }
.dot.warn { background: #eab308; }
.dot.off { background: #6b7280; }
.dot.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.pod-btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 10px; font-size: 13px; font-weight: 600;
}
.pod-btn.stop { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.pod-btn.stop:hover { color: var(--text); border-color: #555; }
.pod-btn:disabled { opacity: 0.6; cursor: default; }
.user-row { display: flex; align-items: center; gap: 10px; }
.me { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.link { background: none; border: 0; color: var(--muted); padding: 0; }
.link:hover { color: var(--text); }
.link.danger:hover { color: var(--danger); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 18px; padding: 2px 6px; }
#toggle-sidebar { display: none; }

/* ---------- wiadomości ---------- */
.messages { flex: 1; overflow-y: auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 18px; }
.messages > * { width: 100%; max-width: 780px; margin: 0 auto; }
.empty { margin: auto; text-align: center; font-size: 26px; font-weight: 600; color: var(--muted); }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--panel); border-radius: 18px; padding: 10px 16px; max-width: 80%; white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant .bubble { width: 100%; line-height: 1.6; }

.thinking { margin-bottom: 10px; border-left: 2px solid var(--border); padding-left: 12px; }
.thinking summary { color: var(--muted); cursor: pointer; font-size: 14px; user-select: none; }
.thinking-body { color: var(--muted); font-size: 13px; white-space: pre-wrap; margin-top: 8px; max-height: 400px; overflow-y: auto; }
.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md pre {
  position: relative; background: #0d0d0d; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; overflow-x: auto; font-size: 13px;
}
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
.md :not(pre) > code { background: var(--panel); padding: 2px 5px; border-radius: 5px; }
.md a { color: #7ab7ff; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }
.copy {
  position: absolute; top: 8px; right: 8px; background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; font-size: 12px; padding: 3px 8px;
}
.copy:hover { color: var(--text); }

/* ---------- pole wpisywania ---------- */
.composer {
  display: flex; gap: 8px; align-items: flex-end; width: 100%; max-width: 780px; margin: 0 auto 18px;
  padding: 0 16px;
}
.composer textarea {
  flex: 1; resize: none; background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 13px 16px; outline: none; max-height: 220px; line-height: 1.4;
}
.composer textarea:focus { border-color: #555; }
.send { background: var(--text); color: #000; border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600; }
.send.stop { background: var(--danger); color: #fff; }

/* ---------- panel admina ---------- */
.dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(520px, 92vw); padding: 20px;
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog h2 { margin: 0; font-size: 18px; }
.users { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 14px; }
.users th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.users td { padding: 8px 4px; border-bottom: 1px solid var(--border); }
.user-actions { display: flex; gap: 12px; justify-content: flex-end; }
.add-user { display: flex; flex-direction: column; gap: 10px; }
.add-user h3 { margin: 6px 0 0; font-size: 15px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }

/* ---------- telefon ---------- */
@media (max-width: 800px) {
  #toggle-sidebar { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, 0.6); }
}
