/**
 * Gestor de Vendas - Tema Dark
 */

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.15);

    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --topbar-height: 60px;

    --bg-base: #0a0a0f;
    --bg-surface: #12121a;
    --bg-elevated: #1a1a26;
    --bg-hover: #222230;
    --bg-input: #14141e;

    --border-color: #2a2a3a;
    --border-light: #333345;

    --text-primary: #e8e8f0;
    --text-secondary: #9898a8;
    --text-muted: #686878;

    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
    --transition: all 0.3s ease;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    margin: 0;
    overflow-x: hidden;
}

/* ===== BOOTSTRAP OVERRIDES ===== */
.form-control,
.form-select {
    background-color: var(--bg-input);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.form-control:focus,
.form-select:focus {
    background-color: var(--bg-input);
    border-color: var(--primary);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.2);
}

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

.input-group-text {
    background-color: var(--bg-elevated);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.form-label {
    color: var(--text-secondary);
}

.modal-content {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
}

.modal-header {
    border-bottom-color: var(--border-color);
}

.modal-footer {
    border-top-color: var(--border-color);
}

.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.dropdown-menu {
    background-color: var(--bg-elevated);
    border-color: var(--border-color);
}

.dropdown-item {
    color: var(--text-primary);
}

.dropdown-item:hover {
    background-color: var(--bg-hover);
}

.page-link {
    background-color: var(--bg-elevated);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.page-link:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.page-item.active .page-link {
    background-color: var(--primary);
    border-color: var(--primary);
}

.page-item.disabled .page-link {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-muted);
}

.alert-info {
    background-color: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.25);
    color: #93c5fd;
}

.alert-warning {
    background-color: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.25);
    color: #fcd34d;
}

.alert-danger {
    background-color: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
}

.alert-success {
    background-color: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.25);
    color: #86efac;
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border-color);
    --bs-table-hover-bg: var(--bg-hover);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.02);
}

hr {
    border-color: var(--border-color);
    opacity: 1;
}

.text-muted {
    color: var(--text-muted) !important;
}

a {
    color: var(--primary);
}

a:hover {
    color: #60a5fa;
}

.btn-outline-secondary {
    color: var(--text-secondary);
    border-color: var(--border-light);
}

.btn-outline-secondary:hover {
    background-color: var(--bg-hover);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.btn-link {
    color: var(--text-secondary);
}

.btn-link:hover {
    color: var(--text-primary);
}

/* ===== APP LAYOUT ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: var(--transition);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .nav-link span {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary);
    font-weight: 700;
    font-size: 1.1rem;
}

.sidebar-header i { font-size: 1.5rem; }

.sidebar-nav {
    padding: 12px 0;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    border-left: 3px solid transparent;
    font-size: 0.95rem;
}

.sidebar-nav .nav-link:hover {
    background: var(--primary-glow);
    color: var(--primary);
}

.sidebar-nav .nav-link.active {
    background: var(--primary-glow);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar-nav .nav-link i {
    font-size: 1.2rem;
    min-width: 24px;
    text-align: center;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    transition: var(--transition);
    min-height: 100vh;
    background: var(--bg-base);
}

.sidebar.collapsed ~ .main-content,
.app-container:has(.sidebar.collapsed) .main-content {
    margin-left: var(--sidebar-collapsed);
}

.top-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    height: var(--topbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
    color: var(--text-primary);
}

.top-bar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.sidebar-toggle {
    color: var(--text-secondary);
    padding: 4px;
}

.page-content {
    padding: 24px;
}

/* ===== CARDS ===== */
.stat-card {
    background: var(--bg-surface);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    transition: var(--transition);
    height: 100%;
}

.stat-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--border-light);
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 8px 0 4px;
}

.stat-card .stat-label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.stat-icon.blue   { background: rgba(59, 130, 246, 0.15);  color: #60a5fa; }
.stat-icon.green  { background: rgba(34, 197, 94, 0.15);   color: #4ade80; }
.stat-icon.orange { background: rgba(251, 146, 60, 0.15);  color: #fb923c; }
.stat-icon.red    { background: rgba(239, 68, 68, 0.15);   color: #f87171; }
.stat-icon.purple { background: rgba(168, 85, 247, 0.15);  color: #c084fc; }
.stat-icon.teal   { background: rgba(45, 212, 191, 0.15);   color: #2dd4bf; }

/* ===== CARDS PANEL ===== */
.panel-card {
    background: var(--bg-surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.panel-card .panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-card .panel-header h5 {
    margin: 0;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.panel-card .panel-body {
    padding: 20px;
}

/* ===== TABLES ===== */
.table-container {
    overflow-x: auto;
}

.table-modern {
    margin: 0;
    font-size: 0.9rem;
}

.table-modern thead th {
    background: var(--bg-elevated);
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.table-modern thead th:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.table-modern tbody tr:hover {
    background: var(--bg-hover);
}

.table-modern .badge {
    font-weight: 500;
}

.table-modern td {
    color: var(--text-primary);
    border-color: var(--border-color);
}

.table-modern a {
    color: #60a5fa;
}

.table-modern a:hover {
    color: #93c5fd;
}

/* ===== SEARCH BAR ===== */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar .search-input {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.search-bar .search-input i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    z-index: 2;
}

.search-bar .search-input input {
    padding-left: 36px;
}

/* ===== PAGINATION ===== */
.pagination-info {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ===== FORMS ===== */
.form-section {
    background: var(--bg-surface);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.form-section h5 {
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== BUTTONS ===== */
.btn-action {
    padding: 4px 8px;
    font-size: 0.85rem;
}

/* ===== TIMELINE ===== */
.timeline {
    position: relative;
    padding-left: 30px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.timeline-item {
    position: relative;
    padding-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -24px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: var(--bg-surface);
}

.timeline-item.venda::before     { border-color: #f87171; background: rgba(239, 68, 68, 0.2); }
.timeline-item.pagamento::before { border-color: #4ade80; background: rgba(34, 197, 94, 0.2); }

.timeline-item .timeline-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.timeline-item .timeline-value {
    font-weight: 600;
}

/* ===== VENDA ===== */
.venda-itens-table input {
    max-width: 100px;
}

.venda-total {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* ===== CLIENTE DETAIL ===== */
.cliente-info-card {
    background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #fff;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 4px 24px rgba(59, 130, 246, 0.1);
}

.cliente-info-card .saldo {
    font-size: 2rem;
    font-weight: 700;
}

/* ===== BADGES DARK ===== */
.badge-categoria {
    background-color: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
    font-weight: 500;
}

.badge-categoria .btn-link {
    line-height: 1;
    opacity: 0.7;
}

.badge-categoria .btn-link:hover {
    opacity: 1;
}

/* ===== LOADING ===== */
.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-muted);
}

.loading-overlay .spinner-border {
    margin-right: 12px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.4;
}

/* ===== SWEETALERT2 DARK ===== */
.swal2-popup {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color);
}

.swal2-title {
    color: var(--text-primary) !important;
}

.swal2-html-container {
    color: var(--text-secondary) !important;
}

.swal2-input,
.swal2-textarea {
    background: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

.swal2-validation-message {
    background: var(--bg-elevated) !important;
    color: #f87171 !important;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== RESPONSIVE ===== */

/* Overlay do menu mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

body.no-scroll {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

@media (max-width: 991.98px) {
    .form-section {
        padding: 18px;
    }

    .panel-card .panel-body {
        padding: 16px;
    }

    .cliente-info-card {
        padding: 18px;
    }

    .cliente-info-card .saldo {
        font-size: 1.6rem;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        z-index: 1001;
        width: min(var(--sidebar-width), 85vw);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        width: min(var(--sidebar-width), 85vw);
        transform: translateX(-100%);
    }

    .sidebar.collapsed.mobile-open {
        transform: translateX(0);
    }

    .sidebar.collapsed .sidebar-title,
    .sidebar.collapsed .nav-link span {
        display: inline;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100%;
    }

    .top-bar {
        padding: 0 12px;
        gap: 8px;
        height: 56px;
    }

    .page-title {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .top-bar-user span {
        display: none;
    }

    .page-content {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    /* Cards dashboard */
    .stat-card {
        padding: 14px;
    }

    .stat-card .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .stat-card .stat-value {
        font-size: 1.25rem;
    }

    .stat-card .stat-label {
        font-size: 0.75rem;
    }

    /* Barra de busca e filtros */
    .search-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .search-bar .search-input,
    .search-bar .form-select,
    .search-bar .btn {
        width: 100%;
        min-width: 0;
    }

    .search-bar .btn {
        padding: 10px 16px;
    }

    /* Painéis */
    .panel-card .panel-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .panel-card .panel-header .form-select {
        width: 100% !important;
    }

    .panel-card .panel-body.border-top.d-flex {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
        text-align: center;
    }

    .panel-card .panel-body.border-top .pagination {
        justify-content: center;
    }

    /* Tabelas — scroll horizontal suave */
    .table-container {
        -webkit-overflow-scrolling: touch;
        margin: 0 -1px;
    }

    .table-modern {
        font-size: 0.82rem;
    }

    .table-modern thead th,
    .table-modern tbody td {
        padding: 10px 12px;
    }

    /* Botões de ação maiores para toque */
    .btn-action {
        padding: 6px 10px;
        min-width: 36px;
        min-height: 36px;
    }

    .btn, .form-control, .form-select {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 36px;
    }

    /* Timeline */
    .timeline {
        padding-left: 24px;
    }

    /* Venda */
    .venda-total {
        font-size: 1.25rem;
    }

    /* Modal */
    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: calc(50% - 4px);
    }

    /* Input groups empilhados quando necessário */
    .input-group:not(.keep-inline) {
        flex-wrap: wrap;
    }

    /* Gráficos */
    .panel-card canvas {
        max-height: 220px;
    }

    /* Empty state */
    .empty-state {
        padding: 24px 16px;
    }

    .empty-state i {
        font-size: 2.5rem;
    }

    .loading-overlay {
        padding: 40px 16px;
    }
}

@media (max-width: 576px) {
    .page-content {
        padding: 10px;
    }

    .form-section {
        padding: 14px;
        border-radius: 10px;
    }

    .stat-card .d-flex.align-items-center.gap-3 {
        flex-direction: column;
        text-align: center;
        gap: 8px !important;
    }

    .cliente-info-card h3 {
        font-size: 1.25rem;
    }

    .modal-footer .btn {
        flex: 1 1 100%;
    }

    /* Tabela vira cards no mobile */
    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody tr {
        display: block;
        margin-bottom: 12px;
        padding: 12px;
        background: var(--bg-elevated);
        border: 1px solid var(--border-color);
        border-radius: 10px;
    }

    .table-mobile-cards tbody tr:hover {
        background: var(--bg-hover);
    }

    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border: none;
        gap: 12px;
        text-align: right;
    }

    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.78rem;
        text-align: left;
        flex-shrink: 0;
    }

    .table-mobile-cards tbody td:last-child {
        justify-content: flex-end;
        padding-top: 10px;
        margin-top: 4px;
        border-top: 1px solid var(--border-color);
    }

    .table-mobile-cards tbody td:last-child::before {
        display: none;
    }
}

/* ===== PRINT ===== */
@media print {
    .sidebar, .top-bar, .search-bar, .btn, .pagination {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    body {
        background: #fff;
        color: #000;
    }
}
