:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e1e4e8;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --gmail: #ea4335;
  --monday: #ff3d57;
  --success: #16a34a;
  --warning: #d97706;
  --error: #dc2626;
  --info: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,.07), 0 12px 24px rgba(0,0,0,.10);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 var(--border);
}

.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.user-chip { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 99px; padding: 4px 12px 4px 6px; }
.user-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.user-name { font-size: .82rem; font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Login overlay ───────────────────────────────────────────────────── */
.login-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  text-align: center;
  max-width: 380px;
  width: 100%;
}
.login-logo { font-size: 2rem; font-weight: 800; letter-spacing: -1px; margin-bottom: 16px; background: linear-gradient(135deg, var(--gmail), var(--monday)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 6px; }
.login-sub { color: var(--text-muted); font-size: .9rem; margin-bottom: 28px; }
.login-btn { display: inline-flex; align-items: center; padding: 12px 24px; font-size: .95rem; }
.login-note { margin-top: 20px; font-size: .75rem; color: var(--text-muted); }
.btn-lg { padding: 12px 28px; font-size: 1rem; }

.header-brand { display: flex; align-items: center; gap: 12px; }
.header-brand h1 { font-size: 1.25rem; font-weight: 700; }
.header-brand .badge {
  background: linear-gradient(135deg, var(--gmail), var(--monday));
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.status-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

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

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background .3s;
}
.dot.green { background: var(--success); box-shadow: 0 0 0 2px #bbf7d0; }
.dot.red   { background: var(--error);   box-shadow: 0 0 0 2px #fecaca; }
.dot.pulse {
  background: var(--warning);
  box-shadow: 0 0 0 2px #fde68a;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: .4; }
}

/* ── Main ─────────────────────────────────────────────────────────────── */
main { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }

/* ── Cards ───────────────────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

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

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

.card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }

.card-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.card-icon.pdf   { background: #fff1f1; color: var(--gmail); }
.card-icon.gmail { background: #fff1f1; color: var(--gmail); }

.card h2 { font-size: 1rem; font-weight: 700; }

.card > p {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

/* ── Drop zone ───────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  position: relative;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--gmail);
  background: #fff5f5;
}
.drop-zone.drag-over .drop-content { opacity: .4; }
.drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: rgba(234,67,53,.08);
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--gmail);
  font-size: .9rem;
}
.drop-zone.drag-over .drop-overlay { display: flex; }

.drop-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #f8f8f8;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 1.3rem;
  color: var(--text-muted);
}

.drop-zone p { font-size: .875rem; color: var(--text-muted); margin-bottom: 12px; }
.file-name { font-size: .8rem; color: var(--info); margin-top: 8px; font-weight: 500; }

/* ── Input group ─────────────────────────────────────────────────────── */
.input-group { display: flex; gap: 8px; margin-bottom: 20px; }
.input-group input { flex: 1; }

input[type="text"], input[type="url"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: var(--bg);
  color: var(--text);
}
input:focus {
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  background: #fff;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled):active { transform: scale(.97); }

.btn-primary  { background: var(--gmail);  color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-text      { background: transparent; color: var(--info); padding: 4px 8px; font-weight: 500; }
.btn-sm        { padding: 6px 14px; font-size: .8rem; }
.btn-full      { width: 100%; justify-content: center; }

/* ── Toggle ──────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.toggle-info strong { display: block; font-size: .875rem; margin-bottom: 2px; }
.toggle-info span   { font-size: .8rem; color: var(--text-muted); line-height: 1.5; }

.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

.polling-query-row {
  margin-top: 10px;
  display: none;
}
.polling-query-row.visible { display: block; }
.polling-query-row label { font-size: .75rem; color: var(--text-muted); display: block; margin-bottom: 4px; }

/* ── Log ─────────────────────────────────────────────────────────────── */
.log-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.log-header h3 { font-size: .9rem; font-weight: 700; }

.log-body {
  max-height: 340px;
  overflow-y: auto;
  padding: 8px 0;
}

.log-empty {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
}

.log-entry {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: .85rem;
  animation: slide-in .2s ease;
}
.log-entry:last-child { border-bottom: none; }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  flex-shrink: 0;
  margin-top: 1px;
}
.log-icon.ok  { background: #dcfce7; color: var(--success); }
.log-icon.err { background: #fee2e2; color: var(--error);   }
.log-icon.inf { background: #dbeafe; color: var(--info);    }

.log-text strong { display: block; }
.log-text time   { color: var(--text-muted); font-size: .78rem; }

/* ── Setup guide ─────────────────────────────────────────────────────── */
.setup-card {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  font-size: .875rem;
}
.setup-card h4 { margin-bottom: 8px; font-size: .9rem; color: #92400e; }
.setup-card ol { padding-left: 18px; color: #78350f; line-height: 2; }
.setup-card a  { color: var(--info); }

/* ── Alert ───────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: .875rem;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* ── Layout sections ──────────────────────────────────────────────────── */
.section { margin-bottom: 32px; }

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-header h2 { font-size: 1rem; font-weight: 700; margin-bottom: 2px; }
.section-desc { font-size: .85rem; color: var(--text-muted); }
.section-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Header right ─────────────────────────────────────────────────────── */
.header-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

/* ── Tracking cards ───────────────────────────────────────────────────── */
.tracking-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  transition: opacity .2s;
}
.tracking-card.paused { opacity: .65; }

.tracking-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.tracking-name { font-weight: 700; font-size: .95rem; margin-bottom: 2px; }
.tracking-subject { font-size: .85rem; color: var(--text-muted); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 480px; }
.tracking-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.meta-tag { font-size: .75rem; background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); padding: 1px 8px; border-radius: 99px; }
.meta-tag.mono { font-family: monospace; }
.meta-tag.muted { color: #bbb; }

.tracking-actions { display: flex; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }

.status-pill { font-size: .75rem; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.status-pill.active { background: #dcfce7; color: var(--success); }
.status-pill.paused { background: #f3f4f6; color: var(--text-muted); }
.status-pill.processing { background: #fef3c7; color: #d97706; animation: pill-pulse 1.6s ease-in-out infinite; }

@keyframes pill-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

/* ── Progress bar (background processing card) ───────────────────────── */
.progress-wrap { height: 6px; background: #e5e7eb; border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s ease; }
.progress-bar.progress-indeterminate { width: 40%; animation: indeterminate 1.4s ease-in-out infinite; }
.progress-pct { font-size: .72rem; color: var(--text-muted); margin-top: 4px; text-align: right; }

@keyframes indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

/* ── Empty state ──────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty-icon { font-size: 2rem; margin-bottom: 12px; }
.empty-sub  { font-size: .85rem; margin-top: 4px; }

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  padding: 24px;
  max-height: 90vh; overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-desc { font-size: .875rem; color: var(--text-muted); margin-bottom: 16px; line-height: 1.6; }
.modal-label { font-size: .85rem; font-weight: 600; margin: 16px 0 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.btn-icon { background: none; border: none; cursor: pointer; font-size: 1rem; color: var(--text-muted); padding: 4px; }

/* Thread preview box */
.thread-preview-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.preview-row { display: flex; gap: 12px; font-size: .875rem; margin-bottom: 4px; }
.preview-row:last-child { margin-bottom: 0; }
.preview-label { font-weight: 600; min-width: 60px; color: var(--text-muted); }

/* Radio options */
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-option { display: flex; align-items: center; gap: 8px; font-size: .875rem; cursor: pointer; }

/* ── AI badge & tipo tag ───────────────────────────────────────────────── */
.ai-badge {
  display: inline-block;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: .4px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.tipo-tag {
  font-size: .78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  background: #dbeafe;
  color: #1d4ed8;
}
.etapa-tag {
  font-size: .78rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}
.pendente-tag {
  font-size: .78rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}
select, .input-full {
  width: 100%;
}
select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--info); background: #fff; }

/* ── Thread search results ────────────────────────────────────────────── */
.thread-results {
  margin-top: 10px;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.thread-result {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.thread-result:hover { background: #f5f6ff; border-color: #c7c9ff; }
.thread-result.selected { border-color: var(--monday); background: #fff0f1; }
.thread-result-subject { font-weight: 600; font-size: .875rem; margin-bottom: 2px; }
.thread-result-meta { font-size: .75rem; color: var(--text-muted); margin-bottom: 2px; }
.thread-result-snippet { font-size: .74rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-searching, .thread-empty { font-size: .85rem; color: var(--text-muted); padding: 12px 0; text-align: center; }

/* ── Progress bar no log ──────────────────────────────────────────────── */
.progress-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin: 5px 0 4px;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--monday), #ff7b8a);
  border-radius: 99px;
  transition: width .4s ease;
}
