:root {
  --primary-hue: 220;
  --primary-color: hsl(var(--primary-hue), 85%, 55%);
  --primary-hover: hsl(var(--primary-hue), 85%, 45%);
  --secondary-color: #64748b;
  --background-bg: #f8fafc;
  --surface-white: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --radius-lg: 12px;
  --nav-height: 70px;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
  height: auto;
  min-height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--background-bg);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-y: auto; /* Enable vertical scroll */
  overflow-x: hidden;
}

/* Nav Bar - Consistent Size */
nav {
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  height: var(--nav-height);
  min-height: var(--nav-height);
  max-height: var(--nav-height);
  padding: 0 2rem;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
}

.nav-left,
.nav-center,
.nav-right {
  display: flex;
  align-items: center;
  min-width: 0;
}

.nav-left {
  flex: 1;
}

.nav-center {
  flex: 0 1 auto;
  justify-content: center;
  gap: 0.5rem;
}

.nav-right {
  flex: 1;
  justify-content: flex-end;
  gap: 0.5rem;
}

.logo-link {
  text-decoration: none;
  display: flex;
  align-items: center;
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: transparent;
  background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
  -webkit-background-clip: text;
  background-clip: text;
  letter-spacing: -0.03em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 100%;
}

.nav-links a,
.nav-links button {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.9rem;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-links button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.nav-links a:hover,
.nav-links button:hover {
  color: var(--primary-color);
  background-color: rgba(59, 130, 246, 0.06);
}

.nav-links a.active,
.nav-links button.active {
  color: var(--primary-color);
  background-color: rgba(59, 130, 246, 0.1);
}

#logout-link:hover {
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.06);
}

.user-menu {
  position: relative;
  display: flex;
  align-items: center;
}

#user-menu-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
}

#user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.12);
  color: var(--primary-color);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.user-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  background: var(--surface-white);
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: var(--shadow-md);
  border-radius: 12px;
  padding: 12px;
  min-width: 220px;
  display: none;
  flex-direction: column;
  gap: 6px;
  z-index: 1200;
}

.user-menu-dropdown.show {
  display: flex;
}

.user-menu-name {
  font-weight: 700;
  color: var(--text-main);
}

.user-menu-email {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.user-menu-dropdown button {
  margin-top: 8px;
  width: 100%;
  border: none;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.user-menu-dropdown button:hover {
  background: #fecaca;
}

.status-valid::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 4px;
  border-left: 2px solid #059669;
  border-bottom: 2px solid #059669;
  transform: rotate(-45deg);
  margin-right: 6px;
  margin-bottom: 1px;
}

/* Page Containers */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.container {
  padding: 2.5rem 2rem;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

.admin-page {
  padding: 1.25rem 2rem 2rem;
  line-height: 1.25;
}

.admin-page h2 {
  margin: 0 0 1rem;
  font-size: 1.45rem;
  line-height: 1.2;
}

.admin-page .config-section {
  padding: 1.2rem;
  margin-bottom: 1rem;
}

.admin-page .config-section h3 {
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  line-height: 1.2;
}

.admin-page .form-group {
  margin-bottom: 0.75rem;
}

.admin-page .form-group label {
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
}

.admin-page .form-group input,
.admin-page .form-group select {
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
}

.admin-page p {
  margin-bottom: 0.5rem;
  line-height: 1.25;
}

.admin-page .form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: end;
}

.admin-page .form-row .form-group {
  margin-bottom: 0;
}

.admin-page .form-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.drive-auth-block {
  padding: 10px;
  background: #f1f5f9;
  border-radius: 12px;
}

.drive-auth-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.drive-auth-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 6px 0 0;
}

.status-inline {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.admin-page .form-row-contents {
  display: contents;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.admin-left,
.admin-right {
  min-width: 0;
}

.admin-right {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.admin-save-panel {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  justify-content: center;
}

.admin-save-panel button {
  width: 100%;
  min-width: 0;
  padding: 0.75rem 1.6rem;
}

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

/* Chat-specific container */
.chat-page-container {
  padding: 1rem 2rem;
  min-height: calc(100vh - var(--nav-height) - 140px);
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: 1000px;
  margin: 0 auto;
}

/* Chat Component - Locked Height */
#chat-container {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  background: var(--surface-white);
  border-radius: 1.5rem;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(226, 232, 240, 0.8);
  height: 650px;
  max-height: 75vh;
}

#chat-history {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.message {
  padding: 0.8rem 1.4rem;
  border-radius: 1.25rem;
  max-width: 75%;
  line-height: 1.6;
  font-size: 0.95rem;
  animation: slideUp 0.3s ease-out;
}

.chat-redirect-toast {
  position: fixed;
  top: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: #fef3c7;
  color: #92400e;
  border: 1px solid rgba(234, 179, 8, 0.5);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  font-weight: 600;
  z-index: 1200;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.user-message {
  background: linear-gradient(135deg, var(--primary-color), #3b82f6);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 0.25rem;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.bot-message {
  background-color: #f1f5f9;
  color: var(--text-main);
  align-self: flex-start;
  border-bottom-left-radius: 0.25rem;
}

.bot-message p {
  margin: 0.4rem 0;
}

.bot-message ul,
.bot-message ol {
  margin: 0.4rem 0 0.4rem 1.2rem;
  padding: 0;
}

.bot-message li {
  margin: 0.2rem 0;
}

.bot-message a {
  color: var(--primary-color);
  text-decoration: underline;
}

.bot-message code {
  background: rgba(15, 23, 42, 0.08);
  border-radius: 6px;
  padding: 0.1rem 0.3rem;
  font-size: 0.85em;
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

.bot-message pre {
  background: #0f172a;
  color: #f8fafc;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

.bot-message pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

#input-area {
  padding: 1.5rem;
  background: white;
  border-top: 1px solid #f1f5f9;
  display: flex;
  gap: 12px;
}

#user-input {
  flex: 1;
  padding: 0.9rem 1.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 9999px;
  outline: none;
  font-size: 0.95rem;
  transition: all 0.2s;
  background-color: #f8fafc;
}

#user-input:focus {
  border-color: var(--primary-color);
  background-color: white;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 0.9rem 1.8rem;
  border-radius: 9999px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3);
}

button:hover {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 15px -3px rgba(59, 130, 246, 0.4);
}

button:active {
  transform: translateY(0);
}

/* Auth & Forms */
.auth-form {
  max-width: 480px;
  margin: 5rem auto;
  padding: 3.5rem;
  background: white;
  border-radius: 2rem;
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(226, 232, 240, 0.8);
  text-align: center;
}

.auth-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 1.5rem;
  background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 2rem;
  font-weight: 800;
  box-shadow: 0 10px 20px -5px rgba(59, 130, 246, 0.4);
}

.auth-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  margin: 0 0 1rem;
  letter-spacing: -0.02em;
}

.auth-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 2.5rem;
}

.nav-logo {
  height: 32px;
  width: 32px;
  margin-right: 12px;
  border-radius: 8px;
}

.auth-logo-img {
  width: 80px;
  height: 80px;
  margin: 0 auto 1.5rem;
  display: block;
  border-radius: 16px;
  box-shadow: 0 10px 20px -5px rgba(59, 130, 246, 0.4);
}

.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: white;
  color: #374151;
  border: 1px solid #e5e7eb;
  padding: 0.8rem 1.5rem;
  font-weight: 600;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  transition: all 0.2s;
}

.google-btn:hover {
  background: #f9fafb;
  border-color: #d1d5db;
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.google-btn svg {
  width: 20px;
  height: 20px;
}

.config-notice {
  margin: 0 auto 1rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid rgba(234, 179, 8, 0.5);
  font-size: 0.9rem;
  font-weight: 600;
}

.config-notice.success {
  background: #dcfce7;
  color: #166534;
  border-color: rgba(34, 197, 94, 0.4);
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: block;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.8rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.95rem;
  background: #fcfcfc;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Config Section */
.config-section {
  background: white;
  padding: 2rem;
  margin-bottom: 2rem;
  border-radius: 1.25rem;
  border: 1px solid #e2e8f0;
}

.config-section h3 {
  margin-top: 0;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #f1f5f9;
}

.app-toast {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  padding-top: 5vh;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.app-toast-body {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text-main);
  border: 1px solid rgba(226, 232, 240, 0.8);
  padding: 20px;
  border-radius: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1),
    0 8px 10px -6px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05);
  max-width: 480px;
  width: calc(100% - 40px);
  transform: translateY(0);
  animation: slideDown 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.app-toast-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #fee2e2;
  color: #ef4444;
}

.app-toast-body.success .app-toast-icon {
  background: #dcfce7;
  color: #22c55e;
}

.app-toast-icon svg {
  width: 24px;
  height: 24px;
}

.app-toast-content {
  flex: 1;
  padding-top: 2px;
}

#app-toast-message {
  font-size: 0.95rem;
  line-height: 1.5;
  font-weight: 500;
  color: #1e293b;
  display: block;
}

.app-toast-body button {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: none;
  align-self: center;
}

.app-toast-body button:hover {
  background: #e2e8f0;
  color: #1e293b;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.app-toast-body button:active {
  transform: translateY(0);
}

/* Specific error styling for message if needed */
.app-toast-body:not(.success) {
  border-left: 4px solid #ef4444;
}

.app-toast-body.success {
  border-left: 4px solid #22c55e;
}

/* Google Drive Folder Row */
.folder-row {
  background: #f8fafc;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  transition: all 0.2s;
}

.folder-row:hover {
  background: #fff;
  border-color: var(--primary-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.folder-row input:disabled {
  background: transparent !important;
  border-color: transparent !important;
  color: var(--text-main);
  font-weight: 600;
  cursor: default;
}

#drive-folders-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.drive-test-results ul,
.drive-test-results li {
  word-break: break-word;
  overflow-wrap: anywhere;
}
/* Footer */
.app-footer {
  margin-top: auto;
  padding: 2rem 1rem;
  background: white;
  border-top: 1px solid #e2e8f0;
  text-align: center;
}

.footer-content {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--primary-color);
}

.footer-copyright {
  color: var(--text-muted);
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .app-footer {
    padding: 1.5rem 1rem;
  }

  .footer-links {
    gap: 1rem;
  }
}
