/*
 * Commercial briefing components (Resumo, Ficha de país, Padrões).
 * Mobile-first; built on the tokens from ct.css. Prefix: ci-.
 */

main.ci-page { max-width: 1440px; display: flex; flex-direction: column; gap: 1rem; }
main.ci-page > * { min-width: 0; }

/* Page head ------------------------------------------------------------ */
.ci-head { display: flex; flex-direction: column; gap: 0.75rem; }
.ci-head h1 { margin: 0; text-wrap: balance; }
.ci-head .subtitle { margin: 0.25rem 0 0; max-width: 72ch; }
.ci-head-meta { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ci-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
@media (min-width: 900px) {
    .ci-head { flex-direction: row; justify-content: space-between; align-items: flex-end; }
    .ci-tools { justify-content: flex-end; }
}

/* Segmented control: big tap targets on touch */
.ci-seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.ci-seg button {
    appearance: none; border: 0; background: transparent; color: var(--text-2);
    font: inherit; font-size: 0.82rem; font-weight: 500;
    min-height: 36px; padding: 0 0.85rem; border-radius: 7px; cursor: pointer;
}
.ci-seg button[aria-pressed="true"] { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.ci-seg button:focus-visible, .ci-btn:focus-visible, .ci-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ci-btn {
    appearance: none; display: inline-flex; align-items: center; gap: 0.4rem;
    min-height: 38px; padding: 0 0.9rem; border-radius: 8px; cursor: pointer;
    font: inherit; font-size: 0.82rem; font-weight: 600; text-decoration: none;
    background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
}
.ci-btn.ghost { background: var(--panel); color: var(--text); border-color: var(--border-strong); }
.ci-btn svg { width: 16px; height: 16px; }

.ci-select {
    min-height: 38px; padding: 0 0.6rem; border-radius: 8px; border: 1px solid var(--border-strong);
    background: var(--panel); color: var(--text); font: inherit; font-size: 0.85rem;
}

/* Notices ---------------------------------------------------------------- */
.ci-notice { border: 1px solid var(--border); background: var(--panel-2); color: var(--text-2); border-radius: var(--radius); padding: 0.65rem 0.85rem; font-size: 0.82rem; }
.ci-notice.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.ci-notice.err { background: var(--err-soft); color: var(--err); border-color: color-mix(in srgb, var(--err) 30%, transparent); }

/* Cards & grids ------------------------------------------------------------ */
.ci-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
    .ci-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ci-grid.wide { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
    .ci-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1200px) { .ci-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.ci-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; min-width: 0; }
.ci-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.ci-card-head h2 { margin: 0; font-size: 0.92rem; font-weight: 600; }
.ci-hint { margin: 0.2rem 0 0.8rem; font-size: 0.78rem; color: var(--muted); line-height: 1.45; }
.ci-link { font-size: 0.78rem; font-weight: 500; color: var(--accent); text-decoration: none; white-space: nowrap; }
.ci-link:hover { text-decoration: underline; }
.ci-foot { margin: 0.75rem 0 0; padding-top: 0.55rem; border-top: 1px dashed var(--border-strong); font-size: 0.74rem; color: var(--muted); }
.ci-empty { color: var(--muted); font-size: 0.82rem; padding: 0.5rem 0; }

/* KPI strip: 2 columns on phones, one row on desktop */
.ci-kpis {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.ci-kpi { padding: 0.75rem 0.85rem; min-width: 0; border-top: 1px solid var(--border); }
.ci-kpi:nth-child(-n+2) { border-top: 0; }
.ci-kpi:nth-child(even) { border-left: 1px solid var(--border); }
.ci-kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
.ci-kpi .l { font-size: 0.72rem; color: var(--muted); font-weight: 500; }
.ci-kpi .v { font-size: 1.3rem; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 0.1rem; }
.ci-kpi .d { font-size: 0.74rem; color: var(--text-2); margin-top: 0.1rem; }
@media (min-width: 900px) {
    .ci-kpis { grid-template-columns: repeat(var(--ci-kpi-cols, 5), minmax(0, 1fr)); }
    .ci-kpi { border-top: 0; border-left: 1px solid var(--border); padding: 0.9rem 1rem; }
    .ci-kpi:first-child { border-left: 0; }
    .ci-kpi:last-child:nth-child(odd) { grid-column: auto; }
    .ci-kpi .v { font-size: 1.45rem; }
}

/* Semantic colours */
.ci-up { color: var(--ok); }
.ci-down { color: var(--err); }
.ci-flat { color: var(--muted); }
.ci-chip { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.72rem; font-weight: 600; padding: 0.1rem 0.45rem; border-radius: 99px; white-space: nowrap; font-variant-numeric: tabular-nums; background: var(--panel-2); color: var(--text-2); }
.ci-chip.up { background: var(--ok-soft); color: var(--ok); }
.ci-chip.down { background: var(--err-soft); color: var(--err); }
.ci-chip.warn { background: var(--warn-soft); color: var(--warn); }
.ci-chip.info { background: var(--accent-soft); color: var(--accent); }
.ci-code { font-family: var(--mono); font-size: 0.72rem; background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: 0.05rem 0.35rem; color: var(--text-2); white-space: nowrap; }
a.ci-code { text-decoration: none; }
a.ci-code:hover { border-color: var(--accent); color: var(--accent); }

/* Headlines ---------------------------------------------------------------- */
.ci-heads { display: flex; flex-direction: column; }
.ci-hl { display: grid; grid-template-columns: 4px minmax(0, 1fr); gap: 0.75rem; padding: 0.7rem 0; border-top: 1px solid var(--border); text-decoration: none; color: inherit; }
.ci-hl:first-child { border-top: 0; padding-top: 0.15rem; }
.ci-hl .bar { border-radius: 2px; background: var(--accent); }
.ci-hl.up .bar { background: var(--ok); }
.ci-hl.down .bar { background: var(--err); }
.ci-hl.warn .bar { background: var(--warn); }
.ci-hl p { margin: 0; font-size: 0.88rem; line-height: 1.45; }
.ci-hl b { font-weight: 650; }
.ci-hl .why { color: var(--muted); font-size: 0.78rem; margin-top: 0.15rem; }
.ci-hl .go { font-size: 0.76rem; color: var(--accent); font-weight: 500; margin-top: 0.25rem; display: inline-block; }
a.ci-hl:hover p b { color: var(--accent); }

/* Bar rows: label | bar | value | chip ------------------------------------- */
.ci-rows { display: flex; flex-direction: column; }
.ci-row {
    display: grid; grid-template-columns: minmax(3.2rem, 7.5rem) minmax(0, 1fr) auto; gap: 0.6rem;
    align-items: center; padding: 0.42rem 0; border-top: 1px solid var(--border); font-size: 0.82rem;
    color: inherit; text-decoration: none;
}
.ci-row:first-child { border-top: 0; }
.ci-row.with-chip { grid-template-columns: minmax(3.2rem, 7.5rem) minmax(0, 1fr) auto 3.6rem; }
.ci-row .k { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-row .k small { display: block; font-weight: 400; color: var(--muted); font-size: 0.7rem; }
.ci-row .n { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.ci-row .ci-chip { justify-self: end; }
a.ci-row:hover .k { color: var(--accent); }
.ci-track { position: relative; height: 8px; background: var(--panel-3); border-radius: 4px; overflow: hidden; }
.ci-track i { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 4px; background: rgba(var(--heat), 0.75); }

/* Diverging movers: centre line at 0, dashed line at market */
.ci-div { position: relative; height: 14px; }
.ci-div::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--border-strong); }
.ci-div i { position: absolute; top: 2px; height: 10px; border-radius: 3px; }
.ci-div i.pos { background: var(--ok); }
.ci-div i.neg { background: var(--err); }
.ci-div .mkt { position: absolute; top: -5px; bottom: -5px; width: 0; border-left: 1.5px dashed var(--text); opacity: 0.55; }
.ci-axis { display: grid; grid-template-columns: minmax(3.2rem, 7.5rem) minmax(0, 1fr) auto; gap: 0.6rem; font-size: 0.68rem; color: var(--muted); margin-top: 0.35rem; }
.ci-axis span { display: flex; justify-content: space-between; }

/* Dumbbell (before → now) */
.ci-dumb { position: relative; height: 14px; }
.ci-dumb::before { content: ""; position: absolute; left: 0; right: 0; top: 6px; height: 2px; background: var(--panel-3); }
.ci-dumb .seg { position: absolute; top: 5px; height: 4px; border-radius: 2px; background: var(--border-strong); }
.ci-dumb .seg.bad { background: var(--err); }
.ci-dumb .seg.good { background: var(--ok); }
.ci-dumb .dot { position: absolute; top: 2px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; }
.ci-dumb .dot.was { background: var(--border-strong); }
.ci-dumb .dot.now { background: var(--accent); box-shadow: 0 0 0 2px var(--panel); }
.ci-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; font-size: 0.72rem; color: var(--muted); margin-top: 0.6rem; }
.ci-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.ci-sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.ci-sw.sq { border-radius: 2px; }

/* Lists ---------------------------------------------------------------------- */
.ci-list { display: flex; flex-direction: column; }
.ci-li { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.5rem 0; border-top: 1px solid var(--border); font-size: 0.82rem; }
.ci-li:first-child { border-top: 0; }
.ci-li .k { font-weight: 600; }
.ci-li .m { color: var(--muted); font-size: 0.74rem; }
.ci-li > :first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ci-li > :last-child { flex: 0 0 auto; text-align: right; }

/* Responsive table → cards on phones ------------------------------------------ */
.ci-table-wrap { overflow-x: auto; }
table.ci-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.ci-table th { text-align: left; font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ci-table td { padding: 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
.ci-table tr:last-child td { border-bottom: 0; }
.ci-table .n { text-align: right; font-variant-numeric: tabular-nums; }
.ci-table td small { display: block; color: var(--muted); font-size: 0.7rem; }
.ci-table a { color: inherit; font-weight: 600; text-decoration: none; }
.ci-table a:hover { color: var(--accent); }
.ci-pace { display: inline-flex; align-items: center; gap: 0.4rem; font-variant-numeric: tabular-nums; }
.ci-pace .ci-track { width: 56px; height: 6px; }
@media (max-width: 720px) {
    table.ci-table.cards thead { display: none; }
    table.ci-table.cards, .ci-table.cards tbody { display: block; }
    .ci-table.cards tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.4rem 0.6rem; padding: 0.65rem 0; border-bottom: 1px solid var(--border); }
    .ci-table.cards tr:last-child { border-bottom: 0; }
    .ci-table.cards td { display: flex; flex-direction: column; gap: 0.05rem; padding: 0; border: 0; white-space: normal; text-align: left; min-width: 0; }
    .ci-table.cards td::before { content: attr(data-label); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
    .ci-table.cards td.title { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; font-size: 0.9rem; }
    .ci-table.cards td.title::before { display: none; }
    .ci-table.cards td.n { text-align: left; }
    .ci-table.cards td.hide-sm { display: none; }
    .ci-table.cards td .v { display: block; min-width: 0; overflow-wrap: anywhere; }
    .ci-table.cards td.title .v { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
}

/* Heatmap -------------------------------------------------------------------- */
.ci-heat { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ci-heat table { border-collapse: separate; border-spacing: 2px; font-size: 0.74rem; min-width: 100%; }
.ci-heat th { font-size: 0.66rem; color: var(--muted); font-weight: 600; padding: 0.3rem 0.25rem; white-space: nowrap; text-align: center; max-width: 6.5rem; overflow: hidden; text-overflow: ellipsis; }
.ci-heat th.row { position: sticky; left: 0; background: var(--panel); color: var(--text); text-align: left; z-index: 1; }
.ci-heat td { text-align: center; padding: 0.4rem 0.3rem; border-radius: 4px; font-variant-numeric: tabular-nums; min-width: 3.2rem; }
.ci-heat td.empty { color: var(--muted); }
.ci-heat td.best { outline: 2px solid var(--ok); outline-offset: -2px; }

/* Coverage bar */
.ci-cov { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--panel-3); margin-top: 0.6rem; }
.ci-cov i { display: block; height: 100%; }
.ci-cov-legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; font-size: 0.76rem; color: var(--text-2); margin-top: 0.55rem; }
.ci-cov-legend b { font-variant-numeric: tabular-nums; }

/* Concentration bar */
.ci-conc { display: flex; height: 26px; border-radius: 7px; overflow: hidden; background: var(--panel-3); }
.ci-conc i { display: flex; align-items: center; padding: 0 0.5rem; font-style: normal; font-size: 0.72rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; min-width: 0; }

/* CPM band (P10–P90 with median) */
.ci-band { position: relative; height: 38px; margin: 0.2rem 0 0.4rem; }
.ci-band .rail { position: absolute; left: 0; right: 0; top: 12px; height: 6px; background: var(--panel-3); border-radius: 3px; }
.ci-band .rng { position: absolute; top: 12px; height: 6px; border-radius: 3px; background: rgba(var(--heat), 0.35); }
.ci-band .med { position: absolute; top: 6px; width: 3px; height: 18px; margin-left: -1.5px; border-radius: 2px; background: var(--accent); }
.ci-band .mk { position: absolute; top: 24px; font-size: 0.68rem; color: var(--muted); transform: translateX(-50%); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ci-band .mk.med-l { color: var(--accent); font-weight: 600; }
.ci-band-label { font-size: 0.76rem; font-weight: 600; }

/* Pitch list */
.ci-pitch { display: flex; flex-direction: column; gap: 0.55rem; margin: 0; padding: 0; list-style: none; font-size: 0.86rem; }
.ci-pitch li { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.1rem; padding-left: 0.7rem; border-left: 3px solid var(--accent-soft); }
.ci-pitch b { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }

/* Feed */
.ci-feed { display: flex; flex-direction: column; }
.ci-fe { display: grid; grid-template-columns: 3rem minmax(0, 1fr); gap: 0.2rem 0.65rem; padding: 0.5rem 0; border-top: 1px solid var(--border); font-size: 0.82rem; align-items: baseline; }
.ci-fe:first-child { border-top: 0; }
.ci-fe time { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); }
.ci-fe .t { min-width: 0; overflow-wrap: anywhere; }
.ci-fe .t .ci-chip { margin-right: 0.35rem; }

/* Charts */
svg.ci-chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.ci-chart text { fill: var(--muted); font-family: var(--font); font-size: 11px; }
svg.ci-chart text.strong { fill: var(--text); font-weight: 600; }

/* Skeleton while loading */
.ci-skel { display: block; height: 0.8rem; border-radius: 4px; background: linear-gradient(90deg, var(--panel-2), var(--panel-3), var(--panel-2)); background-size: 200% 100%; animation: ci-shimmer 1.2s infinite linear; margin: 0.45rem 0; }
@keyframes ci-shimmer { to { background-position: -200% 0; } }

/* Copy fallback */
.ci-copy-fallback { width: 100%; min-height: 9rem; font-family: var(--mono); font-size: 0.74rem; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem; margin-top: 0.6rem; }

/* Phones: tighter cards, sticky window switch */
@media (max-width: 720px) {
    main.ci-page { gap: 0.75rem; }
    .ci-card { padding: 0.85rem; }
    .ci-tools { width: 100%; }
    .ci-tools .ci-seg { flex: 1 1 auto; }
    .ci-tools .ci-seg button { flex: 1 1 0; }
    .ci-sticky {
        position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); z-index: 20;
        margin: 0 -1rem; padding: 0.5rem 1rem;
        background: color-mix(in srgb, var(--bg) 88%, transparent);
        backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
        border-bottom: 1px solid var(--border);
    }
    .ci-row, .ci-row.with-chip, .ci-axis { grid-template-columns: minmax(3rem, 5.5rem) minmax(0, 1fr) auto; }
    .ci-row.with-chip .ci-chip { display: none; }
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
