:root {
  --ink: #0a0a0a;
  --muted: #5c5660;
  --paper: #f7ebe8;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-solid: #ffffff;
  --line: rgba(10, 10, 10, 0.1);
  --accent: #0a0a0a;
  --accent-hover: #2a2a2a;
  --user-bg: rgba(255, 255, 255, 0.9);
  --bot-bg: rgba(255, 255, 255, 0.55);
  --danger: #b42318;
  --shadow: 0 20px 60px rgba(80, 40, 60, 0.1);
  --radius: 18px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background-color: #f2cfc8;
  background-image:
    radial-gradient(ellipse 80% 70% at 0% 0%, #f0b0b8 0%, transparent 55%),
    radial-gradient(ellipse 70% 65% at 100% 0%, #dcb8e0 0%, transparent 55%),
    radial-gradient(ellipse 80% 60% at 100% 100%, #ffc29a 0%, transparent 55%),
    radial-gradient(ellipse 70% 55% at 0% 100%, #f0b8c8 0%, transparent 55%),
    linear-gradient(180deg, #e8c4d8 0%, #f2c8c4 40%, #ffc8a8 100%);
  background-attachment: fixed;
}

/* warstwa .bg nieużywana - gradient jest na body */
.bg { display: none; }

.panel {
  width: min(420px, calc(100% - 2rem));
  margin: 12vh auto 0;
  padding: 2rem;
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-panel {
  background: #fff;
}

.login-panel h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.sub, .muted {
  color: var(--muted);
  font-size: 0.95rem;
}

label {
  display: grid;
  gap: 0.4rem;
  margin-top: 1rem;
  font-size: 0.85rem;
  font-weight: 600;
}

input, textarea, button {
  font: inherit;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  background: var(--panel-solid);
  color: var(--ink);
}

input:focus, textarea:focus {
  outline: 2px solid rgba(10, 10, 10, 0.18);
  outline-offset: 1px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: background 140ms ease, transform 140ms ease;
}

button:hover { background: var(--accent-hover); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

button.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid rgba(10, 10, 10, 0.12);
}

button.ghost:hover {
  background: #f5f5f5;
}

#login-form button[type="submit"] {
  width: 100%;
  margin-top: 1.25rem;
}

.error {
  color: var(--danger);
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
}

.app {
  width: min(860px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 1rem 1rem;
}

/* display:grid powyżej wygrywa z samym [hidden] - wymuś ukrycie */
.app[hidden],
#login-view[hidden],
.top-actions[hidden] {
  display: none !important;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0.25rem;
  position: sticky;
  top: 0;
  background: transparent;
  z-index: 2;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.5rem 0 1.25rem;
  overflow-y: auto;
}

.bubble {
  max-width: min(720px, 92%);
  padding: 0.9rem 1.05rem;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: var(--bot-bg);
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(80, 40, 60, 0.06);
  animation: rise 180ms ease-out;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bg);
  border-color: rgba(10, 10, 10, 0.08);
  color: var(--ink);
}

.bubble.bot {
  align-self: flex-start;
}

.bubble.bot.streaming::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s step-end infinite;
  color: var(--ink);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: end;
  padding: 0.85rem;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.composer textarea {
  min-height: 48px;
  max-height: 160px;
  border: none;
  padding: 0.55rem 0.2rem;
  background: transparent;
  outline: none;
}

dialog {
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  padding: 0;
  width: min(640px, calc(100% - 2rem));
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

dialog::backdrop {
  background: rgba(40, 20, 35, 0.35);
}

.prompt-box {
  padding: 1.25rem;
}

.prompt-box h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
}

.prompt-box textarea {
  font-family: var(--mono);
  font-size: 0.9rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes blink {
  50% { opacity: 0; }
}

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .composer { grid-template-columns: 1fr; }
  .composer button { width: 100%; }
}
