/* Painel C21 — casca sidebar + topbar. Transposto da maqueta aprovada
   (2026-07-20). Tokens claro/escuro, sidebar escura, tiles, chips de estado.
   Carregado DEPOIS do pico.classless para vencer o layout do Pico. */

:root {
  --ground: #eceff4;
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --ink: #1a2230;
  --ink-soft: #5c6675;
  --ink-faint: #8b93a2;
  --line: #e0e5ee;
  --line-soft: #eef1f6;
  --accent: #3a53c5;
  --accent-soft: #eaeeff;
  --accent-ink: #ffffff;
  --sidebar-bg: #151b28;
  --sidebar-ink: #9aa3b6;
  --sidebar-ink-hi: #ffffff;
  --sidebar-active: rgba(255, 255, 255, .09);
  --sidebar-accent: #7d92ff;
  --sidebar-line: rgba(255, 255, 255, .07);
  /* estados do funil */
  --st-novo: #6b7280;        --st-novo-bg: #eef0f3;
  --st-contactado: #2563b6;  --st-contactado-bg: #e6f0fb;
  --st-qualif: #6d4bc4;      --st-qualif-bg: #efe9fb;
  --st-agendado: #b5771a;    --st-agendado-bg: #fbf1de;
  --st-entregue: #1f8f5f;    --st-entregue-bg: #e3f4ec;
  --st-descartado: #b0453f;  --st-descartado-bg: #fae9e8;
  --danger: #c2453f;
  --ok: #1f8f5f;
  --radius: 10px;
  --radius-sm: 7px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-num: "SF Mono", "JetBrains Mono", ui-monospace, "Cascadia Code", monospace;
  --shadow: 0 1px 2px rgba(20, 28, 44, .05), 0 4px 16px rgba(20, 28, 44, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0e131d; --surface: #161d29; --surface-2: #1b2330;
    --ink: #e8ecf3; --ink-soft: #9aa4b4; --ink-faint: #6b7486;
    --line: #263041; --line-soft: #1e2735;
    --accent: #7288ff; --accent-soft: #1e2740; --accent-ink: #0e131d;
    --sidebar-bg: #0b0f18; --sidebar-line: rgba(255, 255, 255, .06);
    --st-novo-bg: #242a34; --st-contactado-bg: #16283f; --st-qualif-bg: #241f3a;
    --st-agendado-bg: #33290f; --st-entregue-bg: #123024; --st-descartado-bg: #331b19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --ground: #0e131d; --surface: #161d29; --surface-2: #1b2330;
  --ink: #e8ecf3; --ink-soft: #9aa4b4; --ink-faint: #6b7486;
  --line: #263041; --line-soft: #1e2735;
  --accent: #7288ff; --accent-soft: #1e2740; --accent-ink: #0e131d;
  --sidebar-bg: #0b0f18; --sidebar-line: rgba(255, 255, 255, .06);
  --st-novo-bg: #242a34; --st-contactado-bg: #16283f; --st-qualif-bg: #241f3a;
  --st-agendado-bg: #33290f; --st-entregue-bg: #123024; --st-descartado-bg: #331b19;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
}
:root[data-theme="light"] {
  --ground: #eceff4; --surface: #ffffff; --surface-2: #f4f6fa;
  --ink: #1a2230; --ink-soft: #5c6675; --ink-faint: #8b93a2;
  --line: #e0e5ee; --line-soft: #eef1f6;
  --accent: #3a53c5; --accent-soft: #eaeeff; --accent-ink: #ffffff;
  --sidebar-bg: #151b28;
  --st-novo-bg: #eef0f3; --st-contactado-bg: #e6f0fb; --st-qualif-bg: #efe9fb;
  --st-agendado-bg: #fbf1de; --st-entregue-bg: #e3f4ec; --st-descartado-bg: #fae9e8;
}

/* --- casca ------------------------------------------------------------- */
* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); }

.app {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--ground);
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
  grid-template-rows: 100vh;
}
.app.rail { grid-template-columns: 68px 1fr; }
/* Overlay só existe em mobile; escondido por defeito para não ocupar célula do grid. */
.scrim { display: none; }

/* ---------- SIDEBAR ---------- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  padding: 14px 12px;
  gap: 4px;
  overflow: hidden;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px 16px;
  color: var(--sidebar-ink-hi);
  white-space: nowrap;
}
.mark {
  width: 30px; height: 30px; flex: none;
  border-radius: 8px;
  background: linear-gradient(150deg, var(--sidebar-accent), var(--accent));
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
}
.brand .name { font-weight: 640; font-size: 15px; letter-spacing: -.01em; }
.brand .name small { display: block; font-weight: 450; font-size: 11px; color: var(--sidebar-ink); letter-spacing: .02em; }
.app.rail .brand .name, .app.rail .nav-label, .app.rail .navlink span,
.app.rail .side-foot .who, .app.rail .badge { display: none; }
.app.rail .navlink { justify-content: center; }

.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-faint); padding: 14px 10px 6px; font-weight: 600;
}
.navlink {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--sidebar-ink); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  position: relative; white-space: nowrap;
  transition: background .12s, color .12s;
}
.navlink svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.navlink:hover { background: var(--sidebar-active); color: var(--sidebar-ink-hi); }
.navlink.active { background: var(--sidebar-active); color: var(--sidebar-ink-hi); }
.navlink.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  background: var(--sidebar-accent); border-radius: 0 3px 3px 0;
}
.badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 650; min-width: 19px; height: 19px;
  border-radius: 10px; display: grid; place-items: center; padding: 0 6px;
  font-variant-numeric: tabular-nums;
}
.side-foot {
  margin-top: auto; padding-top: 12px; border-top: 1px solid var(--sidebar-line);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: linear-gradient(150deg, var(--sidebar-accent), var(--accent));
  color: #fff; display: grid; place-items: center; font-weight: 650; font-size: 12.5px;
}
.side-foot .who { line-height: 1.25; overflow: hidden; }
.side-foot .who b { color: var(--sidebar-ink-hi); font-size: 13px; font-weight: 580; display: block; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.side-foot .who span { font-size: 11.5px; color: var(--ink-faint); }

/* ---------- MAIN ---------- */
.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 60px; flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px;
  padding: 0 22px;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--ink-soft);
  display: grid; place-items: center; cursor: pointer;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 19px; height: 19px; }
.page-title { font-size: 16px; font-weight: 630; letter-spacing: -.01em; }
.page-title small { display: block; font-size: 12px; font-weight: 450; color: var(--ink-faint); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.top-right form { margin: 0; }

.content { flex: 1; overflow-y: auto; padding: 24px; }
.content-inner { max-width: 1180px; margin: 0 auto; }

/* ---------- TOASTS / MENSAGENS ---------- */
.toasts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.toast {
  border: 1px solid var(--line); border-left-width: 3px;
  background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px;
  box-shadow: var(--shadow);
}
.toast.success { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--st-agendado); }
.toast.info { border-left-color: var(--accent); }

/* ---------- STAT TILES ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.tile {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow);
}
/* Cards clicáveis (links): filtram a lista. */
a.tile { text-decoration: none; color: inherit; display: block; transition: border-color .12s, box-shadow .12s; }
a.tile:hover { border-color: var(--accent); }
a.tile.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, var(--shadow); }
.tile .lbl { font-size: 12px; color: var(--ink-soft); font-weight: 500; display: flex; align-items: center; gap: 7px; }
.tile .lbl .dot { width: 8px; height: 8px; border-radius: 50%; }
.tile .val { font-size: 27px; font-weight: 680; letter-spacing: -.02em; margin-top: 8px; font-variant-numeric: tabular-nums; font-family: var(--font-num); }
.tile .sub { font-size: 11.5px; color: var(--ink-faint); margin-top: 2px; }
.tile .sub b { color: var(--st-entregue); font-weight: 600; }

/* ---------- LISTA COM SCROLL PRÓPRIO + THEAD FIXO ---------- */
/* Nesta página a .content não rola: o cartão preenche a altura e só a lista
   (.table-wrap) tem scroll, com o thead sticky. */
.content.fill { overflow: hidden; display: flex; flex-direction: column; }
/* Listas (bolsa/minhas) usam mais largura que as páginas de leitura (1180px). */
.content-inner.fill { flex: 1; min-height: 0; display: flex; flex-direction: column; max-width: 1600px; }
.card.fill { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.card.fill .card-head { flex: none; }
.card.fill .table-wrap { flex: 1; min-height: 120px; overflow-y: auto; }
.card.fill .pag { flex: none; }
.card .table-wrap thead th { position: sticky; top: 0; z-index: 1; }
.pag { padding: 12px 18px; border-top: 1px solid var(--line-soft); }
.pag .count { font-size: 12px; color: var(--ink-faint); }
.pag-nav { display: flex; align-items: center; gap: 14px; }
.pag-nav .count { margin: 0 auto; text-align: center; }
.pag-btn {
  font-size: 12.5px; font-weight: 550; color: var(--ink); text-decoration: none;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 7px 13px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.pag-btn:hover { background: var(--surface); border-color: var(--accent); color: var(--accent); }
.pag-btn.disabled { color: var(--ink-faint); background: transparent; cursor: default; opacity: .6; }
.pag-btn.disabled:hover { border-color: var(--line); color: var(--ink-faint); background: transparent; }

/* ---------- CARD + TABLE ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  margin-bottom: 22px;
}
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 15px 18px; border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { margin: 0; font-size: 14.5px; font-weight: 630; letter-spacing: -.01em; }
.card-head .count { font-size: 12px; color: var(--ink-faint); font-weight: 500; }
.filters { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip-select {
  font: inherit; font-size: 12.5px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 11px; cursor: pointer;
}
/* Controlos reais dos filtros — dominam o Pico (painel.css carrega depois):
   linha compacta, pequenos, sem largura total nem margens do Pico. */
.card-head .filters select {
  font: inherit; font-size: 12.5px; color: var(--ink);
  appearance: auto;
  background-color: var(--surface-2);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 26px 7px 11px; margin: 0;
  width: auto; height: auto; min-width: 0; cursor: pointer;
}
.filter-search {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 7px; padding: 0 10px; color: var(--ink-faint);
}
.filter-search svg { width: 15px; height: 15px; flex: none; }
.filter-search input {
  font: inherit; font-size: 12.5px; color: var(--ink);
  border: 0; background: transparent; outline: none; box-shadow: none;
  padding: 7px 0; margin: 0; width: 200px; max-width: 42vw; height: auto;
}
.card .table-wrap { overflow-x: auto; }
.card table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 0; }
.card thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-faint); font-weight: 600; padding: 11px 18px; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap; background: var(--surface);
}
.card tbody td { padding: 12px 18px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.card tbody tr:last-child td { border-bottom: 0; }
.card tbody tr { transition: background .1s; }
.card tbody tr:hover { background: var(--surface-2); }
.tel { font-family: var(--font-num); font-size: 12.5px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--ink-soft); }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ---------- CHIPS DE ESTADO ---------- */
.st { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 560; padding: 3px 9px 3px 8px; border-radius: 20px; white-space: nowrap; }
.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st.novo { color: var(--st-novo); background: var(--st-novo-bg); }
.st.contactado { color: var(--st-contactado); background: var(--st-contactado-bg); }
.st.qualif { color: var(--st-qualif); background: var(--st-qualif-bg); }
.st.agendado { color: var(--st-agendado); background: var(--st-agendado-bg); }
.st.entregue { color: var(--st-entregue); background: var(--st-entregue-bg); }
.st.descartado { color: var(--st-descartado); background: var(--st-descartado-bg); }

.pricedrop { color: var(--st-descartado); font-weight: 600; font-size: 11.5px; display: inline-flex; align-items: center; gap: 3px; }
.pricedrop svg { width: 12px; height: 12px; }

.hint {
  margin-top: 18px; font-size: 12.5px; color: var(--ink-faint);
  display: flex; align-items: center; gap: 8px;
}

/* Conteúdo funcional das páginas antigas (forms/artigos do Pico) vive dentro de
   .content; garante largura fluida e espaçamento coerente. */
.content h1 { font-size: 18px; font-weight: 640; letter-spacing: -.01em; margin: 0 0 14px; }
.content h2 { font-size: 15px; font-weight: 620; margin: 22px 0 10px; }
.content h3 { font-size: 13.5px; font-weight: 600; margin: 16px 0 8px; }

/* ---------- LOGIN (standalone, sem sidebar) ---------- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  font-family: var(--font-ui); color: var(--ink); background: var(--ground);
}
.auth-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px; width: 100%; max-width: 360px;
}
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.auth-brand .name { font-weight: 640; font-size: 15px; }
.auth-brand .name small { display: block; font-weight: 450; font-size: 11px; color: var(--ink-faint); }

/* ---------- responsivo ---------- */
@media (max-width: 900px) {
  .app, .app.rail { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 40;
    transform: translateX(-100%); transition: transform .22s;
  }
  .app.open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 30; }
  .app.open .scrim { display: block; }
  .hamb { display: grid !important; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
.hamb { display: none; }

/* Em ecrã estreito ou baixo não aprisiones o scroll: a página volta a rolar
   normalmente e a lista mostra-se por inteiro (sem caixa interna nem sticky). */
@media (max-width: 900px), (max-height: 560px) {
  .content.fill { overflow-y: auto; display: block; }
  .content-inner.fill, .card.fill { display: block; min-height: 0; }
  .card.fill .table-wrap { overflow-y: visible; min-height: 0; }
  .card .table-wrap thead th { position: static; }
}

/* ---------- acessibilidade ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.navlink:focus-visible { outline-offset: -2px; }

@media (prefers-reduced-motion: reduce) {
  .sidebar, .navlink, .icon-btn, .card tbody tr { transition: none !important; }
}

/* ---------- badge «investiu no anúncio» (sinais comerciais pagos) ---------- */
.badge-investiu {
  display: inline-block;
  margin-left: .4rem;
  padding: .05rem .4rem;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  color: #7a4b00;
  background: #ffe9c7;
  border: 1px solid #f2c992;
  border-radius: .5rem;
}
.badge-investiu.grande { font-size: .85rem; padding: .15rem .55rem; }
