/* Design tokens — paleta única e consistente (CLAUDE.md §6 — design system) */
:root {
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1f232f;
  --border: #2a2f3d;
  --text: #e6e8ee;
  --text-dim: #9aa3b2;
  --primary: #6366f1;
  --primary-hover: #5457e5;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

/* O atributo [hidden] deve sempre esconder, mesmo quando o elemento tem
   display:flex/grid no CSS (senão a tela de login não some após autenticar). */
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ----------------------------- Topbar ----------------------------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; }
.brand span { color: var(--primary); }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  background: none; border: none; color: var(--text-dim);
  padding: 8px 14px; border-radius: var(--radius); cursor: pointer;
  font-size: 14px; font-weight: 500; transition: all .15s;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: #fff; background: var(--primary); }

.btn-primary {
  margin-left: auto;
  background: var(--primary); color: #fff; border: none;
  padding: 9px 16px; border-radius: var(--radius); cursor: pointer;
  font-weight: 600; font-size: 14px; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-hover); }

/* ------------------------------ Layout ---------------------------- */
#app { padding: 24px; max-width: 1400px; margin: 0 auto; }
.loading { color: var(--text-dim); text-align: center; padding: 60px; }
.view-title { font-size: 22px; margin-bottom: 18px; font-weight: 700; }
.section-title { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; margin: 24px 0 12px; }

/* ------------------------------ Cards ----------------------------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.stat-card .label { color: var(--text-dim); font-size: 13px; }
.stat-card .value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.stat-card.alert .value { color: var(--danger); }
.stat-card.warn .value { color: var(--warn); }
.stat-card.ok .value { color: var(--success); }

/* --------------------------- Pipeline ----------------------------- */
.board { display: grid; grid-template-columns: repeat(6, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-height: 120px; }
.column-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .4px; }
.column-head .count { background: var(--surface-2); border-radius: 20px; padding: 1px 8px; }
.lead-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: border-color .15s, transform .08s;
}
.lead-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.lead-card .name { font-weight: 600; font-size: 14px; }
.lead-card .meta { font-size: 12px; color: var(--text-dim); margin-top: 3px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ------------------------------ Badges ---------------------------- */
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.src-instagram { background: #4324; color: #ec4899; }
.src-linkedin { background: #0a66c224; color: #4aa3ff; }
.src-whatsapp { background: #25d36622; color: #25d366; }
.src-manual, .src-outro { background: var(--surface-2); color: var(--text-dim); }

/* ----------------------------- Agenda ----------------------------- */
.agenda-group { margin-bottom: 24px; }
.fu-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px;
}
.fu-item.overdue { border-left: 3px solid var(--danger); }
.fu-item.today { border-left: 3px solid var(--warn); }
.fu-item .fu-main { flex: 1; cursor: pointer; }
.fu-item .fu-name { font-weight: 600; }
.fu-item .fu-note { font-size: 13px; color: var(--text-dim); }
.fu-date { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.check { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--border); background: none; cursor: pointer; color: var(--success); font-weight: 700; }
.check:hover { border-color: var(--success); }

/* ------------------------------ Forms ----------------------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; color: var(--text); font-size: 14px; font-family: var(--font);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 70px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* --------------------- Modal / Drawer / Toast --------------------- */
.modal, .drawer { position: fixed; inset: 0; z-index: 100; }
.modal-overlay, .drawer-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal-box {
  position: relative; max-width: 480px; margin: 8vh auto 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
}
.drawer-panel {
  position: absolute; right: 0; top: 0; height: 100%; width: min(480px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 24px; overflow-y: auto; box-shadow: var(--shadow);
}
.modal h2, .drawer h2 { font-size: 18px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); padding: 9px 16px; border-radius: var(--radius); cursor: pointer; font-weight: 600; }
.btn-ghost:hover { border-color: var(--text-dim); }
.btn-danger { background: none; color: var(--danger); border: 1px solid var(--danger); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.btn-danger:hover { background: var(--danger); color: #fff; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: var(--radius); box-shadow: var(--shadow); z-index: 200; font-size: 14px;
}
.toast.error { border-color: var(--danger); color: #fca5a5; }
.toast.success { border-color: var(--success); color: #86efac; }

/* --------------------------- Drawer detail ------------------------ */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-meta { font-size: 13px; color: var(--text-dim); margin: 6px 0 16px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.timeline-item { border-left: 2px solid var(--border); padding: 0 0 14px 14px; position: relative; }
.timeline-item::before { content: ''; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline-item .ti-type { font-size: 12px; color: var(--primary); font-weight: 600; text-transform: uppercase; }
.timeline-item .ti-content { font-size: 14px; }
.timeline-item .ti-date { font-size: 11px; color: var(--text-dim); }
.empty { color: var(--text-dim); font-size: 13px; padding: 8px 0; }
.inline-form { display: flex; gap: 8px; margin: 8px 0 4px; }
.inline-form input, .inline-form select { flex: 1; }

/* ------------------------------ Login ----------------------------- */
.login-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.login-brand { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 24px; }
.login-brand span { color: var(--primary); }
.login-submit { width: 100%; margin-top: 6px; }
.login-error { color: #fca5a5; font-size: 13px; margin-top: 12px; text-align: center; }

/* ------------------------- Seletor de cliente --------------------- */
.client-picker select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px; font-size: 14px; font-weight: 600; max-width: 220px;
}
.client-picker select:focus { outline: none; border-color: var(--primary); }
#btn-logout { margin-left: 8px; padding: 8px 12px; }

/* --------------------- Ações diárias (Hoje) ----------------------- */
.daily-date { color: var(--text-dim); font-size: 14px; margin-bottom: 18px; }
.action-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px;
}
.action-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.action-name { font-weight: 600; }
.action-controls { display: flex; align-items: center; gap: 8px; }
.action-controls button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 16px; cursor: pointer; font-weight: 700; }
.action-controls button:hover { border-color: var(--primary); }
.action-controls input { width: 56px; text-align: center; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 6px; font-size: 14px; }
.action-target { color: var(--text-dim); font-size: 13px; min-width: 64px; text-align: right; }
.progress { height: 8px; background: var(--surface-2); border-radius: 20px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .25s; }
.progress > div.done { background: var(--success); }
.daily-summary { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------------------------- Clientes ---------------------------- */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.client-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.client-card h3 { font-size: 16px; margin-bottom: 4px; }
.client-card .cc-meta { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }
.client-card .cc-actions { display: flex; gap: 8px; }
.goal-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.goal-row label { flex: 1; font-size: 14px; }
.goal-row input { width: 80px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 7px; text-align: center; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* Tipos de ação + gatilhos */
.type-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.trigger-label { font-size: 12px; color: var(--text-dim); margin: 6px 0 6px; }
.trigger-list { display: flex; flex-direction: column; gap: 6px; }
.trigger-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.trigger-chip input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.auto-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; background: rgba(99,102,241,.18); color: #a5b4fc; padding: 1px 6px; border-radius: 20px; vertical-align: middle; }

/* ----------------------------- Relatório -------------------------- */
.report-controls { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.report-controls .field { margin-bottom: 0; }
.report-actions { display: flex; gap: 10px; margin: 18px auto 0; max-width: 820px; }

/* Folha do relatório: documento claro (boa leitura e impressão limpa em PDF) */
.report-sheet { background: #fff; color: #1f2430; max-width: 820px; margin: 0 auto; padding: 40px; border-radius: var(--radius); box-shadow: var(--shadow); }
.report-head { border-bottom: 2px solid #e5e7eb; padding-bottom: 16px; margin-bottom: 22px; }
.report-title { font-size: 22px; font-weight: 800; color: #4f46e5; }
.report-sub { font-size: 14px; color: #4b5563; margin-top: 4px; }
.report-section { margin-bottom: 24px; }
.report-section h3 { font-size: 15px; color: #111827; margin-bottom: 10px; border-left: 3px solid #6366f1; padding-left: 8px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.report-table th, .report-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #e5e7eb; }
.report-table th { color: #6b7280; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.report-table td { color: #1f2937; }
.report-kpi { font-size: 14px; color: #374151; margin-top: 10px; }
.report-table tr.report-total td { border-top: 2px solid #d1d5db; color: #4f46e5; }
.commission-won { color: var(--success); font-weight: 700; }

@media print {
  body { background: #fff !important; }
  body * { visibility: hidden; }
  .report-sheet, .report-sheet * { visibility: visible; }
  .report-sheet { position: absolute; left: 0; top: 0; width: 100%; max-width: none; box-shadow: none; border-radius: 0; padding: 0; }
  .no-print, .topbar, #toast { display: none !important; }
}

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .btn-primary, #btn-logout { margin-left: 0; }
  .board { grid-template-columns: 1fr; }
  .client-picker select { max-width: 100%; }
  .report-sheet { padding: 24px; }
}
