* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0e1621;
  --bg-secondary: #17212b;
  --bg-header: #242f3d;
  --bg-input: #242f3d;
  --bg-bot-msg: #182533;
  --bg-user-msg: #2b5278;
  --text-primary: #f5f5f5;
  --text-secondary: #8b9bab;
  --accent: #5eb5f7;
  --accent-hover: #4a9fe0;
  --border: #1f2936;
  --typing-dot: #5eb5f7;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ── Login Screen ── */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--bg-secondary);
}

.login-card {
  background: var(--bg-header);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  text-align: center;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.login-card p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 14px;
}

.login-card input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  margin-bottom: 16px;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.login-card button:hover {
  background: var(--accent-hover);
}

.login-card button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-error {
  color: #e74c3c;
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}

/* ── Chat Screen ── */

#chat-screen {
  display: none;
  flex-direction: column;
  height: 100%;
}

#chat-screen.active {
  display: flex;
}

#chat-screen.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

#chat-screen.drag-over .chat-messages::after {
  content: 'Drop file here';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 22, 33, 0.8);
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
  pointer-events: none;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.bot-info h2 {
  font-size: 16px;
  font-weight: 600;
}

.bot-info span {
  font-size: 12px;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.header-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  position: relative;
  flex-direction: column;
  gap: 4px;
}

.message {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
}

.message.bot {
  align-self: flex-start;
  background: var(--bg-bot-msg);
  border-bottom-left-radius: 4px;
}

.message.user {
  align-self: flex-end;
  background: var(--bg-user-msg);
  border-bottom-right-radius: 4px;
}

.message .time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  text-align: right;
}

.message img {
  max-width: 100%;
  border-radius: 8px;
  margin: 6px 0;
  cursor: pointer;
}

.message .caption {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Inline buttons */
.inline-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.inline-btn {
  padding: 6px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: color 0.2s;
}

.inline-btn:hover {
  color: #fff;
}

/* Typing indicator */
.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--bg-bot-msg);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.typing-indicator.visible {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--typing-dot);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-indicator .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-header);
  border-top: 1px solid var(--border);
}

.chat-input .attach-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

.chat-input .attach-btn:hover {
  color: var(--accent);
}

#message-input {
  flex: 1;
  padding: 10px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}

#message-input:focus {
  border-color: var(--accent);
}

#message-input::placeholder {
  color: var(--text-secondary);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

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

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

/* Hidden file input */
#file-input {
  display: none;
}

/* Mermaid charts */
.mermaid-chart {
  margin: 8px 0;
  overflow-x: auto;
}

.mermaid-chart svg {
  max-width: 100%;
  height: auto;
}

/* Code blocks */
.message pre {
  background: var(--bg-primary);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 13px;
}

.message code {
  background: var(--bg-primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.message a {
  color: var(--accent);
  text-decoration: none;
}

.message a:hover {
  text-decoration: underline;
}

/* Lists inside messages */
.message ul, .message ol {
  margin: 6px 0;
  padding-left: 20px;
}

.message li {
  margin-bottom: 3px;
  line-height: 1.5;
}

/* Headings inside messages */
.message h2, .message h3, .message h4 {
  margin: 10px 0 6px;
  line-height: 1.3;
}

.message h2 {
  font-size: 18px;
}

.message h3 {
  font-size: 16px;
}

.message h4 {
  font-size: 15px;
  color: var(--accent);
}

/* Download link */
.download-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  margin-top: 6px;
}

.download-link:hover {
  background: var(--border);
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Graph Overlay ── */

.graph-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}

.graph-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.graph-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.graph-controls select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.graph-controls select:focus {
  border-color: var(--accent);
}

.graph-level-toggle {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.level-btn {
  padding: 6px 14px;
  border: none;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.level-btn.active {
  background: var(--accent);
  color: #fff;
}

.graph-quit-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid #e74c3c;
  background: transparent;
  color: #e74c3c;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.graph-quit-btn:hover {
  background: #e74c3c;
  color: #fff;
}

.graph-departments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
  flex-shrink: 0;
}

.dept-pill {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.dept-pill.active {
  border-color: var(--accent);
  background: rgba(94, 181, 247, 0.1);
  color: var(--accent);
}

.graph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 16px;
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.graph-card {
  background: var(--bg-bot-msg);
  border-radius: 12px;
  padding: 16px;
  min-height: 400px;
}

.graph-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.graph-card-title .avg-badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

.graph-card canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Responsive */
@media (max-width: 600px) {
  .message {
    max-width: 85%;
  }

  .chat-header {
    padding: 10px 12px;
  }

  .chat-input {
    padding: 10px 12px;
  }

  .login-card {
    margin: 16px;
    width: calc(100% - 32px);
  }

  .graph-grid {
    grid-template-columns: 1fr;
  }

  .graph-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .graph-controls {
    flex-wrap: wrap;
  }
}
