/* StreamControl - CSS Principal v2.1 */
:root {
    --bg: #f8f7f4;
    --bg2: #ffffff;
    --bg3: #f1efe8;
    --border: #e5e3db;
    --text: #1a1915;
    --text2: #6b6860;
    --text3: #9c9a92;
    --primary: #0c447c;
    --info: #0c447c;
    --info-bg: #e6f1fb;
    --radius: 8px;
    --radius-lg: 12px;
    --c-ativo: #27500a;
    --c-ativo-bg: #eaf3de;
    --c-inativo: #444441;
    --c-inativo-bg: #f1efe8;
    --c-analise: #633806;
    --c-analise-bg: #faeeda;
    --c-devendo: #791f1f;
    --c-devendo-bg: #fcebeb;
    --topbar-h: 54px;
    --bottomnav-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    padding-bottom: var(--bottomnav-h);
}

/* ── TOPBAR ── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: var(--topbar-h);
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 12px;
}
.logo {
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    text-decoration: none;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* Badge de notificação */
.notif-badge {
    position: relative;
    display: inline-flex;
}
.notif-badge .dot {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-devendo);
    border: 2px solid var(--bg2);
}

/* ── NAV DESKTOP ── */
.nav {
    display: flex;
    gap: 2px;
}
.nav a {
    font-size: 13px;
    padding: 7px 11px;
    border-radius: var(--radius);
    color: var(--text2);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background .15s;
    white-space: nowrap;
}
.nav a:hover, .nav a.active {
    background: var(--bg3);
    color: var(--text);
    font-weight: 500;
}

/* ── BOTTOM NAV MOBILE ── */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottomnav-h);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    z-index: 100;
    align-items: center;
    justify-content: space-around;
    padding: 0 4px;
}
.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text3);
    font-size: 10px;
    padding: 6px 8px;
    border-radius: var(--radius);
    flex: 1;
    transition: background .15s;
    position: relative;
}
.bottom-nav a.active {
    color: var(--primary);
    background: var(--info-bg);
}
.bottom-nav a .icon { font-size: 20px; line-height: 1; }
.bottom-nav a .badge-dot {
    position: absolute;
    top: 4px;
    right: calc(50% - 14px);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-devendo);
    border: 2px solid var(--bg2);
}

/* Menu "Mais" no bottom nav */
.more-menu {
    display: none;
    position: fixed;
    bottom: var(--bottomnav-h);
    left: 0;
    right: 0;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 99;
    padding: 8px 0 16px;
    box-shadow: 0 -4px 20px rgba(0,0,0,.1);
}
.more-menu.open { display: block; }
.more-menu-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 8px 12px;
}
.more-menu a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: var(--text2);
    font-size: 11px;
    padding: 10px 4px;
    border-radius: var(--radius);
}
.more-menu a .icon { font-size: 22px; }
.more-menu a:hover, .more-menu a.active { background: var(--info-bg); color: var(--primary); }
.more-menu-title {
    font-size: 11px;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 8px 16px 4px;
    font-weight: 600;
}
.more-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 98;
}
.more-menu-overlay.open { display: block; }

/* ── CONTENT ── */
.content { padding: 20px 24px; max-width: 100%; }

/* ── CARDS MÉTRICAS ── */
.metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.metric {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
}
.metric-label { font-size: 12px; color: var(--text3); margin-bottom: 6px; font-weight: 500; }
.metric-value { font-size: 30px; font-weight: 700; line-height: 1.1; }
.metric-sub { font-size: 12px; color: var(--text3); margin-top: 6px; }

/* ── ATALHOS RÁPIDOS (mobile dashboard) ── */
.quick-actions {
    display: none;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.quick-action {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    text-decoration: none;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    transition: background .15s;
}
.quick-action:hover { background: var(--bg3); }
.quick-action .qa-icon { font-size: 24px; flex-shrink: 0; }
.quick-action .qa-label { font-size: 13px; font-weight: 600; }
.quick-action .qa-sub { font-size: 11px; color: var(--text3); margin-top: 1px; }
.quick-action.qa-danger { border-color: #f0b0b0; background: var(--c-devendo-bg); }
.quick-action.qa-warning { border-color: #e8d4a0; background: var(--c-analise-bg); }
.quick-action.qa-success { border-color: #b0d48a; background: var(--c-ativo-bg); }
.quick-action.qa-info { border-color: #b3cfe8; background: var(--info-bg); }

/* ── SEÇÕES ── */
.section {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 16px;
}
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.section-title {
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* ── BOTÕES ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, box-shadow .15s;
    white-space: nowrap;
    font-family: inherit;
    font-weight: 500;
}
.btn:active { transform: translateY(1px); }
.btn:hover { background: var(--bg3); }
.btn-primary { background: var(--info-bg); border-color: #b3cfe8; color: var(--info); }
.btn-primary:hover { background: #d0e5f5; }
.btn-success { background: var(--c-ativo-bg); border-color: #b0d48a; color: var(--c-ativo); }
.btn-success:hover { background: #d5ebba; }
.btn-danger { background: var(--c-devendo-bg); border-color: #f0b0b0; color: var(--c-devendo); }
.btn-wpp { background: transparent; border: 1px solid #25D366; color: #128c4a; }
.btn-wpp:hover { background: #eaf3de; }
.btn-sm { font-size: 12px; padding: 5px 10px; }
.btn-icon { padding: 6px 8px; }

/* Botão flutuante de ação (FAB) */
.fab {
    display: none;
    position: fixed;
    bottom: calc(var(--bottomnav-h) + 16px);
    right: 16px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 24px;
    border: none;
    cursor: pointer;
    z-index: 90;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
    align-items: center;
    justify-content: center;
}

/* ── TABELA ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th {
    font-size: 11px;
    color: var(--text3);
    font-weight: 600;
    padding: 9px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--bg);
}
td {
    font-size: 13px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }
.td-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }

/* ── BADGES ── */
.badge {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 600;
    white-space: nowrap;
}
.s-ativo    { background: var(--c-ativo-bg);   color: var(--c-ativo); }
.s-inativo  { background: var(--c-inativo-bg); color: var(--c-inativo); }
.s-analise  { background: var(--c-analise-bg); color: var(--c-analise); }
.s-devendo  { background: var(--c-devendo-bg); color: var(--c-devendo); }
.badge-plano { background: #faeeda; color: #633806; }
.badge-app   { background: var(--info-bg); color: var(--info); }

/* ── FORMULÁRIO ── */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text2); }
input, select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--bg2);
    color: var(--text);
    transition: border-color .15s;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #7ab5e0;
    box-shadow: 0 0 0 3px rgba(122,181,224,.15);
}
textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

/* ── BUSCA E FILTROS ── */
.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.search-bar input { flex: 1; min-width: 200px; }
.filter-pill {
    font-size: 12px;
    padding: 4px 11px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: all .15s;
}
.filter-pill.on, .filter-pill:hover {
    background: var(--info-bg);
    border-color: #b3cfe8;
    color: var(--info);
}

/* ── MODAL ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--bg2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 20px;
    width: 100%;
    max-width: 640px;
    max-height: 92vh;
    overflow-y: auto;
    position: relative;
    /* Drag handle visual */
    padding-top: 28px;
}
.modal::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
}
.modal-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: var(--bg3);
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text2);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── ALERTAS ── */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-size: 13px;
    animation: slideIn .2s ease;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.alert-success { background: var(--c-ativo-bg); color: var(--c-ativo); border: 1px solid #b0d48a; }
.alert-danger  { background: var(--c-devendo-bg); color: var(--c-devendo); border: 1px solid #f0b0b0; }
.alert-info    { background: var(--info-bg); color: var(--info); border: 1px solid #b3cfe8; }

/* ── LOGIN ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    width: 100%;
    max-width: 380px;
}
.login-logo { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 24px; }

/* ── OUTROS ── */
.legend { display: flex; gap: 14px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text2); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tabs-inner { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-btn {
    font-size: 13px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    flex-shrink: 0;
}
.tab-btn.active { color: var(--info); border-bottom-color: var(--info); font-weight: 600; }
.obs-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 10px 14px; }
.obs-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.obs-tag { display: inline-flex; font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; margin-bottom: 4px; }
.obs-tag-acordo { background: var(--c-analise-bg); color: var(--c-analise); }
.obs-tag-livre { background: var(--info-bg); color: var(--info); }
.obs-resolvido { opacity: .5; }
.mac-mono { font-family: 'Courier New', monospace; font-size: 12px; color: var(--text2); }
.page-label { font-size: 12px; color: var(--text3); padding: 8px 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ── TABELA DENSA ESTILO PLANILHA ── */
.table-wrap table td { padding: 4px 8px; font-size: 12px; vertical-align: middle; }
.table-wrap table th { padding: 6px 8px; font-size: 11px; letter-spacing: .3px; text-transform: uppercase; }
.table-wrap table tr:hover td { background: #f5f4f0; }
.table-wrap table tr { border-bottom: 1px solid var(--border); }

@media (max-width: 768px) {
    .table-wrap table td { padding: 4px 6px; font-size: 11px; }
    .table-wrap table th { padding: 5px 6px; font-size: 10px; }
}

/* ── RESPONSIVO MOBILE ── */
@media (max-width: 768px) {
    body { padding-bottom: var(--bottomnav-h); }

    /* Esconder nav desktop, mostrar bottom nav */
    /* Nav desktop escondida em mobile */
    .nav { display: none !important; }
    .bottom-nav { display: flex; }
    .hamburger { display: none !important; }

    /* Mostrar atalhos rápidos no dashboard */
    .quick-actions { display: grid; }

    /* FAB */
    .fab { display: flex; }

    /* Content */
    .content { padding: 10px; }

    /* Métricas 2x2 */
    .metrics { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .metric { padding: 12px; }
    .metric-value { font-size: 22px; }

    /* Grid 2 vira 1 */
    .grid-2 { grid-template-columns: 1fr !important; }
    .form-grid, .form-grid-3 { grid-template-columns: 1fr !important; }
    .cards-financeiro { grid-template-columns: 1fr !important; }
    .cobrancas-grid { grid-template-columns: 1fr !important; }

    /* Tabelas */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 520px; }
    td, th { padding: 8px 10px; font-size: 12px; }

    /* Botões menores no mobile */
    .btn { font-size: 12px; padding: 6px 10px; }
    .btn-sm { font-size: 11px; padding: 4px 8px; }
    .td-actions { gap: 3px; flex-wrap: nowrap; }

    /* Modal full-bottom no mobile */
    .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 88vh; margin: 0; }
    .modal-overlay { align-items: flex-end; }

    /* Abas com scroll */
    .tabs-inner { flex-wrap: nowrap; }

    /* Form actions */
    .form-actions { flex-wrap: wrap; }

    /* Seção header */
    .section-header { padding: 10px 12px; flex-wrap: wrap; gap: 6px; }

    /* Search bar */
    .search-bar { padding: 8px 10px; gap: 6px; }
    .search-bar input { min-width: 120px; }
}

/* Autocomplete select com busca */
.select-busca { position:relative; }
.select-busca input {
    width:100%; padding:9px 12px; border:1px solid var(--border);
    border-radius:var(--radius); font-size:14px; background:var(--bg2);
}
.select-busca-lista {
    display:none; position:absolute; top:100%; left:0; right:0;
    background:var(--bg2); border:1px solid var(--border);
    border-radius:var(--radius); z-index:200;
    max-height:220px; overflow-y:auto;
    box-shadow:0 4px 16px rgba(0,0,0,.1);
}
.select-busca-lista.open { display:block; }
.select-busca-item {
    padding:9px 12px; cursor:pointer; font-size:13px;
    border-bottom:1px solid var(--border);
}
.select-busca-item:hover, .select-busca-item.sel { background:var(--info-bg); color:var(--info); }
.select-busca-item:last-child { border-bottom:none; }

/* Desktop */
@media (min-width: 769px) {
    body { padding-bottom: 0; }
    .bottom-nav { display: none; }
    .hamburger { display: none; }
    .quick-actions { display: none; }
    .fab { display: none; }
    .more-menu { display: none !important; }
    /* Modal centralizado no desktop */
    .modal-overlay { align-items: center; padding: 20px; }
    .modal { border-radius: var(--radius-lg); max-width: 600px; }
    .modal::before { display: none; }
    /* Nav desktop flexível */
    .nav { display: flex !important; flex-wrap: wrap; gap: 2px; }
    /* Content se adapta */
    .content { padding: 20px 28px; }
    /* Topbar flexível */
    .topbar { flex-wrap: wrap; min-height: var(--topbar-h); height: auto; padding: 8px 16px; gap: 8px; }
}

/* Tela média — tablet/laptop pequeno */
@media (min-width: 769px) and (max-width: 1100px) {
    .nav a { font-size: 12px; padding: 6px 8px; }
    .metrics { grid-template-columns: repeat(2, 1fr); }
    table { font-size: 12px; }
    td, th { padding: 6px 8px; }
}

/* ── MODO ESCURO ── */
/* Modo escuro — aplicado no html para variáveis CSS herdarem em toda a página */
html[data-tema="escuro"] {
    --bg: #1a1a1f;
    --bg2: #22222a;
    --bg3: #2a2a35;
    --border: #3a3a48;
    --text: #e8e6e0;
    --text2: #a8a6a0;
    --text3: #6b6a68;
    --primary: #5b9bd5;
    --info: #5b9bd5;
    --info-bg: #1a2a3a;
    --c-ativo: #5cb85c;
    --c-ativo-bg: #1a2a1a;
    --c-devendo: #e05555;
    --c-devendo-bg: #2a1a1a;
    --c-analise: #e0a030;
    --c-analise-bg: #2a2010;
    --c-inativo: #888;
    --c-inativo-bg: #2a2a2a;
    color-scheme: dark;
}
html[data-tema="escuro"] body {
    background: var(--bg);
    color: var(--text);
}
html[data-tema="escuro"] .topbar,
html[data-tema="escuro"] .bottom-nav,
html[data-tema="escuro"] .more-menu,
html[data-tema="escuro"] .modal,
html[data-tema="escuro"] .section,
html[data-tema="escuro"] .metric,
html[data-tema="escuro"] .card {
    box-shadow: none;
    background: var(--bg2);
}
html[data-tema="escuro"] .section-header,
html[data-tema="escuro"] .search-bar,
html[data-tema="escuro"] .tabs-inner {
    background: var(--bg2);
    border-color: var(--border);
}
html[data-tema="escuro"] table thead tr {
    background: var(--bg3);
}
html[data-tema="escuro"] table td,
html[data-tema="escuro"] table th {
    border-color: var(--border);
    color: var(--text);
}
html[data-tema="escuro"] table tr:hover td {
    background: var(--bg3);
}
html[data-tema="escuro"] input,
html[data-tema="escuro"] select,
html[data-tema="escuro"] textarea {
    background: var(--bg3);
    color: var(--text);
    border-color: var(--border);
}
html[data-tema="escuro"] .btn {
    color: var(--text);
    border-color: var(--border);
}
html[data-tema="escuro"] .btn:hover {
    background: var(--bg3);
}
html[data-tema="escuro"] .nav a {
    color: var(--text2);
}
html[data-tema="escuro"] .nav a:hover,
html[data-tema="escuro"] .nav a.active {
    background: var(--bg3);
    color: var(--text);
}
html[data-tema="escuro"] .filter-pill {
    background: var(--bg3);
    border-color: var(--border);
    color: var(--text2);
}
html[data-tema="escuro"] .filter-pill.on {
    background: var(--primary);
    color: #fff;
}
html[data-tema="escuro"] .modal-overlay {
    background: rgba(0,0,0,0.7);
}
html[data-tema="escuro"] .select-busca-lista,
html[data-tema="escuro"] #nav-rev-dropdown,
html[data-tema="escuro"] #nav-cli-dropdown,
html[data-tema="escuro"] #busca-global-lista {
    background: var(--bg2);
    border-color: var(--border);
}
html[data-tema="escuro"] .select-busca-item:hover {
    background: var(--bg3);
}