/* ===========================================================================
   CRM Helpe — estilos
   Tema claro por padrão, escuro automático conforme a preferência do sistema.

   As cores da marca saíram da própria logo:
     ciano #4FCEE9  →  azul #1480D8  →  azul escuro #0057DC
   =========================================================================== */

:root {
  --bg:          #f4f7fa;
  --surface:     #ffffff;
  --surface-2:   #eef3f8;
  --border:      #dde5ed;
  --text:        #14202c;
  --muted:       #5d6e7e;
  --brand:       #0f72ce;
  --brand-soft:  #e3f1fb;
  --brand-text:  #0a5397;
  --grad-1:      #4fcee9;
  --grad-2:      #1480d8;
  --grad-3:      #0057dc;
  --serie-receita: #1480d8;   /* validado: ΔE 33,5 normal · 24,2 protan */
  --serie-despesa: #eb6834;
  --ok:          #1f7a4d;
  --ok-soft:     #e2f3e9;
  --warn:        #8c6410;
  --warn-soft:   #fbf1da;
  --danger:      #b3453d;
  --danger-soft: #fbe6e4;
  --shadow:      0 1px 2px rgba(16, 32, 48, .06), 0 8px 24px rgba(16, 32, 48, .07);
  --radius:      12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #101720;
    --surface:     #171f2a;
    --surface-2:   #1e2836;
    --border:      #2a3646;
    --text:        #e7eef6;
    --muted:       #90a1b4;
    --brand:       #4fb8ea;
    --brand-soft:  #10283d;
    --brand-text:  #7fd3f2;
    --serie-receita: #4295ea;   /* re-escalonado para o fundo escuro */
    --serie-despesa: #e06a33;
    --ok:          #63c294;
    --ok-soft:     #152b22;
    --warn:        #e0b45c;
    --warn-soft:   #2e2716;
    --danger:      #e08a83;
    --danger-soft: #331d1b;
    --shadow:      0 1px 2px rgba(0, 0, 0, .34), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ===================== Tela de entrada ===================== */
.gate {
  position: fixed; inset: 0; z-index: 500;
  background: var(--bg);
  display: grid; place-items: center; padding: 24px;
}
/* Sem isto o `display: grid` acima vence o `hidden` (que vem da folha do
   navegador) e a tela de entrada continua cobrindo o sistema já montado. */
.gate[hidden] { display: none; }
.gate-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: 38px 34px; text-align: center; max-width: 380px; width: 100%;
}
.gate-logo { height: 58px; width: auto; margin-bottom: 18px; }
.gate-title { margin: 0; font-size: 21px; font-weight: 680; letter-spacing: -.02em; }
.gate-sub { margin: 7px 0 24px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.gate-btn { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }
.gate-btn[hidden] { display: none; }

/* Espera: enquanto o app confere a sessão ou carrega os dados */
.gate-espera {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px; font-size: 14px; color: var(--muted);
}
.gate-espera[hidden] { display: none; }
.girador {
  width: 16px; height: 16px; flex-shrink: 0; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--brand);
  animation: girar .7s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .girador { animation-duration: 2.4s; } }
.gate-erro { margin: 16px 0 0; font-size: 13px; color: var(--danger); line-height: 1.5; }
.gate-erro:empty { display: none; }
.gate-diag {
  margin: 16px 0 0; padding: 10px; text-align: left;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted); background: var(--surface-2);
  border-radius: 8px; max-height: 190px; overflow: auto; white-space: pre-wrap;
}
.gate-diag:empty { display: none; }
.gate-diag[hidden] { display: none; }

/* ===================== Layout ===================== */
.app { display: flex; min-height: 100vh; }
.app[hidden] { display: none; }

.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 22px; }
.brand-logo { height: 30px; width: auto; display: block; flex-shrink: 0; }
.brand-name { font-weight: 680; letter-spacing: -.015em; font-size: 17px; }
.brand-name-sub {
  font-weight: 600; font-size: 11px; letter-spacing: .07em;
  color: var(--brand); margin-left: 5px; vertical-align: 2px;
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center;
  padding: 9px 13px; border-radius: 9px;
  border: none; background: none; width: 100%;
  color: var(--muted); font: inherit; text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item--on {
  background: var(--brand-soft); color: var(--brand-text); font-weight: 600;
  position: relative;
}
/* Filete com as cores da logo marcando a aba aberta */
.nav-item--on::before {
  content: ''; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, var(--grad-1), var(--grad-3));
}
.nav-count {
  margin-left: auto; font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--muted); background: var(--surface-2);
  padding: 1px 7px; border-radius: 20px;
}
.nav-item--on .nav-count { background: var(--surface); color: var(--brand-text); }

.sidebar-foot { margin-top: auto; padding-top: 14px; }
.sync {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-radius: 9px; background: var(--surface-2);
  cursor: pointer; width: 100%; border: none; text-align: left;
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.sync-dot--on   { background: var(--ok); }
.sync-dot--err  { background: var(--danger); }
.sync-text { line-height: 1.35; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 22px 26px 16px;
}
.page-title { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.02em; }
.page-sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

.content { padding: 0 26px 40px; }

/* ===================== Componentes ===================== */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-size: 14px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { background: var(--surface-2); }
/* Gradiente da logo. Começa num azul escuro o bastante para o texto branco
   passar em contraste AA (4.7:1) — o ciano da marca fica para os enfeites. */
.btn--primary {
  background: linear-gradient(135deg, #1275cc, #0b57cc);
  border-color: transparent; color: #fff;
}
.btn--primary:hover { filter: brightness(1.09); }
.btn--danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn--ghost { border-color: transparent; background: none; color: var(--muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

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

.grid { display: grid; gap: 14px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.stat { padding: 15px 17px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 25px; font-weight: 650; margin-top: 5px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-note { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat-value--ok { color: var(--ok); }
.stat-value--danger { color: var(--danger); }

.section-title { font-size: 14px; font-weight: 650; margin: 26px 0 11px; }

/* Barra de filtros */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.input, .select, .textarea {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 11px; border-radius: 9px; font: inherit; font-size: 14px;
  width: 100%; min-width: 0;
}
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.textarea { resize: vertical; min-height: 66px; }
.search { max-width: 280px; }
.filters .select { width: auto; }

/* Tabela */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.num    { text-align: right;  font-variant-numeric: tabular-nums; white-space: nowrap; }
.centro { text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num    { text-align: right; }
th.centro { text-align: center; }
.linha-projecao td { opacity: .62; }
.cell-strong { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); }

/* Etiquetas de status */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.tag--ok     { background: var(--ok-soft);     color: var(--ok); }
.tag--warn   { background: var(--warn-soft);   color: var(--warn); }
.tag--danger { background: var(--danger-soft); color: var(--danger); }
.tag--brand  { background: var(--brand-soft);  color: var(--brand-text); }

/* Funil (kanban) */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.column {
  flex: 0 0 232px; background: var(--surface-2);
  border-radius: var(--radius); padding: 10px; min-height: 120px;
}
.column--over { outline: 2px dashed var(--brand); outline-offset: -2px; }
.column-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 9px; padding: 0 3px; }
.column-name { font-size: 13px; font-weight: 650; }
.column-sum { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.deal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 11px; margin-bottom: 8px; cursor: grab;
}
.deal:hover { border-color: var(--brand); }
.deal--drag { opacity: .45; }
.deal-title { font-weight: 600; font-size: 14px; }
.deal-client { font-size: 12px; color: var(--muted); margin-top: 1px; }
.deal-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; }
.deal-value { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 14px; }

/* Vazio */
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-title { font-weight: 600; color: var(--text); margin: 0 0 5px; font-size: 15px; }
.empty-text { font-size: 14px; margin: 0 0 16px; }

/* Modal */
.overlay {
  position: fixed; inset: 0; background: rgba(9, 18, 17, .45);
  /* acima da tela de entrada (500), senão avisos importantes ficam escondidos */
  display: grid; place-items: center; padding: 20px; z-index: 600;
  animation: fade .14s ease;
}
.modal {
  background: var(--surface); border-radius: 15px; box-shadow: var(--shadow);
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  padding: 22px 24px; animation: pop .16s ease;
}
.modal--wide { max-width: 660px; }
.modal-title { margin: 0 0 3px; font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.modal-sub { margin: 0 0 18px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }
.modal-actions .btn--danger { margin-right: auto; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } }

/* Formulário */
.field { margin-bottom: 13px; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ===================== Gráficos =====================
   As duas cores de série passaram no validador de daltonismo nos dois temas.
   Não trocar por verde/vermelho: é justamente o par que some para quem tem
   deficiência de visão de cores. */
.gr { display: flex; flex-direction: column; }
.gr-titulo { font-size: 14px; font-weight: 650; margin-bottom: 2px; }
.gr-legenda { display: flex; gap: 14px; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.gr-leg-item { display: inline-flex; align-items: center; gap: 6px; }
.gr-leg-cor { width: 9px; height: 9px; border-radius: 2px; }
.gr-palco { position: relative; width: 100%; }
.gr-svg { width: 100%; height: auto; display: block; overflow: visible; }
.gr-grade { stroke: var(--border); stroke-width: 1; }
.gr-zero  { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; }
.gr-eixo  { fill: var(--muted); font-size: 10.5px; font-family: inherit; }
.gr-linha { fill: none; stroke: var(--serie-receita); stroke-width: 2;
            stroke-linejoin: round; stroke-linecap: round; }
.gr-area  { fill: var(--serie-receita); opacity: .13; }
.gr-ponto { fill: var(--serie-receita); stroke: var(--surface); stroke-width: 2; }
.gr-alvo  { cursor: default; }
.gr-eixo--fraco { opacity: .65; }
.gr-divisor { stroke: var(--border); stroke-width: 1; stroke-dasharray: 4 4; }
.gr-linha--proj { stroke-dasharray: 5 4; opacity: .75; }
.gr-ponto--proj { opacity: .5; }
.gr-nota  { font-size: 12px; color: var(--muted); margin: 10px 2px 0; line-height: 1.5; }

.dica {
  display: none; position: absolute; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 8px 11px; border-radius: 9px; font-size: 12px;
  pointer-events: none; white-space: nowrap; z-index: 5; box-shadow: var(--shadow);
}
.dica-linha { display: flex; align-items: center; gap: 7px; }
.dica-linha + .dica-linha { margin-top: 3px; }
.dica-cor { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.dica-rotulo { opacity: .8; }
.dica-valor { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; }

.val-ok     { color: var(--ok); }
.val-danger { color: var(--danger); }

/* Contador do período gratuito */
.contador-topo { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.contador-rotulo { font-size: 14px; font-weight: 650; }
.contador-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.contador-num { display: flex; align-items: baseline; gap: 6px; flex-shrink: 0; }
.contador-dias {
  font-size: 38px; font-weight: 700; letter-spacing: -.03em; line-height: 1;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.contador-unid { font-size: 12px; color: var(--muted); }
.contador-legenda { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 7px; }
.trilho--g { height: 8px; }

/* Barrinha de progresso */
.trilho { height: 4px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.trilho-fill { height: 100%; background: linear-gradient(90deg, var(--grad-1), var(--grad-3)); }

/* Seleção de várias categorias */
.multi { display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips--tabela { max-width: 260px; }
.chips-vazio { font-size: 13px; color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--brand-soft); color: var(--brand-text);
  padding: 3px 5px 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.chip-x {
  border: none; background: none; cursor: pointer; padding: 0;
  color: inherit; opacity: .6; font-size: 15px; line-height: 1;
  width: 16px; height: 16px; border-radius: 50%;
}
.chip-x:hover { opacity: 1; background: rgba(0, 0, 0, .1); }
.opt-list {
  max-height: 190px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
}
.opt-row {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 11px; font-size: 14px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.opt-row:last-child { border-bottom: none; }
.opt-row:hover { background: var(--surface-2); }
.opt-row input { cursor: pointer; margin: 0; flex-shrink: 0; }
.opt-vazio { padding: 14px; font-size: 13px; color: var(--muted); text-align: center; }

/* Detalhe */
.detail-row { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-row:last-of-type { border-bottom: none; }
.detail-label { color: var(--muted); }
.detail-value { text-align: right; font-weight: 500; }

/* Lista simples */
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.list-row:last-child { border-bottom: none; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 550; }
.list-sub { font-size: 12px; color: var(--muted); }

/* Avisos */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 900; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 17px; border-radius: 22px; font-size: 14px;
  box-shadow: var(--shadow); animation: toastin .18s ease;
}
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }

.callout { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; margin-bottom: 16px; }
.callout--brand { background: var(--brand-soft); color: var(--brand-text); }

/* Celular */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: auto; height: auto; position: static;
    flex-direction: row; align-items: center; gap: 10px;
    padding: 10px 12px; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0 6px 0 0; }
  .brand-name { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav-item { padding: 7px 10px; white-space: nowrap; }
  .nav-count { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; }
  .sync-text { display: none; }
  .sync { padding: 8px; }
  .topbar { padding: 16px 16px 12px; flex-wrap: wrap; }
  .content { padding: 0 16px 32px; }
}
