/* ==========================================================
   DESIGN TOKENS
   ========================================================== */
:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-light: #eef2ff;
    --ink: #1e293b;
    --ink-soft: #475569;
    --muted: #94a3b8;
    --surface: #ffffff;
    --bg: #f4f5fa;
    --border: #e7e9f2;
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(30, 41, 59, 0.04), 0 1px 1px rgba(30, 41, 59, 0.03);
    --shadow-md: 0 10px 25px -8px rgba(30, 41, 59, 0.12), 0 4px 6px -4px rgba(30, 41, 59, 0.06);
    --shadow-lg: 0 20px 40px -12px rgba(30, 41, 59, 0.18);
}

/* Wrapper para telas de autenticação: centraliza verticalmente
   descontando a navbar (~70px) + footer (~55px) para evitar scroll
   desnecessário em páginas como login, cadastro, confirmação de e-mail */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 145px);
    padding: 2rem 0.75rem;
}

* { -webkit-font-smoothing: antialiased; box-sizing: border-box; }

html { overflow-x: hidden; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: var(--bg);
    color: var(--ink);
    overflow-x: hidden;
    width: 100%;
}
.container-fluid { max-width: 100vw; }

h1, h2, h3, h4, h5, h6, .fw-bold, .navbar-brand { letter-spacing: -0.01em; }

/* ==========================================================
   TOPBAR
   ========================================================== */
.navbar.app-topbar {
    background: linear-gradient(90deg, #171a2b 0%, #24273f 100%) !important;
    padding: 0.65rem 0;
    box-shadow: 0 2px 10px rgba(15, 17, 33, 0.15);
}

.navbar.app-topbar .container-fluid {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
}

.app-topbar-left {
    min-width: 0;
}

.app-topbar .navbar-brand {
    font-weight: 700;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.app-topbar .app-brand-logo {
    display: block;
    width: auto;
    max-width: 180px;
    max-height: 40px;
    object-fit: contain;
}
.app-topbar .app-brand-fallback {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
}
.app-topbar .app-brand-fallback[hidden] {
    display: none;
}
.app-topbar .brand-mark {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--brand), #8183f4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.45);
}
.app-topbar .btn-toggle-mobile {
    background: rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
}
.app-topbar .btn-toggle-mobile:hover { background: rgba(255,255,255,0.12); }

/* Grupo de itens da direita */
.app-topbar .navbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.trial-status { white-space: nowrap; font-size: 0.75rem; padding: 0.5rem 0.7rem; }
.trial-status-short { display: none; }
@media (max-width: 767px) {
    .trial-status { margin-right: 0 !important; padding: 0.3rem 0.45rem; }
    .trial-status-label { display: none; }
    .trial-status-short { display: inline; }
}

/* ==========================================================
   COMBOBOX COM BUSCA - SEM ÍCONE
   ========================================================== */
.app-topbar .empresa-selector-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 340px;
    max-width: 40vw;
    flex-shrink: 0;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.app-topbar .empresa-selector-wrapper:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.app-topbar .empresa-selector-wrapper:focus-within {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: var(--brand);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.25);
}

/* Campo de busca principal - SEM ÍCONE */
.app-topbar .empresa-search-input {
    flex: 1;
    min-width: 0;
    height: 36px;
    padding: 0 8px 0 14px;
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 500;
    outline: none;
}

.app-topbar .empresa-search-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
    font-weight: 400;
}

/* Seta para abrir/fechar */
.app-topbar .empresa-arrow {
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.7rem;
    padding: 0 14px 0 4px;
    cursor: pointer;
    transition: transform 0.25s ease;
}

.app-topbar .empresa-arrow.open {
    transform: rotate(180deg);
}

/* ==========================================================
   DROPDOWN COM BUSCA INTERNA
   ========================================================== */
.app-topbar .empresa-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background-color: #1a1d2e;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    max-height: 320px;
    overflow: hidden;
    display: none;
    z-index: 9999;
    padding: 6px 0;
}

.app-topbar .empresa-dropdown.open {
    display: block;
}

/* Campo de busca dentro do dropdown */
.app-topbar .empresa-dropdown-search-wrapper {
    position: relative;
    padding: 0 12px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 4px;
}

.app-topbar .dropdown-search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.25);
    font-size: 0.8rem;
}

.app-topbar .empresa-dropdown-search {
    width: 100%;
    height: 32px;
    padding: 0 12px 0 32px;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    color: #ffffff;
    font-size: 0.8rem;
    outline: none;
    transition: all 0.2s ease;
}

.app-topbar .empresa-dropdown-search::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.app-topbar .empresa-dropdown-search:focus {
    border-color: rgba(79, 70, 229, 0.4);
    background-color: rgba(255, 255, 255, 0.08);
}

/* Lista de resultados */
.app-topbar #empresaDropdownList {
    max-height: 200px;
    overflow-y: auto;
    padding: 4px 0;
}

/* Cabeçalho do dropdown */
.app-topbar .empresa-dropdown-header {
    padding: 6px 14px 6px;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.25);
    font-weight: 600;
}

/* Itens do dropdown */
.app-topbar .empresa-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 14px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.12s ease;
}

.app-topbar .empresa-dropdown-item:hover {
    background-color: rgba(79, 70, 229, 0.15);
    color: #ffffff;
}

.app-topbar .empresa-dropdown-item.active {
    background-color: rgba(79, 70, 229, 0.12);
    color: #a5b4fc;
}

/* Mensagem de nenhum resultado */
.app-topbar .empresa-dropdown-empty {
    padding: 16px 14px;
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.85rem;
    text-align: center;
}

/* Scrollbar do dropdown */
.app-topbar #empresaDropdownList::-webkit-scrollbar {
    width: 4px;
}

.app-topbar #empresaDropdownList::-webkit-scrollbar-track {
    background: transparent;
}

.app-topbar #empresaDropdownList::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 4px;
}

.app-topbar #empresaDropdownList::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================
   USER PILL
   ========================================================== */
.app-topbar .user-pill {
    background: rgba(255,255,255,0.06) !important;
    border: 1px solid rgba(255,255,255,0.08) !important;
    border-radius: 999px !important;
    padding: 0.3rem 0.9rem !important;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}
.app-topbar .user-pill:hover { background: rgba(255,255,255,0.12) !important; }
.app-topbar .user-pill i { color: #a5b4fc; }
.app-topbar .user-pill .user-email { margin-left: 0.25rem; }

.dropdown-menu { border: none; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 0.5rem; }
.dropdown-item { border-radius: var(--radius-sm); padding: 0.55rem 0.75rem; font-weight: 500; font-size: 0.92rem; }
.dropdown-item:hover { background-color: var(--brand-light); }
.dropdown-item i { width: 18px; display: inline-block; }

/* ==========================================================
   SIDEBAR (base layout)
   ========================================================== */
#dashboard-wrapper { background-color: var(--bg); }
.container-fluid.flex-grow-1 { display: flex; flex-direction: column; min-height: 0; }
#sidebar {
    background-color: var(--surface);
    border-right: 1px solid var(--border);
}
.menu-item {
    border-radius: var(--radius-sm);
    margin: 2px 10px;
    width: calc(100% - 20px);
    color: var(--ink-soft) !important;
    font-weight: 500;
    font-size: 0.93rem;
}
.menu-item:hover { background-color: var(--bg); }
.menu-item.active-menu {
    background-color: var(--brand-light) !important;
    border-left: none !important;
    color: var(--brand-dark) !important;
    font-weight: 600;
}
.menu-item.active-menu .menu-icon { color: var(--brand); }

/* ==========================================================
   CARDS — reskin genérico para todas as telas
   ========================================================== */
.card { border: none; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-header { border-bottom: none; font-weight: 700; }
.card-header.bg-dark      { background: linear-gradient(135deg, #1e2337, #2c3352) !important; }
.card-header.bg-primary   { background: linear-gradient(135deg, var(--brand-dark), var(--brand)) !important; }
.card-header.bg-success   { background: linear-gradient(135deg, #0f9d68, #16b981) !important; }
.card-header.bg-danger    { background: linear-gradient(135deg, #d92e4c, #ef4d67) !important; }
.card-header.bg-warning   { background: linear-gradient(135deg, #e0932c, #f5a623) !important; color: #fff !important; }
.card-header.bg-secondary { background: linear-gradient(135deg, #495569, #64748b) !important; }
.card-header.bg-info      { background: linear-gradient(135deg, #0891b2, #22b8d6) !important; }

/* ==========================================================
   BOTÕES
   ========================================================== */
.btn { border-radius: var(--radius-sm); font-weight: 600; letter-spacing: 0.01em; }
.btn-primary { background: linear-gradient(135deg, var(--brand-dark), var(--brand)); border: none; }
.btn-primary:hover { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); }
.btn-lg { border-radius: var(--radius-md); }

/* ==========================================================
   BADGES / ALERTS / FORM
   ========================================================== */
.badge { font-weight: 600; border-radius: 999px; }
.alert { border: none; border-radius: var(--radius-md); }
.form-control, .form-select { border-radius: var(--radius-sm); border-color: var(--border); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15); }

.pin-box { background-color: #14162a; color: #34d399; font-family: 'SFMono-Regular', Menlo, monospace; }

/* ==========================================================
   LOADING OVERLAY
   ========================================================== */
#tela-carregamento { backdrop-filter: blur(2px); }

/* ==========================================================
   RESPONSIVIDADE
   ========================================================== */
@media (max-width: 1200px) {
    .app-topbar .empresa-selector-wrapper {
        width: 260px;
    }
}

@media (max-width: 992px) {
    .app-topbar .empresa-selector-wrapper {
        width: 200px;
    }
    .app-topbar .empresa-search-input {
        font-size: 0.75rem;
        height: 32px;
        padding: 0 6px 0 10px;
    }
    .app-topbar .empresa-arrow {
        font-size: 0.65rem;
        padding-right: 10px;
    }
    .app-topbar .empresa-dropdown-search {
        font-size: 0.75rem;
        height: 28px;
    }
    .app-topbar .empresa-dropdown-item {
        font-size: 0.75rem;
        padding: 5px 10px;
    }
}

@media (max-width: 768px) {
    .btn-toggle-mobile { display: inline-flex !important; }

    .app-topbar .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .app-topbar .navbar-brand {
        font-size: 0.85rem;
    }

    .app-topbar .brand-mark {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .app-topbar .navbar-right {
        gap: 0.4rem;
    }

    .app-topbar .empresa-selector-wrapper {
        width: 160px;
    }

    .app-topbar .empresa-search-input {
        font-size: 0.7rem;
        height: 28px;
        padding: 0 4px 0 8px;
    }

    .app-topbar .empresa-arrow {
        font-size: 0.6rem;
        padding-right: 8px;
    }

    .app-topbar .empresa-dropdown {
        max-height: 250px;
        min-width: 220px;
        right: 0;
        left: auto;
    }

    .app-topbar .empresa-dropdown-search {
        font-size: 0.7rem;
        height: 26px;
        padding: 0 8px 0 28px;
    }

    .app-topbar .dropdown-search-icon {
        font-size: 0.7rem;
        left: 16px;
    }

    .app-topbar .empresa-dropdown-item {
        font-size: 0.7rem;
        padding: 4px 10px;
    }

    .app-topbar #empresaDropdownList {
        max-height: 150px;
    }

    .app-topbar .user-pill {
        padding: 0.2rem 0.5rem !important;
        font-size: 0.7rem;
    }
}

@media (max-width: 576px) {
    .app-topbar .container-fluid {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    .app-topbar .navbar-brand {
        font-size: 0.7rem;
        gap: 4px;
    }

    .app-topbar .app-brand-logo {
        max-width: 72px;
        max-height: 28px;
        margin-right: 0;
    }

    .app-topbar .btn-toggle-mobile {
        margin-right: 0.35rem !important;
        padding: 0.25rem 0.4rem;
    }

    .app-topbar .brand-mark {
        width: 24px;
        height: 24px;
        font-size: 0.6rem;
    }

    .app-topbar .empresa-selector-wrapper {
        width: clamp(88px, 30vw, 120px);
    }

    .app-topbar .empresa-search-input {
        font-size: 0.6rem;
        height: 24px;
        padding: 0 2px 0 6px;
    }

    .app-topbar .empresa-arrow {
        font-size: 0.5rem;
        padding-right: 6px;
    }

    .app-topbar .empresa-dropdown {
        max-height: 200px;
        min-width: 180px;
    }

    .app-topbar .empresa-dropdown-search {
        font-size: 0.6rem;
        height: 22px;
        padding: 0 6px 0 24px;
    }

    .app-topbar .dropdown-search-icon {
        font-size: 0.6rem;
        left: 14px;
    }

    .app-topbar .empresa-dropdown-item {
        font-size: 0.6rem;
        padding: 3px 8px;
    }

    .app-topbar #empresaDropdownList {
        max-height: 120px;
    }

    .app-topbar .user-pill {
        padding: 0.15rem 0.35rem !important;
        font-size: 0.6rem;
    }

    .app-topbar .user-pill .user-email {
        display: none !important;
    }

    .app-topbar .navbar-right {
        gap: 0.2rem;
    }
}

@media (max-width: 360px) {
    .app-topbar .app-brand-logo {
        max-width: 62px;
    }

    .app-topbar .empresa-selector-wrapper {
        width: 88px;
    }
}
