/* ── Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;700&display=swap');

/* ── Variables ── */
:root {
  --bg-base:      #0b0b14;
  --bg-panel:     #111827;
  --bg-elevated:  #1a2035;
  --bg-input:     #0f1729;
  --accent:       #AA5DFB;
  --accent-hover: #9333ea;
  --accent-light: #C084FC;
  --user-bubble:  #AA5DFB;
  --bot-bubble:   #1e293b;
  --border-glow:  #00FFAB;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:   #475569;
  --border:       #1e2d45;
  --border-light: #2d3f5e;
  --error:        #ef4444;
  --success:      #22c55e;
  --radius:       12px;
  --radius-sm:    8px;
  --radius-pill:  999px;
  --shadow:       0 4px 24px rgba(0,0,0,0.5);
  --transition:   0.18s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.muted-text { color: var(--text-secondary); font-size: 13px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: transparent;
  color: var(--border-glow);
  border: 1px solid var(--border-glow);
}
.btn-secondary:hover:not(:disabled) { background: rgba(0,255,171,0.08); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) { color: var(--text-primary); background: var(--bg-elevated); }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

/* ── Login Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  font-family: 'Raleway', sans-serif;
}

.modal-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 28px;
}

.modal-logo-img {
  height: 112px;
  width: auto;
  max-width: 260px;
  display: block;
}

.modal-subtitle {
  font-family: 'Raleway', sans-serif;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 400;
  margin-bottom: 28px;
  text-align: center;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field-group label {
  font-family: 'Raleway', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.field-group input {
  font-family: 'Raleway', sans-serif;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}
.field-group input:focus { border-color: var(--accent); }
.field-group input::placeholder { color: var(--text-muted); }

.modal .btn {
  font-family: 'Raleway', sans-serif;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.field-textarea {
  font-family: 'Raleway', sans-serif;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  resize: vertical;
  min-height: 80px;
  transition: border-color var(--transition);
  width: 100%;
}
.field-textarea:focus { border-color: var(--accent); }
.field-textarea::placeholder { color: var(--text-muted); }

.pdf-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

.modal-link-row {
  text-align: center;
  margin-top: 16px;
}
.modal-link {
  font-family: 'Raleway', sans-serif;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}
.modal-link:hover { color: var(--accent-light); }

.success-banner {
  font-family: 'Raleway', sans-serif;
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: var(--radius-sm);
  color: #86efac;
  font-size: 13px;
}

.error-banner {
  font-family: 'Raleway', sans-serif;
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 13px;
}

/* ── App Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
}

.header-logo-img {
  height: 36px;
  width: auto;
  display: block;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-email { color: var(--text-secondary); font-size: 13px; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.toolbar-label {
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
}

.select-wrapper {
  position: relative;
}
.select-wrapper::after {
  content: '▾';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
  font-size: 11px;
}

#agent-selector {
  appearance: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 7px 32px 7px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  min-width: 160px;
  transition: border-color var(--transition);
}
#agent-selector:focus { border-color: var(--accent); }

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Main Content ── */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
  padding: 8px;
}

/* ── Panel Resizer ── */
.panel-resizer {
  width: 8px;
  flex-shrink: 0;
  cursor: col-resize;
  position: relative;
  background: transparent;
  transition: background var(--transition);
  z-index: 10;
}
.panel-resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 48px;
  background: var(--border-glow);
  border-radius: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.panel-resizer:hover { background: rgba(0,255,171,0.06); }
.panel-resizer:hover::after,
.panel-resizer.is-dragging::after { opacity: 0.8; }
.panel-resizer.is-dragging { background: rgba(0,255,171,0.1); }

/* ── Chat Panel ── */
.chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border-glow);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.credits-label {
  color: var(--text-secondary);
  font-size: 13px;
}
.credits-label strong { color: var(--accent-light); }

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.messages-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 10px;
  user-select: none;
}
.messages-empty-icon {
  width: 52px;
  height: 52px;
  opacity: 0.7;
}
.messages-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
}
.messages-empty-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Messages ── */
.message {
  display: flex;
  max-width: 80%;
}
.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.message.bot { align-self: flex-start; }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.bot .bubble {
  background: var(--bot-bubble);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.message.bot.loading .bubble {
  color: var(--text-muted);
  font-style: italic;
}

/* ── Input Area ── */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 140px;
  line-height: 1.5;
  transition: border-color var(--transition);
}
#message-input:focus { border-color: var(--border-glow); }
#message-input::placeholder { color: var(--text-muted); }

.chat-footer {
  padding: 8px 20px;
  text-align: center;
  flex-shrink: 0;
}
.chat-footer p {
  color: var(--text-muted);
  font-size: 11px;
}

/* ── Info Panel ── */
.info-panel {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius);
  overflow-y: auto;
}
.info-panel::-webkit-scrollbar { width: 4px; }
.info-panel::-webkit-scrollbar-thumb { background: var(--border-light); }

.info-title {
  padding: 16px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.info-content {
  padding: 16px 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.ref-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}
.ref-item p { color: var(--text-primary); font-size: 13px; margin-bottom: 6px; }
.ref-item .source {
  color: var(--accent-light);
  font-size: 11px;
  word-break: break-all;
}

/* ── Responsive ── */
@media (max-width: 768px) {

  /* Header */
  .app-header { padding: 0 14px; }
  .header-logo-img { height: 28px; }
  .user-email { font-size: 11px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Toolbar */
  .toolbar { flex-direction: column; align-items: stretch; padding: 10px 14px; gap: 8px; }
  .toolbar-label { display: none; }
  .toolbar-left { width: 100%; }
  .select-wrapper { width: 100%; }
  #agent-selector { width: 100%; }
  .toolbar-right { display: flex; gap: 8px; }
  .toolbar-right .btn { flex: 1; justify-content: center; font-size: 12px; padding: 7px 10px; }

  /* Main layout */
  .main-content { padding: 6px; gap: 0; }
  .info-panel { display: none; }

  /* Chat panel */
  .chat-panel { border-radius: 8px; }
  .chat-header { padding: 10px 14px; }
  .messages-container { padding: 12px; gap: 10px; }

  /* Messages - prevent overflow */
  .message { max-width: 85%; }
  .bubble { font-size: 13px; padding: 10px 12px; }

  /* Input area */
  .input-area { padding: 10px 12px; gap: 8px; }
  #message-input { font-size: 14px; }
  #send-btn { padding: 10px 16px; white-space: nowrap; }

  /* Footer */
  .chat-footer { padding: 6px 12px; }
  .chat-footer p { font-size: 10px; }
}
