:root {
  color-scheme: dark;
  background: #0f172a;
  color: #e2e8f0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  padding: 24px;
  background: radial-gradient(circle at top, #172554 0%, #020617 100%);
}

.app-grid {
  width: min(1200px, 100%);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 24px;
  height: calc(100vh - 48px);
  min-height: 0;
}

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.12);
  min-height: 640px;
  max-height: calc(100vh - 48px);
  overflow: hidden;
}

.history-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}

.new-chat-btn {
  position: sticky;
  bottom: 0;
  margin-top: 8px;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  background: #2563eb;
  color: white;
  font-weight: 600;
  cursor: pointer;
  z-index: 2;
}

.new-chat-btn:hover {
  background: #1d4ed8;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.2);
  object-fit: contain;
  padding: 4px;
}

.brand-title-row h2 {
  margin: 0 0 2px;
  font-size: 1.1rem;
}

.brand-title-row p,
.brand-description {
  margin: 0;
  color: #94a3b8;
  font-size: 0.9rem;
}

.sidebar-header h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.sidebar-header p {
  margin: 0;
  color: #94a3b8;
  font-size: 0.95rem;
}

.history-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-item-row.is-deleting {
  opacity: 0.7;
}

.history-item-row .history-delete-btn {
  opacity: 0;
  visibility: hidden;
  transition: opacity 120ms ease, visibility 120ms ease;
}

.history-item-row:hover .history-delete-btn,
.history-item-row:focus-within .history-delete-btn {
  opacity: 1;
  visibility: visible;
}

.history-item,
.history-empty {
  width: 100%;
  display: block;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.12);
  color: #e2e8f0;
  text-align: left;
  font-size: 0.95rem;
  cursor: pointer;
}

.history-item:hover,
.history-item.active {
  border-color: #60a5fa;
  background: rgba(37, 99, 235, 0.12);
}

.history-delete-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.24);
  color: #fecaca;
  font-size: 1.1rem;
  cursor: pointer;
}

.history-delete-btn:hover {
  background: rgba(239, 68, 68, 0.34);
}

.history-delete-btn.is-deleting {
  background: rgba(239, 68, 68, 0.28);
  color: transparent;
}

.history-delete-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(254, 202, 202, 0.4);
  border-top-color: #fecaca;
  border-radius: 50%;
  display: inline-block;
  animation: history-delete-spin 0.8s linear infinite;
}

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

.history-empty {
  cursor: default;
  color: #94a3b8;
}

.app-shell {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 0;
}

.session-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.user-summary {
  color: #cbd5e1;
  font-size: 0.95rem;
}

#logout-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.2);
  color: #dbeafe;
  cursor: pointer;
}

#logout-btn:hover {
  background: rgba(37, 99, 235, 0.35);
}

.chat-window {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  padding: 24px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.12);
  overflow-y: auto;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border-radius: 18px;
  line-height: 1.6;
}

.message.user {
  align-self: flex-end;
  background: #1e293b;
}

.message.assistant {
  align-self: flex-start;
  background: #111827;
}

.message-label {
  font-size: 0.85rem;
  color: #94a3b8;
}

.message-text {
  white-space: pre-wrap;
}

.message-link {
  color: #93c5fd;
  word-break: break-word;
  text-decoration: underline;
}

.message-image-preview {
  margin-top: 12px;
}

.message-image-preview img {
  display: block;
  max-width: 100%;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.attachment-previews {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.attachment-previews .message-image-preview {
  width: 120px;
  height: 80px;
  overflow: hidden;
}

.attachment-previews .message-image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-form {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 14px;
  padding: 24px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.12);
  box-shadow: 0 -12px 30px rgba(2, 8, 23, 0.25);
  z-index: 3;
  flex-shrink: 0;
}

.chat-form label {
  font-size: 0.95rem;
  color: #cbd5e1;
}

.chat-form input[type="file"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: #e2e8f0;
}

.chat-form input[type="file"]::-webkit-file-upload-button {
  border: none;
  padding: 10px 14px;
  border-radius: 12px;
  background: #2563eb;
  color: white;
  cursor: pointer;
}

.chat-form input[type="file"]::-moz-file-upload-button {
  border: none;
  padding: 10px 14px;
  border-radius: 12px;
  background: #2563eb;
  color: white;
  cursor: pointer;
}

.chat-form textarea {
  width: 100%;
  min-height: 120px;
  padding: 14px;
  border-radius: 14px;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: #e2e8f0;
  resize: vertical;
}

.chat-form button {
  width: fit-content;
  padding: 12px 20px;
  border: none;
  border-radius: 14px;
  background: #2563eb;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.chat-form button:hover {
  background: #1d4ed8;
}

@media (max-width: 960px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }
}

.auth-shell {
  width: min(480px, 100%);
  min-height: calc(100vh - 48px);
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  padding: 32px;
  border-radius: 24px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: 0 20px 60px rgba(2, 8, 23, 0.35);
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #60a5fa;
}

.auth-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  font-size: 2rem;
}

.auth-title > a {
  display: flex;
  flex: 0 0 auto;
}

.auth-title img {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  object-fit: contain;
}

.auth-copy,
.small-print {
  color: #94a3b8;
  line-height: 1.6;
}

.status {
  min-height: 24px;
  margin: 16px 0 8px;
  color: #bfdbfe;
}

.status.error {
  color: #fda4af;
}

.provider-list {
  display: grid;
  gap: 12px;
  margin: 20px 0 16px;
}

.provider-button {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  padding: 14px 16px;
  border-radius: 14px;
  text-decoration: none;
  color: white;
  font-weight: 600;
}

.provider-button.github {
  background: #111827;
}

.provider-button.microsoft {
  background: #2563eb;
}

.provider-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
}

@media (max-width: 720px) {
  body {
    align-items: flex-start;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .session-panel {
    flex-wrap: wrap;
  }
}
