/* MadTiger CRM — folha de estilos (sem dependências externas) */
:root {
    /* Paleta preto e branco; verde/âmbar/vermelho só para estados */
    --bg: #f4f4f4;
    --surface: #ffffff;
    --border: #e2e2e2;
    --text: #111111;
    --muted: #6b6b6b;
    --accent: #111111;
    --accent-dark: #333333;
    --accent-soft: #ececec;
    --ok: #15803d;
    --ok-soft: #e8f6ec;
    --warn: #b45309;
    --warn-soft: #fdf3e2;
    --danger: #b91c1c;
    --danger-soft: #fdecec;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .05);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: underline; text-decoration-color: rgba(0, 0, 0, .25); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }
.sidebar a, .brand, .btn, .kcard a, .column .add, .pagination a, a.badge { text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }

/* Layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #0a0a0a; color: #e5e5e5; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 4px 10px 20px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 160px; max-width: 100%; height: auto; display: block; }
/* O logótipo original é preto: no menu escuro é mostrado a branco */
.brand .logo-on-dark { filter: brightness(0) invert(1); }
.brand-sub { font-size: 11px; font-weight: 700; letter-spacing: 3px; color: #fff; opacity: .7; }
.auth .brand-sub { color: var(--text); }
.sidebar a.nav { display: block; padding: 8px 10px; border-radius: 8px; color: #cfcfcf; }
.sidebar a.nav:hover { background: #1f1f1f; color: #fff; }
.sidebar a.nav.active { background: #fff; color: #000; font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .who { padding: 10px; border-top: 1px solid #262626; font-size: 13px; }
.sidebar .who small { color: #9a9a9a; display: block; }
.sidebar .who form button { background: none; border: 0; color: #fff; text-decoration: underline; text-underline-offset: 2px; opacity: .8; padding: 0; cursor: pointer; font: inherit; margin-top: 6px; }
.sidebar .who form button:hover { opacity: 1; }
.main { padding: 26px 32px 60px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
/* Numa grelha o espaçamento vem do gap: sem esta regra, o 2.º cartão em diante descia 16px e ficava mais baixo */
.grid > .card + .card { margin-top: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack > * + * { margin-top: 16px; }

.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); }
.up { color: var(--ok); } .down { color: var(--danger); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
tbody tr:hover { background: #f7f7f7; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eeeeee; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent-dark); }

/* Forms */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b5b5b5; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.field .error { color: var(--danger); font-size: 12px; margin-top: 3px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters .field { margin: 0; }
.filters input, .filters select { width: auto; min-width: 140px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f0f0f0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #f3c4c4; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 500; }
.inline { display: inline; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert.success { background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe5c9; }
.alert.error { background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c4c4; }
.alert ul { margin: 0; padding-left: 18px; }

/* Chart (barras CSS) */
.bars { display: flex; align-items: end; gap: 14px; height: 180px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: end; height: 100%; gap: 6px; }
.bars .bar .fill { width: 100%; max-width: 56px; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 2px; }
.bars .bar .fill { background: #c4c4c4; }
.bars .bar.current .fill { background: #111; }
.bars .bar .v { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars .bar .l { font-size: 12px; color: var(--muted); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
dl.details { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }

/* Timeline de contactos */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Linhas da venda */
.sale-lines td { padding: 6px; }
.sale-lines select { min-width: 260px; }
.sale-lines input[type=number] { width: 80px; }
.totals { margin-left: auto; width: 300px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-size: 18px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }

/* Quadro Kanban (pipeline) */
.board { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.column { background: #ececec; border-radius: var(--radius); display: flex; flex-direction: column; min-height: 300px; }
.column-head { padding: 10px 12px 8px; border-top: 4px solid var(--stage, #d4d4d4); border-radius: var(--radius) var(--radius) 0 0; }
.column-head .title { color: var(--text); display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.column-head .count { background: #fff; border-radius: 999px; padding: 0 8px; font-size: 12px; color: var(--muted); }
.column-head .sum { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.column-body { flex: 1; padding: 4px 8px 8px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; border-radius: 0 0 var(--radius) var(--radius); transition: background .15s; }
.column-body.over { background: #dcdcdc; }
.column .add { margin: 0 8px 8px; text-align: center; padding: 6px; border-radius: 8px; color: var(--muted); border: 1px dashed #c4c4c4; }
.column .add:hover { background: #fff; color: var(--accent); }
.kcard { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px; cursor: grab; box-shadow: var(--shadow); }
.kcard:hover { border-color: #bdbdbd; }
.kcard.dragging { opacity: .45; }
.kcard .k-title { font-weight: 600; display: block; color: var(--text); }
.kcard .k-title:hover { color: var(--accent); }
.kcard .k-contact { font-size: 13px; color: var(--muted); }
.kcard .k-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; gap: 6px; }
.kcard .k-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.kcard .k-owner { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #111; color: #fff; font-size: 9px; font-weight: 700; flex: none; }
.kcard .k-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; padding-top: 7px; border-top: 1px dashed var(--border); font-size: 11px; color: var(--muted); }
.kcard .k-meta time { white-space: nowrap; }
.kcard .k-seller { display: inline-flex; align-items: center; gap: 5px; min-width: 0; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kcard { cursor: pointer; }
.kcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kcard.flash { animation: kflash .9s ease-out; }
@keyframes kflash { from { box-shadow: 0 0 0 3px #111; } to { box-shadow: var(--shadow); } }

.kcard .k-items { display: block; color: var(--muted); font-size: 11px; }

/* Produtos da oportunidade */
.items-editor { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }
.items-table td, .items-table th { padding: 6px 8px; }
.items-table input[type=number] { width: 70px; text-align: right; padding: 4px 6px; }
.items-table tfoot td { border-bottom: 0; padding-top: 10px; }
.items-add { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.items-add input[type=number] { width: 80px; }
.items-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.items-import { display: flex; align-items: center; gap: 10px; }
.items-editor .alert { padding: 8px 12px; margin-bottom: 10px; }
.items-table .row-notes { margin-top: 4px; padding: 4px 8px; font-size: 12px; border-style: dashed; }
.items-table .row-notes:focus { border-style: solid; }
.items-table .row-actions { white-space: nowrap; }
.team-import { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; background: #fafafa; }
.team-import label { display: block; font-weight: 600; margin-bottom: 6px; }
.team-import textarea { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.team-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.team-models { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.team-file { margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 999px; background: #111; color: #fff; font-size: 12px; }
.chip small { color: #bdbdbd; }
.chip button { border: 0; background: #333; color: #fff; width: 18px; height: 18px; border-radius: 50%; cursor: pointer; line-height: 1; padding: 0; }
.chip button:hover { background: var(--danger); }
.items-table .row-actions .btn + .btn { margin-left: 10px; }

/* Autocomplete */
.autocomplete { position: relative; flex: 1; min-width: 0; }
.ac-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); max-height: 280px; overflow-y: auto; }
.ac-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.ac-list li.active, .ac-list li[data-i]:hover { background: #111; color: #fff; }
.ac-list li.active .ac-meta, .ac-list li[data-i]:hover .ac-meta { color: #cfcfcf; }
.ac-list .ac-meta { color: var(--muted); white-space: nowrap; font-size: 12px; }
.ac-list .ac-empty { color: var(--muted); cursor: default; }
.ac-list mark { background: #fde68a; color: inherit; border-radius: 2px; padding: 0 1px; }
.ac-list li.active mark, .ac-list li[data-i]:hover mark { background: #525252; }
input[readonly] { background: #f4f4f4; color: var(--muted); }

/* Modal */
.modal { border: 0; border-radius: 14px; padding: 0; width: min(780px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--text); }
.modal::backdrop { background: rgba(0, 0, 0, .55); }
.modal[open] { animation: modal-in .15s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-close { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: #f7f7f7; }
.modal-foot-left { display: flex; gap: 8px; }
.invalid { border-color: var(--danger) !important; background: var(--danger-soft) !important; }
.btn:disabled { opacity: .6; cursor: wait; }

.board-toast { position: fixed; bottom: 18px; right: 18px; background: #111; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.board-toast.show { opacity: 1; }
/* Cor por fase do pipeline */
.stage-novo { --stage: #64748b; }        /* cinza-azulado */
.stage-contactado { --stage: #2563eb; }  /* azul */
.stage-interessado { --stage: #7c3aed; } /* roxo */
.stage-reservado { --stage: #d97706; }   /* âmbar */
.stage-ganho { --stage: #16a34a; }       /* verde */
.stage-perdido { --stage: #dc2626; }     /* vermelho */

/* A cor da fase aparece no topo da coluna, num ponto junto ao nome e na faixa dos cartões */
.column-head .title [data-label] { display: inline-flex; align-items: center; gap: 7px; }
.column-head .title [data-label]::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--stage); }
.column-body .kcard { border-left: 4px solid var(--stage); }
.column-body.over { background: color-mix(in srgb, var(--stage) 12%, #ececec); }

/* Paginação */
.pagination { display: flex; gap: 4px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); }
.pagination .active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination .disabled { color: #bbb; }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; background: #0a0a0a; }
.auth .card { width: 360px; }
.auth .brand { align-items: center; padding: 4px 0 20px; }
.auth .brand .logo { width: 220px; }

@media (max-width: 960px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
    .sidebar .spacer { display: none; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .main { padding: 18px; }
}

/* ---------- <select> com autocomplete (select-autocomplete.js) ---------- */
.select-ac { flex: none; }
.select-ac input { padding-right: 28px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E") no-repeat right 10px center; }
.filters .select-ac input { min-width: 200px; }
.ac-list li.ac-none { color: var(--muted); font-style: italic; }
select.invalid + .select-ac input { border-color: var(--danger) !important; background-color: var(--danger-soft) !important; }

/* ---------- Oportunidades: tabela, detalhe e histórico ---------- */
.stage-pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; vertical-align: middle;
              background: color-mix(in srgb, var(--stage) 12%, #fff); color: color-mix(in srgb, var(--stage) 80%, #000); }
.stage-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--stage); }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.history { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); }
.history-item { position: relative; padding: 0 0 14px 4px; font-size: 13px; }
.history-item::before { content: ""; position: absolute; left: -21px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid #111; }
.history-item.type-criada::before { background: #111; }
.history-item.type-eliminada::before { border-color: var(--danger); background: var(--danger); }
.history-item.type-restaurada::before { border-color: var(--ok); background: var(--ok); }
.history-head time { font-size: 12px; margin-left: 4px; }
.history-changes { margin: 4px 0 0; padding-left: 16px; font-size: 12px; }
.history-changes li { margin: 2px 0; }
.history del { color: var(--muted); }
.history ins { text-decoration: none; font-weight: 600; }
.modal-quotes { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 10px; }
.modal-quotes-head { font-weight: 600; margin-bottom: 6px; }
.modal-quotes ul { list-style: none; margin: 0; padding: 0; }
.modal-quotes li { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; border-bottom: 1px dashed var(--border); }
.modal-quotes li:last-child { border-bottom: 0; }
.modal-history { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 10px; }
.modal-history summary { cursor: pointer; font-weight: 600; }
.modal-history summary .count { font-weight: 500; color: var(--muted); }
.modal-history[open] summary { margin-bottom: 10px; }
.modal-history > div { max-height: 260px; overflow-y: auto; margin-bottom: 8px; }

/* ---------- Orçamentos ---------- */
.sidebar a.nav .nav-count { float: right; min-width: 20px; padding: 0 6px; border-radius: 999px; background: #d97706; color: #fff; font-size: 11px; font-weight: 700; line-height: 20px; text-align: center; }
.quote-lines .price-input { width: 95px; text-align: right; padding: 4px 6px; }
.quote-lines td .badge { margin-top: 4px; }
tr.discounted td { background: #fffbeb; }
.approval-box { margin-top: 14px; padding: 12px 14px; border: 1px solid #f5d49a; background: var(--warn-soft); border-radius: 8px; color: #78350f; }
.approval-card { border-color: #f5d49a; background: #fffbeb; }
.approval-card h2 { color: #92400e; }

@media print {
    .sidebar, .no-print { display: none !important; }
    .app { display: block; }
    .card { border: 0; box-shadow: none; }
}
