/* MT Beauté — painel de leads. Tema da marca (ouro sobre marrom escuro). Sem estilos inline: a CSP só aceita 'self'. */
:root {
    --bg: #14100c;
    --bg-2: #1a1510;
    --card: #221c15;
    --card-2: #2a231a;
    --line: #3a3024;
    --text: #f3ece0;
    --muted: #b3a48c;
    --gold: #c9a15c;
    --gold-2: #e0be7e;
    --ok: #4caf7d;
    --bad: #d16a6a;
    --warn: #e0a84a;
    --radius: 12px;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; color: var(--gold-2); }
a { color: var(--gold-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- topo e navegação ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 16px;
    padding: calc(10px + var(--safe-t)) 16px 10px;
    background: rgb(20, 16, 12);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; letter-spacing: .04em; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 8px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--card); text-decoration: none; color: var(--text); }
.nav a.active { color: var(--gold-2); background: var(--card); }
.nav .badge-count { margin-left: 6px; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-name { color: var(--muted); font-size: .9rem; }

.container { max-width: 1240px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { flex: 1 1 auto; }
.page-head .field { margin-bottom: 0; }

/* ---------- botões, campos ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; min-height: 42px;
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--card-2); color: var(--text);
    font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--gold); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1a1510; border-color: transparent; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { background: #6e2f2f; border-color: #8d4444; }
.btn-whats { background: #1f7a4a; border-color: #2b9660; color: #fff; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .9rem; }
.btn-block { width: 100%; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="date"], input[type="number"], input[type="search"], select, textarea {
    width: 100%; min-height: 42px; padding: 9px 12px;
    background: var(--bg-2); color: var(--text);
    border: 1px solid var(--line); border-radius: 10px; font: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: transparent; }
.field .err { color: var(--bad); font-size: .85rem; margin-top: 4px; }
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid var(--line); }
.alert-error { background: #3a1f1f; border-color: #6e2f2f; color: #f0b9b9; }
.alert-warn { background: #3a2f17; border-color: #7a6228; color: #f0d9a3; }
.alert-ok { background: #1b3327; border-color: #2b6a4a; color: #b8e6cc; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 50% 0%, #2b2015 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-logo { display: block; width: 240px; max-width: 100%; height: auto; margin: 0 auto 8px; }
.login-title { text-align: center; font-size: 1.3rem; }
.login-sub { text-align: center; color: var(--muted); margin: 4px 0 20px; }

/* ---------- filtros ---------- */
.filters { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.filters > summary { list-style: none; cursor: pointer; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; font-weight: 500; }
.filters > summary::-webkit-details-marker { display: none; }
.filters[open] > summary { border-bottom: 1px solid var(--line); }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 12px; padding: 14px; }
.filters-grid .field { margin: 0; }
.filters-actions { display: flex; gap: 8px; padding: 0 14px 14px; flex-wrap: wrap; }
.chip { display: inline-block; background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: .8rem; color: var(--muted); margin: 0 4px 4px 0; }

/* ---------- cartões de métricas ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .label { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: 8px; }
.card .value { font-size: 1.7rem; font-weight: 600; margin-top: 4px; line-height: 1.2; }
.card .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
a.card { color: inherit; display: block; }
a.card:hover { border-color: var(--gold); text-decoration: none; }
.card-wide { grid-column: span 2; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--gold); flex: none; }
.section { margin: 24px 0; }
.section > h2 { margin-bottom: 10px; }
.empty { text-align: center; padding: 36px 16px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 6px; }

/* ---------- tabelas ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; background: var(--card-2); }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--card-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--gold); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--card-2); border: 1px solid var(--line); white-space: nowrap; }
.badge-count { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--gold); color: #1a1510; font-size: .75rem; font-weight: 700; text-align: center; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- detalhe do lead ---------- */
.lead-head { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; margin-bottom: 14px; }
.lead-head h1 { flex: 1 1 260px; word-break: break-word; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.panel h3 { margin-bottom: 10px; }
dl.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .85rem; }
dl.kv dd { margin: 0; word-break: break-word; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 16px; border-left: 2px solid var(--line); position: relative; margin-left: 4px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); }
.timeline .when { color: var(--muted); font-size: .8rem; }
.status-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- modal e avisos ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .65); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { padding: 16px 18px 6px; }
.modal-body { padding: 8px 18px 6px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 18px 18px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 14px; }
.radio-list { display: grid; gap: 8px; margin: 8px 0 14px; }
.radio-list label { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--bg-2); }
.radio-list input { margin-top: 3px; accent-color: var(--gold); }
.radio-list label.on { border-color: var(--gold); }

.toasts { position: fixed; z-index: 60; right: 12px; bottom: calc(12px + var(--safe-b)); display: grid; gap: 8px; width: min(360px, calc(100vw - 24px)); }
.toast { background: var(--card-2); border: 1px solid var(--gold); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; }
.toast strong { display: block; color: var(--gold-2); }
.toast.plain { border-color: var(--line); cursor: default; }
.toast.err { border-color: var(--bad); }

.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- responsivo ---------- */
@media (max-width: 760px) {
    body { font-size: 15px; }
    .topbar { gap: 10px; padding-left: 12px; padding-right: 12px; }
    .user-name { display: none; }
    /* Navegação vira barra inferior (estilo app) */
    .nav {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; gap: 0;
        background: rgba(20, 16, 12, .97); border-top: 1px solid var(--line);
        padding-bottom: var(--safe-b);
    }
    .nav a { flex: 1; text-align: center; padding: 12px 4px; border-radius: 0; font-size: .85rem; }
    .container { padding: 14px 12px calc(84px + var(--safe-b)); }
    .toasts { bottom: calc(72px + var(--safe-b)); }
    .card-wide { grid-column: span 1; }
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .card .value { font-size: 1.35rem; }
    /* tabela de leads vira lista de cartões */
    table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
    table.stack thead { display: none; }
    table.stack tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
    table.stack td { padding: 2px 0; border: 0; display: flex; gap: 8px; justify-content: space-between; text-align: right; }
    table.stack td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; flex: none; }
    table.stack td.first { justify-content: flex-start; font-weight: 600; font-size: 1.05rem; text-align: left; }
    table.stack td.first::before { display: none; }
    dl.kv { grid-template-columns: 1fr; gap: 0; }
    dl.kv dt { margin-top: 8px; }
    .grid-2 { grid-template-columns: 1fr; }
    .filters-grid { grid-template-columns: 1fr 1fr; }
    .modal-backdrop { align-items: flex-end; padding: 0; }
    .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 92vh; }
    .choice { grid-template-columns: 1fr 1fr; }
    .btn { min-height: 46px; }
}
@media (max-width: 420px) {
    .filters-grid { grid-template-columns: 1fr; }
}
