/* ============================================
   Controle de Estoque – Estilos
   ============================================ */

/* KPI Cards */
.ce-kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.ce-kpi-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    border-radius: 14px;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
    transition: transform .15s ease, box-shadow .15s ease;
}

.ce-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px -10px rgba(15, 23, 42, .18);
}

.ce-kpi-icon {
    flex: none;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
}

.ce-kpi-icon--total   { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.ce-kpi-icon--value   { background: linear-gradient(135deg, #10b981, #059669); }
.ce-kpi-icon--expired { background: linear-gradient(135deg, #ef4444, #dc2626); }
.ce-kpi-icon--groups  { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }

.ce-kpi-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.ce-kpi-label {
    font-size: 11.5px;
    color: var(--text-muted, #64748b);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.ce-kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    line-height: 1.15;
    margin-top: 2px;
}

.ce-kpi-sub {
    font-size: 10.5px;
    color: var(--text-muted, #94a3b8);
    margin-top: 1px;
}

/* Filters bar */
.ce-filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 20px;
    padding: 16px 20px;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
}

.ce-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}

.ce-filter-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #475569);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.ce-filter-input {
    padding: 8px 12px;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 8px;
    background: var(--bg-body, #fff);
    font-size: 13px;
    color: var(--text-primary, #0f172a);
    transition: border-color .15s, box-shadow .15s;
}

.ce-filter-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
}

/* Buttons */
.ce-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    white-space: nowrap;
}

.ce-btn--primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
}

.ce-btn--primary:hover {
    filter: brightness(1.08);
    box-shadow: 0 4px 12px rgba(37, 99, 235, .3);
}

.ce-btn--outline {
    background: transparent;
    color: var(--text-primary, #374151);
    border-color: var(--border, #d1d5db);
}

.ce-btn--outline:hover {
    background: var(--bg-hover, #f1f5f9);
}

/* Section card */
.ce-section {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 16px;
    padding: 22px 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.ce-section__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.ce-section__title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    display: flex;
    align-items: center;
    gap: 10px;
}

.ce-section__title i {
    color: #3b82f6;
    font-size: 18px;
}

.ce-section__meta {
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

/* Table */
.ce-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ce-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.ce-table th {
    position: sticky;
    top: 0;
    background: var(--bg-thead, #f8fafc);
    border-bottom: 2px solid var(--border, #e2e8f0);
    padding: 10px 12px;
    text-align: left;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted, #475569);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.ce-table th:hover {
    color: var(--text-primary, #0f172a);
}

.ce-table th .sort-icon {
    margin-left: 4px;
    opacity: .4;
    font-size: 10px;
}

.ce-table th.sorted .sort-icon {
    opacity: 1;
    color: #3b82f6;
}

.ce-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border, #f1f5f9);
    color: var(--text-primary, #1e293b);
    vertical-align: middle;
}

.ce-table .col-setor,
.ce-table .col-fabricante {
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
}

.ce-table tr:hover td {
    background: rgba(59, 130, 246, .03);
}

.ce-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
}

/* Status badges */
.ce-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.ce-badge--ok      { background: #dcfce7; color: #166534; }
.ce-badge--warn    { background: #fef9c3; color: #854d0e; }
.ce-badge--danger  { background: #fee2e2; color: #991b1b; }
.ce-badge--blocked { background: #e2e8f0; color: #475569; }
.ce-badge--info    { background: #dbeafe; color: #1e40af; }
.ce-badge--purple  { background: #ede9fe; color: #5b21b6; }

/* ABC Class badges */
.ce-abc {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .02em;
}

.ce-abc--A { background: #fee2e2; color: #dc2626; }
.ce-abc--B { background: #fef3c7; color: #d97706; }
.ce-abc--C { background: #dbeafe; color: #2563eb; }

/* Stock status badges */
.ce-stock-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.ce-stock-status--critico    { background: #fee2e2; color: #991b1b; }
.ce-stock-status--saudavel   { background: #dcfce7; color: #166534; }
.ce-stock-status--excesso    { background: #dbeafe; color: #1e40af; }
.ce-stock-status--sem_consumo { background: #f1f5f9; color: #64748b; }
.ce-stock-status--sem_estoque { background: #fef9c3; color: #854d0e; }

/* Previsão validade badges */
.ce-prev {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.ce-prev--vencido        { background: #1f2937; color: #f9fafb; }
.ce-prev--vai_vencer     { background: #fee2e2; color: #991b1b; }
.ce-prev--atencao        { background: #fef3c7; color: #92400e; }
.ce-prev--sera_consumido { background: #dcfce7; color: #166534; }
.ce-prev--sem_consumo    { background: #f1f5f9; color: #64748b; }

/* Coverage bar */
.ce-cov-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 100px;
}

.ce-cov-bar__track {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    overflow: hidden;
}

.ce-cov-bar__fill {
    height: 100%;
    border-radius: 3px;
    transition: width .3s ease;
}

.ce-cov-bar__label {
    font-size: 11px;
    font-weight: 600;
    min-width: 48px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Pagination */
.ce-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 14px;
    font-size: 13px;
    color: var(--text-muted, #64748b);
    flex-wrap: wrap;
}

.ce-pagination-btns {
    display: flex;
    gap: 6px;
}

.ce-pagination-btns button {
    padding: 6px 12px;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 6px;
    background: var(--bg-card, #fff);
    color: var(--text-primary, #374151);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all .15s;
}

.ce-pagination-btns button:hover:not(:disabled) {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.ce-pagination-btns button:disabled {
    opacity: .4;
    cursor: not-allowed;
}

/* Empty / Loading */
.ce-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted, #94a3b8);
}

.ce-empty i { font-size: 48px; margin-bottom: 12px; opacity: .5; }
.ce-empty p { font-size: 14px; margin: 0; }

.ce-loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted, #64748b);
}

.ce-loading i {
    font-size: 24px;
    animation: ceSpin 1s linear infinite;
    margin-bottom: 8px;
}

@keyframes ceSpin { to { transform: rotate(360deg); } }

/* Sidebar collapsed tooltip (rendered via JS into body) */
.ce-tooltip {
    position: fixed;
    z-index: 10000;
    background: #1e293b;
    color: #f8fafc;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 4px 14px rgba(0,0,0,.25);
    opacity: 0;
    transition: opacity .12s ease;
}

.ce-tooltip.visible {
    opacity: 1;
}

.ce-tooltip::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: #1e293b;
}

/* ═══════════════════════════════════════════════
   Consumo Médio – estilo tabela azul
   ═══════════════════════════════════════════════ */
.cm-filters {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 20px;
    padding: 20px 24px;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
}

.cm-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}

.cm-filter-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted, #475569);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.cm-filter-input {
    padding: 9px 14px;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 8px;
    background: var(--bg-body, #fff);
    font-size: 13px;
    color: var(--text-primary, #0f172a);
    transition: border-color .15s, box-shadow .15s;
}

.cm-filter-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.cm-section {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .05);
}

.cm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.cm-table thead {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
}

.cm-table th {
    padding: 12px 10px;
    text-align: left;
    font-weight: 700;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #fff;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    border-right: 1px solid rgba(255,255,255,.12);
    position: sticky;
    top: 0;
    z-index: 2;
}

.cm-table th:last-child { border-right: none; }

.cm-table th .sort-icon {
    margin-left: 3px;
    opacity: .5;
    font-size: 9px;
}

.cm-table th.sorted .sort-icon {
    opacity: 1;
    color: #fbbf24;
}

.cm-table th:hover {
    background: rgba(255,255,255,.08);
}

.cm-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
}

.cm-table td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--border, #f1f5f9);
    color: var(--text-primary, #1e293b);
    vertical-align: middle;
    font-size: 12.5px;
}

.cm-table tbody tr:hover td {
    background: rgba(37, 99, 235, .04);
}

.cm-table tbody tr:nth-child(even) td {
    background: rgba(241, 245, 249, .5);
}

.cm-table tbody tr:nth-child(even):hover td {
    background: rgba(37, 99, 235, .06);
}

.cm-th-fixed {
    min-width: 180px;
    max-width: 280px;
}

.cm-table th.num {
    text-align: right;
    padding: 12px 6px;
    font-size: 10px;
}

.cm-table td.num {
    padding: 10px 6px;
    font-size: 11.5px;
}

.cm-th-total {
    background: rgba(0,0,0,.15) !important;
    min-width: 90px;
}

.cm-td-total {
    font-weight: 700 !important;
    color: #1e3a8a !important;
    background: rgba(30, 58, 138, .06);
    min-width: 90px;
}

.cm-th-media {
    background: rgba(0,0,0,.15) !important;
    min-width: 80px;
}

.cm-td-media {
    font-weight: 700 !important;
    color: #2563eb !important;
    background: rgba(37, 99, 235, .06);
    min-width: 80px;
}

.cm-td-nome {
    font-weight: 600;
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cm-td-zero {
    color: #cbd5e1 !important;
}

.cm-td-ano {
    font-weight: 700;
    color: #1e3a8a;
    text-align: center;
}

@media (max-width: 768px) {
    .cm-filters { flex-direction: column; }
    .cm-filter-group { min-width: unset; width: 100%; }
}

/* View transitions */
.ce-view {
    animation: ceViewIn .2s ease;
}

@keyframes ceViewIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 768px) {
    .ce-kpi-row { grid-template-columns: 1fr 1fr; }
    .ce-filters { flex-direction: column; }
    .ce-filter-group { min-width: unset; width: 100%; }
}

@media (max-width: 480px) {
    .ce-kpi-row { grid-template-columns: 1fr; }
}

/* ============================================
   Folha de Contagem de Inventário (impressão)
   ============================================ */

/* Em tela, a folha fica oculta. */
.ce-print-sheet { display: none; }

@media print {
    /* Esconde toda a aplicação e mostra só a folha. */
    body.ce-printing #ceApp,
    body.ce-printing .sidebar-overlay,
    body.ce-printing .ce-tooltip { display: none !important; }

    body.ce-printing .ce-print-sheet {
        display: block;
        position: static;
        color: #000;
        background: #fff;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 10px;
    }

    @page {
        size: A4 landscape;
        margin: 10mm 8mm;
    }

    body.ce-printing { background: #fff !important; }

    .ps-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 20px;
        border-bottom: 2px solid #000;
        padding-bottom: 8px;
        margin-bottom: 10px;
    }
    .ps-title h1 {
        font-size: 16px;
        margin: 0 0 6px;
        font-weight: 700;
    }
    .ps-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 4px 16px;
        font-size: 10px;
    }
    .ps-sign {
        text-align: right;
        font-size: 10px;
        white-space: nowrap;
    }
    .ps-sign-line { margin-bottom: 14px; }

    .ps-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 9.5px;
    }
    .ps-table th,
    .ps-table td {
        border: 1px solid #555;
        padding: 4px 6px;
        text-align: left;
        vertical-align: middle;
    }
    .ps-table thead th {
        background: #e8e8e8 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        font-weight: 700;
        text-transform: uppercase;
        font-size: 8.5px;
    }
    /* Repete o cabeçalho em cada página impressa. */
    .ps-table thead { display: table-header-group; }
    .ps-table tr { page-break-inside: avoid; }

    .ps-table .ps-num { width: 28px; text-align: center; }
    .ps-table .ps-prod { font-weight: 600; }
    .ps-table .ps-c { text-align: center; }
    .ps-table .ps-r { text-align: right; white-space: nowrap; }
    /* Colunas a preencher à mão. */
    .ps-table .ps-fill {
        width: 90px;
        background: #fafafa !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    /* Zebra leve p/ leitura na prateleira. */
    .ps-table tbody tr:nth-child(even) td {
        background: #f4f4f4 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .ps-footer {
        margin-top: 10px;
        font-size: 8px;
        color: #333;
        text-align: center;
        border-top: 1px solid #999;
        padding-top: 4px;
    }
}
