:root {
  --bg: #f4f5fb; --surface: rgba(255,255,255,.72); --surface-solid: #fff;
  --text: #14151a; --muted: #6b6f80; --border: rgba(20,21,26,.10); --input: #fff;
  --accent: #6c5ce7; --accent-2: #00b8d9; --danger: #e5484d; --ai-bubble: #fff;
  --shadow: 0 20px 60px rgba(30,30,60,.12); --radius: 16px;
  --blob-1: #a29bfe; --blob-2: #74b9ff; --blob-3: #81ecec;
}
[data-theme="dark"] {
  --bg: #0d0e14; --surface: rgba(22,24,34,.72); --surface-solid: #161822;
  --text: #eceef5; --muted: #9aa0b4; --border: rgba(255,255,255,.08); --input: #1c1f2b;
  --ai-bubble: #1c1f2b; --shadow: 0 20px 60px rgba(0,0,0,.45);
  --blob-1: #4b3fb5; --blob-2: #1d4e89; --blob-3: #0e6b6b;
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--text);
  transition: background .4s, color .4s; -webkit-font-smoothing: antialiased;
}

/* Tło z płynącymi plamami */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: -1; }
.bg span {
  position: absolute; width: 42vmax; height: 42vmax; border-radius: 50%;
  filter: blur(80px); opacity: .55; animation: float 18s ease-in-out infinite;
}
.bg span:nth-child(1) { background: var(--blob-1); top: -10%; left: -10%; }
.bg span:nth-child(2) { background: var(--blob-2); bottom: -15%; right: -10%; animation-delay: -6s; }
.bg span:nth-child(3) { background: var(--blob-3); top: 40%; left: 45%; width: 30vmax; height: 30vmax; animation-delay: -12s; }
@keyframes float {
  0%, 100% { transform: translate(0,0) scale(1); }
  33% { transform: translate(6vw,4vh) scale(1.08); }
  66% { transform: translate(-4vw,6vh) scale(.95); }
}

/* Karta logowania */
.auth-page { display: grid; place-items: center; padding: 24px; }
.card {
  width: 100%; max-width: 400px; padding: 36px 32px; background: var(--surface);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border); border-radius: 28px; box-shadow: var(--shadow);
  animation: cardIn .6s cubic-bezier(.2,.8,.2,1);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(24px) scale(.97); } }
.brand { font-size: 28px; font-weight: 700; text-align: center; margin-bottom: 24px; letter-spacing: -.5px; }
.brand span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.view { display: flex; flex-direction: column; gap: 12px; animation: viewIn .45s cubic-bezier(.2,.8,.2,1); }
.view.hidden { display: none; }
@keyframes viewIn { from { opacity: 0; transform: translateX(16px); } }
h2 { font-size: 20px; font-weight: 600; margin-bottom: 4px; }

input, select, textarea {
  font: inherit; color: inherit; width: 100%; background: var(--input);
  border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  outline: none; transition: border-color .2s, box-shadow .2s, transform .2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}

.btn {
  font: inherit; font-weight: 600; color: #fff; border: 0; border-radius: var(--radius);
  padding: 14px; margin-top: 4px; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); background-size: 200% 200%;
  transition: transform .15s, box-shadow .25s, background-position .5s;
}
.btn:hover { transform: translateY(-2px); background-position: 100% 0; box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .6; pointer-events: none; }
.btn.loading { color: transparent; position: relative; }
.btn.loading::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px;
  border: 2.5px solid #fff; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

a { color: var(--accent); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }
.forgot { align-self: flex-end; font-size: 13px; margin-top: -4px; }
.switch { text-align: center; font-size: 14px; color: var(--muted); margin-top: 8px; }
.muted { color: var(--muted); font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.check input { width: auto; }
.error { color: var(--danger); font-size: 14px; text-align: center; min-height: 20px; margin-top: 12px; }
.notice {
  padding: 12px 14px; border-radius: var(--radius); font-size: 14px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* Pola kodu */
.code { display: flex; gap: 12px; justify-content: center; margin: 8px 0; }
.code input { width: 60px; height: 68px; padding: 0; text-align: center; font-size: 28px; font-weight: 700; border-radius: 18px; }
.code input:focus { transform: translateY(-3px); }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* Powiadomienie */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translate(-50%, -150%); z-index: 100;
  max-width: calc(100% - 32px); padding: 12px 20px; border-radius: 14px; font-size: 14px;
  background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .45s cubic-bezier(.2,.8,.2,1);
}
.toast.show { transform: translate(-50%, 0); }

.theme-toggle {
  position: fixed; top: 16px; right: 16px; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); backdrop-filter: blur(12px);
  color: var(--text); font-size: 18px; cursor: pointer; transition: transform .4s;
}
.theme-toggle:hover { transform: rotate(180deg); }

/* Czat */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.sidebar {
  display: flex; flex-direction: column; gap: 12px; padding: 20px 16px;
  background: var(--surface); backdrop-filter: blur(20px); border-right: 1px solid var(--border);
}
.sidebar .brand { font-size: 22px; text-align: left; margin: 0 0 8px 8px; }
.chat-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.chat-list li {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-radius: 14px;
  cursor: pointer; transition: background .2s, transform .2s; animation: viewIn .35s;
}
.chat-list li:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); transform: translateX(3px); }
.chat-list li.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.chat-list .title { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .del { opacity: 0; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 14px; transition: opacity .2s; }
.chat-list li:hover .del { opacity: 1; }
.limit { font-size: 12px; color: var(--muted); padding: 0 8px; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.user { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 38px; height: 38px; flex: none; border-radius: 12px; border: 1px solid var(--border);
  background: transparent; color: var(--text); cursor: pointer; font-size: 16px;
  transition: background .2s, transform .2s;
}
.icon-btn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); transform: translateY(-1px); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 16px 24px;
  background: var(--surface); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border);
}
.topbar h2 { flex: 1; margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ghost {
  font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--text); transition: all .2s;
}
.ghost:hover { border-color: var(--danger); color: var(--danger); }

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.msg {
  max-width: min(720px, 85%); padding: 12px 16px; border-radius: 20px; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere; animation: msgIn .35s cubic-bezier(.2,.8,.2,1);
}
.msg.user { align-self: flex-end; color: #fff; border-bottom-right-radius: 6px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.msg.assistant { align-self: flex-start; background: var(--ai-bubble); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.error-msg { border-color: var(--danger); color: var(--danger); }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.empty { margin: auto; text-align: center; color: var(--muted); animation: viewIn .5s; }
.empty h3 { font-size: 24px; color: var(--text); margin-bottom: 8px; }
.typing span {
  display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%;
  background: var(--muted); animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-4px); } }

.composer { display: flex; gap: 10px; align-items: flex-end; padding: 16px 24px 24px; }
.composer textarea { resize: none; max-height: 180px; border-radius: 20px; }
.send { width: 52px; height: 52px; flex: none; border-radius: 50%; padding: 0; margin: 0; font-size: 20px; }
.menu-btn { display: none; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 20;
    transform: translateX(-100%); transition: transform .35s cubic-bezier(.2,.8,.2,1);
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .messages, .composer { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
