/* ── Reset & Base ─────────────────────────────────────────── */
:root {
    --sidebar-w: 220px;
    --topbar-h: 52px;
    --color-primary: #1D9E75;
    --color-primary-dark: #0F6E56;
    --color-primary-light: #E1F5EE;
    --color-danger: #E24B4A;
    --color-warning-bg: #FAEEDA;
    --color-warning-text: #854F0B;
    --color-info-bg: #E6F1FB;
    --color-info-text: #185FA5;
    --color-border: #e5e7eb;
    --color-bg: #f5f6fa;
    --color-surface: #ffffff;
    --color-text: #111827;
    --color-muted: #6b7280;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
}

a { text-decoration: none; color: inherit; }

/* ── App Layout ───────────────────────────────────────────── */
.app-wrapper {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 1.1rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: var(--color-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 14px; font-weight: 600; color: var(--color-text); }
.brand-sub  { font-size: 10px; color: var(--color-muted); }

.sidebar-nav { padding: .5rem 0; flex: 1; }

.nav-section {
    font-size: 10px;
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    padding: .9rem 1rem .3rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 1rem;
    font-size: 13px;
    color: var(--color-muted);
    border-left: 2px solid transparent;
    cursor: pointer;
    transition: all .15s;
}

.nav-item:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.nav-item.active {
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    background: var(--color-primary-light);
    font-weight: 500;
}

.nav-item i { font-size: 15px; flex-shrink: 0; }

.sidebar-footer {
    border-top: 1px solid var(--color-border);
    padding: .5rem 0;
}

.text-danger-item { color: var(--color-danger) !important; }
.text-danger-item:hover { background: #fef2f2 !important; }

/* ── Main Area ────────────────────────────────────────────── */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    flex-shrink: 0;
}

.topbar-left  { display: flex; align-items: center; gap: .75rem; }
.topbar-title { font-size: 14px; font-weight: 600; color: var(--color-text); }

.topbar-right { display: flex; align-items: center; gap: 1rem; }

.vendor-badge { display: flex; align-items: center; gap: 8px; }

.vendor-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--color-primary-dark);
    flex-shrink: 0;
}

.vendor-info { display: flex; flex-direction: column; line-height: 1.25; }
.vendor-name { font-size: 13px; font-weight: 500; }
.vendor-role { font-size: 10px; color: var(--color-muted); }

/* ── Page Content ─────────────────────────────────────────── */
.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* ── Page Header ──────────────────────────────────────────── */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-text);
}

.page-header p {
    font-size: 13px;
    color: var(--color-muted);
    margin-top: 2px;
}

/* ── Stat Cards ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.stat-label { font-size: 12px; color: var(--color-muted); margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 600; color: var(--color-text); }
.stat-delta { font-size: 11px; color: var(--color-primary); margin-top: 3px; }
.stat-delta.neg { color: var(--color-danger); }

/* ── Card ─────────────────────────────────────────────────── */
.card-pw {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.card-pw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.card-pw-title { font-size: 14px; font-weight: 600; }

/* ── Data Table ───────────────────────────────────────────── */
.table-pw {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table-pw th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 0 .5rem .6rem;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.table-pw td {
    padding: 9px .5rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    vertical-align: middle;
}

.table-pw tr:last-child td { border-bottom: none; }
.table-pw tbody tr:hover td { background: #fafafa; }

/* ── Badges ───────────────────────────────────────────────── */
.badge-pw {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 9px;
    border-radius: var(--radius-sm);
}

.badge-success { background: var(--color-primary-light); color: var(--color-primary-dark); }
.badge-warning { background: var(--color-warning-bg);    color: var(--color-warning-text); }
.badge-info    { background: var(--color-info-bg);       color: var(--color-info-text); }
.badge-danger  { background: #fef2f2;                    color: var(--color-danger); }

/* ── Forms ────────────────────────────────────────────────── */
.form-control-pw, .form-select-pw {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.form-control-pw:focus, .form-select-pw:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(29,158,117,.12);
}

.form-label-pw {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-muted);
    margin-bottom: 4px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-pw {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    cursor: pointer;
    background: var(--color-surface);
    color: var(--color-text);
    transition: all .15s;
}

.btn-pw:hover { background: var(--color-bg); }

.btn-pw-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.btn-pw-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-pw-primary:disabled { background: #9ca3af; border-color: #9ca3af; cursor: not-allowed; }

/* ── Nova Venda Layout ────────────────────────────────────── */
.venda-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1rem;
    align-items: start;
}

.search-row {
    display: flex;
    gap: 8px;
    margin-bottom: 1rem;
}

/* ── Produto Cards ────────────────────────────────────────── */
.produto-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
}

.produto-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    cursor: pointer;
    transition: all .15s;
    user-select: none;
}

.produto-card:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.produto-card.sem-preco {
    opacity: .45;
    cursor: not-allowed;
}

.produto-card.sem-preco:hover {
    border-color: var(--color-border);
    background: var(--color-surface);
}

.prod-nome { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prod-cod  { font-size: 10px; color: var(--color-muted); margin-top: 1px; }
.prod-preco { font-size: 13px; font-weight: 600; color: var(--color-primary); margin-top: 5px; }
.prod-sem-preco { font-size: 10px; color: var(--color-danger); margin-top: 5px; }
.prod-tag-sp { display: inline-block; font-size: 9px; background: #fef2f2; color: var(--color-danger); padding: 1px 5px; border-radius: 3px; margin-top: 2px; }

/* ── Pedido Panel ─────────────────────────────────────────── */
.pedido-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    position: sticky;
    top: 0;
    box-shadow: var(--shadow-sm);
}

.pedido-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--color-border);
}

.pedido-empty {
    text-align: center;
    padding: 2rem 0;
    color: var(--color-muted);
    font-size: 13px;
}

.pedido-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 0;
    border-bottom: 1px solid var(--color-border);
}

.pedido-item:last-of-type { border-bottom: none; }

.pi-info { flex: 1; min-width: 0; }
.pi-nome { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pi-unit { font-size: 10px; color: var(--color-muted); }

.qty-control { display: flex; align-items: center; gap: 4px; }

.qty-btn {
    width: 22px; height: 22px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    color: var(--color-text);
}

.qty-btn:hover { background: var(--color-border); }
.qty-val { width: 26px; text-align: center; font-size: 13px; font-weight: 600; }

.pi-subtotal { font-size: 12px; font-weight: 500; min-width: 60px; text-align: right; }

.pi-rm {
    background: none;
    border: none;
    color: var(--color-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
}

.pi-rm:hover { color: var(--color-danger); background: #fef2f2; }

.pedido-totais {
    padding-top: .75rem;
    margin-top: .5rem;
    border-top: 1px solid var(--color-border);
}

.tot-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--color-muted);
    margin-bottom: 3px;
}

.tot-row.total {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    margin-top: 5px;
}

/* ── Mobile Sidebar ───────────────────────────────────────── */
.btn-toggle-sidebar {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--color-text);
    padding: 4px;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    z-index: 90;
}

@media (max-width: 767px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.15);
    }

    .app-wrapper { display: block; }

    .main-area {
        height: 100vh;
        width: 100%;
    }

    .venda-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── Mobile Venda — Drawer + FAB ──────────────────────────── */

/* Botão flutuante do carrinho (só mobile) */
.fab-carrinho {
    display: none;
}

@media (max-width: 767px) {

    /* No mobile o painel do pedido some do fluxo normal */
    .pedido-panel {
        display: none;
    }

    /* FAB fixo no canto inferior direito */
    .fab-carrinho {
        display: flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        bottom: 1.25rem;
        right: 1.25rem;
        z-index: 200;
        background: var(--color-primary);
        color: white;
        border: none;
        border-radius: 50px;
        padding: 13px 20px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        box-shadow: 0 4px 16px rgba(29,158,117,.45);
        transition: transform .15s, box-shadow .15s;
    }

    .fab-carrinho:active {
        transform: scale(0.96);
    }

    .fab-badge {
        background: white;
        color: var(--color-primary);
        border-radius: 50px;
        padding: 1px 8px;
        font-size: 12px;
        font-weight: 700;
        min-width: 22px;
        text-align: center;
    }

    /* Drawer — painel deslizante de baixo */
    .pedido-drawer {
        position: fixed;
        inset: 0;
        z-index: 300;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        pointer-events: none;
        visibility: hidden;
    }

    .pedido-drawer.open {
        pointer-events: all;
        visibility: visible;
    }

    .drawer-overlay {
        position: absolute;
        inset: 0;
        background: rgba(0,0,0,.4);
        opacity: 0;
        transition: opacity .25s;
    }

    .pedido-drawer.open .drawer-overlay {
        opacity: 1;
    }

    .drawer-panel {
        position: relative;
        background: var(--color-surface);
        border-radius: 16px 16px 0 0;
        padding: 0 1rem 1.5rem;
        max-height: 90vh;
        overflow-y: auto;
        transform: translateY(100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
    }

    .pedido-drawer.open .drawer-panel {
        transform: translateY(0);
    }

    .drawer-handle {
        width: 36px;
        height: 4px;
        background: var(--color-border);
        border-radius: 2px;
        margin: 12px auto 16px;
    }

    .drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: .75rem;
        border-bottom: 1px solid var(--color-border);
        margin-bottom: .5rem;
    }

    .drawer-close {
        background: none;
        border: none;
        font-size: 20px;
        color: var(--color-muted);
        cursor: pointer;
        padding: 4px;
        line-height: 1;
    }

    /* Nos produtos, no mobile, aumenta o tamanho do card para facilitar o toque */
    .produto-card {
        padding: 12px 14px;
    }

    .prod-nome { font-size: 13px; }
    .prod-preco { font-size: 14px; }

    /* Busca sticky no topo do mobile */
    .search-row-sticky {
        position: sticky;
        top: 0;
        background: var(--color-bg);
        padding: 8px 0;
        z-index: 10;
        margin-bottom: .5rem;
    }
}
