* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; height: 100vh; display: flex; }

/* Auth page */
.auth-container {
  margin: auto; width: 380px; background: #fff; border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1); padding: 40px;
}
.auth-container h1 { font-size: 24px; margin-bottom: 8px; text-align: center; }
.auth-container p.subtitle { color: #666; text-align: center; margin-bottom: 24px; font-size: 14px; }
.auth-container input {
  width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 6px;
  font-size: 14px; margin-bottom: 12px; outline: none;
}
.auth-container input:focus { border-color: #4f46e5; }
.auth-container button {
  width: 100%; padding: 10px; background: #4f46e5; color: #fff; border: none;
  border-radius: 6px; font-size: 14px; cursor: pointer; margin-bottom: 12px;
}
.auth-container button:hover { background: #4338ca; }
.auth-container .toggle { text-align: center; font-size: 13px; color: #666; }
.auth-container .toggle a { color: #4f46e5; cursor: pointer; text-decoration: none; }
.auth-container .error { color: #dc2626; font-size: 13px; margin-bottom: 12px; display: none; }
.auth-container .notice { color: #16a34a; font-size: 13px; margin-bottom: 12px; display: none; }
.auth-container .resend { text-align: center; margin-bottom: 12px; display: none; }
/* Link-styled button: override the full-width .auth-container button rules. */
.auth-container .resend-btn {
  width: auto; padding: 0; margin: 0; background: none; color: #4f46e5;
  font-size: 13px; cursor: pointer; text-decoration: underline;
}
.auth-container .resend-btn:hover { background: none; color: #4338ca; }

/* Chat layout */
.chat-app { display: flex; width: 100%; height: 100vh; }

/* Sidebar */
.sidebar {
  width: 280px; background: #1e1e2e; color: #cdd6f4; display: flex; flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 16px; border-bottom: 1px solid #313244; display: flex;
  justify-content: space-between; align-items: center;
}
.sidebar-header h2 { font-size: 16px; color: #cdd6f4; }
.sidebar-header .user-info { font-size: 12px; color: #a6adc8; }
.new-chat-btn {
  margin: 12px 16px; padding: 10px; background: #4f46e5; color: #fff; border: none;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.new-chat-btn:hover { background: #4338ca; }
.conversations-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  padding: 10px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
  margin-bottom: 4px; display: flex; align-items: center; gap: 8px;
}
.conv-item:hover { background: #313244; }
.conv-item.active { background: #45475a; }
.conv-item .conv-title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .delete-btn {
  display: none; background: none; border: none; color: #a6adc8; cursor: pointer;
  font-size: 14px; padding: 2px 4px; border-radius: 4px; flex-shrink: 0;
}
.conv-item:hover .delete-btn { display: block; }
.conv-item .delete-btn:hover { color: #f38ba8; background: #45475a; }
.conv-item .conv-date { font-size: 11px; color: #6c7086; }
.logout-btn {
  margin: 12px 16px; padding: 8px; background: transparent; color: #a6adc8;
  border: 1px solid #45475a; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.logout-btn:hover { background: #313244; }

/* Chat main area */
.chat-main { flex: 1; display: flex; flex-direction: column; background: #fff; }
.chat-header {
  padding: 16px 24px; border-bottom: 1px solid #e5e7eb; font-size: 16px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
/* EB360 connection status pill (top-right of chat header) */
.eb360-status {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 999px;
  font-size: 13px; font-weight: 500; color: #6b7280; cursor: pointer;
}
.eb360-status:hover { background: #e5e7eb; }
.eb360-status .eb360-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; flex-shrink: 0;
}
.eb360-status.connected { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
.eb360-status.connected:hover { background: #dcfce7; }
.eb360-status.connected .eb360-dot { background: #22c55e; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal {
  width: 380px; background: #fff; border-radius: 8px; padding: 28px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.modal h2 { font-size: 18px; margin-bottom: 6px; }
.modal p.subtitle { color: #666; font-size: 13px; margin-bottom: 18px; }
.modal label { display: block; font-size: 12px; color: #374151; margin-bottom: 4px; font-weight: 500; }
.modal input {
  width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 6px;
  font-size: 14px; margin-bottom: 14px; outline: none;
}
.modal input:focus { border-color: #4f46e5; }
.modal .error { color: #dc2626; font-size: 13px; margin-bottom: 12px; display: none; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.modal button {
  flex: 1; padding: 10px; border-radius: 6px; font-size: 14px; cursor: pointer; border: none;
}
.modal .btn-primary { background: #4f46e5; color: #fff; }
.modal .btn-primary:hover { background: #4338ca; }
.modal .btn-primary:disabled { background: #9ca3af; cursor: not-allowed; }
.modal .btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; }
.modal .btn-secondary:hover { background: #e5e7eb; }
.modal .btn-danger { background: #fff; color: #dc2626; border: 1px solid #fecaca; }
.modal .btn-danger:hover { background: #fef2f2; }
.messages {
  flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px;
}
.message { max-width: 720px; line-height: 1.6; font-size: 14px; }
.message.user {
  align-self: flex-end; background: #4f46e5; color: #fff; padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
}
.message.assistant {
  align-self: flex-start; background: #f3f4f6; color: #1f2937; padding: 10px 16px;
  border-radius: 16px 16px 16px 4px;
}
.message.assistant pre {
  background: #e5e7eb; padding: 8px 12px; border-radius: 4px; overflow-x: auto;
  margin: 8px 0; font-size: 13px;
}
.message.assistant code {
  background: #e5e7eb; padding: 2px 5px; border-radius: 3px; font-size: 13px;
}
.message.assistant pre code {
  background: none; padding: 0;
}
.message.assistant h1, .message.assistant h2, .message.assistant h3 {
  margin: 12px 0 6px 0; line-height: 1.3;
}
.message.assistant h1 { font-size: 18px; }
.message.assistant h2 { font-size: 16px; }
.message.assistant h3 { font-size: 15px; }
.message.assistant p { margin: 6px 0; }
.message.assistant ul, .message.assistant ol {
  margin: 6px 0; padding-left: 20px;
}
.message.assistant li { margin: 3px 0; }
.message.assistant table {
  border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px;
}
.message.assistant th, .message.assistant td {
  border: 1px solid #d1d5db; padding: 6px 10px; text-align: left;
}
.message.assistant th {
  background: #e5e7eb; font-weight: 600;
}
.message.assistant strong { font-weight: 600; }
.message.assistant hr { border: none; border-top: 1px solid #d1d5db; margin: 10px 0; }
.message.assistant blockquote {
  border-left: 3px solid #d1d5db; padding-left: 12px; margin: 6px 0; color: #6b7280;
}
.empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: #9ca3af; font-size: 15px;
}

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* Applied only to a freshly streamed answer, so loading a conversation's
   history does not animate every message at once. */
.message.arriving {
  animation: message-in 340ms ease-out;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Agent progress */
.progress {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 16px;
  max-width: 720px;
  align-self: stretch;
  font-size: 13px;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
}

/* Pulls back most of the 16px .messages gap so the summary sits just under
   the answer it belongs to. */
.progress.collapsed {
  display: block;
  padding: 0;
  margin-top: -12px;
}

.progress-rail {
  display: flex;
  align-items: center;
  height: 25px;
}

.progress-stage {
  position: relative;
  overflow: hidden;
  flex: 1;
}

.progress-branch {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  animation: branch-in 220ms ease-out;
}

.progress-branch .dur {
  color: #9ca3af;
  font-size: 0.667em;
}

.progress-branch .tick {
  color: #059669;
}

.progress-branch .tick.failed {
  color: #b91c1c;
}

.progress-branch.queued .label {
  color: #b0b6c0;
}

.progress-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.progress-dots span {
  width: 5px;
  height: 5px;
  background: #9ca3af;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.progress-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.progress-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

.progress-branch.pending .label {
  background: linear-gradient(
    90deg, #9ca3af 0%, #9ca3af 35%, #e5e7eb 50%, #9ca3af 65%, #9ca3af 100%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
  from {
    background-position: 110% 0;
  }
  to {
    background-position: -110% 0;
  }
}

.progress-block {
  animation: block-in 260ms ease-out;
}

/* Out of flow so the incoming block takes the same slot rather than
   stacking beneath it and snapping up when this one is removed. */
.progress-block.leaving {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  animation: block-out 240ms ease-in forwards;
}

.progress-summary {
  background: none;
  border: none;
  padding: 2px 8px;
  cursor: pointer;
  font: inherit;
  color: #6b7280;
  text-align: left;
}

.progress-summary:hover {
  color: #374151;
}

.progress-detail {
  padding-left: 16px;
}

.progress-error {
  color: #b91c1c;
  padding: 4px 0;
}

@keyframes branch-in {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes block-in {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes block-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(-100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-branch,
  .progress-block,
  .progress-block.leaving {
    animation: none;
  }
  .message.arriving {
    animation: none;
  }
  .progress-dots span {
    animation: none;
  }
  .progress-branch.pending .label {
    animation: none;
    background: none;
    -webkit-text-fill-color: #6b7280;
  }
}

/* Input area */
.input-area {
  padding: 16px 24px; border-top: 1px solid #e5e7eb; display: flex; gap: 12px;
}
.input-area input {
  flex: 1; padding: 10px 16px; border: 1px solid #d1d5db; border-radius: 8px;
  font-size: 14px; outline: none;
}
.input-area input:focus { border-color: #4f46e5; }
.input-area button {
  padding: 10px 20px; background: #4f46e5; color: #fff; border: none;
  border-radius: 8px; cursor: pointer; font-size: 14px;
}
.input-area button:hover { background: #4338ca; }
.input-area button:disabled { background: #9ca3af; cursor: not-allowed; }

/* Settings (cog) menu in the sidebar header */
.settings-menu { position: relative; flex-shrink: 0; }
.settings-btn {
  background: none; border: none; color: #a6adc8; font-size: 18px;
  cursor: pointer; padding: 4px 6px; border-radius: 6px; line-height: 1;
}
.settings-btn:hover { background: #313244; color: #cdd6f4; }
.settings-dropdown {
  position: absolute; right: 0; top: 34px; background: #313244;
  border: 1px solid #45475a; border-radius: 6px; min-width: 170px; padding: 4px;
  z-index: 20; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.settings-dropdown a {
  display: block; padding: 8px 10px; font-size: 13px; color: #cdd6f4;
  cursor: pointer; border-radius: 4px; text-decoration: none;
}
.settings-dropdown a:hover { background: #45475a; }
