/* ─── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --accent:       #6d5e97;
  --accent-soft:  rgba(109, 94, 151, 0.10);
  --accent-hover: rgba(109, 94, 151, 0.16);

  --bg-main:    #f2f2f7;
  --bg-card:    #ffffff;

  --text-main:  #1c1c1e;
  --text-muted: rgba(60, 60, 67, 0.6);

  --border:     rgba(0, 0, 0, 0.06);
  --separator:  rgba(60, 60, 67, 0.12);

  --radius-xl:   28px;
  --radius-lg:   20px;
  --radius-md:   14px;
  --radius-sm:   10px;
  --radius-pill: 9999px;

  --space-1:  4px;
  --space-2:  8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:      cubic-bezier(0, 0, 0.2, 1);
  --ease-standard: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --dur-fast:   180ms;
  --dur-normal: 300ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-main:   #000000;
    --bg-card:   #1c1c1e;
    --text-main: rgba(255, 255, 255, 1);
    --text-muted:rgba(235, 235, 245, 0.6);
    --border:    rgba(255, 255, 255, 0.08);
    --separator: rgba(84, 84, 88, 0.5);
  }
}

/* ─── Base ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: none;
}

button {
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Screen ─────────────────────────────────────────────────────────────── */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ─── Login ──────────────────────────────────────────────────────────────── */
.login-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  padding-bottom: max(var(--space-8), env(safe-area-inset-bottom));
  gap: var(--space-8);
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}

.login-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
}

.login-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border: 0.5px solid rgba(109, 94, 151, 0.2);
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-main);
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: -0.08px;
}

.login-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.field-password-wrap {
  position: relative;
}

.field-password-wrap .field-input {
  padding-right: 48px;
}

.btn-toggle-pass {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: color var(--dur-fast) var(--ease-out);
}

.btn-toggle-pass:hover { color: var(--accent); }
.btn-toggle-pass:active { opacity: 0.7; }

.login-error {
  font-size: 13px;
  color: #c62828;
  text-align: center;
  padding: var(--space-2) var(--space-3);
  background: rgba(198, 40, 40, 0.08);
  border-radius: var(--radius-sm);
}

/* ─── Card ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  padding: var(--space-5);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.04),
    0 2px 8px rgba(0, 0, 0, 0.04),
    0 8px 24px rgba(0, 0, 0, 0.05);
}

/* ─── Form Fields ────────────────────────────────────────────────────────── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.field-input {
  height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border);
  background: rgba(120, 120, 128, 0.08);
  color: var(--text-main);
  font-size: max(16px, 1em);
  font-family: inherit;
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  width: 100%;
}

.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-card);
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  height: 50px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: white;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.4px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
  box-shadow: 0 1px 4px rgba(109, 94, 151, 0.3);
}

.btn-primary:active {
  opacity: 0.75;
  transform: scale(0.98);
}

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

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Topbar icon button */
.btn-topbar-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  border: 0.5px solid rgba(0, 0, 0, 0.09);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), inset 0 0.5px 0 rgba(255,255,255,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--dur-fast) var(--ease-out);
  position: relative;
}

.btn-topbar-icon::before {
  content: "";
  position: absolute;
  inset: -6px;
}

.btn-topbar-icon:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(109, 94, 151, 0.2);
}

.btn-topbar-icon:active {
  opacity: 0.7;
  transform: scale(0.95);
}

/* ─── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px var(--space-6);
  padding-top: max(16px, env(safe-area-inset-top));
  padding-left: max(var(--space-6), env(safe-area-inset-left));
  padding-right: max(var(--space-6), env(safe-area-inset-right));
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  .topbar {
    background: rgba(28, 28, 30, 0.72);
    border-bottom-color: rgba(255, 255, 255, 0.08);
  }
  .btn-topbar-icon {
    background: rgba(44, 44, 46, 0.8);
    border-color: rgba(255, 255, 255, 0.1);
  }
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: -0.2px;
}

/* ─── Main Content ───────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: var(--space-6);
  padding-left: max(var(--space-6), env(safe-area-inset-left));
  padding-right: max(var(--space-6), env(safe-area-inset-right));
  padding-bottom: max(var(--space-8), env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ─── Query Card ─────────────────────────────────────────────────────────── */
.query-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.query-hint {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 0.5px solid rgba(109, 94, 151, 0.15);
  transition: all var(--dur-fast) var(--ease-out);
  text-transform: lowercase;
}

.mode-badge.passagem {
  background: rgba(48, 176, 199, 0.10);
  color: #1a8fa0;
  border-color: rgba(48, 176, 199, 0.2);
}

.hint-text {
  font-size: 12px;
  color: var(--text-muted);
}

.query-textarea {
  width: 100%;
  min-height: 110px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border);
  background: rgba(120, 120, 128, 0.06);
  color: var(--text-main);
  font-size: max(16px, 1em);
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

.query-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-card);
}

.query-textarea::placeholder {
  color: var(--text-muted);
}

.query-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.char-count {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.btn-query {
  width: auto;
  min-width: 120px;
  height: 40px;
  font-size: 15px;
  padding: 0 var(--space-5);
  flex-shrink: 0;
}

/* ─── Result Meta ────────────────────────────────────────────────────────── */
.result-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 var(--space-1);
}

.result-meta .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.5;
}

/* ─── Result Cards ───────────────────────────────────────────────────────── */
.result-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  overflow: hidden;
  animation: card-in var(--dur-normal) var(--ease-spring);
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.result-section {
  padding: var(--space-4) var(--space-5);
  border-bottom: 0.5px solid var(--separator);
}

.result-section:last-child {
  border-bottom: none;
}

.result-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06px;
  margin-bottom: var(--space-2);
}

.result-termo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.result-termo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

.result-definicao {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-main);
  letter-spacing: -0.2px;
}

.result-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-main);
}

.result-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.result-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 0.5px solid rgba(109, 94, 151, 0.15);
}

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 500;
}

.source-badge.laplanche {
  background: rgba(52, 199, 89, 0.10);
  color: #2e7d32;
  border: 0.5px solid rgba(52, 199, 89, 0.2);
}

.source-badge.expanded {
  background: rgba(255, 149, 0, 0.10);
  color: #b35900;
  border: 0.5px solid rgba(255, 149, 0, 0.2);
}

.result-error-card {
  padding: var(--space-5);
  background: rgba(198, 40, 40, 0.05);
  border-color: rgba(198, 40, 40, 0.15);
}

[hidden] { display: none !important; }

.result-error-text {
  font-size: 14px;
  color: #c62828;
  text-align: center;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .main-content {
    padding: var(--space-4);
    padding-bottom: max(var(--space-8), env(safe-area-inset-bottom));
  }
}

/* ─── Motion ─────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
