/* Sistema de facturación — tokens y componentes (Bootstrap 5 como base) */
:root {
    --app-font: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --app-mono: "JetBrains Mono", "SF Mono", Consolas, monospace;
    --app-sidebar-bg: #0f172a;
    --app-sidebar-hover: #1e293b;
    --app-sidebar-active: #0ea5e9;
    --app-sidebar-text: #e2e8f0;
    --app-page-bg: #f1f5f9;
    --app-card-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --app-radius: 0.75rem;
    --app-primary: #0ea5e9;
    --app-primary-dark: #0284c7;
    /* Advanced Engineering (logo) */
    --app-brand-teal: #62b4bc;
    --app-brand-teal-dark: #4a9aa2;
}

/* —— Marca: logo Advanced Engineering —— */
.brand-logo {
    display: block;
    max-width: 100%;
    height: auto;
}

.sidebar-brand {
    display: block;
    background: #fff;
    border-radius: var(--app-radius);
    padding: 0.55rem 0.65rem;
    margin: 0 0.5rem 0.75rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.sidebar-brand .brand-logo {
    max-height: 2.85rem;
    width: auto;
    margin: 0 auto;
}

.brand-logo--compact {
    max-height: 1.65rem;
    width: auto;
}

.brand-logo--login {
    max-height: 4.75rem;
    width: auto;
    margin-left: auto;
    margin-right: auto;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

body {
    font-family: var(--app-font);
    background-color: var(--app-page-bg);
}

.skip-link {
    position: absolute;
    left: -9999px;
    z-index: 9999;
    padding: 0.5rem 1rem;
    background: var(--app-primary);
    color: #fff;
    text-decoration: none;
    border-radius: 0.25rem;
}
.skip-link:focus {
    left: 0.5rem;
    top: 0.5rem;
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    min-height: 100vh;
    background-color: var(--app-sidebar-bg);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar .nav-link {
    color: var(--app-sidebar-text);
    padding: 0.65rem 1rem;
    border-radius: 0.5rem;
    margin: 0.15rem 0.5rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar .nav-link:hover {
    background-color: var(--app-sidebar-hover);
    color: #fff;
}

.sidebar .nav-link:focus-visible {
    outline: 2px solid var(--app-sidebar-active);
    outline-offset: 2px;
}

.sidebar .nav-link.active {
    background: linear-gradient(90deg, #0369a1 0%, var(--app-sidebar-active) 100%);
    color: #fff;
}

.sidebar .nav-link i {
    width: 1.35rem;
    text-align: center;
    opacity: 0.9;
}

.main-content {
    padding: 1.5rem 1.25rem 2.5rem;
}

@media (min-width: 768px) {
    .main-content {
        padding: 2rem 2rem 3rem;
    }
}

.card {
    box-shadow: var(--app-card-shadow);
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: var(--app-radius);
}

.card-header {
    background: rgba(248, 250, 252, 0.9);
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
    font-weight: 600;
}

/* Tarjetas de métricas: variantes de gradiente */
.stat-card {
    border: none;
    border-radius: var(--app-radius);
    color: #fff;
    overflow: hidden;
}

.stat-card .card-body {
    padding: 1.35rem 1.5rem;
}

.stat-card--sky {
    background: linear-gradient(135deg, #0369a1 0%, #0ea5e9 100%);
}

.stat-card--violet {
    background: linear-gradient(135deg, #5b21b6 0%, #7c3aed 100%);
}

.stat-card--emerald {
    background: linear-gradient(135deg, #047857 0%, #10b981 100%);
}

.stat-card--amber {
    background: linear-gradient(135deg, #b45309 0%, #f59e0b 100%);
}

.stat-card--rose {
    background: linear-gradient(135deg, #be123c 0%, #f43f5e 100%);
}

.stat-card--slate {
    background: linear-gradient(135deg, #334155 0%, #64748b 100%);
}

/* Retrocompatibilidad con plantillas que solo usan .stat-card */
.stat-card:not([class*="stat-card--"]) {
    background: linear-gradient(135deg, #0369a1 0%, #6366f1 100%);
}

.table th {
    background-color: #f8fafc;
    border-top: none;
    padding: 12px 8px;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: #475569;
}

.table td {
    padding: 12px 8px;
    vertical-align: middle;
}

.table td:nth-child(2),
.table td.descripcion {
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    overflow-wrap: break-word;
    hyphens: auto;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.currency {
    white-space: nowrap;
    font-family: var(--app-mono);
    font-size: 0.95em;
}

.table .text-end {
    text-align: right !important;
    padding-right: 15px;
}

.table th.text-end {
    text-align: right !important;
}

.totals-section .row {
    margin-bottom: 8px;
}

.totals-section .col-6:first-child {
    padding-right: 20px;
}

.totals-section .col-6:last-child {
    padding-left: 20px;
    text-align: right;
}

.totals-section .currency {
    margin-left: 10px;
}

.btn-primary {
    background-color: var(--app-primary);
    border-color: var(--app-primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--app-primary-dark);
    border-color: var(--app-primary-dark);
}

.mobile-topbar {
    background: var(--app-sidebar-bg) !important;
}

/* Login (body.login-page) */
.login-page .login-header {
    background: #fff;
    color: #0f172a;
    border-bottom: 1px solid #e2e8f0;
    padding: 1.5rem 1.75rem;
    text-align: center;
}

.login-page .btn-login {
    background: linear-gradient(90deg, var(--app-brand-teal-dark), var(--app-brand-teal));
    border: none;
}

.login-page .btn-login:hover,
.login-page .btn-login:focus {
    filter: brightness(1.06);
    box-shadow: 0 6px 20px rgba(74, 154, 162, 0.35);
}

.login-page .form-control:focus {
    border-color: var(--app-brand-teal);
    box-shadow: 0 0 0 0.2rem rgba(98, 180, 188, 0.22);
}

.page-heading {
    letter-spacing: -0.02em;
}

/* —— Formulario factura (nueva / editar) —— */
.form-card-invoice {
    border-top: 3px solid var(--app-primary);
}

.form-card-invoice .card-header {
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    font-weight: 600;
    color: #0f172a;
}

.invoice-line {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: var(--app-radius);
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.invoice-line:hover {
    border-color: #cbd5e1;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

.invoice-line__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #0369a1, #0ea5e9);
    border-radius: 0.35rem;
    margin-bottom: 0.75rem;
}

.invoice-items-toolbar .btn {
    border-radius: 0.5rem;
    font-weight: 600;
}

.totals-panel {
    border: none;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
}

.totals-panel .card-header {
    background: linear-gradient(90deg, #0f172a 0%, #1e3a5f 100%);
    color: #fff;
    border: none;
    font-weight: 600;
}

.totals-panel .currency-row {
    font-size: 0.95rem;
    padding: 0.35rem 0;
}

.totals-panel .currency-row--grand {
    font-size: 1.15rem;
    margin-top: 0.25rem;
}

.totals-panel .amount {
    font-family: var(--app-mono);
    font-weight: 600;
    color: #0f172a;
}

.totals-panel .amount--grand {
    font-size: 1.25rem;
    color: #0369a1;
}

@media (min-width: 992px) {
    .totals-panel--sticky {
        position: sticky;
        top: 1rem;
    }
}

.invoice-actions .btn-primary {
    font-weight: 600;
    padding: 0.65rem 1rem;
    border-radius: 0.5rem;
}

.item-total.form-control {
    background-color: #f8fafc;
    font-family: var(--app-mono);
    font-weight: 500;
}

/* Reporte: cuadro de facturas emitidas */
.report-cuadro-card {
    border: none;
    box-shadow: var(--app-card-shadow);
    overflow: hidden;
}

.report-cuadro-card > .card-header {
    background: linear-gradient(90deg, #0f172a 0%, #1e3a5f 100%);
    color: #fff;
    border: none;
    font-weight: 600;
}

.report-cuadro-card > .card-header .text-white-50 {
    color: rgba(255, 255, 255, 0.65) !important;
}

.report-cuadro-table {
    margin-bottom: 0;
    font-size: 0.9375rem;
}

.report-cuadro-table thead th {
    background: #f8fafc;
    color: #475569;
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}

.report-cuadro-table tbody td {
    vertical-align: middle;
    border-color: #f1f5f9;
}

.report-cuadro-table tbody tr:hover {
    background-color: #f8fafc;
}

.report-cuadro-table tfoot th {
    background: #e2e8f0;
    color: #0f172a;
    font-weight: 700;
    border-top: 2px solid #cbd5e1;
    font-family: var(--app-mono);
    font-size: 0.9rem;
}

.report-cuadro-table .col-ncf {
    max-width: 14rem;
    word-break: break-word;
}

.stat-card .stat-card__amount {
    font-family: var(--app-mono);
    font-weight: 700;
    font-size: 1.2rem;
    line-height: 1.3;
}

@media (min-width: 992px) {
    .stat-card .stat-card__amount {
        font-size: 1.35rem;
    }
}

/* Detalle cotización / factura */
.detail-hero-card {
    border: none;
    box-shadow: var(--app-card-shadow);
    overflow: hidden;
}

.detail-hero-card > .card-header {
    background: linear-gradient(90deg, #0f172a 0%, #1e3a5f 100%);
    color: #fff;
    border: none;
    font-weight: 600;
}

.detail-card {
    border: none;
    box-shadow: var(--app-card-shadow);
}

.detail-card > .card-header {
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    font-weight: 600;
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.detail-meta dt {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.detail-meta dd {
    margin-bottom: 0.9rem;
}

.detail-meta dd:last-of-type {
    margin-bottom: 0;
}

.detail-prose {
    font-size: 0.9375rem;
    line-height: 1.55;
    color: #475569;
}

.detail-items-wrap {
    padding: 0;
}

.detail-items-wrap .table-responsive {
    margin: 0;
}

/* Facturas por moneda — espacios DOP / USD */
.sidebar-subnav .nav-link {
    font-size: 0.8125rem;
    opacity: 0.92;
}

.sidebar-subnav .nav-link:not(.active) {
    color: rgba(226, 232, 240, 0.78);
}

.currency-space-card--dop {
    border-color: rgba(14, 165, 233, 0.35) !important;
    box-shadow: 0 1px 0 rgba(14, 165, 233, 0.12);
}

.currency-space-card--usd {
    border-color: rgba(34, 197, 94, 0.4) !important;
    box-shadow: 0 1px 0 rgba(34, 197, 94, 0.1);
}

.currency-space-card--dop .card-header {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.08), transparent);
}

.currency-space-card--usd .card-header {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.08), transparent);
}
