/* ─── Via Varejo Integrado - Design System ──────────────────────── */

:root, [data-theme="dark"] {
    /* Color Palette - Premium Dark Theme */
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #1e2130;
    --bg-card-hover: #252840;
    --bg-input: #161825;
    --bg-glass: rgba(30, 33, 48, 0.85);

    --accent-primary: #6c5ce7;
    --accent-primary-light: #a29bfe;
    --accent-secondary: #00cec9;
    --accent-warning: #fdcb6e;
    --accent-danger: #ff6b6b;
    --accent-success: #00b894;

    --text-primary: #e8e8f0;
    --text-secondary: #9395a5;
    --text-muted: #5f6175;

    --border-color: rgba(108, 92, 231, 0.15);
    --border-subtle: rgba(255, 255, 255, 0.06);

    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 30px rgba(108, 92, 231, 0.15);
    --shadow-btn: 0 4px 15px rgba(108, 92, 231, 0.4);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --invert-icon: 0.8;
    --btn-close-filter: invert(0.8);
}

/* ─── Light Theme ──────────────────────────────────────────────── */

[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #e4e7ec;
    --bg-card: #ffffff;
    --bg-card-hover: #f8f9fb;
    --bg-input: #f5f6f8;
    --bg-glass: rgba(255, 255, 255, 0.88);

    --accent-primary: #5b4cdb;
    --accent-primary-light: #6c5ce7;
    --accent-secondary: #0097a7;
    --accent-warning: #e6a817;
    --accent-danger: #e53e3e;
    --accent-success: #0d9f6e;

    --text-primary: #1a202c;
    --text-secondary: #5a6070;
    --text-muted: #9ca3b0;

    --border-color: rgba(108, 92, 231, 0.2);
    --border-subtle: rgba(0, 0, 0, 0.08);

    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.06);
    --shadow-glow: 0 4px 20px rgba(108, 92, 231, 0.1);
    --shadow-btn: 0 3px 10px rgba(108, 92, 231, 0.25);

    --invert-icon: 0;
    --btn-close-filter: none;
}

/* ─── Global ───────────────────────────────────────────────────── */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.4s ease, color 0.4s ease;
}

a { color: var(--accent-primary-light); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent-primary); }

/* ─── Scrollbar ────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--accent-primary); border-radius: 3px; }

/* ─── Navbar ───────────────────────────────────────────────────── */

.navbar-custom {
    background: var(--bg-glass) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.6rem 0;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 1050;
}

.navbar-custom .navbar-brand {
    font-weight: 800;
    font-size: 1.35rem;
    letter-spacing: -0.5px;
}

.brand-via { color: #002776; } /* Azul Brasil */
.brand-lar { color: #009c3b; } /* Verde Brasil */
.brand-brasil { color: #ffdf00; } /* Amarelo Brasil */

[data-theme="dark"] .brand-via { color: #4facfe; } /* Adjusted for dark mode */
[data-theme="dark"] .brand-lar { color: #00d26a; } /* Adjusted for dark mode */
[data-theme="dark"] .brand-brasil { color: #ffd700; } /* Adjusted for dark mode */

.navbar-custom .nav-link {
    color: var(--text-secondary) !important;
    font-weight: 500;
    font-size: 0.9rem;
    padding: 0.5rem 1rem !important;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    position: relative;
}

.navbar-custom .nav-link:hover,
.navbar-custom .nav-link.active {
    color: var(--text-primary) !important;
    background: rgba(108, 92, 231, 0.1);
}

.navbar-custom .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--accent-primary);
    border-radius: 2px;
}

.navbar-custom .navbar-toggler {
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.6rem;
}

.navbar-custom .navbar-toggler-icon { filter: invert(var(--invert-icon)); }

/* ─── Theme toggle ────────────────────────────────────────────── */

.theme-toggle {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.1rem;
}

.theme-toggle:hover {
    background: rgba(108, 92, 231, 0.1);
    color: var(--accent-primary-light);
    border-color: var(--accent-primary);
}

/* ─── Main Content ─────────────────────────────────────────────── */

.main-content { padding: 2rem 0; min-height: calc(100vh - 64px); }

/* ─── Cards ────────────────────────────────────────────────────── */

.card-custom {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    transition: var(--transition);
    overflow: hidden;
}

.card-custom:hover {
    border-color: var(--border-color);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.card-custom .card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-subtle);
    padding: 1.2rem 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-custom .card-body { padding: 1.5rem; }

/* ─── KPI Cards ────────────────────────────────────────────────── */

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
}

.kpi-card.kpi-purple::before { background: linear-gradient(90deg, var(--accent-primary), var(--accent-primary-light)); }
.kpi-card.kpi-teal::before { background: linear-gradient(90deg, var(--accent-secondary), #55efc4); }
.kpi-card.kpi-red::before { background: linear-gradient(90deg, var(--accent-danger), #ee5a24); }
.kpi-card.kpi-yellow::before { background: linear-gradient(90deg, var(--accent-warning), #f0932b); }
.kpi-card.kpi-green::before { background: linear-gradient(90deg, var(--accent-success), #55efc4); }

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow);
    border-color: var(--border-color);
}

.kpi-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; margin-bottom: 1rem;
}

.kpi-icon.purple { background: rgba(108, 92, 231, 0.15); color: var(--accent-primary-light); }
.kpi-icon.teal { background: rgba(0, 206, 201, 0.15); color: var(--accent-secondary); }
.kpi-icon.red { background: rgba(255, 107, 107, 0.15); color: var(--accent-danger); }
.kpi-icon.yellow { background: rgba(253, 203, 110, 0.15); color: var(--accent-warning); }
.kpi-icon.green { background: rgba(0, 184, 148, 0.15); color: var(--accent-success); }

.kpi-value { font-size: 1.8rem; font-weight: 800; letter-spacing: -1px; line-height: 1.1; margin-bottom: 0.25rem; }
.kpi-label { font-size: 0.85rem; color: var(--text-secondary); font-weight: 500; }

/* ─── Tables ───────────────────────────────────────────────────── */

.table-custom { width: 100%; border-collapse: separate; border-spacing: 0; }

.table-custom thead th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600; font-size: 0.8rem;
    text-transform: uppercase; letter-spacing: 0.5px;
    padding: 0.9rem 1rem; border: none; white-space: nowrap;
}

.table-custom thead th:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.table-custom thead th:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.table-custom tbody tr { transition: var(--transition); }
.table-custom tbody tr:hover { background: rgba(108, 92, 231, 0.05); }

.table-custom tbody td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.9rem; vertical-align: middle;
}

/* ─── Forms ────────────────────────────────────────────────────── */

.form-control-custom,
.form-control-custom.form-control,
.form-control-custom.form-select {
    background: var(--bg-input) !important;
    border: 1px solid var(--border-subtle) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    padding: 0.65rem 1rem; font-size: 0.9rem;
    transition: var(--transition);
}

.form-control-custom:focus {
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15) !important;
    outline: none;
}

.form-control-custom::placeholder { color: var(--text-muted) !important; }

.form-label-custom {
    font-size: 0.85rem; font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    text-transform: uppercase; letter-spacing: 0.3px;
}

/* ─── Buttons ──────────────────────────────────────────────────── */

.btn-primary-custom {
    background: linear-gradient(135deg, var(--accent-primary), #5b4cdb);
    border: none; color: #fff; font-weight: 600;
    padding: 0.6rem 1.5rem; border-radius: var(--radius-sm);
    transition: var(--transition); box-shadow: var(--shadow-btn); font-size: 0.9rem;
}
.btn-primary-custom:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.5);
    background: linear-gradient(135deg, #7c6ff0, var(--accent-primary)); color: #fff;
}

.btn-success-custom {
    background: linear-gradient(135deg, var(--accent-success), #00a085);
    border: none; color: #fff; font-weight: 600;
    padding: 0.6rem 1.5rem; border-radius: var(--radius-sm);
    transition: var(--transition); font-size: 0.9rem;
}
.btn-success-custom:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 184, 148, 0.4); color: #fff; }

.btn-danger-custom {
    background: linear-gradient(135deg, var(--accent-danger), #e55039);
    border: none; color: #fff; font-weight: 600;
    padding: 0.6rem 1.5rem; border-radius: var(--radius-sm);
    transition: var(--transition); font-size: 0.9rem;
}
.btn-danger-custom:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4); color: #fff; }

.btn-outline-custom {
    background: transparent; border: 1px solid var(--border-color);
    color: var(--text-secondary); font-weight: 500;
    padding: 0.5rem 1.2rem; border-radius: var(--radius-sm);
    transition: var(--transition); font-size: 0.85rem;
}
.btn-outline-custom:hover {
    background: rgba(108, 92, 231, 0.1);
    border-color: var(--accent-primary); color: var(--accent-primary-light);
}

.btn-icon {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); border: none;
    transition: var(--transition); font-size: 0.9rem; padding: 0;
}

.btn-icon.edit { background: rgba(108, 92, 231, 0.1); color: var(--accent-primary-light); }
.btn-icon.edit:hover { background: var(--accent-primary); color: #fff; }
.btn-icon.delete { background: rgba(255, 107, 107, 0.1); color: var(--accent-danger); }
.btn-icon.delete:hover { background: var(--accent-danger); color: #fff; }
.btn-icon.success { background: rgba(0, 184, 148, 0.1); color: var(--accent-success); }
.btn-icon.success:hover { background: var(--accent-success); color: #fff; }

/* ─── Badges ───────────────────────────────────────────────────── */

.badge-status { padding: 0.35rem 0.8rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-rascunho { background: rgba(253, 203, 110, 0.15); color: var(--accent-warning); }
.badge-finalizada { background: rgba(0, 184, 148, 0.15); color: var(--accent-success); }
.badge-cancelada { background: rgba(255, 107, 107, 0.15); color: var(--accent-danger); }

/* ─── PDV ──────────────────────────────────────────────────────── */

.pdv-form-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem; position: sticky; top: 80px;
}

.pdv-cart-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg); overflow: hidden;
}

.pdv-cart-header {
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.1), rgba(0, 206, 201, 0.05));
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex; align-items: center; justify-content: space-between;
}

.pdv-total {
    font-size: 2rem; font-weight: 800;
    background: linear-gradient(135deg, var(--accent-primary-light), var(--accent-secondary));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* ─── Login ────────────────────────────────────────────────────── */

.login-container {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--bg-primary); position: relative; overflow: hidden;
}
.login-container::before {
    content: ''; position: absolute; width: 600px; height: 600px; border-radius: 50%;
    background: radial-gradient(circle, rgba(108, 92, 231, 0.15), transparent 70%);
    top: -200px; right: -200px;
}
.login-container::after {
    content: ''; position: absolute; width: 400px; height: 400px; border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 206, 201, 0.1), transparent 70%);
    bottom: -150px; left: -150px;
}

.login-card {
    background: var(--bg-card); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl); padding: 3rem;
    width: 100%; max-width: 420px; box-shadow: var(--shadow-card);
    position: relative; z-index: 1;
}

.login-title {
    font-weight: 800; font-size: 1.8rem; margin-bottom: 0.3rem;
}
.login-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 2rem; }

/* ─── Modal ────────────────────────────────────────────────────── */

.modal-content { background: var(--bg-card) !important; border: 1px solid var(--border-color) !important; border-radius: var(--radius-lg) !important; }
.modal-header { border-bottom: 1px solid var(--border-subtle) !important; padding: 1.2rem 1.5rem !important; }
.modal-title { color: var(--text-primary) !important; font-weight: 700 !important; }
.modal-body { padding: 1.5rem !important; }
.modal-footer { border-top: 1px solid var(--border-subtle) !important; padding: 1rem 1.5rem !important; }
.btn-close { filter: var(--btn-close-filter); }

/* ─── Alerts ───────────────────────────────────────────────────── */

.alert-custom {
    border-radius: var(--radius-sm); border: none;
    padding: 0.8rem 1.2rem; font-size: 0.9rem; font-weight: 500;
    animation: slideDown 0.3s ease;
}
.alert-custom.alert-success { background: rgba(0, 184, 148, 0.15); color: var(--accent-success); }
.alert-custom.alert-danger { background: rgba(255, 107, 107, 0.15); color: var(--accent-danger); }
.alert-custom.alert-info { background: rgba(108, 92, 231, 0.15); color: var(--accent-primary-light); }
.alert-custom.alert-warning { background: rgba(253, 203, 110, 0.15); color: var(--accent-warning); }

/* ─── Page Header ──────────────────────────────────────────────── */

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem;
}
.page-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.5px; margin: 0; }
.page-title i { color: var(--accent-primary-light); margin-right: 0.5rem; }

/* ─── Receipt ──────────────────────────────────────────────────── */

.recibo-card {
    background: var(--bg-card); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg); overflow: hidden;
    max-width: 700px; margin: 0 auto;
}
.recibo-header {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    padding: 2rem; text-align: center; color: #fff;
}
.recibo-header h2 { font-weight: 800; margin-bottom: 0.3rem; }
.recibo-body { padding: 2rem; }

/* ─── Financial Filter Tabs ────────────────────────────────────── */

.filter-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }

.filter-tab {
    padding: 0.5rem 1.2rem; border-radius: 20px;
    font-size: 0.85rem; font-weight: 600;
    border: 1px solid var(--border-subtle);
    background: transparent; color: var(--text-secondary);
    transition: var(--transition); text-decoration: none;
}
.filter-tab:hover { border-color: var(--accent-primary); color: var(--accent-primary-light); }
.filter-tab.active { background: var(--accent-primary); border-color: var(--accent-primary); color: #fff; }

/* ─── Empty State ──────────────────────────────────────────────── */

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; display: block; }
.empty-state p { font-size: 1rem; margin: 0; }

/* ─── Animations ───────────────────────────────────────────────── */

@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fadeIn 0.4s ease; }

/* ─── HTMX Indicator ──────────────────────────────────────────── */

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }

/* ─── Responsive ───────────────────────────────────────────────── */

@media (max-width: 768px) {
    .page-title { font-size: 1.3rem; }
    .kpi-value { font-size: 1.4rem; }
    .pdv-form-panel { position: static; }
    .main-content { padding: 1rem 0; }
    .login-card { margin: 1rem; padding: 2rem; }
    .pdv-total { font-size: 1.5rem; }
}

/* ─── Dropdown ─────────────────────────────────────────────────── */

.dropdown-menu { background: var(--bg-card) !important; border: 1px solid var(--border-subtle) !important; border-radius: var(--radius-sm) !important; box-shadow: var(--shadow-card) !important; }
.dropdown-item { color: var(--text-secondary) !important; font-size: 0.9rem; padding: 0.5rem 1rem; transition: var(--transition); }
.dropdown-item:hover { background: rgba(108, 92, 231, 0.1) !important; color: var(--text-primary) !important; }

/* ─── Parcela row atrasada ─────────────────────────────────────── */

.parcela-atrasada { border-left: 3px solid var(--accent-danger) !important; }

/* ─── Search input ──────────────────────────────────────────────── */

.search-input-wrapper { position: relative; }
.search-input-wrapper i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-input-wrapper input { padding-left: 38px !important; }

/* ─── Input group for dark/light ───────────────────────────────── */

.input-group-text {
    background: var(--bg-input) !important;
    border: 1px solid var(--border-subtle) !important;
    color: var(--text-muted) !important;
}

/* ─── Progress bar for parcelas ────────────────────────────────── */

.progress-thin {
    height: 4px;
    background: var(--bg-secondary);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.progress-thin .bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.4s ease;
}

.progress-thin .bar.success { background: var(--accent-success); }
.progress-thin .bar.warning { background: var(--accent-warning); }
