/* ==========================================
   Nexus CRM - Modern Stylesheet
   ========================================== */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed: 0px;
    --topbar-height: 64px;
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #1e1b4b;
    --bg-sidebar-hover: #312e81;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-sidebar: #c7d2fe;
    --text-sidebar-active: #ffffff;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
    --radius: 8px;
    --radius-lg: 8px;
    --transition: all .2s ease;
    --control-height: 36px;
    --control-height-sm: 30px;
}

[data-bs-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #0f0d2e;
    --bg-sidebar-hover: #1e1b4b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    transition: transform .3s ease;
}

.sidebar-header {
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
}

.sidebar-brand i {
    font-size: 28px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
}

.nav-section {
    margin-bottom: 8px;
}

.nav-section-title {
    display: block;
    padding: 12px 12px 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6366f1;
}

.nav-link-sidebar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text-sidebar);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 400;
    transition: var(--transition);
    margin-bottom: 2px;
}

.nav-link-sidebar:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.nav-link-sidebar.active {
    background: var(--primary);
    color: #fff;
    font-weight: 500;
}

.nav-link-sidebar i {
    font-size: 18px;
    width: 22px;
    text-align: center;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar i {
    font-size: 32px;
    color: var(--primary-light);
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    display: block;
    color: #fff;
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    display: block;
    color: var(--text-sidebar);
    font-size: 11px;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin .3s ease, width .3s ease;
    width: calc(100% - var(--sidebar-width));
    min-width: 0;
}

/* Topbar */
.topbar {
    height: var(--topbar-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1020;
    gap: 12px;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.25;
    min-width: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-toggle {
    color: var(--text-secondary);
    padding: 4px 8px;
    text-decoration: none;
    min-width: var(--control-height-sm);
    min-height: var(--control-height-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 992px) {
    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-collapsed .main-content {
        margin-left: 0;
        width: 100%;
    }

    .sidebar-backdrop,
    .sidebar-backdrop.show {
        display: none;
    }
}

/* Content Wrapper */
.content-wrapper {
    padding: 24px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Stat Cards */
.stat-card {
    border: none;
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 12px;
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.stat-card.stat-primary { background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%); }
.stat-card.stat-primary .stat-icon { background: var(--primary); color: #fff; }
.stat-card.stat-primary .stat-value { color: var(--primary-dark); }

.stat-card.stat-success { background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%); }
.stat-card.stat-success .stat-icon { background: #059669; color: #fff; }
.stat-card.stat-success .stat-value { color: #065f46; }

.stat-card.stat-warning { background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%); }
.stat-card.stat-warning .stat-icon { background: #d97706; color: #fff; }
.stat-card.stat-warning .stat-value { color: #92400e; }

.stat-card.stat-danger { background: linear-gradient(135deg, #fef2f2 0%, #fecaca 100%); }
.stat-card.stat-danger .stat-icon { background: #dc2626; color: #fff; }
.stat-card.stat-danger .stat-value { color: #991b1b; }

[data-bs-theme="dark"] .stat-card.stat-primary { background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%); }
[data-bs-theme="dark"] .stat-card.stat-primary .stat-value { color: #a5b4fc; }

[data-bs-theme="dark"] .stat-card.stat-success { background: linear-gradient(135deg, #064e3b 0%, #065f46 100%); }
[data-bs-theme="dark"] .stat-card.stat-success .stat-value { color: #6ee7b7; }

[data-bs-theme="dark"] .stat-card.stat-warning { background: linear-gradient(135deg, #451a03 0%, #78350f 100%); }
[data-bs-theme="dark"] .stat-card.stat-warning .stat-value { color: #fcd34d; }

[data-bs-theme="dark"] .stat-card.stat-danger { background: linear-gradient(135deg, #450a0a 0%, #7f1d1d 100%); }
[data-bs-theme="dark"] .stat-card.stat-danger .stat-value { color: #fca5a5; }

/* Tables */
.table {
    color: var(--text-primary);
    margin-bottom: 0;
}

.table thead th {
    background: var(--bg-body);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    padding: 12px 16px;
    white-space: nowrap;
}

.table tbody td {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.table tbody tr:hover {
    background: rgba(79, 70, 229, .03);
}

.clientes-table th,
.clientes-table td {
    padding-left: 12px;
    padding-right: 12px;
}

.clientes-table .text-nowrap,
.clientes-table .badge {
    white-space: nowrap !important;
    overflow-wrap: normal;
    word-break: normal;
}

.clientes-table .cliente-email-cell {
    min-width: 220px;
    overflow-wrap: normal;
    word-break: normal;
}

.venda-id-col {
    min-width: 82px;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
}

.audit-data {
    max-width: 520px;
    max-height: 240px;
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 11px;
    white-space: pre-wrap;
}

.table-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

/* Forms */
.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 14px;
    background-color: var(--bg-card);
    color: var(--text-primary);
    transition: var(--transition);
    min-height: var(--control-height);
}

.form-select {
    padding-right: 2.25rem;
}

.form-control-sm, .form-select-sm {
    min-height: var(--control-height-sm);
    padding-top: 4px;
    padding-bottom: 4px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.form-label {
    font-weight: 500;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* Buttons */
.btn {
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 14px;
    padding: 7px 12px;
    min-height: var(--control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    line-height: 1.25;
    white-space: nowrap;
    transition: var(--transition);
    overflow: hidden;
}

.btn.btn-sm {
    font-size: 12px;
    padding: 4px 9px;
    min-height: var(--control-height-sm);
    line-height: 1.25;
}

.btn.btn-lg {
    font-size: 15px;
    padding: 9px 14px;
    min-height: 42px;
}

.btn i {
    line-height: 1;
}

.btn.btn-icon {
    width: var(--control-height);
    padding-left: 0;
    padding-right: 0;
}

.btn.btn-sm.btn-icon {
    width: var(--control-height-sm);
    padding-left: 0;
    padding-right: 0;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary);
    color: #fff;
}

.btn-whatsapp {
    background: #25d366;
    border-color: #25d366;
    color: #fff;
}

.btn-whatsapp:hover {
    background: #1da851;
    border-color: #1da851;
    color: #fff;
}

/* Badges */
.badge {
    font-weight: 500;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1.2;
    white-space: normal;
    text-align: center;
}

.badge-soft-danger {
    background: rgba(220, 38, 38, .08);
    color: #b91c1c;
    border: 1px solid rgba(220, 38, 38, .18);
}

.card-header-soft-danger {
    background: rgba(220, 38, 38, .06);
    color: #991b1b;
    border-bottom-color: rgba(220, 38, 38, .16);
}

[data-bs-theme="dark"] .badge-soft-danger {
    background: rgba(248, 113, 113, .14);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, .24);
}

[data-bs-theme="dark"] .card-header-soft-danger {
    background: rgba(248, 113, 113, .10);
    color: #fecaca;
    border-bottom-color: rgba(248, 113, 113, .18);
}

/* Vencimentos */
.vencimento-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.vencimento-item:last-child {
    border-bottom: none;
}

.vencimento-item:hover {
    background: rgba(79, 70, 229, .03);
}

.vencimento-date {
    min-width: 60px;
    text-align: center;
    margin-right: 16px;
}

.vencimento-date .day {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    color: var(--primary);
}

.vencimento-date .month {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.vencimento-date.is-overdue {
    background: rgba(220, 38, 38, .06);
    border: 1px solid rgba(220, 38, 38, .14);
    border-radius: var(--radius);
    padding: 8px 6px;
}

.vencimento-date.is-overdue .day {
    color: #b91c1c;
}

.vencimento-date.is-overdue .month {
    color: #991b1b;
}

[data-bs-theme="dark"] .vencimento-date.is-overdue {
    background: rgba(248, 113, 113, .10);
    border-color: rgba(248, 113, 113, .18);
}

[data-bs-theme="dark"] .vencimento-date.is-overdue .day,
[data-bs-theme="dark"] .vencimento-date.is-overdue .month {
    color: #fca5a5;
}

.vencimento-info {
    flex: 1;
    min-width: 0;
}

.vencimento-info .client-name {
    font-weight: 600;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.vencimento-info .product-name {
    font-size: 12px;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.vencimento-value {
    font-weight: 600;
    font-size: 14px;
    text-align: right;
    min-width: 100px;
}

.vencimento-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Login Page */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4f46e5 100%);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    padding: 40px;
}

.login-card .login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-card .login-logo i {
    font-size: 48px;
    color: var(--primary);
}

.login-card .login-logo h2 {
    font-weight: 700;
    margin-top: 8px;
    color: var(--text-primary);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 32px 20px;
    display: block;
}

.empty-state > i {
    font-size: 36px;
    color: var(--text-secondary);
    opacity: .45;
    display: block;
}

.empty-state h5, .empty-state h6 {
    color: var(--text-secondary);
    margin-top: 12px;
    margin-bottom: 4px;
    font-weight: 500;
    font-size: 15px;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 12px;
}

.empty-state .btn {
    width: auto !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin-top: 0;
}

/* Search Bar */
.search-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    align-items: center;
}

.search-bar .form-control {
    max-width: 260px;
    min-width: 160px;
}

.search-bar .form-select {
    min-width: 130px;
    width: var(--filter-width, auto);
    max-width: var(--filter-max-width, none);
    flex-shrink: 0;
}

.page-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.listing-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.card-header,
.modal-title,
.page-title,
.table td,
.table th {
    overflow-wrap: anywhere;
}

.table-responsive {
    width: 100%;
}

.listing-toolbar .search-bar {
    margin-bottom: 0;
    flex: 1;
    min-width: 0;
}

.listing-toolbar > .btn,
.listing-toolbar > .page-actions {
    flex-shrink: 0;
}

.metric-value {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.min-w-0 {
    min-width: 0;
}

.searchable-field {
    min-width: 0;
}

.searchable-dropdown {
    position: absolute;
    top: calc(100% - 18px);
    left: 0;
    right: 0;
    z-index: 1060;
    display: none;
    max-height: min(260px, 45vh);
    overflow-y: auto;
    margin: 0 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    color: var(--text-primary);
}

/* Toolbar de clientes (filtros + ações na mesma linha) */
.searchable-dropdown > div {
    min-height: 44px;
    display: flex;
    align-items: center;
}

@media (max-width: 575.98px) {
    .searchable-dropdown {
        top: calc(100% - 8px);
        max-height: 52vh;
        margin: 0 8px;
    }
}

.clientes-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.clientes-filters {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.clientes-filters .form-control {
    width: 200px;
    flex-shrink: 1;
    min-width: 120px;
}

.clientes-filters .form-select {
    width: 140px;
    flex-shrink: 1;
    min-width: 110px;
}

.clientes-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Badges de tipo de cliente */
.badge-tipo-cliente    { background-color: #4f46e5; color: #fff; }
.badge-tipo-revendedor { background-color: #0891b2; color: #fff; }
.badge-tipo-fornecedor { background-color: #059669; color: #fff; }

/* Linha de cliente inativo */
tr.cliente-inativo {
    background-color: #f8f0f0 !important;
}

tr.cliente-inativo td {
    color: #94a3b8 !important;
    font-style: italic;
}

tr.cliente-inativo td.fw-medium {
    color: #94a3b8 !important;
    font-weight: 400 !important;
}

tr.cliente-inativo .badge-tipo-cliente,
tr.cliente-inativo .badge-tipo-revendedor,
tr.cliente-inativo .badge-tipo-fornecedor {
    filter: grayscale(80%) !important;
    opacity: 0.6 !important;
}

tr.cliente-inativo a {
    color: #94a3b8 !important;
    pointer-events: none;
}

tr.cliente-inativo:hover {
    background-color: #f0e8e8 !important;
}

[data-bs-theme="dark"] tr.cliente-inativo {
    background-color: rgba(148, 163, 184, 0.06) !important;
}

[data-bs-theme="dark"] tr.cliente-inativo td {
    color: #475569 !important;
}

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,.5);
        z-index: 1040;
        display: none;
    }

    .sidebar-backdrop.show {
        display: block;
    }
}

@media (max-width: 991.98px) {
    input,
    select,
    textarea,
    .form-control,
    .form-select,
    .form-control-sm,
    .form-select-sm {
        font-size: 16px;
    }
}

@media (max-width: 576px) {
    .content-wrapper {
        padding: 16px;
    }

    .stat-card .stat-value {
        font-size: 22px;
    }

    .search-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-bar .form-control,
    .search-bar .form-select {
        max-width: 100%;
        min-width: 0;
        width: 100%;
    }

    .clientes-toolbar {
        flex-wrap: wrap;
    }

    .clientes-filters {
        flex-wrap: wrap;
        width: 100%;
    }

    .clientes-filters .form-control,
    .clientes-filters .form-select {
        width: 100%;
        min-width: 0;
    }

    .clientes-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .topbar {
        padding: 0 16px;
    }

    .topbar-actions {
        gap: 4px;
    }

    .page-title {
        font-size: 16px;
    }

    .page-actions {
        justify-content: stretch;
    }

    .page-actions .btn {
        flex: 1 1 auto;
    }

    .listing-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .listing-toolbar > .btn,
    .listing-toolbar > .page-actions {
        width: 100%;
    }

    .metric-value {
        font-size: 1.05rem;
    }

    .vencimento-item {
        align-items: flex-start;
        gap: 12px;
        flex-wrap: wrap;
    }

    .vencimento-info {
        flex: 1 1 calc(100% - 72px);
    }

    .vencimento-actions {
        width: 100%;
        justify-content: space-between;
    }

    .vencimento-value {
        text-align: left;
        min-width: 0;
    }

    .vencimento-actions .table-actions {
        margin-left: auto;
    }
}

/* Modal adjustments */
.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 12px 20px;
}

.modal-content {
    border-radius: var(--radius-lg);
    border: none;
    box-shadow: var(--shadow-lg);
    background: var(--bg-card);
}

/* Scrollbar */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.15);
    border-radius: 4px;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.content-wrapper > * {
    animation: fadeIn .3s ease;
}
