/*
 * Poptur Admin - estilos compartilhados do painel, do login e do portal do licenciado.
 *
 * Breakpoints (os mesmos do Bootstrap):
 *   < 576px  celular
 *   < 992px  tabelas .table-stack viram cartões (até 1199px se tiverem 9+ colunas; ver admin.js)
 *   < 992px  tablet                          -> menu lateral vira gaveta (off-canvas)
 */

:root {
    color-scheme: light;
    --app-font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --app-bg: #f8fafc;
    --app-surface: #ffffff;
    --app-border: #e5e7eb;
    --app-border-soft: #e2e8f0;
    --app-text: #0f172a;
    --app-text-soft: #475569;
    --app-muted: #64748b;
    --app-hover: #f1f5f9;
    --app-primary: #0d6efd;
    --app-radius: 1rem;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --topbar-height: 64px;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    background: var(--app-bg);
    color: var(--app-text);
    font-family: var(--app-font);
    overflow-x: hidden;
}

body.no-scroll {
    overflow: hidden;
}

img,
svg,
video,
iframe {
    max-width: 100%;
}

/* Foco visível para navegação por teclado */
:focus-visible {
    outline: 2px solid var(--app-primary);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    top: -100px;
    left: 1rem;
    z-index: 2000;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    background: var(--app-text);
    color: #fff;
    text-decoration: none;
}

.skip-link:focus {
    top: 0.75rem;
    color: #fff;
}

/* ------------------------------------------------------------------ */
/* Superfícies                                                         */
/* ------------------------------------------------------------------ */

.card-blank {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
}

.bg-slate-50 {
    background: #f8fafc !important;
}

.bg-slate-200 {
    background: #e2e8f0 !important;
}

/* ------------------------------------------------------------------ */
/* Menu lateral                                                        */
/* ------------------------------------------------------------------ */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: var(--app-surface);
    border-right: 1px solid var(--app-border);
    transition: width 0.25s ease, transform 0.25s ease;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--topbar-height);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--app-border);
    font-weight: 700;
    color: var(--app-text);
}

.sidebar .brand a {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.sidebar .brand img {
    height: 36px;
    width: auto;
    flex-shrink: 0;
}

.sidebar .brand .label {
    font-size: 1.15rem;
    white-space: nowrap;
}

.sidebar-close {
    display: none;
    margin-left: auto;
}

.sidebar-nav {
    flex: 1 1 auto;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem 0.75rem;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.25rem;
    border: 0;
    border-radius: 0.75rem;
    background: transparent;
    color: var(--app-text-soft);
    text-align: left;
    white-space: nowrap;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar .nav-link:hover,
.sidebar .nav-link:focus-visible {
    background: var(--app-hover);
    color: var(--app-text);
}

.sidebar .nav-link.active {
    background: #e8f0fe;
    color: #0b4fc7;
    font-weight: 600;
}

.sidebar .nav-icon {
    display: inline-flex;
    justify-content: center;
    flex-shrink: 0;
    width: 1.5rem;
    margin-right: 0.75rem;
    font-size: 1.1rem;
}

.sidebar .nav-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar .nav-submenu .nav-sublink {
    white-space: normal;
}

.nav-chevron {
    display: inline-flex;
    margin-left: auto;
    padding-left: 0.5rem;
    font-size: 0.75rem;
    color: #94a3b8;
    transition: transform 0.2s ease;
}

.nav-group-toggle[aria-expanded="true"] .nav-chevron {
    transform: rotate(180deg);
}

.nav-submenu {
    margin: 0.125rem 0 0.5rem 1.6rem;
    padding-left: 0.75rem;
    border-left: 2px solid var(--app-border-soft);
}

.sidebar .nav-submenu .nav-sublink {
    min-height: 40px;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    font-size: 0.925rem;
    font-weight: 400;
    color: var(--app-muted);
}

.sidebar .nav-submenu .nav-sublink:hover {
    background: var(--app-hover);
    color: var(--app-text);
}

.sidebar .nav-submenu .nav-sublink.active {
    background: #e8f0fe;
    color: #0b4fc7;
    font-weight: 600;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1035;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* Menu recolhido (só ícones) - apenas em telas grandes */
@media (min-width: 992px) {
    .sidebar.collapsed {
        width: var(--sidebar-collapsed-width);
    }

    .sidebar.collapsed .brand {
        justify-content: center;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .sidebar.collapsed .brand .label,
    .sidebar.collapsed .nav-text,
    .sidebar.collapsed .nav-chevron,
    .sidebar.collapsed .nav-submenu {
        display: none !important;
    }

    .sidebar.collapsed .nav-link {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    .sidebar.collapsed .nav-icon {
        margin-right: 0;
    }

    .sidebar.collapsed ~ .main-content {
        margin-left: var(--sidebar-collapsed-width);
    }
}

/* ------------------------------------------------------------------ */
/* Área principal e barra superior                                     */
/* ------------------------------------------------------------------ */

.main-content {
    min-width: 0;
    min-height: 100vh;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.25s ease;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--topbar-height);
    padding: 0.5rem 1.5rem;
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 1px solid var(--app-border);
    backdrop-filter: blur(10px);
}

.topbar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 1.25rem;
}

.topbar-title {
    min-width: 0;
    flex: 1 1 auto;
}

.topbar-title .breadcrumb {
    flex-wrap: nowrap;
    margin: 0;
    font-size: 0.8rem;
    color: var(--app-muted);
}

.topbar-title .breadcrumb-item,
.topbar-title .breadcrumb-item.active {
    color: var(--app-muted);
}

.topbar-title h1 {
    margin: 0;
    overflow: hidden;
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem;
    border-radius: 999px;
    color: var(--app-text);
    text-decoration: none;
}

.user-menu-toggle:hover {
    background: var(--app-hover);
    color: var(--app-text);
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e2e8f0;
    font-weight: 600;
    text-transform: uppercase;
}

.page-container {
    padding: 1.5rem;
}

/* Mensagens de retorno (sucesso/erro) */
.flash-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    border-radius: 0.85rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.flash-alert > .bi {
    font-size: 1.15rem;
    line-height: 1.4;
}

.flash-alert .flash-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ */
/* Cabeçalho de página                                                 */
/* ------------------------------------------------------------------ */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-head > :first-child {
    flex: 1 1 320px;
    min-width: 0;
}

.page-container h2,
.portal-main h2 {
    font-size: clamp(1.35rem, 1.1rem + 1vw, 1.85rem);
    font-weight: 600;
    overflow-wrap: anywhere;
}

.page-head h2 {
    margin-top: 0.75rem !important;
    margin-bottom: 0.35rem !important;
}

.page-head > :not(:first-child) {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Botões de ação de cabeçalho isolados (um único <a>/<button>) */
.page-head > a.btn,
.page-head > button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ------------------------------------------------------------------ */
/* Barras de filtro                                                    */
/* ------------------------------------------------------------------ */

.filter-search {
    min-width: 220px;
}

.per-page {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Tabelas                                                             */
/* ------------------------------------------------------------------ */

.table > :not(caption) > * > th {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--app-text-soft);
    white-space: nowrap;
}

.table-responsive {
    -webkit-overflow-scrolling: touch;
}

.table-actions {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.25rem;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

/* Paginação */
.pagination {
    gap: 0.25rem;
}

.pagination .page-link {
    border-radius: 0.5rem !important;
}

/* ------------------------------------------------------------------ */
/* Modais                                                              */
/* ------------------------------------------------------------------ */

.modal-content {
    border: 0;
    border-radius: var(--app-radius);
}

/* ------------------------------------------------------------------ */
/* Portal do licenciado e telas de login                               */
/* ------------------------------------------------------------------ */

.portal-navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: var(--topbar-height);
    padding: 0.5rem 1.5rem;
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
}

.portal-navbar img {
    height: 32px;
    width: auto;
}

.portal-main {
    padding: 1.5rem;
}

.portal-container {
    width: 100%;
    max-width: 1300px;
    margin-left: auto;
    margin-right: auto;
}

.portal-container.narrow {
    max-width: 820px;
}

.portal-container.medium {
    max-width: 1100px;
}

.portal-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.portal-head h2 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
}

.portal-card-link {
    display: block;
    height: 100%;
    border-radius: var(--app-radius);
    color: inherit;
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.portal-card-link:hover .card-blank,
.portal-card-link:focus-visible .card-blank {
    border-color: #bfd3fb;
    box-shadow: 0 12px 30px rgba(13, 110, 253, 0.1);
}

.portal-card-link .bi {
    font-size: 1.5rem;
    color: var(--app-primary);
}

.auth-body {
    min-height: 100vh;
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--app-surface);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 1.5rem;
    box-shadow: 0 30px 60px rgba(15, 23, 42, 0.08);
    overflow: hidden;
}

.auth-card .card-body {
    padding: 2rem;
}

.auth-logo {
    display: block;
    height: 96px;
    width: auto;
    margin: 0 auto 0.5rem;
}

.auth-footer {
    padding: 1.25rem;
    background: #f8fafc;
    color: var(--app-muted);
    font-size: 0.95rem;
    text-align: center;
}

.form-control:focus,
.form-select:focus {
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

/* ------------------------------------------------------------------ */
/* Tablet (< 992px): menu lateral vira gaveta                          */
/* ------------------------------------------------------------------ */

@media (max-width: 991.98px) {
    .sidebar {
        width: min(300px, 85vw);
        transform: translateX(-100%);
        box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
        visibility: hidden;
        transition: transform 0.25s ease, visibility 0.25s ease;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        visibility: visible;
    }

    .sidebar-close {
        display: inline-flex;
    }

    .sidebar-backdrop.show {
        opacity: 1;
        visibility: visible;
    }

    .main-content,
    .sidebar.collapsed ~ .main-content {
        margin-left: 0;
    }
}

/* ------------------------------------------------------------------ */
/* Tabelas em cartões (tablet e celular)                               */
/* ------------------------------------------------------------------ */

/* Tabela -> lista de cartões. A classe .is-stacked é ligada pelo admin.js conforme a
   largura da tela: até 991px, ou até 1199px quando a tabela tem muitas colunas. */
.table-responsive:has(> .table-stack.is-stacked) {
    overflow: visible;
}

.table-stack.is-stacked,
.table-stack.is-stacked > tbody,
.table-stack.is-stacked > tbody > tr,
.table-stack.is-stacked > tbody > tr > td {
    display: block;
    width: 100%;
}

.table-stack.is-stacked > thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.table-stack.is-stacked > tbody > tr {
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--app-border);
    border-radius: 0.85rem;
    background: var(--app-surface);
}

.table-stack.is-stacked > tbody > tr:last-child {
    margin-bottom: 0;
}

.table-stack.is-stacked > tbody > tr > td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    min-height: 2.25rem;
    padding: 0.45rem 0;
    border-bottom: 1px dashed var(--app-border-soft);
    text-align: right !important;
    overflow-wrap: anywhere;
}

.table-stack.is-stacked > tbody > tr > td:last-child {
    border-bottom: 0;
}

.table-stack.is-stacked .td-value {
    min-width: 0;
    text-align: right;
}

.table-stack.is-stacked > tbody > tr > td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    max-width: 40%;
    overflow-wrap: normal;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--app-muted);
    text-align: left;
}

.table-stack.is-stacked > tbody > tr > td[data-label=""]::before,
.table-stack.is-stacked > tbody > tr > td[colspan]::before {
    display: none;
}

.table-stack.is-stacked > tbody > tr > td[colspan] {
    justify-content: center;
    text-align: center !important;
}

/* Coluna de ações ocupa a largura toda, com botões maiores para toque */
.table-stack.is-stacked > tbody > tr > td.td-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    padding-top: 0.65rem;
}

.table-stack.is-stacked > tbody > tr > td.td-actions::before {
    display: none;
}

.table-stack.is-stacked .btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.75rem;
}

.table-stack.is-stacked > tbody > tr > td > .d-inline-flex,
.table-stack.is-stacked .table-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.table-stack.is-stacked > tbody > tr:hover > * {
    --bs-table-accent-bg: transparent;
}

/* A partir de 576px, os cartões ficam em duas colunas */
@media (min-width: 576px) {
    .table-stack.is-stacked > tbody {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .table-stack.is-stacked > tbody > tr {
        margin-bottom: 0;
    }

    .table-stack.is-stacked > tbody > tr:has(> td[colspan]) {
        grid-column: 1 / -1;
    }
}

/* Desktop: valores, datas e status não quebram no meio */
@media (min-width: 992px) {
    .table:not(.is-stacked) td.text-end,
    .table:not(.is-stacked) td.text-center {
        white-space: nowrap;
    }

    .table:not(.is-stacked) .table-actions {
        flex-wrap: nowrap;
    }
}

/* ------------------------------------------------------------------ */
/* Celular grande (< 768px)                                            */
/* ------------------------------------------------------------------ */

@media (max-width: 767.98px) {
    .topbar {
        padding: 0.5rem 1rem;
    }

    .page-container,
    .portal-main {
        padding: 1rem;
    }

    .portal-navbar {
        padding: 0.5rem 1rem;
    }

    .card-blank.p-4,
    .card-blank > .card-body.p-4 {
        padding: 1rem !important;
    }

    .card-blank > .card-body {
        padding: 1rem;
    }

}

/* ------------------------------------------------------------------ */
/* Celular (< 576px)                                                   */
/* ------------------------------------------------------------------ */

@media (max-width: 575.98px) {
    .topbar-title .breadcrumb {
        display: none;
    }

    .page-head {
        align-items: stretch;
        margin-bottom: 1rem;
    }

    .page-head > :not(:first-child) {
        width: 100%;
    }

    .page-head > :not(:first-child) > .btn,
    .page-head > :not(:first-child) > form,
    .page-head > :not(:first-child) > a,
    .page-head > a.btn,
    .page-head > button.btn {
        flex: 1 1 auto;
    }

    .page-head > :not(:first-child) > form > .btn {
        width: 100%;
    }

    .page-head > a.btn,
    .page-head > button.btn {
        width: 100%;
    }

    /* Filtros: cada campo ocupa a linha inteira; o "Mostrar N" continua em linha */
    .filter-bar > .form-control,
    .filter-bar > .form-select,
    .filter-bar > .input-group,
    .filter-search {
        flex: 1 1 100%;
        width: 100% !important;
        min-width: 0 !important;
    }

    .filter-bar > .btn {
        flex: 1 1 0;
    }


    .filter-bar > .ms-md-auto,
    .filter-bar > .ms-md-3 {
        margin-left: 0 !important;
    }

    .nav-pills .nav-link,
    .nav-tabs .nav-link {
        padding: 0.4rem 0.75rem;
        font-size: 0.9rem;
    }

    .auth-card .card-body {
        padding: 1.5rem;
    }

    .auth-logo {
        height: 72px;
    }

    .portal-head h2 {
        font-size: 1.15rem;
    }

    .modal-footer {
        flex-wrap: wrap;
    }

    .modal-footer > .btn {
        flex: 1 1 auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}

/* Modal de visualização de documento (comprovantes) */
.modal-viewer {
    height: 92vh;
}

@media (max-width: 575.98px) {
    .modal-viewer {
        height: 100%;
    }
}

.input-group-search {
    max-width: 420px;
}

dd {
    overflow-wrap: anywhere;
}

/* Cartões de indicador (KPIs): duas colunas no celular */
.kpi-card .badge {
    white-space: normal;
}

@media (max-width: 575.98px) {
    .kpi-card {
        padding: 0.85rem 0.6rem !important;
    }

    .kpi-card .fs-3,
    .kpi-card .fs-2 {
        font-size: 1.1rem !important;
        overflow-wrap: anywhere;
    }

    .kpi-card .badge {
        font-size: 0.7rem;
    }
}
