/* RAG Chat — nowoczesny UI/UX, białe tło, czarne akcenty */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --fg: #0f0f0f;
  --fg-soft: #1a1a1a;
  --border: #e5e5e5;
  --border-focus: #0f0f0f;
  --muted: #737373;
  --muted-bg: #f0f0f0;
  --user-bg: #0f0f0f;
  --user-fg: #fafafa;
  --model-bg: #ffffff;
  --model-border: #e5e5e5;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
  --transition: 0.2s ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ----- Login ----- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: linear-gradient(180deg, var(--bg) 0%, var(--muted-bg) 100%);
}

.login-box {
  width: 100%;
  max-width: 400px;
  padding: 2.5rem;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.login-box h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.login-subtitle {
  margin: 0 0 1.75rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

.login-error {
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
}

.login-form label {
  display: block;
  margin-top: 1.25rem;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--fg-soft);
}

.login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--fg);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.login-form input:hover {
  border-color: var(--muted);
}

.login-form input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(15, 15, 15, 0.08);
}

.password-wrap {
  position: relative;
  display: block;
}

.password-wrap input {
  width: 100%;
  padding-right: 2.75rem;
  padding-left: 1rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.5rem;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  transition: color var(--transition), background var(--transition), transform 0.15s ease;
}

.password-toggle:hover {
  color: var(--fg);
  background: var(--muted-bg);
}

.password-toggle:active {
  transform: translateY(-50%) scale(0.92);
}

.password-toggle .password-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  pointer-events: none;
}

.password-toggle .password-icon svg {
  display: block;
}

/* Hasło ukryte (kropki) → pokazuj ikonę "oko" (klik = pokaż hasło) */
.password-toggle .password-icon--show {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

/* Hasło widoczne (tekst) → pokazuj ikonę "oko przekreślone" (klik = ukryj hasło) */
.password-wrap.is-revealed .password-toggle .password-icon--show {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8);
}

.password-wrap.is-revealed .password-toggle .password-icon--hide {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

.login-form button[type="submit"] {
  margin-top: 1.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--fg);
  color: var(--user-fg);
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform 0.15s ease;
}

.login-form button[type="submit"]:hover {
  background: var(--fg-soft);
}

.login-form button[type="submit"]:active {
  transform: scale(0.99);
}

.login-hint {
  margin: 1.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ----- App layout ----- */
.app {
  display: flex;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.sidebar {
  width: 340px;
  min-width: 300px;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.sidebar-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.sidebar-title {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.btn-logout {
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.btn-logout:hover {
  color: var(--fg);
  border-color: var(--fg);
  background: var(--muted-bg);
}

.upload-zone {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.upload-feedback {
  min-height: 0;
  margin-bottom: 0.75rem;
}

.upload-error {
  margin: 0;
  padding: 0.75rem 1rem;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
}

.upload-success {
  margin: 0;
  padding: 0.75rem 1rem;
  background: #ecfdf5;
  color: #047857;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.upload-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--fg-soft);
}

.upload-form input[type="file"] {
  font-size: 0.875rem;
  color: var(--fg);
  padding: 0.5rem 0;
}

.upload-form input[type="file"]::file-selector-button {
  padding: 0.5rem 1rem;
  margin-right: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--muted-bg);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background var(--transition);
}

.upload-form input[type="file"]::file-selector-button:hover {
  background: var(--border);
}

.upload-form button {
  padding: 0.625rem 1rem;
  background: var(--fg);
  color: var(--user-fg);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform 0.15s ease;
}

.upload-form button:hover {
  background: var(--fg-soft);
}

.upload-form button:active {
  transform: scale(0.99);
}

/* Animacja indexowania pliku */
.indexing-indicator {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted-bg);
  font-size: 0.875rem;
  color: var(--muted);
}

.indexing-indicator.htmx-request {
  display: flex;
}

.indexing-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: indexing-spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes indexing-spin {
  to { transform: rotate(360deg); }
}

.indexing-bars {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 16px;
}

.indexing-bars span {
  width: 4px;
  height: 100%;
  background: var(--muted);
  border-radius: 2px;
  animation: indexing-bar 1s ease-in-out infinite both;
}

.indexing-bars span:nth-child(1) { animation-delay: 0s; }
.indexing-bars span:nth-child(2) { animation-delay: 0.1s; }
.indexing-bars span:nth-child(3) { animation-delay: 0.2s; }
.indexing-bars span:nth-child(4) { animation-delay: 0.3s; }
.indexing-bars span:nth-child(5) { animation-delay: 0.4s; }

@keyframes indexing-bar {
  0%, 100% { transform: scaleY(0.4); opacity: 0.6; }
  50% { transform: scaleY(1); opacity: 1; }
}

.indexing-text {
  flex: 1;
}

.document-list {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.5rem;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0;
  padding: 1rem 0;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.25rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  transition: background var(--transition);
}

.doc-item:hover {
  background: var(--muted-bg);
}

.doc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-soft);
}

.btn-delete {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

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

/* ----- Chat area ----- */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.chat-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.usage-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  color: var(--muted);
  padding: 0.35rem 0.65rem;
  background: var(--muted-bg);
  border-radius: var(--radius-md);
}

.usage-badge .usage-icon {
  flex-shrink: 0;
  color: var(--fg-soft);
}

.usage-badge .usage-text {
  white-space: nowrap;
}

.usage-badge .usage-text strong {
  color: var(--fg);
  font-weight: 600;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  padding: 0.375rem 0.75rem;
  background: var(--muted-bg);
  border-radius: var(--radius-full);
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 48rem;
  margin: 0 auto;
  width: 100%;
}

.chat-empty-state {
  text-align: center;
  padding: 2rem 1rem;
  margin: auto 0;
}

.chat-messages:has(.message) .chat-empty-state {
  display: none;
}

.message {
  max-width: 85%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  line-height: 1.6;
  transition: box-shadow var(--transition);
}

.message-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-content.is-typing::after {
  content: '|';
  margin-left: 2px;
  animation: cursor-blink 1s step-end infinite;
  color: var(--fg);
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.message-user {
  align-self: flex-end;
  background: var(--user-bg);
  color: var(--user-fg);
  box-shadow: var(--shadow-md);
}

.message-user .message-content {
  color: var(--user-fg);
}

.message-model {
  align-self: flex-start;
  background: var(--model-bg);
  color: var(--fg);
  border: 1px solid var(--model-border);
  box-shadow: var(--shadow-sm);
}

.message-loading {
  padding: 1rem 1.25rem;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.4s ease-in-out infinite both;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.85); opacity: 0.6; }
  40% { transform: scale(1.1); opacity: 1; }
}

.chat-form {
  display: flex;
  gap: 0.75rem;
  max-width: 48rem;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 2rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.04);
}

.chat-form input {
  flex: 1;
  padding: 0.875rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-form input:hover {
  border-color: var(--muted);
}

.chat-form input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(15, 15, 15, 0.06);
}

.chat-form input::placeholder {
  color: var(--muted);
}

.chat-form button {
  padding: 0.875rem 1.5rem;
  background: var(--fg);
  color: var(--user-fg);
  border: none;
  border-radius: var(--radius-full);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform 0.15s ease;
  flex-shrink: 0;
}

.chat-form button:hover {
  background: var(--fg-soft);
}

.chat-form button:active {
  transform: scale(0.98);
}

/* HTMX */
.htmx-request .htmx-indicator {
  display: inline;
}

.htmx-indicator {
  display: none;
}

/* Ukryty pasek przewijania (scroll nadal działa) */
.document-list,
.chat-messages {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.document-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
  display: none;
}
