/* === COMPONENTS: KPI, panels, tables, charts === */

/* ── Account bar ────────────────────────────────────────────────────────────── */
.account-bar {
    display: flex; gap: 0.75rem; flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 1rem;
    margin-bottom: 1rem;
    align-items: center;
}
.account-info-item {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.78rem; color: var(--text2);
}
.account-info-item i { color: var(--green); font-size: 0.72rem; }
.account-info-item strong { color: var(--text); font-weight: 600; }
@media (max-width: 767px) {
    .account-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
        padding: 0.55rem 0.75rem;
    }
    .account-info-item { font-size: 0.72rem; flex-wrap: wrap; }
    .account-bar .account-info-item:last-child button { width: 100%; justify-content: center; }
}

/* ── KPI Section ────────────────────────────────────────────────────────────── */
.kpi-section { margin-bottom: 1rem; }
.kpi-section-title {
    font-size: 0.65rem;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
    padding-left: 0.1rem;
}

/* ── KPI Grid — 2 colunas mobile, 4 desktop ─────────────────────────────────── */
.kpi-grid, .kpi-grid-3, .kpi-grid-4 {
    display: grid;
    gap: 0.6rem;
    grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 768px) {
    .kpi-grid-3 { grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
    .kpi-grid-4 { grid-template-columns: repeat(4, 1fr); gap: 0.75rem; }
}

/* ── KPI Card ───────────────────────────────────────────────────────────────── */
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: border-color .2s, transform .15s;
    min-width: 0;
}
.kpi-card:hover { border-color: rgba(0,168,255,.25); transform: translateY(-1px); }
.kpi-card-highlight { border-color: rgba(16,185,129,.3) !important; }

.kpi-icon {
    width: 32px; height: 32px; flex-shrink: 0;
    background: rgba(0,168,255,.1);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--blue); font-size: 0.85rem;
}

.kpi-info { flex: 1; min-width: 0; }
.kpi-label {
    display: block;
    font-size: 0.6rem;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 0.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-value {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-variation {
    display: block;
    font-size: 0.62rem;
    font-weight: 600;
    margin-top: 0.1rem;
}

@media (min-width: 768px) {
    .kpi-card { padding: 1rem 1.1rem; gap: 0.9rem; }
    .kpi-icon { width: 40px; height: 40px; font-size: 1rem; border-radius: 10px; }
    .kpi-label { font-size: 0.68rem; }
    .kpi-value { font-size: 1.25rem; }
    .kpi-variation { font-size: 0.68rem; }
}

/* ── Panel ──────────────────────────────────────────────────────────────────── */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    overflow: hidden;
    max-width: 100%;
}
.panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border);
    gap: 0.5rem;
    flex-wrap: wrap;
}
.panel-header h3 {
    font-size: 0.82rem; font-weight: 600;
    display: flex; align-items: center; gap: 0.4rem;
    min-width: 0;
}
.panel-header h3 i { color: var(--orange); font-size: 0.8rem; flex-shrink: 0; }

@media (min-width: 768px) {
    .panel-header { padding: 0.85rem 1.1rem; }
    .panel-header h3 { font-size: 0.88rem; }
    .panel { margin-bottom: 1.25rem; }
}

/* ── Collapsible ────────────────────────────────────────────────────────────── */
.panel-header-toggle { cursor: pointer; user-select: none; }
.panel-header-toggle .toggle-icon {
    transition: transform .25s; color: var(--text3); font-size: 0.72rem;
}
.panel-header-toggle.collapsed .toggle-icon { transform: rotate(-90deg); }
.panel-body-collapsible { max-height: 3000px; overflow: visible; transition: max-height .35s ease; }
.panel-body-collapsible.collapsed { max-height: 0; overflow: hidden; }

/* ── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}
@media (max-width: 767px) {
    .table-wrap::after {
        content: '';
        position: absolute;
        top: 0; right: 0;
        width: 20px; height: 100%;
        background: linear-gradient(to right, transparent, var(--surface));
        pointer-events: none;
    }
}
table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
thead { background: var(--bg); }
th {
    padding: 8px 10px;
    text-align: left; color: var(--text2); font-weight: 600;
    white-space: nowrap; font-size: 0.68rem;
    text-transform: uppercase; letter-spacing: 0.4px;
}
td { padding: 8px 10px; border-top: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: rgba(0,168,255,.03); }
.empty-state { text-align: center; color: var(--text3); padding: 2rem !important; }

@media (min-width: 768px) {
    th, td { padding: 9px 12px; }
    table { font-size: 0.8rem; }
    th { font-size: 0.72rem; }
}

/* ── Executive Summary ──────────────────────────────────────────────────────── */
.exec-summary {
    background: linear-gradient(135deg, var(--surface) 0%, var(--bg) 100%);
    border: 1px solid rgba(0,168,255,.2);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
}
.exec-summary-title { font-size: 0.75rem; font-weight: 700; color: var(--blue); margin-bottom: 0.75rem; }
.exec-insights {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}
@media (max-width: 767px) {
    .exec-insights { grid-template-columns: repeat(2, 1fr); }
}
.exec-insight {
    background: rgba(11,17,32,.6);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.exec-insight-icon {
    width: 28px; height: 28px; flex-shrink: 0;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem;
    background: rgba(255,255,255,.05);
}
.exec-insight-icon.insight-good    { background: rgba(16,185,129,.12); }
.exec-insight-icon.insight-bad     { background: rgba(248,113,113,.12); }
.exec-insight-icon.insight-neutral { background: rgba(0,168,255,.1); color: var(--blue); }
.exec-insight-body { display: flex; flex-direction: column; min-width: 0; }
.exec-insight-label { font-size: 0.58rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.4px; }
.exec-insight-value { font-size: 0.92rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.exec-insight-delta { font-size: 0.62rem; font-weight: 600; margin-top: 1px; }
.landscape-hint { display: none; }
.insight-good { color: var(--green); }
.insight-warn { color: var(--yellow); }
.insight-bad  { color: #f87171; }

/* ── IS Bars ────────────────────────────────────────────────────────────────── */
.is-bar-container { display: flex; align-items: center; gap: 0.4rem; width: 100%; }
.is-bar-track { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; min-width: 40px; }
.is-bar-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }
.is-bar-fill-green  { background: var(--green); }
.is-bar-fill-red    { background: #f87171; }
.is-bar-fill-yellow { background: var(--yellow); }
.is-bar-label { font-size: 0.72rem; font-weight: 600; min-width: 38px; text-align: right; }

/* ── QS Badge ───────────────────────────────────────────────────────────────── */
.qs-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 50%;
    font-weight: 700; font-size: 0.78rem;
}
.qs-badge-good { background: rgba(16,185,129,.15); color: var(--green);  border: 2px solid var(--green); }
.qs-badge-mid  { background: rgba(245,158,11,.15);  color: var(--yellow); border: 2px solid var(--yellow); }
.qs-badge-bad  { background: rgba(248,113,113,.15); color: #f87171;       border: 2px solid #f87171; }

.qs-component { font-size: 0.68rem; padding: 2px 5px; border-radius: 4px; font-weight: 500; }
.qs-above   { background: rgba(16,185,129,.12); color: var(--green); }
.qs-average { background: rgba(245,158,11,.12);  color: var(--yellow); }
.qs-below   { background: rgba(248,113,113,.12); color: #f87171; }

/* ── Hourly chart ───────────────────────────────────────────────────────────── */
.hour-bars-wrap { padding: 0.75rem 0.75rem 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.hour-bars { display: flex; align-items: flex-end; gap: 3px; height: 100px; min-width: 480px; }
@media (max-width: 767px) {
    .hour-bars { min-width: 320px; }
}
.hour-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; height: 100%; justify-content: flex-end; }
.hour-bar {
    width: 100%; background: var(--border);
    border-radius: 3px 3px 0 0;
    position: relative; min-height: 4px;
    transition: background .2s;
}
.hour-bar.hour-peak { background: var(--green); }
.hour-bar.hour-low  { background: #f87171; }
.hour-bar.hour-mid  { background: var(--border); }
.hour-bar-label { font-size: 0.55rem; color: var(--text3); text-align: center; white-space: nowrap; padding-bottom: 3px; }
.hour-bar-tooltip {
    display: none; position: absolute; bottom: 105%; left: 50%; transform: translateX(-50%);
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; padding: 3px 7px; font-size: 0.65rem;
    white-space: nowrap; z-index: 10; color: var(--text);
}
.hour-bar:hover .hour-bar-tooltip { display: block; }

/* ── Campaign tags ──────────────────────────────────────────────────────────── */
.campaign-tag {
    display: inline-block;
    background: rgba(66,133,244,.12); color: var(--blue);
    padding: 1px 5px; border-radius: 4px; font-size: 0.68rem; font-weight: 600;
}

/* ── Ad detail (modal) ──────────────────────────────────────────────────────── */
.ad-detail { margin-bottom: 0.85rem; }
.ad-detail-label { font-size: 0.7rem; color: var(--text2); text-transform: uppercase; margin-bottom: 0.25rem; }
.ad-detail-value { font-size: 0.85rem; color: var(--text); line-height: 1.5; white-space: pre-wrap; }
.ad-link { color: var(--orange); font-size: 0.82rem; word-break: break-all; }
.ad-link:hover { text-decoration: underline; }

/* ── Bot screen ─────────────────────────────────────────────────────────────── */
.bot-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
@media (max-width: 767px) {
    .bot-grid { grid-template-columns: 1fr; }
}

/* ── Search terms campanha col ──────────────────────────────────────────────── */
.td-campanha {
    font-size: 0.75rem;
    color: var(--text2);
    white-space: normal;
    max-width: 120px;
    word-break: break-word;
}
.td-campanha-main {
    color: var(--blue);
    font-weight: 500;
    white-space: normal;
    max-width: 200px;
    word-break: break-word;
}
@media (max-width: 767px) {
    .td-campanha     { max-width: 80px;  font-size: 0.68rem; }
    .td-campanha-main { max-width: 120px; font-size: 0.72rem; }
    /* Esconde colunas secundarias no mobile */
    .col-hide-mobile { display: none !important; }
}

/* ── KPI span 2 ─────────────────────────────────────────────────────────────── */
.kpi-card-span2 { grid-column: span 2; }
@media (max-width: 767px) {
    .kpi-card-span2 { grid-column: span 2; }
}

/* ── Prompt textarea mobile ─────────────────────────────────────────────────── */
@media (max-width: 767px) {
    #promptTextarea { height: 240px !important; font-size: 0.76rem !important; }
    .btn-primary { font-size: 0.82rem; padding: 9px 12px; }
}

/* Bot screen: esconde pizzaria no bottom nav */
@media (max-width: 767px) {
    .bot-screen #nav-pizzaria { display: none !important; }
}

/* ── Skeleton Loading ───────────────────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s infinite;
    border-radius: 4px;
}
@keyframes skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 0.75rem;
    display: flex; align-items: center; gap: 0.6rem;
}
.skeleton-icon  { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
.skeleton-line  { height: 10px; border-radius: 4px; }
.skeleton-value { height: 20px; border-radius: 4px; margin-top: 6px; }

/* ── Pull to Refresh ────────────────────────────────────────────────────────── */
.ptr-indicator {
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    height: 0; overflow: hidden;
    font-size: 0.78rem; color: var(--text2);
    transition: height .2s ease;
    background: var(--bg);
}
.ptr-indicator.ptr-visible { height: 48px; }
.ptr-indicator i { font-size: 1rem; color: var(--blue); transition: transform .3s; }
.ptr-indicator.ptr-ready i { transform: rotate(180deg); color: var(--green); }

/* ── KPI Mobile melhorado ───────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .kpi-value { font-size: 1.15rem !important; }
    .kpi-label { font-size: 0.62rem !important; }
    .kpi-card  { padding: 0.75rem !important; }

    /* Feedback tátil */
    .kpi-card:active { transform: scale(0.97); transition: transform .1s; }
    .nav-item:active { opacity: 0.7; }
    .btn-primary:active { transform: scale(0.97); }
}

/* ── Seções colapsadas por padrão no mobile ─────────────────────────────────── */
@media (max-width: 767px) {
    .panel-mobile-collapsed .panel-body-collapsible {
        max-height: 0 !important;
        overflow: hidden !important;
    }
    .panel-mobile-collapsed .panel-header-toggle { }
    .panel-mobile-collapsed .toggle-icon { transform: rotate(-90deg) !important; }
}

/* ── Swipe indicator ────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .swipe-hint {
        text-align: center;
        font-size: 0.65rem;
        color: var(--text3);
        padding: 0.3rem;
        display: none;
    }
    .swipe-hint.visible { display: block; }
}

/* ── Portrait: versão enxuta ────────────────────────────────────────────────── */
@media (max-width: 767px) and (orientation: portrait) {
    /* Esconde seções secundárias */
    .portrait-hide { display: none !important; }

    /* Hint para rotacionar — só portrait mobile */
    .landscape-hint {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        background: rgba(0,168,255,.08);
        border: 1px solid rgba(0,168,255,.2);
        border-radius: var(--radius);
        padding: 0.6rem 1rem;
        font-size: 0.72rem;
        color: var(--text2);
        margin-bottom: 1rem;
    }
    .landscape-hint i { color: var(--blue); }
}

/* ── Landscape: versão completa ─────────────────────────────────────────────── */
@media (max-width: 767px) and (orientation: landscape) {
    .portrait-hide { display: unset !important; }
    .landscape-hint { display: none !important; }

    /* Bottom nav menor no landscape */
    .sidebar { height: 48px !important; }
    .sidebar .nav-item { height: 48px !important; }
    .sidebar-footer .nav-item { height: 48px !important; }
    .main-area { padding-bottom: 48px !important; }
}
