/* ============================================================
   CRM Salvatore — Design System (layout Kommo · alma Salvatore)
   Tokens consolidados do parecer do squad (Brad Frost + Uma + Nano)
   ============================================================ */
:root {
  /* Vinho */
  --vinho-50:#F5EDEC; --vinho-100:#EAD9D7; --vinho-200:#D4B3AF; --vinho-300:#B98880;
  --vinho-400:#8C5955; --vinho:#573835; --vinho-600:#462C2A; --vinho-700:#342021;
  /* Caramelo */
  --car-50:#FAF4EE; --car-100:#F2E6D9; --car-200:#E4CBB3; --car-300:#D0A983;
  --car-400:#BC8B6A; --car:#B0866A; --car-600:#8D6A52; --car-700:#6B4F3C;
  /* Sand / bege */
  --sand-50:#FDFBF9; --sand-100:#F7F3EE; --sand-200:#EDE6DC; --sand:#DAD3CB;
  --line:#E5DDD4; --sand-400:#C6BCB2; --sand-500:#AFA49A; --sand-600:#8F8279;
  /* Texto */
  --muted:#7A6B64; --txt-2:#5C4E48; --txt:#373435; --txt-strong:#231F1E;
  /* Superfícies */
  --bg:#F7F3EE; --surface:#FCFAF7; --white:#FFFFFF;
  /* Status do funil (quente — sem verde/vermelho de CRM) */
  --st-petroleo:#1F4E4A; --st-musgo:#4A5036;
  /* Sombras quentes */
  --sh-1:0 1px 3px rgba(55,34,33,.06), 0 1px 2px rgba(55,34,33,.07);
  --sh-2:0 4px 8px rgba(55,34,33,.07), 0 2px 4px rgba(55,34,33,.05);
  --sh-3:0 8px 24px rgba(55,34,33,.10), 0 4px 8px rgba(55,34,33,.07);
  --sh-4:0 16px 40px rgba(55,34,33,.15), 0 6px 16px rgba(55,34,33,.10);
  /* Raios */
  --r-sm:6px; --r-md:8px; --r-lg:12px; --r-pill:999px;
  /* Movimento */
  --ease:cubic-bezier(.2,.8,.2,1); --t:180ms var(--ease);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--txt); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: 'Cormorant Garamond', serif; font-weight: 600; }
svg { stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* ---- App shell ---- */
.app { display: flex; height: 100vh; overflow: hidden; }

/* RAIL */
.rail { width: 76px; flex-shrink: 0; background: var(--vinho); display: flex; flex-direction: column; align-items: center; padding: 18px 0 14px; }
.rail-logo { width: 42px; height: 42px; border-radius: 11px; background: rgba(255,255,255,.07); color: var(--car); font-family: 'Cormorant Garamond'; font-weight: 700; font-size: 22px; display: flex; align-items: center; justify-content: center; margin-bottom: 22px; letter-spacing: -.5px; }
.rail-nav { display: flex; flex-direction: column; gap: 4px; width: 100%; align-items: center; }
.rail-item { position: relative; width: 60px; height: 58px; border: none; background: transparent; color: rgba(255,255,255,.5); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; border-radius: 10px; transition: var(--t); }
.rail-item svg { width: 22px; height: 22px; }
.rail-item span { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.rail-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.rail-item.active { color: var(--car); background: rgba(176,134,106,.14); }
.rail-item.active::before { content: ''; position: absolute; left: -8px; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--car); }
.rail-badge { position: absolute; top: 8px; right: 9px; min-width: 16px; height: 16px; padding: 0 4px; background: #9C4A2E; color: #fff; font-size: 10px; font-weight: 700; font-style: normal; border-radius: var(--r-pill); display: none; align-items: center; justify-content: center; }
.rail-foot { margin-top: auto; width: 38px; height: 38px; border-radius: 50%; background: var(--car); color: #fff; font-family: 'Cormorant Garamond'; font-weight: 600; font-size: 15px; display: flex; align-items: center; justify-content: center; }

/* MAIN */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 60px; flex-shrink: 0; background: var(--bg); border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 24px; gap: 16px; }
.topbar h1 { font-size: 24px; color: var(--vinho); flex-shrink: 0; }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.search-wrap { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 0 14px; height: 38px; width: 280px; transition: var(--t); }
.search-wrap:focus-within { border-color: var(--car); box-shadow: 0 0 0 3px rgba(176,134,106,.18); }
.ic-search { width: 16px; height: 16px; color: var(--sand-600); flex-shrink: 0; }
.search-wrap input { border: none; background: none; outline: none; font-family: 'Inter'; font-size: 14px; width: 100%; color: var(--txt); }
.btn-primary { background: var(--vinho); color: var(--sand-50); border: none; font-family: 'Inter'; font-weight: 600; font-size: 14px; padding: 0 18px; height: 38px; border-radius: var(--r-md); cursor: pointer; transition: var(--t); white-space: nowrap; }
.btn-primary:hover { background: var(--vinho-600); }
.btn-primary:active { transform: scale(.98); }

.content { flex: 1; overflow: hidden; position: relative; }
.view { display: none; height: 100%; overflow-y: auto; padding: 22px 24px; }
.view#view-funil, .view#view-inbox { padding: 0; }
.view.active { display: block; }
.view#view-inbox.active, .view#view-funil.active { display: flex; }

.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.sec-head h2 { font-size: 26px; color: var(--vinho); }
.sub { color: var(--muted); margin: -8px 0 16px; font-size: 14px; }
select { font-family: 'Inter'; padding: 9px 13px; border-radius: var(--r-md); border: 1px solid var(--sand-400); background: var(--surface); color: var(--txt); font-size: 14px; cursor: pointer; }

/* ---- FUNIL / Kanban ---- */
.board { display: flex; gap: 16px; overflow-x: auto; padding: 22px 24px; align-items: flex-start; height: 100%; background: var(--white); width: 100%; }
.col { width: 296px; flex-shrink: 0; display: flex; flex-direction: column; }
.col-head { position: sticky; top: 0; padding: 12px 4px 12px; }
.col-bar { height: 3px; border-radius: 3px; margin-bottom: 10px; }
.col-top { display: flex; align-items: center; gap: 8px; }
.col-top h3 { font-family: 'Inter'; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--txt-2); }
.col-count { background: var(--sand); color: var(--vinho); font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: var(--r-pill); }
.col-total { font-size: 12px; color: var(--muted); margin-top: 3px; }
.col-body { display: flex; flex-direction: column; gap: 12px; padding: 4px 4px 30px; min-height: 30px; }
.card { background: var(--surface); border: 1px solid transparent; border-radius: var(--r-md); padding: 13px 14px; cursor: pointer; box-shadow: var(--sh-1); transition: transform var(--t), box-shadow var(--t), border-color var(--t); }
.card:hover { transform: translateY(-2px); box-shadow: var(--sh-2); border-color: var(--sand-400); }
.card-top { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #fff; background: var(--car); }
.card-id { min-width: 0; }
.card .nome { font-weight: 600; font-size: 14px; color: var(--txt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .tel { font-size: 12px; color: var(--muted); }
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.card .valor { color: var(--vinho); font-weight: 600; font-size: 13px; }

/* Tags / pills */
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; padding: 2px 9px; border-radius: var(--r-pill); background: rgba(176,134,106,.14); color: var(--car-700); }
.pill { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: var(--r-pill); text-transform: uppercase; letter-spacing: .04em; }
.pill-lead       { background:#EAD9D7; color:#462C2A; }
.pill-agendamento{ background:#FAF4EE; color:#6B4F3C; border:1px solid #E4CBB3; }
.pill-consulta   { background:#F2E6D9; color:#8D6A52; }
.pill-fechamento { background:#573835; color:#FAF4EE; }
.pill-referido   { background:#E8F3F2; color:#1F4E4A; }
.pill-perdido    { background:#F0ECEB; color:#8F8279; }
.pill-novo       { background:var(--sand-200); color:var(--muted); }
/* barra do topo da coluna por etapa */
.bar-lead{background:#B98880}.bar-agendamento{background:#B0866A}.bar-consulta{background:#BC8B6A}
.bar-fechamento{background:#573835}.bar-referido{background:#1F4E4A}.bar-perdido{background:#C6BCB2}

/* ---- LISTA ---- */
.lista-head { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.tabela-wrap { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-1); overflow: hidden; }
.tabela { width: 100%; border-collapse: collapse; }
.tabela th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.tabela td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tabela tr:last-child td { border-bottom: none; }
.tabela tbody tr { cursor: pointer; transition: background var(--t); }
.tabela tbody tr:hover { background: var(--white); }
.td-nome { display: flex; align-items: center; gap: 10px; }
.td-nome .avatar { width: 28px; height: 28px; font-size: 11px; }
.td-nome strong { font-weight: 600; }

/* ---- INBOX ---- */
.inbox { display: flex; width: 100%; height: 100%; }
.inbox-list { width: 340px; flex-shrink: 0; border-right: 1px solid var(--line); overflow-y: auto; background: var(--bg); }
.conv { display: flex; gap: 11px; padding: 13px 16px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background var(--t); position: relative; }
.conv:hover { background: rgba(176,134,106,.06); }
.conv.ativa { background: var(--surface); }
.conv.ativa::before { content:''; position:absolute; left:0; top:8px; bottom:8px; width:3px; background:var(--vinho); border-radius:3px; }
.conv .avatar { width: 42px; height: 42px; font-size: 14px; }
.conv-mid { min-width: 0; flex: 1; }
.conv-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.conv-nome { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-n { font-size: 10px; background: var(--vinho); color: var(--sand-50); padding: 1px 7px; border-radius: var(--r-pill); flex-shrink: 0; }
.conv-prev { font-size: 12.5px; color: var(--muted); margin: 3px 0 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.inbox-chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--white); }
.empty-chat { margin: auto; text-align: center; color: var(--muted); }
.empty-ic { font-size: 40px; margin-bottom: 8px; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 13px 18px; border-bottom: 1px solid var(--line); background: var(--bg); }
.chat-head .who { display: flex; align-items: center; gap: 11px; }
.chat-head .nome { font-weight: 600; font-size: 15px; }
.chat-sub { font-size: 12px; color: var(--muted); }
.chat-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.bolha { max-width: 66%; padding: 9px 13px; border-radius: var(--r-lg); font-size: 13.5px; white-space: pre-wrap; line-height: 1.45; box-shadow: var(--sh-1); }
.bolha.in { background: var(--surface); align-self: flex-start; border-bottom-left-radius: 4px; }
.bolha.out { background: var(--car-100); align-self: flex-end; border-bottom-right-radius: 4px; color: var(--txt); }

.inbox-lead { width: 300px; flex-shrink: 0; border-left: 1px solid var(--line); overflow-y: auto; background: var(--bg); padding: 20px 18px; }
.inbox-lead.hide { display: none; }
.lead-card-head { text-align: center; margin-bottom: 18px; }
.lead-card-head .avatar { width: 60px; height: 60px; font-size: 22px; margin: 0 auto 10px; }
.lead-card-head .nome { font-family: 'Cormorant Garamond'; font-size: 22px; color: var(--vinho); }
.lead-card-head .tel { font-size: 13px; color: var(--muted); }
.lead-meta { background: var(--surface); border-radius: var(--r-md); padding: 13px; margin-bottom: 10px; box-shadow: var(--sh-1); }
.lead-meta .lm-row { display: flex; justify-content: space-between; font-size: 13px; padding: 5px 0; }
.lead-meta .lm-row .k { color: var(--muted); }

/* ---- TAREFAS ---- */
.task-item { display: flex; align-items: center; gap: 13px; background: var(--surface); border-radius: var(--r-md); padding: 13px 16px; box-shadow: var(--sh-1); margin-bottom: 9px; border-left: 3px solid var(--car); transition: var(--t); }
.task-item.atrasada { border-left-color: #9C4A2E; }
.task-item.feito { opacity: .55; }
.task-item.feito .task-titulo { text-decoration: line-through; }
.task-check { width: 19px; height: 19px; cursor: pointer; accent-color: var(--vinho); flex-shrink: 0; }
.task-mid { flex: 1; }
.task-titulo { font-weight: 600; font-size: 14px; }
.task-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.task-del { background: none; border: none; color: var(--sand-400); font-size: 22px; cursor: pointer; line-height: 1; transition: var(--t); }
.task-del:hover { color: #9C4A2E; }

/* ---- PAINEL ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 26px; }
.num-card { background: var(--surface); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--sh-1); position: relative; overflow: hidden; }
.num-card::after { content:''; position:absolute; top:-30px; right:-30px; width:90px; height:90px; border-radius:50%; background:radial-gradient(circle, rgba(176,134,106,.10), transparent 70%); }
.num-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.num-card .num { font-family: 'Cormorant Garamond'; font-size: 40px; font-weight: 700; color: var(--vinho); line-height: 1.1; margin-top: 4px; }
.num-card .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.num-card.alerta .num { color: #9C4A2E; }
.painel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.painel-box { background: var(--surface); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--sh-1); }
.painel-box h3 { color: var(--vinho); margin-bottom: 14px; font-size: 20px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 13px; }
.bar-row .k { width: 130px; flex-shrink: 0; }
.bar-track { flex: 1; background: var(--sand-200); border-radius: var(--r-pill); height: 14px; overflow: hidden; }
.bar-fill { background: var(--car); height: 100%; border-radius: var(--r-pill); }
.bar-row .v { width: 28px; text-align: right; font-weight: 600; color: var(--vinho); }

/* ---- FOLLOW-UP ---- */
.fu-item { background: var(--surface); border-radius: var(--r-md); padding: 13px 16px; box-shadow: var(--sh-1); display: flex; align-items: center; gap: 13px; margin-bottom: 9px; border-left: 3px solid var(--car); }
.fu-item.alta { border-left-color: #9C4A2E; }
.fu-item .avatar { width: 36px; height: 36px; }
.fu-nome { font-weight: 600; }
.fu-tipo { font-size: 13px; color: var(--muted); }
.fu-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.fu-horas { font-size: 12px; color: var(--muted); }
.wa { background: var(--st-musgo); color: #fff; text-decoration: none; padding: 7px 13px; border-radius: var(--r-md); font-size: 13px; font-weight: 600; white-space: nowrap; transition: var(--t); }
.wa:hover { filter: brightness(1.1); }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; font-size: 15px; }

/* ---- MODAL ---- */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(55,52,53,.5); z-index: 100; align-items: flex-start; justify-content: center; padding: 44px 16px; overflow-y: auto; backdrop-filter: blur(2px); }
.modal-bg.show { display: flex; }
.modal { background: var(--sand-50); border-radius: var(--r-lg); width: 100%; max-width: 480px; padding: 26px; position: relative; box-shadow: var(--sh-4); }
.modal-close { position: absolute; top: 14px; right: 16px; background: none; border: none; font-size: 26px; cursor: pointer; color: var(--sand-500); line-height: 1; }
.modal h2 { color: var(--vinho); font-size: 24px; margin-bottom: 16px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; font-family: 'Inter'; font-size: 14px; padding: 9px 11px; border: 1px solid var(--sand-400); border-radius: var(--r-sm); background: var(--white); color: var(--txt); transition: var(--t); }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--car); box-shadow: 0 0 0 3px rgba(176,134,106,.18); }
.field textarea { resize: vertical; min-height: 56px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; align-items: center; }
.btn { padding: 9px 16px; border-radius: var(--r-sm); border: none; font-family: 'Inter'; font-weight: 600; font-size: 14px; cursor: pointer; transition: var(--t); }
.btn-save { background: var(--vinho); color: #fff; }
.btn-save:hover { background: var(--vinho-600); }
.btn-ghost { background: transparent; color: var(--vinho); border: 1px solid var(--car); }
.btn-ghost:hover { background: var(--car-50); }
.btn-danger { background: transparent; color: #9C4A2E; border: 1px solid #d8b3a9; margin-left: auto; }
.move-grid { display: flex; flex-wrap: wrap; gap: 7px; margin: 6px 0 4px; }
.move-grid button { font-size: 12px; padding: 7px 11px; border-radius: var(--r-sm); border: 1px solid var(--car); background: var(--white); color: var(--vinho); cursor: pointer; font-weight: 600; transition: var(--t); }
.move-grid button:hover { background: var(--car); color: #fff; }
.hint-label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.tpl-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.tpl { font-size: 12px; padding: 7px 12px; border-radius: var(--r-sm); border: 1px solid var(--st-musgo); background: #EBF1EC; color: var(--st-musgo); cursor: pointer; font-weight: 600; transition: var(--t); }
.tpl:hover { background: var(--st-musgo); color: #fff; }
.hist { margin-top: 8px; max-height: 150px; overflow-y: auto; border-top: 1px solid var(--line); padding-top: 8px; }
.hist-item { font-size: 12px; color: var(--muted); padding: 3px 0; }

/* scrollbars discretas */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--sand-400); border-radius: var(--r-pill); border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--sand-500); }

@media (max-width: 820px) {
  .painel-grid { grid-template-columns: 1fr; }
  .inbox-lead { display: none; }
  .search-wrap { width: 160px; }
  .topbar h1 { font-size: 20px; }
}
