:root {
  --bg: #121014;
  --surface: #1c191f;
  --surface-2: #26222a;
  --ink: #efe8f2;
  --ink-2: #aaa1b0;
  --ink-3: #6f6775;
  --line: #2e2933;
  --accent: #e0855a;
  --bubble-me: #e7dcea;
  --bubble-me-ink: #19161b;
  --danger: #ff7a6e;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 24px rgb(0 0 0 / .25);
  --radius: 18px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", -apple-system, system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 5;
}
.bar h1 { font: 600 26px/1.1 var(--serif); margin: 0; flex: 1; letter-spacing: -.01em; }
.bar .title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.bar .title b { font: 600 18px/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--ink-2); flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- avatars ---------- */
.avatar {
  --c: var(--accent);
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--c) 22%, var(--surface));
  color: var(--c);
  font: 600 19px/1 var(--serif);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 40%, transparent);
}
.avatar.sm { width: 34px; height: 34px; font-size: 15px; }
.avatar.lg { width: 72px; height: 72px; font-size: 30px; }

/* ---------- list ---------- */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.list { padding: 8px 8px calc(env(safe-area-inset-bottom) + 96px); }
.row {
  display: flex; gap: 14px; align-items: center; width: 100%;
  padding: 12px; border: 0; background: transparent; border-radius: 14px; text-align: left;
}
.row:hover { background: var(--surface-2); }
.row .meta { flex: 1; min-width: 0; }
.row .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.row .name time { font-weight: 400; font-size: 13px; color: var(--ink-3); flex: none; }
.row .last { display: block; color: var(--ink-2); font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(env(safe-area-inset-bottom) + 20px);
  height: 52px; padding: 0 22px 0 18px; border-radius: 26px; border: 0;
  background: var(--ink); color: var(--bg); font-weight: 600;
  display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow);
}
.fab svg { width: 20px; height: 20px; }
.empty { text-align: center; color: var(--ink-2); padding: 64px 32px; }
.empty h2 { font: 600 24px var(--serif); color: var(--ink); margin: 0 0 8px; }

/* ---------- chat ---------- */
.messages {
  flex: 1; overflow-y: auto; padding: 16px 16px 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.msg {
  max-width: 82%; padding: 10px 14px; border-radius: var(--radius);
  white-space: pre-wrap; overflow-wrap: anywhere;
  animation: pop .18s ease-out;
}
.msg.user { align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-ink); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.user + .msg.assistant, .msg.assistant + .msg.user { margin-top: 8px; }
.msg em { color: var(--ink-2); }
.msg.user em { color: inherit; opacity: .75; }
.msg.error { align-self: center; background: transparent; color: var(--danger); font-size: 14px; border: 0; text-align: center; }
.note {
  align-self: flex-start; font-size: 12.5px; color: var(--ink-3);
  display: flex; align-items: center; gap: 5px; padding: 0 6px;
}
.note svg { width: 13px; height: 13px; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
.intro { text-align: center; color: var(--ink-2); padding: 40px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; margin: auto 0; }
.intro b { font: 600 22px var(--serif); color: var(--ink); }

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--line); background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 44px;
  padding: 11px 16px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--surface); outline: none; line-height: 1.35;
}
.composer textarea:focus { border-color: var(--ink-3); }
.send {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: #fff; display: grid; place-items: center;
}
.send:disabled { opacity: .35; cursor: default; }
.send svg { width: 20px; height: 20px; }

/* ---------- forms ---------- */
.form { padding: 20px 16px calc(env(safe-area-inset-bottom) + 32px); display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.field small { color: var(--ink-3); font-size: 13px; }
.input, .area {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none;
}
.input:focus, .area:focus { border-color: var(--ink-3); }
.area { min-height: 220px; resize: vertical; font: 14.5px/1.5 ui-monospace, "SF Mono", Menlo, monospace; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--c); box-shadow: inset 0 0 0 2px rgb(0 0 0 / .08); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--c); }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 500; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.btn {
  height: 48px; border-radius: 14px; border: 0; padding: 0 20px;
  background: var(--ink); color: var(--bg); font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.btn:disabled { opacity: .5; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.hint { color: var(--ink-2); font-size: 14.5px; margin: 0; }
.err { color: var(--danger); font-size: 14px; min-height: 1em; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 20; animation: pop .2s ease-out;
}

/* ---------- lista: przycisk opcji ---------- */
.row-wrap { display: flex; align-items: center; gap: 2px; }
.row-wrap .row { flex: 1; min-width: 0; }
.row-more { opacity: .7; }

/* ---------- akcje wiadomości ---------- */
.msg.user, .msg.assistant { cursor: pointer; }
.msg-actions { display: flex; gap: 6px; padding: 2px 4px 6px; animation: pop .15s ease-out; }
.msg-actions.user { align-self: flex-end; }
.msg-actions.assistant { align-self: flex-start; }
.msg-actions button {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 16px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); font-size: 13.5px;
}
.msg-actions button:hover { color: var(--ink); }
.msg-actions svg { width: 15px; height: 15px; }
.msg.editing { width: 82%; cursor: default; padding: 8px; background: var(--surface); color: var(--ink); border: 1px solid var(--ink-3); }
.msg-edit textarea {
  width: 100%; border: 0; background: transparent; outline: none; resize: none; padding: 4px 6px; line-height: 1.45; display: block;
}
.msg-edit-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }
.msg-edit-actions button { height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line); background: transparent; font-size: 14px; }
.msg-edit-actions .primary { background: var(--accent); border-color: var(--accent); color: #1a120d; font-weight: 600; }

/* ---------- arkusz akcji ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 520px; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 12px); animation: up .2s ease-out;
}
.sheet-title { text-align: center; color: var(--ink-3); font-size: 13px; padding: 10px 0 8px; }
.sheet-item {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; border: 0;
  background: transparent; border-radius: 12px; text-align: left; font-size: 16px;
}
.sheet-item:hover { background: var(--surface-2); }
.sheet-item svg { width: 20px; height: 20px; color: var(--ink-2); }
.sheet-item.danger, .sheet-item.danger svg { color: var(--danger); }
.sheet-item.cancel { justify-content: center; color: var(--ink-2); margin-top: 4px; border-top: 1px solid var(--line); border-radius: 0 0 12px 12px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- ekran hasła ---------- */
.lock {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  animation: fade .2s;
}
.lock-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.lock-icon { width: 56px; height: 56px; margin: 0 auto 4px; border-radius: 18px; display: grid; place-items: center; background: var(--surface-2); color: var(--accent); }
.lock-icon svg { width: 26px; height: 26px; }
.lock h2 { font: 600 28px var(--serif); margin: 0; }
.lock .input { text-align: center; font-size: 17px; }
.lock details { color: var(--ink-3); font-size: 13px; }
.lock summary { cursor: pointer; padding: 4px; }
.lock details .input { margin-top: 8px; font-size: 14px; }
