/* ===== SOPROTEC — Tema empresarial ===== */
:root {
    --sp-navy: #3d3d3d;
    --sp-navy-dark: #2b2b2b;
    --sp-navy-light: #1f4066;
    --sp-accent: #9e2b25;
    --sp-accent-light: #f5e9e8;
    --sp-gray-100: #f4f6f9;
    --sp-gray-200: #e5e9f0;
    --sp-gray-600: #5b6b7f;
    --sp-sidebar-w: 248px;
}

body {
    background: var(--sp-gray-100);
    font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
    color: #26313f;
    font-size: 0.925rem;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sp-sidebar-w);
    min-height: 100vh;
    background: linear-gradient(180deg, var(--sp-navy) 0%, var(--sp-navy-dark) 100%);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform .25s ease;
}

.sidebar-brand {
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    color: #fff;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .65rem;
}

.sidebar-brand .brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--sp-accent);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
}

.sidebar-brand .brand-name {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: .4px;
    line-height: 1.1;
}

.sidebar-brand small {
    display: block;
    font-weight: 400;
    font-size: .68rem;
    color: rgba(255, 255, 255, .55);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.sidebar-nav {
    padding: .85rem .7rem;
    flex: 1;
    overflow-y: auto;
}

.sidebar-nav .nav-section {
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: rgba(255, 255, 255, .4);
    padding: .9rem .65rem .35rem;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    color: rgba(255, 255, 255, .75);
    padding: .55rem .65rem;
    border-radius: 8px;
    margin-bottom: 2px;
    font-size: .9rem;
    transition: all .15s;
}

.sidebar-nav .nav-link i {
    width: 18px;
    text-align: center;
    font-size: .9rem;
}

.sidebar-nav .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
}

.sidebar-nav .nav-link.active {
    color: #fff;
    background: var(--sp-accent);
    font-weight: 600;
}

.sidebar-footer {
    padding: .9rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, .08);
    color: rgba(255, 255, 255, .6);
    font-size: .75rem;
}

/* ---- Conteúdo ---- */
.main-wrapper {
    margin-left: var(--sp-sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--sp-gray-200);
    padding: .75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar .page-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--sp-navy);
    margin: 0;
}

.topbar .user-chip {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.topbar .user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--sp-navy);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: .8rem;
}

.content {
    padding: 1.5rem;
    flex: 1;
}

/* ---- Cards ---- */
.card {
    border: 1px solid var(--sp-gray-200);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(16, 42, 67, .06);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--sp-gray-200);
    padding: .9rem 1.25rem;
    font-weight: 600;
    color: var(--sp-navy);
    border-radius: 12px 12px 0 0 !important;
}

.stat-card {
    border-radius: 12px;
    border: 1px solid var(--sp-gray-200);
    background: #fff;
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 100%;
}

.stat-card .stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.stat-card .stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--sp-navy);
    line-height: 1.15;
}

.stat-card .stat-label {
    font-size: .78rem;
    color: var(--sp-gray-600);
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* ---- Tabelas ---- */
.table {
    font-size: .9rem;
    vertical-align: middle;
}

.table thead th {
    background: var(--sp-gray-100);
    color: var(--sp-navy);
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 2px solid var(--sp-gray-200);
    white-space: nowrap;
}

.table-hover tbody tr:hover {
    background: var(--sp-accent-light);
}

/* ---- Formulários ---- */
.form-label {
    font-weight: 600;
    font-size: .8rem;
    color: var(--sp-navy);
    margin-bottom: .3rem;
}

.form-control, .form-select {
    border-color: #d3dbe5;
    font-size: .9rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--sp-accent);
    box-shadow: 0 0 0 .2rem rgba(47, 127, 208, .15);
}

.form-section-title {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sp-accent);
    border-bottom: 2px solid var(--sp-accent-light);
    padding-bottom: .4rem;
    margin-bottom: 1rem;
}

/* ---- Botões ---- */
.btn-primary {
    --bs-btn-bg: var(--sp-accent);
    --bs-btn-border-color: var(--sp-accent);
    --bs-btn-hover-bg: #2568ab;
    --bs-btn-hover-border-color: #2568ab;
}

.btn-navy {
    --bs-btn-bg: var(--sp-navy);
    --bs-btn-border-color: var(--sp-navy);
    --bs-btn-color: #fff;
    --bs-btn-hover-bg: var(--sp-navy-light);
    --bs-btn-hover-border-color: var(--sp-navy-light);
    --bs-btn-hover-color: #fff;
}

.btn-outline-navy {
    --bs-btn-color: var(--sp-navy);
    --bs-btn-border-color: var(--sp-navy);
    --bs-btn-hover-bg: var(--sp-navy);
    --bs-btn-hover-color: #fff;
}

/* ---- Badges ---- */
.badge {
    font-weight: 600;
    letter-spacing: .3px;
}

/* ---- Autocomplete produtos ---- */
.autocomplete-results {
    position: absolute;
    z-index: 1050;
    width: 100%;
    max-height: 260px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--sp-gray-200);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(16, 42, 67, .12);
}

.autocomplete-results .autocomplete-item {
    padding: .55rem .85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--sp-gray-100);
    font-size: .85rem;
}

.autocomplete-results .autocomplete-item:hover,
.autocomplete-results .autocomplete-item.active {
    background: var(--sp-accent-light);
}

.autocomplete-results .autocomplete-item:last-child {
    border-bottom: none;
}

/* ---- Utilitários ---- */
.text-navy { color: var(--sp-navy) !important; }
.bg-navy { background: var(--sp-navy) !important; }
.text-money { font-variant-numeric: tabular-nums; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1.25rem;
}

.page-header h4 {
    color: var(--sp-navy);
    font-weight: 700;
    margin: 0;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--sp-gray-600);
}

.empty-state i {
    font-size: 2.5rem;
    color: var(--sp-gray-200);
    margin-bottom: .75rem;
}

/* ---- Login ---- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--sp-navy-dark) 0%, var(--sp-navy) 55%, var(--sp-accent) 130%);
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    padding: 2.25rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}

/* ---- Responsivo ---- */
.sidebar-toggler { display: none; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .sidebar-toggler { display: inline-flex; }
    .sidebar-backdrop {
        position: fixed; inset: 0;
        background: rgba(0,0,0,.45);
        z-index: 1035; display: none;
    }
    .sidebar-backdrop.show { display: block; }
}

/* ===== Mobile-first refinements ===== */
@media (max-width: 991.98px) {
    /* toque confortável (min 44px) */
    .btn, .form-select, .form-control { min-height: 42px; }
    .btn-sm { min-height: 36px; }
    .form-check-input { width: 1.25rem; height: 1.25rem; }

    /* topbar compacta */
    .topbar { padding: .6rem .9rem; }
    .topbar .page-title { font-size: .95rem; }
    .content { padding: .9rem; }

    /* header de página empilha e botões ocupam largura */
    .page-header { flex-direction: column; align-items: stretch; gap: .5rem; }
    .page-header h4 { font-size: 1.05rem; }
    .page-header .btn, .page-header .d-flex > * { width: 100%; }
    .page-header .d-flex { flex-wrap: wrap; gap: .5rem; }

    /* badge do breadcrumb com wrap */
    .badge .fa-chevron-right { display: none; }
    .topbar .badge { flex-wrap: wrap; white-space: normal; text-align: left; }

    /* cards e stats mais compactos */
    .stat-card { padding: .8rem .9rem; gap: .7rem; }
    .stat-card .stat-icon { width: 38px; height: 38px; font-size: 1rem; }
    .stat-card .stat-value { font-size: 1.1rem; }
    .card-body { padding: .9rem; }

    /* tabelas: fonte menor, scroll visível */
    .table { font-size: .8rem; }
    .table thead th { font-size: .65rem; padding: .45rem .4rem; }
    .table td { padding: .45rem .4rem; white-space: nowrap; }
    .table-responsive { -webkit-overflow-scrolling: touch; }

    /* resumo lateral do orçamento deixa de ser sticky */
    .position-sticky { position: static !important; }

    /* modais mais úteis no mobile */
    .modal-dialog { margin: .5rem; }
    .modal-body { padding: .9rem; }

    /* filtros empilham */
    .card .row.g-2 > [class*="col-"] { margin-bottom: .4rem; }

    /* autocomplete não estoura a tela */
    .autocomplete-results { max-height: 200px; }

    /* itens do orçamento: rolagem horizontal suave */
    .table-responsive > table[style*="min-width"] { min-width: 760px !important; }
}

@media (max-width: 575.98px) {
    .content { padding: .7rem; }
    .row.g-3 > [class*="col-"] { padding-left: .5rem; padding-right: .5rem; }
    .stat-value[style*="font-size"] { font-size: .9rem !important; }
    .empty-state { padding: 2rem .5rem; }
}

/* hint de scroll horizontal nas tabelas */
@media (max-width: 991.98px) {
    .table-responsive { position: relative; }
    .table-responsive::-webkit-scrollbar { height: 5px; }
    .table-responsive::-webkit-scrollbar-thumb { background: var(--sp-accent); border-radius: 4px; }
}

/* ===== Skeleton loading ===== */
.skeleton-overlay {
    position: fixed; inset: 0; z-index: 2000; background: rgba(244,246,249,.92);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 90px 20px 20px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.skeleton-overlay.show { opacity: 1; pointer-events: all; }
.skeleton-box { width: 100%; max-width: 1000px; }
.skel {
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 400% 100%; animation: skel-shimmer 1.3s infinite;
    border-radius: 8px;
}
.skel-card { height: 90px; margin-bottom: 14px; }
.skel-line { height: 14px; margin-bottom: 10px; }
.skel-table { height: 260px; }
@keyframes skel-shimmer { 0% { background-position: 100% 0 } 100% { background-position: 0 0 } }

/* Logo SoproTec */
.sidebar-brand img, .brand-logo { height: 42px; width: auto; background: #fff; border-radius: 8px; padding: 4px 8px; }
.navbar-site img.brand-logo { height: 34px; }

/* ===== Bottom nav mobile ===== */
.mobile-bottom-nav {
    display: none;
}
@media (max-width: 991.98px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed; bottom: 0; left: 0; right: 0; z-index: 1035;
        background: #fff;
        border-top: 1px solid var(--sp-gray-200, #e5e9f0);
        box-shadow: 0 -4px 20px rgba(0,0,0,.08);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0));
        align-items: flex-end;
        justify-content: space-around;
    }
    .mbn-item {
        display: flex; flex-direction: column; align-items: center; gap: 2px;
        text-decoration: none; color: var(--sp-gray-600, #5b6b7f);
        font-size: .62rem; padding: 4px 10px; border-radius: 10px;
        min-width: 56px; transition: color .15s;
    }
    .mbn-item i { font-size: 1.15rem; }
    .mbn-item.active { color: var(--sp-accent); font-weight: 700; }
    .mbn-fab {
        width: 58px; height: 58px; border-radius: 50%;
        background: var(--sp-accent); color: #fff;
        display: grid; place-items: center;
        font-size: 1.4rem; margin-top: -26px;
        box-shadow: 0 6px 18px rgba(0,0,0,.28), 0 0 0 5px #fff;
        text-decoration: none; flex-shrink: 0;
    }
    .mbn-fab:active { transform: scale(.94); }
    /* espaço pra não cobrir o fim do conteúdo */
    .content { padding-bottom: 86px; }
}

/* ===== Filtros recolhíveis no mobile ===== */
@media (max-width: 991.98px) {
    .filter-card form[method="get"] { display: none; }
    .filter-card.open form[method="get"] { display: block; margin-top: .75rem; }
    .filter-toggle {
        display: inline-flex; align-items: center; gap: .5rem; width: 100%;
        justify-content: space-between; background: none; border: none;
        padding: 0; font-weight: 600; color: var(--sp-accent); font-size: .9rem;
    }
    .filter-toggle .chev { transition: transform .2s; }
    .filter-card.open .filter-toggle .chev { transform: rotate(180deg); }
    /* badge com qtd de filtros ativos */
    .filter-count { background: var(--sp-accent); color: #fff; font-size: .65rem;
        border-radius: 10px; padding: 1px 8px; font-weight: 700; }
}
.filter-toggle { display: none; }

/* ===== Mobile-first: tabelas viram cards (zero scroll lateral) ===== */
@media (max-width: 767.98px) {
    .table-responsive { overflow: visible !important; border: none; }
    .table[style*="min-width"] { min-width: 0 !important; }
    .table { display: block; }
    .table thead { display: none; }
    .table tbody, .table tr, .table td, .table th { display: block; }
    .table tbody tr {
        background: #fff;
        border: 1px solid var(--sp-gray-200, #e5e9f0);
        border-radius: 12px;
        padding: .8rem .9rem;
        margin-bottom: .8rem;
        box-shadow: 0 1px 4px rgba(16,42,67,.07);
    }
    .table td {
        display: flex; align-items: center; gap: .6rem;
        padding: .35rem 0 !important;
        border: none !important;
        white-space: normal !important;
        font-size: .85rem;
        text-align: left !important;
    }
    .table td::before {
        content: attr(data-label);
        flex: 0 0 38%;
        font-size: .68rem; font-weight: 700; text-transform: uppercase;
        letter-spacing: .5px; color: var(--sp-gray-600, #5b6b7f);
    }
    /* célula sem rótulo (identidade/ações) ocupa a linha toda */
    .table td[data-label=""]::before,
    .table td[data-label="Ações"]::before,
    .table td[data-label="#"]::before { display: none; }
    .table td[data-label=""] , .table td[data-label="Ações"] { display: block; }
    .table td:first-child {
        font-weight: 700; font-size: .95rem; color: var(--sp-navy);
        padding-bottom: .5rem !important;
        border-bottom: 1px solid var(--sp-gray-200) !important;
        margin-bottom: .35rem;
    }
    .table td:first-child::before { display: none; }
    .table td.text-end, .table td:last-child {
        justify-content: flex-end; padding-top: .5rem !important;
    }
    .table .empty-state { padding: 1.5rem .5rem; }
    /* badges e botões legíveis */
    .table .badge { font-size: .72rem; }
    .table .btn-sm { min-height: 38px; }
    /* botões de ação em linha wrap */
    .table td > .d-inline, .table td form.d-inline { display: inline-block; }
}

/* ===== Ações em cards mobile: barra igual com ícone+label ===== */
@media (max-width: 767.98px) {
    .table td[data-label="Ações"] {
        display: flex; gap: .5rem;
        padding-top: .7rem !important;
        border-top: 1px dashed var(--sp-gray-200, #e5e9f0) !important;
        margin-top: .4rem;
    }
    .table td[data-label="Ações"] > * { flex: 1; }
    .table td[data-label="Ações"] form.d-inline { display: flex !important; }
    .table td[data-label="Ações"] .btn {
        width: 100%; min-height: 44px;
        display: inline-flex; align-items: center; justify-content: center;
        gap: .4rem; font-size: .8rem; border-radius: 10px;
    }
    .table td[data-label="Ações"] .btn::after {
        content: attr(title);
        font-size: .72rem; font-weight: 600;
    }
    .table td[data-label="Ações"] .btn:not([title])::after { display: none; }
    /* selects de ação (status) ocupam largura total */
    .table td[data-label="Ações"] select.form-select {
        flex: 1; width: 100% !important; min-height: 44px;
    }
}
