:root {
    --sidebar: #172033;
    --sidebar-soft: #233149;
    --primary: #1f7aec;
    --accent: #00a896;
    --warning: #f59f00;
    --danger: #d64550;
    --bg: #f4f7fb;
    --text: #202939;
    --muted: #667085;
    --line: #d9e2ef;
    --panel: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

body.sidebar-collapsed {
    grid-template-columns: 0 1fr;
}

body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
}

.sidebar {
    background: linear-gradient(180deg, var(--sidebar), #111827);
    color: #fff;
    padding: 24px;
    transition: transform .2s ease, padding .2s ease;
    z-index: 30;
}

.sidebar-backdrop {
    display: none;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding-bottom: 28px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}

.brand-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #b8c4d9;
    margin-top: 3px;
}

nav {
    display: grid;
    gap: 8px;
    margin-top: 28px;
}

nav a {
    color: #d7deea;
    text-decoration: none;
    padding: 12px 14px;
    border-radius: 8px;
}

nav a.active,
nav a:hover {
    background: var(--sidebar-soft);
    color: #fff;
}

.content {
    padding: 28px;
    min-width: 0;
}

.menu-toggle {
    width: 42px;
    min-height: 38px;
    padding: 0;
    margin-bottom: 14px;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: 0 8px 22px rgba(22, 34, 51, .08);
    font-size: 22px;
    position: sticky;
    top: 10px;
    z-index: 35;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 18px;
}

p {
    color: var(--muted);
    margin-top: 5px;
}

.status {
    padding: 10px 14px;
    border-radius: 999px;
    color: #fff;
    background: var(--warning);
    font-weight: 700;
}

.status.prod {
    background: var(--accent);
}

.panel,
.alert {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(22, 34, 51, .08);
}

.alert {
    padding: 18px;
    margin-bottom: 18px;
    display: grid;
    gap: 10px;
}

.alert.success {
    border-left: 5px solid var(--accent);
}

.alert.error {
    border-left: 5px solid var(--danger);
}

.paths {
    display: grid;
    gap: 8px;
}

code,
pre {
    background: #101828;
    color: #d1fadf;
    border-radius: 8px;
    padding: 10px;
    overflow: auto;
}

.section {
    padding: 22px;
    border-bottom: 1px solid var(--line);
}

.section > div:first-child {
    margin-bottom: 18px;
}

.grid {
    display: grid;
    gap: 16px;
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.wide {
    grid-column: span 2;
}

label {
    display: grid;
    gap: 7px;
    color: #344054;
    font-weight: 700;
    font-size: 14px;
}

input,
select {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    background: #fff;
    font: inherit;
}

input:focus,
select:focus {
    outline: 3px solid rgba(31, 122, 236, .16);
    border-color: var(--primary);
}

.autocomplete {
    position: relative;
    display: block;
}

.autocomplete-results {
    position: absolute;
    inset: calc(100% + 6px) 0 auto 0;
    display: grid;
    max-height: 260px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 45px rgba(22, 34, 51, .18);
    z-index: 50;
}

.autocomplete-results[hidden] {
    display: none;
}

.autocomplete-option {
    min-height: auto;
    display: grid;
    gap: 3px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 0;
    border-bottom: 1px solid #edf2f7;
    background: #fff;
    color: var(--text);
    text-align: left;
    font-weight: 700;
}

.autocomplete-option:hover,
.autocomplete-option:focus {
    background: #eef4ff;
    filter: none;
}

.autocomplete-option small,
.stock-hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.product-cell {
    min-width: 280px;
}

.product-autocomplete {
    margin-bottom: 6px;
}

.product-autocomplete .autocomplete-results {
    position: static;
    margin-top: 6px;
    max-height: 190px;
}

.actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 22px;
}

.check {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.check input {
    width: 18px;
    min-height: 18px;
}

button {
    border: 0;
    border-radius: 8px;
    min-height: 44px;
    padding: 0 18px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    font-weight: 800;
    cursor: pointer;
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    font-weight: 800;
}

body.login-page {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    min-height: 100vh;
    width: 100%;
    padding: 22px;
    background: linear-gradient(135deg, #172033, #1f7aec);
}

.login-box {
    width: min(420px, 100%);
    margin: 0 auto;
}

.login-card {
    overflow: hidden;
}

.login-card .section {
    padding: 30px;
}

.login-card h1 {
    font-size: 34px;
    line-height: 1.08;
}

.login-form {
    display: grid;
    gap: 16px;
}

.login-form label {
    gap: 8px;
}

.login-form input {
    font-size: 16px;
    font-weight: 600;
}

.login-card button {
    width: 100%;
    margin-top: 14px;
}

.login-hint {
    font-size: 14px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 18px 45px rgba(22, 34, 51, .08);
}

.stat-card span {
    color: var(--muted);
    display: block;
    margin-bottom: 8px;
}

.stat-card strong {
    font-size: 26px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.mini-link {
    display: inline-flex;
    margin-right: 8px;
    color: var(--primary);
    font-weight: 800;
    text-decoration: none;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.table-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #1f2937;
    text-decoration: none;
    font-weight: 800;
    font-size: 13px;
}

.as-button {
    cursor: pointer;
}

.danger-action {
    border-color: #fecdd3;
    color: var(--danger);
    background: #fff5f5;
}

.compact-table th,
.compact-table td {
    padding: 8px 10px;
    font-size: 13px;
}

.compact-table th {
    font-size: 11px;
}

.compact-section {
    padding: 16px;
}

.compact-topbar h1 {
    font-size: 24px;
}

.search-form {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(680px, 100%);
}

.search-form input {
    min-height: 38px;
}

.search-form button,
.search-form .button-link {
    min-height: 38px;
    white-space: nowrap;
}

.report-filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    gap: 12px;
    align-items: end;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.pagination a {
    min-width: 34px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    color: var(--text);
    background: #fff;
    text-decoration: none;
    font-weight: 800;
}

.pagination a.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.modal {
    width: min(760px, calc(100vw - 32px));
    border: 0;
    border-radius: 10px;
    padding: 22px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, .25);
}

.modal::backdrop {
    background: rgba(15, 23, 42, .45);
}

.bar-chart {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(120px, 220px) 1fr 70px;
    align-items: center;
    gap: 12px;
}

.bar-row span {
    font-weight: 700;
    overflow-wrap: anywhere;
}

.bar-track {
    height: 14px;
    border-radius: 999px;
    background: #e8eef7;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}

.table-action:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}

.table-action span {
    font-size: 15px;
    line-height: 1;
}

.invoice-status {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.status-cell {
    min-width: 0;
}

.break-anywhere {
    overflow-wrap: anywhere;
    word-break: break-word;
    display: block;
}

.xml-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.invoice-status span {
    color: var(--muted);
    display: block;
}

.ok-text {
    color: #00875a;
}

.bad-text {
    color: var(--danger);
}

.print-page {
    display: block;
    background: #fff !important;
    color: #000 !important;
}

.ride-toolbar {
    text-align: right;
    margin-bottom: 12px;
}

.sri-ride-page {
    width: 190mm;
    min-height: 277mm;
    margin: 12px auto;
    padding: 7mm;
    background: #fff !important;
    color: #000 !important;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 8.8px;
    line-height: 1.15;
}

.sri-ride-page * {
    color: #000 !important;
    box-sizing: border-box;
}

.sri-top {
    display: grid;
    grid-template-columns: 89mm 1fr;
    gap: 6mm;
    align-items: stretch;
}

.sri-emisor,
.sri-autorizacion {
    min-height: 78mm;
}

.sri-emisor {
    padding: 0;
}

.sri-logo,
.sri-logo-fallback {
    width: 32mm;
    height: 22mm;
    object-fit: contain;
    margin: 2mm 0 4mm 7mm;
    display: grid;
    place-items: center;
    text-align: center;
    color: #087bc0 !important;
    border: 1px solid #087bc0;
    font-weight: 800;
}

.emisor-name {
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 3mm;
}

.plain-table,
.auth-table,
.cliente-box table,
.detalle-box table,
.pagos-table,
.totales-sri {
    width: 100%;
    border-collapse: collapse;
}

.plain-table td {
    border: 0;
    padding: 1.4mm 0;
    vertical-align: top;
}

.label-cell {
    width: 18mm;
    font-weight: 800;
}

.accounting {
    font-weight: 800;
    padding-top: 4mm !important;
}

.sri-autorizacion {
    border: 1px solid #000;
    padding: 3mm;
}

.auth-table td {
    border: 0;
    padding: .8mm 0;
    vertical-align: top;
}

.auth-label {
    font-weight: 800;
}

.auth-value {
    font-size: 11px;
}

.doc-title {
    font-size: 13px;
    font-weight: 800;
    text-align: left;
    padding-top: 2mm !important;
}

.mono,
.clave-box {
    font-family: "Courier New", monospace;
    word-break: break-all;
}

.clave-box {
    border: 1px solid #000;
    min-height: 13mm;
    padding: 2mm;
    text-align: center;
    font-size: 8px;
}

.cliente-box {
    border: 1px solid #000;
    margin-top: 3mm;
}

.cliente-box td {
    border: 0;
    padding: 1.8mm 2mm;
    vertical-align: top;
}

.detalle-box {
    margin-top: 3mm;
}

.detalle-box th,
.detalle-box td,
.pagos-table th,
.pagos-table td {
    border: 1px solid #000;
    padding: 1.3mm;
    vertical-align: top;
}

.detalle-box th,
.pagos-table th {
    text-align: center;
    font-weight: 800;
    background: #fff;
}

.num {
    text-align: right;
    white-space: nowrap;
}

.inferior-grid {
    display: grid;
    grid-template-columns: 1fr 61mm;
    gap: 5mm;
    margin-top: 4mm;
    align-items: start;
}

.info-title {
    font-weight: 800;
    margin-bottom: 2mm;
}

.info-pagos p {
    margin: 1mm 0;
}

.pagos-table {
    margin-top: 5mm;
}

.totales-sri td {
    border: 0;
    padding: 1.15mm 0;
}

.totales-sri td:first-child {
    font-weight: 800;
    text-align: right;
    padding-right: 4mm;
}

.valor-total td {
    font-weight: 800;
}

@media print {
    @page {
        size: A4;
        margin: 8mm;
    }

    html,
    body,
    .print-page {
        background: #fff !important;
        color: #000 !important;
    }

    .ride-actions {
        display: none;
    }
    .ride-toolbar {
        display: none;
    }
    .ride {
        margin: 0;
        width: 194mm;
        max-width: 194mm;
        min-height: auto;
        padding: 0;
        box-shadow: none;
    }

    .sri-ride-page {
        margin: 0;
        padding: 0;
        width: 194mm;
        min-height: auto;
    }

    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px;
    text-align: left;
    vertical-align: top;
}

th {
    color: #344054;
    font-size: 13px;
    text-transform: uppercase;
}

.role-panel {
    margin-bottom: 18px;
}

.permissions-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

button:hover {
    filter: brightness(.96);
}

.button-secondary,
.icon-button {
    background: #eef4ff;
    color: var(--primary);
}

.icon-button {
    width: 38px;
    min-height: 38px;
    padding: 0;
    font-size: 24px;
}

.muted-link {
    background: #e5e7eb;
    color: #344054;
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.totals-box {
    display: flex;
    justify-content: flex-end;
    gap: 28px;
}

.totals-box div {
    min-width: 150px;
}

.totals-box span {
    display: block;
    color: var(--muted);
}

.totals-box strong {
    font-size: 24px;
}

.check-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    margin-bottom: 16px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbff;
}

.check-card input {
    width: 20px;
    height: 20px;
    min-height: auto;
}

.check-card strong,
.check-card small {
    display: block;
}

.check-card small {
    color: var(--muted);
    margin-top: 3px;
}

.is-disabled {
    opacity: .45;
    pointer-events: none;
}

.danger-text {
    color: #c2410c;
}

.final-consumer-fields[hidden] {
    display: none;
}

@media (max-width: 900px) {
    body:not(.login-page):not(.diagnostic-page) {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(82vw, 300px);
        transform: translateX(-100%);
        padding: 24px;
        overflow-y: auto;
        box-shadow: 18px 0 45px rgba(15, 23, 42, .28);
    }

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

    body.sidebar-collapsed .sidebar {
        padding: 24px;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(15, 23, 42, .45);
    }

    body.sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .content {
        padding: 16px;
    }

    .menu-toggle {
        position: sticky;
        top: 10px;
    }

    .grid.two,
    .grid.three {
        grid-template-columns: 1fr;
    }

    .wide {
        grid-column: auto;
    }

    .topbar,
    .quick-actions,
    .actions,
    .section-title-row,
    .totals-box,
    .search-form {
        align-items: stretch;
        flex-direction: column;
    }

    .stats-grid,
    .permissions-grid,
    .report-filters {
        grid-template-columns: 1fr;
    }

    .bar-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    body.login-page {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
        padding: 16px;
    }

    .login-card .section {
        padding: 24px 20px;
    }

    .login-card h1 {
        font-size: 28px;
    }

    .login-card p {
        font-size: 16px;
    }

    .login-hint {
        font-size: 13px;
    }
}

.diagnostic-page {
    display: block;
}

.diagnostic {
    max-width: 980px;
    margin: 32px auto;
    padding: 0 18px;
}
