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

:root {
  --bg:          #0f172a;
  --surface:     #1e293b;
  --surface-2:   #283548;
  --border:      #334155;
  --primary:     #3b82f6;
  --primary-h:   #2563eb;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --radius:      8px;
  --radius-lg:   12px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --transition:  .18s ease;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* ── Login page ──────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, #1e3a5f 0%, var(--bg) 70%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 48px 40px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

.logo-mark {
  width: 44px;
  height: 44px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-mark svg { color: #fff; }

.logo-text {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--text);
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-description {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
  line-height: 1.7;
}

.login-footer {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
}

.error-banner {
  background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.4);
  border-radius: var(--radius);
  color: #fca5a5;
  font-size: 13px;
  padding: 10px 14px;
  margin-bottom: 20px;
  display: none;
}

.error-banner.visible { display: block; }

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-lg   { padding: 13px 28px; font-size: 15px; }
.btn-full { width: 100%; }
.btn-sm   { padding: 6px 14px; font-size: 13px; }

/* ── Navbar ──────────────────────────────────── */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
}

.navbar-brand .logo-mark { width: 32px; height: 32px; border-radius: 7px; }

.navbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.user-avatar {
  width: 30px;
  height: 30px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

/* ── Layout ──────────────────────────────────── */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px;
}

.main-content {
  padding: 40px 0 80px;
}

.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Card ────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

/* ── Form ────────────────────────────────────── */
.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  padding: 10px 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

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

.form-group textarea { resize: vertical; min-height: 100px; }
.form-group select option { background: var(--surface); }

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

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

/* ── Spinner ─────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ── Results ─────────────────────────────────── */
#results { display: none; margin-top: 28px; }
#results.visible { display: block; }

.result-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.result-header h2 { font-size: 18px; font-weight: 700; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3px;
}

.badge-buy     { background: rgba(34,197,94,.15);  color: var(--success);  border: 1px solid rgba(34,197,94,.4); }
.badge-invest  { background: rgba(245,158,11,.15); color: var(--warning);  border: 1px solid rgba(245,158,11,.4); }
.badge-avoid   { background: rgba(239,68,68,.15);  color: var(--danger);   border: 1px solid rgba(239,68,68,.4); }

.risk-low  { background: rgba(34,197,94,.1);  color: var(--success); border: 1px solid rgba(34,197,94,.3); }
.risk-mid  { background: rgba(245,158,11,.1); color: var(--warning); border: 1px solid rgba(245,158,11,.3); }
.risk-high { background: rgba(239,68,68,.1);  color: var(--danger);  border: 1px solid rgba(239,68,68,.3); }

.value-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* standalone value-box fora de grid mantém espaçamento */
.result-metrics + * { margin-top: 16px; }

.value-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.value-number { font-size: 20px; font-weight: 700; color: var(--text); }

.result-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 600px) { .result-metrics { grid-template-columns: 1fr; } }

.value-box-profit {
  border-color: rgba(34,197,94,.4);
  background: rgba(34,197,94,.07);
  justify-content: space-between;
}

.value-box-profit .value-label { color: #86efac; }
.value-box-profit .value-number { color: var(--success); }

.profit-icon {
  color: var(--success);
  opacity: .6;
  flex-shrink: 0;
}

.reasoning-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 20px;
}

.reasoning-label {
  font-weight: 600;
  color: var(--text);
  margin-right: 6px;
}

.analysis-text {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.75;
  margin-bottom: 20px;
  white-space: pre-wrap;
}

.key-points-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.key-points-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.key-points-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

.key-points-list li::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 8px;
}

/* ── Highlights section ──────────────────────── */
#highlights-section { margin-bottom: 28px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
}

.section-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.btn-refresh:hover { background: var(--surface-2); color: var(--text); }
.btn-refresh.spinning #refresh-icon { animation: spin .7s linear infinite; }

/* Skeleton */
.highlights-skeleton {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.skeleton-card {
  height: 180px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  animation: shimmer 1.4s infinite;
}

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

/* Error / empty */
.highlights-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 14px;
}

/* Grid */
.highlights-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

/* Highlight card */
.highlight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.highlight-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(59,130,246,.2);
}

.highlight-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  flex-shrink: 0;
}

.source-receita   { background: rgba(34,197,94,.15);  color: #4ade80; }
.source-judicial  { background: rgba(245,158,11,.15); color: #fbbf24; }
.source-mega      { background: rgba(59,130,246,.15); color: #60a5fa; }
.source-bid       { background: rgba(168,85,247,.15); color: #c084fc; }
.source-zukerman  { background: rgba(239,68,68,.15);  color: #f87171; }
.source-bsb       { background: rgba(16,185,129,.15);  color: #34d399; }
.source-parque    { background: rgba(99,102,241,.15);  color: #818cf8; }
.source-correios  { background: rgba(251,191,36,.15);  color: #fbbf24; }
.source-default   { background: rgba(148,163,184,.15); color: var(--text-muted); }

.highlight-card-rec {
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.rec-buy    { color: var(--success); }
.rec-invest { color: var(--warning); }
.rec-avoid  { color: var(--danger); }

.highlight-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.highlight-reason {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
}

.highlight-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.highlight-chip {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.highlight-chip-loc {
  color: #67e8f9;
  background: rgba(103,232,249,.1);
}

.highlight-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn-analyze-item {
  flex: 1;
  padding: 8px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-analyze-item:hover { background: var(--primary-h); }

.btn-view-lot {
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background var(--transition), color var(--transition);
}

.btn-view-lot:hover { background: var(--border); color: var(--text); }

/* Responsive */
@media (max-width: 860px) {
  .highlights-grid,
  .highlights-skeleton { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 540px) {
  .highlights-grid,
  .highlights-skeleton { grid-template-columns: 1fr; }
  .section-title { font-size: 16px; }
  .skeleton-card { height: 140px; }
}

/* ── Fallback banner ─────────────────────────── */
.fallback-banner {
  background: rgba(245,158,11,.1);
  border: 1px solid rgba(245,158,11,.3);
  border-radius: var(--radius);
  color: var(--warning);
  font-size: 13px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

/* ── Share button ────────────────────────────── */
.btn-share {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 7px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-share:hover { background: var(--border); color: var(--text); }
.btn-share:active { transform: scale(.96); }

/* ── Toast ───────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #334155;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 999;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Mobile (≤ 540px) ────────────────────────── */
@media (max-width: 540px) {

  /* Evita zoom automático no iOS ao focar inputs */
  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px;
  }

  /* Safe area iOS (notch / home indicator) */
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* Login */
  .login-page { padding: 16px; align-items: flex-start; padding-top: 60px; }
  .login-card  { padding: 32px 20px; border-radius: var(--radius-lg); }
  .logo-text   { font-size: 24px; }
  .login-description { font-size: 13px; }

  /* Navbar */
  .navbar { padding: 0 16px; height: 56px; }
  .navbar-brand .logo-mark { width: 28px; height: 28px; }
  .navbar-brand { font-size: 16px; }
  #user-name { display: none; }          /* só o avatar em telas pequenas */
  .btn-sm    { padding: 8px 12px; }      /* touch target mínimo 44px */

  /* Layout */
  .container { padding: 0 12px; }
  .main-content { padding: 20px 0 64px; }

  /* Page header */
  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 20px; }
  .page-header p  { font-size: 13px; }

  /* Card */
  .card { padding: 16px; border-radius: var(--radius); }
  .card-title { font-size: 15px; margin-bottom: 16px; padding-bottom: 12px; }

  /* Form */
  .form-group { margin-bottom: 16px; }
  .form-group input,
  .form-group select {
    padding: 12px 14px;       /* touch target ≥ 44px */
    min-height: 44px;
  }
  .form-group textarea { min-height: 88px; }

  /* Submit: largura total em mobile */
  #submit-btn { width: 100%; justify-content: center; padding: 14px; font-size: 15px; }

  /* Results */
  .result-header { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 16px; }
  .result-header h2 { font-size: 16px; }
  .result-metrics { gap: 8px; margin-bottom: 12px; }
  .value-box { padding: 12px 14px; }
  .value-number { font-size: 17px; }
  .value-label { font-size: 11px; }

  .reasoning-box { font-size: 12px; padding: 10px 12px; }
  .analysis-text { font-size: 13px; }
  .key-points-list li { font-size: 13px; }

  /* Badge wrap */
  .badge { font-size: 12px; padding: 4px 10px; }

  /* Share: esconde label, mantém ícone */
  .share-label { display: none; }
  .btn-share { padding: 8px 10px; margin-left: 0; }

  /* Result header: badges + share na mesma linha */
  .result-header { display: grid; grid-template-columns: 1fr auto; row-gap: 8px; }
  .result-header h2 { grid-column: 1 / -1; }
  .result-header .badge:first-of-type { justify-self: start; }
}

/* ── Alert ───────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}

.alert.visible { display: block; }
.alert-error {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5;
}
