:root {
  --bg-base: #09090b;
  --bg-elevated: #121216;
  --bg-panel: #18181d;
  --bg-hover: #22222a;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-glow: rgba(79, 70, 229, 0.28);
  --text-main: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --danger: #ef4444;
  --danger-hover: #dc2626;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-base);
  background-image: radial-gradient(circle at 50% 0%, rgba(79, 70, 229, 0.12), transparent 55%);
  color: var(--text-main);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================
   1. EKRAN AUTORYZACJI
   ========================================== */
.lock-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  width: 100%;
  padding: 20px;
}

.lock-card {
  background: rgba(24, 24, 29, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 32px 26px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.lock-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.25), rgba(59, 130, 246, 0.1));
  border: 1px solid rgba(99, 102, 241, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #818cf8;
  margin-bottom: 4px;
}

.lock-title {
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}

.lock-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin: 0 0 8px 0;
  line-height: 1.45;
}

.lock-input {
  background: var(--bg-base);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  width: 100%;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.lock-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
  background: linear-gradient(135deg, #4f46e5, #3b82f6);
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  width: 100%;
  transition: transform 0.1s, opacity 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.95;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.99);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.lock-error {
  color: #f87171;
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* ==========================================
   2. GŁÓWNY UKŁAD I PASEK BOCZNY
   ========================================== */
.app-wrapper {
  display: none;
  height: 100dvh;
  width: 100%;
  position: relative;
}

.app-wrapper.unlocked {
  display: flex;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 40;
}

.sidebar-backdrop.visible {
  display: block;
}

.sidebar {
  width: 275px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
  flex-shrink: 0;
  z-index: 50;
  transition: margin-left 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar.collapsed {
  margin-left: -275px;
}

.sidebar-top {
  padding-bottom: 4px;
}

.new-chat-btn {
  width: 100%;
  background: linear-gradient(135deg, #4f46e5, #3b82f6);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
  transition: opacity 0.15s, transform 0.1s;
}

.new-chat-btn:hover {
  opacity: 0.94;
}

.new-chat-btn:active {
  transform: scale(0.98);
}

.sidebar-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 6px 2px 6px;
  font-weight: 600;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-bottom: 40px;
}

.chat-list::-webkit-scrollbar {
  width: 4px;
}

.chat-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.chat-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 8px 9px 11px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.chat-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.chat-item.active {
  background: rgba(79, 70, 229, 0.14);
  border-color: rgba(99, 102, 241, 0.3);
  color: #fff;
  font-weight: 500;
}

.chat-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Przycisk 3 kropek i rozwijane menu */
.chat-menu-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.chat-menu-btn:hover,
.chat-menu-btn.open {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.chat-dropdown {
  position: absolute;
  right: 8px;
  top: 38px;
  background: #1e1e26;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 5px;
  z-index: 60;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.7);
  min-width: 165px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: fadeIn 0.12s ease-out;
}

.chat-dropdown-item {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  font-family: inherit;
  transition: background 0.12s;
}

.chat-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.chat-dropdown-item.danger {
  color: #f87171;
}

.chat-dropdown-item.danger:hover {
  background: rgba(239, 68, 68, 0.14);
}

/* ==========================================
   3. GŁÓWNA KOLUMNA I GÓRNY PASEK
   ========================================== */
.main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-width: 0;
  position: relative;
}

.top-bar {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: rgba(18, 18, 22, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 20;
}

.top-left {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-strong);
}

select {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 9px;
  outline: none;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

select:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

select:focus {
  border-color: #6366f1;
}

.btn-ghost {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-strong);
}

.kv-warning {
  background: rgba(234, 179, 8, 0.1);
  border-bottom: 1px solid rgba(234, 179, 8, 0.3);
  color: #fde047;
  padding: 8px 16px;
  font-size: 12.5px;
  text-align: center;
  display: none;
}

/* ==========================================
   4. OBSZAR WIADOMOŚCI (CZAT)
   ========================================== */
.chat-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.chat-scroll-area::-webkit-scrollbar {
  width: 6px;
}

.chat-scroll-area::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

.chat-inner-stream {
  width: 100%;
  max-width: 840px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: rgba(79, 70, 229, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #818cf8;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.empty-subtitle {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

.msg {
  border-radius: 14px;
  padding: 15px 18px;
  line-height: 1.65;
  font-size: 14.5px;
  overflow-x: auto;
  animation: fadeIn 0.18s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user {
  background: linear-gradient(135deg, #27273a, #1e2436);
  border: 1px solid rgba(99, 102, 241, 0.28);
  align-self: flex-end;
  max-width: 85%;
  min-width: 180px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.msg-assistant {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  width: 100%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.model-badge {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  padding: 2px 8px;
  border-radius: 6px;
  color: #c7d2fe;
  font-size: 11px;
}

.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }

.msg-content p { margin: 0 0 12px 0; }
.msg-content ul, .msg-content ol { margin: 0 0 12px 0; padding-left: 22px; }
.msg-content li { margin-bottom: 4px; }

.msg-attachments {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.msg-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
}

.att-badge {
  font-size: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border-subtle);
  padding: 4px 10px;
  border-radius: 6px;
  color: #e4e4e7;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* ==========================================
   5. DOLNY KOMPOZYTOR PROMPTU
   ========================================== */
.composer-wrapper {
  flex-shrink: 0;
  width: 100%;
  max-width: 872px;
  margin: 0 auto;
  padding: 6px 16px calc(14px + env(safe-area-inset-bottom, 0px)) 16px;
}

.composer-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.composer-card:focus-within {
  border-color: #6366f1;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 0 2px var(--accent-glow);
}

.composer-card.dragover {
  border-color: #6366f1;
  background: #1b1d2e;
}

.preview-area {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preview-area:empty {
  display: none;
}

.img-wrapper {
  position: relative;
  width: 68px;
  height: 68px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-base);
}

.img-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-base);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 7px 28px 7px 10px;
  font-size: 12.5px;
  color: var(--text-main);
  max-width: 220px;
}

.file-chip span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  cursor: pointer;
  font-size: 10px;
  line-height: 18px;
  text-align: center;
  padding: 0;
}

.remove-btn:hover {
  background: var(--danger);
}

textarea {
  width: 100%;
  min-height: 44px;
  max-height: 180px;
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 2px 0;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  font-family: inherit;
}

textarea::placeholder {
  color: var(--text-muted);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.attach-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 7px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.attach-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-strong);
}

.send-btn {
  background: linear-gradient(135deg, #4f46e5, #3b82f6);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  box-shadow: 0 3px 12px rgba(79, 70, 229, 0.35);
  transition: opacity 0.15s, transform 0.1s;
}

.send-btn:hover:not(:disabled) {
  opacity: 0.94;
}

.send-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==========================================
   6. BLOKI KODU I MODALE (ZMIANA NAZWY / USUWANIE)
   ========================================== */
pre {
  position: relative;
  background: #0b0b0e;
  padding: 14px 16px;
  border-radius: 10px;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  margin: 12px 0;
}

code {
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 13px;
}

p code, li code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 12.5px;
}

.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #1f1f27;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.copy-code-btn:hover {
  background: #2e2e3a;
  color: #fff;
}

.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 14px;
}

.dot-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6366f1;
  animation: pulse 1s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Modale */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 390px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  animation: fadeIn 0.15s ease-out;
}

.modal-icon-edit {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(79, 70, 229, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #818cf8;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}

.modal-icon-danger {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}

.modal-title {
  font-size: 16.5px;
  font-weight: 600;
  margin: 0;
}

.modal-desc {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin: 0 0 6px 0;
  line-height: 1.45;
}

.modal-input {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  margin-bottom: 4px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.modal-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn-cancel {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 9px;
  font-weight: 500;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}

.btn-cancel:hover {
  background: var(--bg-hover);
}

.btn-save {
  flex: 1;
  background: linear-gradient(135deg, #4f46e5, #3b82f6);
  border: none;
  color: #fff;
  padding: 10px 14px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}

.btn-save:hover:not(:disabled) {
  opacity: 0.94;
}

.btn-danger {
  flex: 1;
  background: var(--danger);
  border: none;
  color: #fff;
  padding: 10px 14px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

/* ==========================================
   7. RESPONSYWNOŚĆ NA TELEFON (MOBILE)
   ========================================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    margin-left: 0 !important;
    transform: translateX(-100%);
    box-shadow: 12px 0 32px rgba(0, 0, 0, 0.75);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .top-bar {
    padding: 8px 12px;
  }

  select, textarea, .modal-input {
    font-size: 16px;
  }

  select {
    padding: 7px 10px;
    max-width: 215px;
  }

  .lock-btn-text {
    display: none;
  }

  .chat-scroll-area {
    padding: 14px 10px 8px 10px;
  }

  .msg {
    padding: 12px 14px;
    font-size: 14px;
  }

  .msg-user {
    max-width: 92%;
  }

  .composer-wrapper {
    padding: 4px 10px calc(10px + env(safe-area-inset-bottom, 0px)) 10px;
  }

  .composer-card {
    padding: 10px 12px;
    border-radius: 14px;
  }
}