/* =========================================================
   PDV - ENVIE E RETIRE
   css/style.css
   ========================================================= */

:root {
    --primary: #111827;
    --primary-light: #1f2937;
    --secondary: #374151;

    --success: #15803d;
    --success-light: #dcfce7;

    --warning: #b45309;
    --warning-light: #fef3c7;

    --danger: #b91c1c;
    --danger-light: #fee2e2;

    --info: #0369a1;
    --info-light: #e0f2fe;

    --whatsapp: #25d366;

    --background: #f3f4f6;
    --surface: #ffffff;
    --surface-soft: #f9fafb;

    --border: #e5e7eb;
    --border-dark: #d1d5db;

    --text: #111827;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;

    --radius: 10px;
    --radius-small: 6px;

    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 5px 18px rgba(0, 0, 0, 0.10);

    --sidebar-width: 250px;
    --header-height: 64px;

    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Arial,
        sans-serif;

    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

img {
    max-width: 100%;
}

body.modal-open {
    overflow: hidden;
}

/* =========================================================
   LAYOUT
   ========================================================= */

#app {
    min-height: 100vh;
}

.app-header {
    height: var(--header-height);

    background: var(--surface);
    border-bottom: 1px solid var(--border);

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 20px;

    position: sticky;
    top: 0;

    z-index: 900;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.brand-text strong {
    font-size: 15px;
    font-weight: 750;
}

.brand-text span {
    color: var(--text-muted);
    font-size: 11px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-layout {
    display: flex;
    align-items: flex-start;
}

/* =========================================================
   SIDEBAR
   ========================================================= */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));

    position: sticky;
    top: var(--header-height);

    background: var(--primary);
    color: #fff;

    overflow-y: auto;

    z-index: 800;
}

.main-menu {
    padding: 14px 10px;

    display: flex;
    flex-direction: column;
}

.main-menu .menu-item {
    width: 100%;

    border: 0;
    background: transparent;

    color: #d1d5db;

    min-height: 42px;

    padding: 9px 11px;
    margin-bottom: 2px;

    border-radius: 7px;

    display: flex;
    align-items: center;
    gap: 11px;

    text-align: left;
    font-size: 13px;

    transition:
        background var(--transition),
        color var(--transition);
}

.main-menu .menu-item span:first-child {
    width: 20px;
    min-width: 20px;
    text-align: center;
    font-size: 16px;
}

.main-menu .menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.main-menu .menu-item.active {
    background: rgba(255, 255, 255, 0.13);
    color: #fff;
    font-weight: 600;
}

.menu-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 10px 4px;
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */

.main-content {
    flex: 1;
    min-width: 0;

    padding: 24px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.page-header {
    margin-bottom: 22px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 15px;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 24px;
    line-height: 1.2;
    font-weight: 750;
}

.page-header p {
    color: var(--text-muted);
    margin-top: 4px;
    font-size: 13px;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* =========================================================
   CARDS DE RESUMO (dashboard, caixa, encomendas)
   ========================================================= */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;

    margin-bottom: 20px;
}

.dashboard-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);

    padding: 18px;

    box-shadow: var(--shadow);

    display: flex;
    align-items: center;
    gap: 14px;

    transition:
        transform var(--transition),
        box-shadow var(--transition);
}

.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.card-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;

    border-radius: 10px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--background);

    font-size: 19px;
}

.card-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.card-label {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
}

.card-value {
    font-size: 22px;
    font-weight: 750;
    line-height: 1;
}

/* =========================================================
   PAINÉIS
   ========================================================= */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);

    margin-bottom: 20px;
}

.panel-header {
    padding: 16px 18px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    border-bottom: 1px solid var(--border);

    gap: 12px;
    flex-wrap: wrap;
}

.panel-header h2 {
    font-size: 15px;
    font-weight: 700;
}

.panel-header p {
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 2px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.dashboard-grid .panel {
    margin-bottom: 0;
}

/* =========================================================
   BARRA DE BUSCA / FILTROS
   ========================================================= */

.toolbar {
    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius);

    padding: 14px;

    margin-bottom: 16px;

    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar .search-box {
    flex: 1;
    min-width: 220px;
}

.toolbar select {
    width: auto;
    min-width: 160px;
}

.search-box {
    position: relative;
}

.search-box span {
    position: absolute;

    left: 12px;
    top: 50%;

    transform: translateY(-50%);

    color: var(--text-muted);
    font-size: 13px;

    pointer-events: none;
}

.search-box input {
    padding-left: 34px;
}

/* =========================================================
   FORMULÁRIOS
   ========================================================= */

.form-group {
    margin-bottom: 15px;
    display: block;
}

.form-group span {
    display: block;

    color: var(--text-secondary);

    font-size: 12px;
    font-weight: 600;

    margin-bottom: 6px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 14px;
}

.form-full {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

input,
select,
textarea {
    width: 100%;

    background: #fff;
    color: var(--text);

    border: 1px solid var(--border-dark);
    border-radius: var(--radius-small);

    padding: 10px 11px;

    outline: none;

    transition:
        border-color var(--transition),
        box-shadow var(--transition);
}

input,
select {
    min-height: 40px;
}

textarea {
    min-height: 80px;
    resize: vertical;
}

input::placeholder,
textarea::placeholder {
    color: #9ca3af;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #6b7280;
    box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.12);
}

.input-with-button {
    display: flex;
    gap: 8px;
}

.input-with-button input {
    flex: 1;
}

.report-filters {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);

    padding: 16px;
    margin-bottom: 18px;

    display: flex;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
}

.report-filters .form-group {
    margin-bottom: 0;
    min-width: 170px;
}

/* =========================================================
   BOTÕES
   ========================================================= */

.btn {
    min-height: 40px;

    border: 1px solid transparent;
    border-radius: var(--radius-small);

    padding: 9px 14px;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;

    font-size: 13px;
    font-weight: 650;

    white-space: nowrap;

    transition:
        background var(--transition),
        border-color var(--transition),
        color var(--transition),
        transform var(--transition);
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-light);
    border-color: var(--primary-light);
}

.btn-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border-dark);
}

.btn-secondary:hover {
    background: var(--background);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #991b1b;
}

.btn-whatsapp {
    background: var(--whatsapp);
    color: #fff;
    border-color: var(--whatsapp);
}

.btn-whatsapp:hover {
    background: #1ebe57;
}

.btn-small {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
}

.btn-icon {
    width: 38px;
    height: 38px;

    padding: 0;

    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-small);

    color: var(--text);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.btn-icon:hover {
    background: var(--background);
}

.btn-icon.danger {
    color: var(--danger);
}

/* =========================================================
   TABELAS
   ========================================================= */

.table-container {
    width: 100%;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.table-container table,
.table-scroll table {
    width: 100%;
    border-collapse: collapse;
    min-width: 650px;
}

.table-container th,
.table-scroll th {
    background: var(--surface-soft);

    color: var(--text-secondary);

    font-size: 11px;
    font-weight: 700;

    text-align: left;
    white-space: nowrap;

    padding: 11px 12px;

    border-bottom: 1px solid var(--border);
}

.table-container td,
.table-scroll td {
    color: var(--text);

    font-size: 12px;

    padding: 12px;

    border-bottom: 1px solid var(--border);

    vertical-align: middle;
}

.table-container tbody tr:hover,
.table-scroll tbody tr:hover {
    background: #fafafa;
}

.table-container tbody tr:last-child td,
.table-scroll tbody tr:last-child td {
    border-bottom: 0;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.table-subtext {
    display: block;
    color: var(--text-muted);
    font-size: 10px;
    margin-top: 2px;
}

/* =========================================================
   LISTAS SIMPLES (dashboard)
   ========================================================= */

.simple-list {
    display: flex;
    flex-direction: column;
}

.list-row {
    padding: 12px 18px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;

    border-bottom: 1px solid var(--border);
}

.list-row:last-child {
    border-bottom: 0;
}

.list-row strong {
    display: block;
    font-size: 13px;
}

.list-row small {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 2px;
}

/* =========================================================
   BADGES
   ========================================================= */

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 4px 8px;

    border-radius: 999px;

    font-size: 10px;
    font-weight: 700;

    white-space: nowrap;
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

/* =========================================================
   MODAL
   ========================================================= */

.modal-overlay {
    position: fixed;
    inset: 0;

    background: rgba(17, 24, 39, 0.58);

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    z-index: 5000;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    width: 100%;
    max-width: 620px;
    max-height: calc(100vh - 40px);

    background: #fff;

    border-radius: var(--radius);

    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);

    display: flex;
    flex-direction: column;

    overflow: hidden;
}

.modal-header {
    min-height: 58px;

    padding: 14px 18px;

    border-bottom: 1px solid var(--border);

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.modal-header p {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 2px;
}

.modal-content {
    padding: 18px;
    overflow-y: auto;
}

.modal-footer {
    padding: 14px 18px;

    border-top: 1px solid var(--border);

    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.scanner-modal {
    max-width: 480px;
}

/* =========================================================
   TOAST / NOTIFICAÇÕES
   ========================================================= */

.toast-container {
    position: fixed;

    top: 75px;
    right: 20px;

    z-index: 9000;

    display: flex;
    flex-direction: column;
    gap: 8px;

    width: min(360px, calc(100vw - 40px));
}

.toast {
    background: #fff;

    border: 1px solid var(--border);
    border-left: 4px solid var(--text-muted);

    border-radius: var(--radius);

    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);

    padding: 13px 15px;

    font-size: 12px;

    opacity: 0;
    transform: translateX(20px);

    transition:
        opacity var(--transition),
        transform var(--transition);
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-success {
    border-left-color: var(--success);
}

.toast-warning {
    border-left-color: var(--warning);
}

.toast-error {
    border-left-color: var(--danger);
}

.toast-info {
    border-left-color: var(--info);
}

/* =========================================================
   CAIXA / VENDA - CARRINHO
   ========================================================= */

.venda-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.produto-selector {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.item-selector {
    max-height: 220px;
    overflow-y: auto;

    display: flex;
    flex-direction: column;
    gap: 6px;

    border: 1px solid var(--border);
    border-radius: var(--radius-small);

    padding: 6px;
}

.sale-item {
    width: 100%;

    border: 1px solid var(--border);
    background: #fff;

    border-radius: var(--radius-small);

    padding: 10px 11px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 10px;

    text-align: left;
}

.sale-item:hover {
    background: var(--surface-soft);
}

.sale-item small {
    display: block;
    color: var(--text-muted);
    font-size: 10px;
    margin-top: 2px;
}

.cart-container {
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
}

.cart-list {
    display: flex;
    flex-direction: column;
}

.cart-row {
    padding: 10px 12px;

    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 12px;

    border-bottom: 1px solid var(--border);
}

.cart-row:last-child {
    border-bottom: 0;
}

.cart-row small {
    display: block;
    color: var(--text-muted);
    font-size: 10px;
    margin-top: 2px;
}

.quantity-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.quantity-control button {
    width: 26px;
    height: 26px;

    border: 1px solid var(--border-dark);
    background: #fff;
    border-radius: 6px;

    display: flex;
    align-items: center;
    justify-content: center;
}

.sale-total {
    border-top: 1px solid var(--border);

    padding-top: 14px;

    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sale-total span {
    color: var(--text-secondary);
    font-size: 13px;
}

.sale-total strong {
    font-size: 22px;
}

/* =========================================================
   DETALHE DE VENDA
   ========================================================= */

.sale-detail {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.detail-grid span {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
    margin-bottom: 3px;
}

.detail-grid strong {
    font-size: 13px;
}

/* =========================================================
   RELATÓRIOS
   ========================================================= */

.report-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;

    padding: 18px;
}

.report-box {
    background: var(--surface-soft);

    border: 1px solid var(--border);
    border-radius: var(--radius);

    padding: 16px;
}

.report-box span {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
}

.report-box strong {
    display: block;
    font-size: 21px;
    font-weight: 750;
    margin-top: 5px;
}

.report-info {
    padding: 0 18px 18px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* =========================================================
   SCANNER
   ========================================================= */

.scanner-container {
    width: 100%;

    background: #111;

    position: relative;

    display: flex;
    align-items: center;
    justify-content: center;
}

.scanner-container video {
    width: 100%;
    max-height: 380px;

    display: block;

    object-fit: cover;
}

.scanner-frame {
    position: absolute;

    width: min(80%, 380px);
    height: 120px;

    border: 2px solid #fff;
    border-radius: 10px;

    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);

    pointer-events: none;
}

.scanner-footer {
    padding: 12px;

    background: #111;

    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.scanner-status {
    color: #fff;
    font-size: 12px;
    text-align: center;
}

.scanner-manual-link {
    background: transparent;
    border: 0;
    color: #93c5fd;
    text-decoration: underline;
    font-size: 12px;
    margin-left: 4px;
}

/* =========================================================
   BACKUP
   ========================================================= */

.backup-actions {
    padding: 18px;
}

/* =========================================================
   ESTADO VAZIO
   ========================================================= */

.empty-state {
    padding: 45px 20px;

    text-align: center;

    color: var(--text-muted);
}

.empty-state.compact {
    padding: 22px 15px;
}

.empty-state span:first-child {
    display: block;
    font-size: 28px;
    margin-bottom: 10px;
}

.empty-state strong {
    display: block;

    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 12px;
    max-width: 420px;
    margin: 0 auto;
}

/* =========================================================
   RESPONSIVIDADE
   ========================================================= */

@media (max-width: 1100px) {
    :root {
        --sidebar-width: 220px;
    }

    .cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        height: auto;

        transform: translateX(-100%);
        transition: transform 0.25s ease;

        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.18);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        padding: 16px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-actions {
        width: 100%;
    }

    .page-actions .btn {
        flex: 1;
    }

    .cards-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .report-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .report-summary {
        grid-template-columns: 1fr;
    }

    .modal-overlay {
        padding: 10px;
    }

    .modal {
        max-height: calc(100vh - 20px);
    }

    .toast-container {
        top: 65px;
        right: 10px;
        width: calc(100vw - 20px);
    }

    .cart-row {
        grid-template-columns: 1fr auto;
        row-gap: 8px;
    }
}

@media (max-width: 480px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }
}