:root {
  --bg: #f8f7f4;
  --surface: #ffffff;
  --surface-subtle: #f1efe9;
  --border: #e2dfd7;
  --text: #1c2421;
  --text-muted: #5a6660;
  --primary: #0f5132;
  --primary-hover: #0b3d26;
  --primary-soft: #e6f2ec;
  --accent-yt: #b42318;
  --accent-yt-soft: #fef3f2;
  --error-bg: #fef2f2;
  --error-text: #991b1b;
  --info-bg: #eff6ff;
  --info-text: #1e40af;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 41, 29, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.urdu-text {
  font-family: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Inter", serif;
  direction: rtl;
  text-align: right;
  line-height: 2.25;
  font-size: 1.08rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  padding: 0.6rem 1.05rem;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn-link {
  background: transparent;
  color: var(--primary);
  padding: 0.25rem;
  font-weight: 500;
}

.btn-link:hover {
  text-decoration: underline;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid #fecaca;
}

.alert-info {
  background: var(--info-bg);
  color: var(--info-text);
  border: 1px solid #bfdbfe;
}

/* Auth View */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2rem;
}

.brand-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

.auth-title {
  margin: 0 0 0.4rem;
  font-size: 1.5rem;
}

.auth-subtitle,
.form-note {
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.field input,
textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.96rem;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 81, 50, 0.12);
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.logo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.topbar-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.quota-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
}

.quota-hint {
  font-size: 0.68rem;
  font-weight: 500;
  opacity: 0.85;
}

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

/* Main Workspace */
.workspace {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.25rem 2.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.25rem;
  align-items: start;
}

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

.ask-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.ask-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.ask-form textarea {
  resize: vertical;
  min-height: 88px;
}

.ask-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.char-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Loading */
.loading-card {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.loading-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.loading-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Answer Card */
.answer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.answer-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
}

.badge-cache {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-live {
  background: #fef3c7;
  color: #92400e;
}

.badge-muted {
  background: var(--surface-subtle);
  color: var(--text-muted);
}

.asked-echo {
  font-weight: 600;
  font-size: 1.02rem;
  margin-bottom: 0.9rem;
  color: var(--text);
}

.answer-body {
  font-size: 0.98rem;
  line-height: 1.72;
}

.answer-body p {
  margin: 0 0 0.75rem;
}

.answer-body p:last-child {
  margin-bottom: 0;
}

.answer-body ul {
  margin: 0.4rem 0 0.8rem;
  padding-inline-start: 1.35rem;
}

.answer-body li {
  margin-bottom: 0.35rem;
}

.answer-body a,
.inline-yt-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
  word-break: break-word;
}

.citations-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.citations-heading {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.citations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.65rem;
}

.citation-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  text-decoration: none;
  color: var(--text);
  font-size: 0.84rem;
}

.citation-card.is-youtube {
  border-color: #fecdca;
  background: var(--accent-yt-soft);
}

.citation-card.is-youtube:hover {
  border-color: var(--accent-yt);
}

.citation-kind {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
}

.citation-card.is-youtube .citation-kind {
  color: var(--accent-yt);
}

.citation-title {
  font-weight: 600;
  line-height: 1.35;
}

.citation-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.empty-state h2 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
}

.empty-state p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.93rem;
}

/* History Sidebar */
.history-card {
  padding: 1rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.history-header h2 {
  margin: 0;
  font-size: 0.98rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 68vh;
  overflow-y: auto;
}

.history-item {
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.history-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.history-q {
  font-size: 0.86rem;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-meta {
  margin-top: 0.3rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.history-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }
}
