:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-bg: #eef2ff;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --yellow: #ca8a04;
  --yellow-bg: #fefce8;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 8px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

.hidden { display: none !important; }

/* ---- Auth screen ---- */
#authScreen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-box { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px; width: 340px; }
.auth-box h1 { font-size: 18px; margin: 0 0 4px; }
.auth-box p.sub { color: var(--text-muted); margin: 0 0 20px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff;
}
.field textarea { resize: vertical; min-height: 60px; }
.btn { border: none; border-radius: 8px; padding: 9px 14px; font-size: 13.5px; font-weight: 600; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.error-msg { color: var(--red); font-size: 12.5px; margin-top: 8px; }

/* ---- App shell ---- */
#appShell { display: flex; min-height: 100vh; }
.sidebar {
  width: 226px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px; flex-shrink: 0;
}
.brand { font-weight: 800; font-size: 15px; padding: 0 8px 18px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); }
.nav-item {
  display: flex; align-items: center; justify-content: space-between; padding: 9px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 13.5px; margin-bottom: 2px; font-weight: 500; background: none; border: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--primary-bg); color: var(--primary-dark); }
.nav-item .badge { font-size: 11px; background: var(--border); color: var(--text-muted); padding: 1px 7px; border-radius: 20px; font-weight: 700; }
.nav-item.active .badge { background: var(--primary); color: #fff; }
.nav-item .badge.alert { background: var(--red); color: #fff; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 4px; }
.sidebar-footer { margin-top: auto; padding: 8px; }
.sidebar-footer button { background: none; border: none; color: var(--text-muted); font-size: 12.5px; padding: 6px 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; align-items: center;
  padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-size: 17px; margin: 0; flex-shrink: 0; }
.search-box { flex: 1; max-width: 420px; }
.search-box input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 20px; font-size: 13px; }
.content { padding: 22px 26px; flex: 1; }

/* ---- Cards / board ---- */
.filters-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: #fff; padding: 6px 13px; border-radius: 20px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.empty-state { color: var(--text-muted); padding: 40px 0; text-align: center; font-size: 13.5px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 15px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 9px;
}
.card.card-alert { border-color: #fecaca; background: linear-gradient(180deg, var(--red-bg), #fff 40%); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-title { font-weight: 700; font-size: 14px; }
.card-sub { color: var(--text-muted); font-size: 12px; margin-top: 1px; }
.card-handle { color: var(--primary); font-size: 12.5px; font-weight: 600; }
.status-badge { font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }

.action-box { background: var(--bg); border-radius: 8px; padding: 9px 11px; font-size: 12.5px; }
.action-box .action-label { color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; font-weight: 700; letter-spacing: .03em; margin-bottom: 3px; }
.action-box .action-text { font-weight: 600; }
.msg-preview { background: #fff; border: 1px dashed var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--text-muted); max-height: 70px; overflow: hidden; }

.card-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.card-btns .btn { font-size: 12px; padding: 7px 10px; flex: 1; min-width: fit-content; }
.btn-ghost { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-success { background: var(--green-bg); color: var(--green); border: 1px solid #bbf7d0; }
.btn-warn { background: var(--yellow-bg); color: var(--yellow); border: 1px solid #fde68a; }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }
.card-footer { font-size: 11px; color: var(--text-muted); }
.card-open { background: none; border: none; color: var(--text-muted); font-size: 11px; text-decoration: underline; padding: 0; align-self: flex-start; }

/* ---- Dashboard ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .kpi-value { font-size: 22px; font-weight: 800; }
.kpi .kpi-label { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.section-title { font-size: 14px; font-weight: 700; margin: 26px 0 12px; }
.funil-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.funil-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.funil-row:last-child { border-bottom: none; }
.funil-row .fname { width: 160px; font-weight: 600; font-size: 12.5px; flex-shrink: 0; }
.funil-bar-wrap { flex: 1; background: var(--bg); border-radius: 6px; height: 20px; overflow: hidden; }
.funil-bar { background: var(--primary); height: 100%; border-radius: 6px; }
.funil-row .fval { width: 90px; text-align: right; font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

table.simple-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.simple-table th, table.simple-table td { text-align: left; padding: 10px 14px; font-size: 12.5px; border-bottom: 1px solid var(--border); }
table.simple-table th { background: var(--bg); color: var(--text-muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .02em; }
table.simple-table tr:last-child td { border-bottom: none; }

/* ---- Abordagens ---- */
.abordagem-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.abordagem-card .ab-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.abordagem-card .ab-metrics { display: flex; gap: 16px; margin-top: 10px; font-size: 11.5px; color: var(--text-muted); flex-wrap: wrap; }
.abordagem-card .ab-metrics b { color: var(--text); }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: var(--radius); width: 460px; max-width: 100%; max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close { background: none; border: none; font-size: 18px; color: var(--text-muted); }
.modal-body { padding: 18px 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.option-btn { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; margin-bottom: 8px; font-size: 13px; }
.option-btn:hover { background: var(--bg); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--border); position: relative; font-size: 12.5px; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline .t-date { color: var(--text-muted); font-size: 11px; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 13px; z-index: 100; box-shadow: var(--shadow); }

@media (max-width: 820px) {
  .sidebar { position: fixed; left: -240px; top: 0; bottom: 0; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; }
  .topbar { padding: 0 14px; }
  .content { padding: 16px; }
  .board-grid { grid-template-columns: 1fr; }
}
