:root {
    --bg: #f3f5f7;
    --surface: #ffffff;
    --sidebar: #202833;
    --sidebar-soft: #2b3441;
    --primary: #2f80ed;
    --text: #1f2933;
    --muted: #64748b;
    --border: #d8dee6;
    --success: #15803d;
    --warning: #b45309;
    --danger: #b91c1c;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--sidebar);
    color: #e5edf6;
    padding: 16px 12px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    height: 50px;
    margin: 0 4px 14px;
    padding: 7px 0;
}

.sidebar-brand img {
    display: block;
    width: 187px;
    max-height: 36px;
    filter: invert(1) brightness(1.9) contrast(.9);
    object-fit: contain;
    object-position: left center;
}

.sidebar-nav {
    display: grid;
    gap: 4px;
}

.sidebar-scroll {
    min-height: 0;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    min-height: 34px;
    padding: 0 10px;
    border-radius: 6px;
    color: #dbe6f3;
    text-decoration: none;
}

.nav-link:hover,
.nav-link.is-active {
    background: var(--sidebar-soft);
    color: #ffffff;
}

.nav-link.is-active {
    border-left: 3px solid var(--primary);
}

.nav-link.is-muted {
    color: #7e8a99;
}

.nav-group {
    display: grid;
    gap: 4px;
}

.nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 38px;
    padding: 0 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #dbe6f3;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-align: left;
}

.nav-group-toggle::after {
    content: "+";
    color: #94a3b8;
    font-weight: 700;
}

.nav-group-toggle:hover,
.nav-group.is-open > .nav-group-toggle {
    background: var(--sidebar-soft);
    color: #ffffff;
}

.nav-group.is-open > .nav-group-toggle::after {
    content: "-";
}

.nav-group-panel {
    display: none;
    gap: 3px;
    padding: 2px 0 8px 10px;
}

.nav-group.is-open > .nav-group-panel {
    display: grid;
}

.nav-group-panel .nav-link {
    min-height: 31px;
    padding-left: 12px;
    font-size: 13px;
    color: #b7c6d9;
}

.sidebar-logout {
    margin-top: auto;
    padding: 14px 4px 0;
}

.sidebar-logout button {
    width: 100%;
    height: 36px;
    border: 1px solid #3b4654;
    border-radius: 6px;
    background: transparent;
    color: #e5edf6;
    cursor: pointer;
}

.sidebar-logout button:hover {
    background: var(--sidebar-soft);
}

.app-main {
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-height: 64px;
    padding: 10px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.eyebrow {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    margin-top: 2px;
    font-size: 20px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.select-field {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.select-field select,
.global-search input,
.user-button {
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
}

.select-field select {
    padding: 0 28px 0 8px;
}

.global-search input {
    width: 240px;
    padding: 0 10px;
}

.user-button {
    padding: 0 12px;
}

.primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--primary);
    border-radius: 6px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
}

.primary-button.as-link {
    text-decoration: none;
}

.content {
    padding: 28px 30px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-header h2 {
    font-size: 22px;
}

.page-header p {
    margin-top: 4px;
    color: var(--muted);
}

.action-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.report-summary {
    padding: 16px 16px 0;
}

.metric,
.work-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.metric {
    padding: 16px;
}

.metric-label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
}

.metric strong {
    font-size: 26px;
}

.metric p {
    margin-top: 8px;
    color: var(--muted);
}

.work-panel {
    overflow: hidden;
}

.panel-title {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
}

.empty-state {
    padding: 18px 16px;
    color: var(--muted);
}

.toolbar,
.table-panel,
.settings-list {
    margin-bottom: 16px;
}

.toolbar,
.table-panel,
.settings-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.toolbar {
    padding: 12px;
}

.filter-form {
    display: flex;
    gap: 8px;
}

.filter-form input,
.filter-form select,
.filter-form button,
.settings-item button {
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
}

.filter-form input {
    width: min(360px, 100%);
    padding: 0 10px;
}

.filter-form select {
    padding: 0 28px 0 8px;
}

.filter-form button,
.settings-item button,
.secondary-link {
    padding: 0 12px;
}

.secondary-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--muted);
    text-decoration: none;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

.quick-add-button {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    color: var(--text);
    font-size: 22px;
    font-weight: 400;
    line-height: 1;
}

.row-action {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
    text-decoration: none;
}

.data-table td .row-action,
.data-table td .secondary-link {
    min-height: 28px;
    margin-right: 6px;
    padding: 0 9px;
    font-size: 13px;
    white-space: nowrap;
}

.data-table td .secondary-link {
    color: var(--muted);
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.inline-form .secondary-link {
    min-height: 28px;
    padding: 0 9px;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}

.table-panel {
    overflow-x: auto;
}

.table-panel h3 {
    padding: 14px 16px 0;
    font-size: 15px;
}

.split-panels {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

.compact-table {
    min-width: 0;
}

.data-table th,
.data-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.data-table tr.is-clickable {
    cursor: pointer;
}

.data-table tr.is-clickable:hover td {
    background: #f8fafc;
}

.data-table tr.is-clickable:focus {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

.data-table tr.is-clickable:focus td {
    background: #f8fafc;
}

.actions-column {
    width: 110px;
}

.empty-row {
    color: var(--muted);
    text-align: center;
}

.settings-list {
    display: grid;
    gap: 10px;
}

.subnav {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
}

.subnav a {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
    text-decoration: none;
}

.subnav a.is-active {
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 700;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
}

.settings-item h3 {
    font-size: 15px;
}

.settings-item p {
    margin-top: 4px;
    color: var(--muted);
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .topbar,
    .topbar-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .global-search input {
        width: 100%;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

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

    .filter-form,
    .settings-item {
        align-items: stretch;
        flex-direction: column;
    }

    .split-panels {
        grid-template-columns: 1fr;
    }
}

.auth-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    background: #eef2f6;
}

.auth-shell {
    width: min(100% - 32px, 820px);
}

.login-panel {
    display: grid;
    grid-template-columns: minmax(260px, .9fr) minmax(320px, 1fr);
    min-height: 430px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 24px 60px rgba(15, 23, 42, .16);
    overflow: hidden;
}

.login-visual {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: 36px 30px;
    background: var(--sidebar);
    color: #dbe6f3;
}

.login-visual img {
    display: block;
    width: min(260px, 100%);
    max-height: 72px;
    filter: invert(1) brightness(1.9) contrast(.9);
    object-fit: contain;
}

.login-visual span {
    color: #aebed1;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.login-form {
    align-content: center;
    display: grid;
    gap: 16px;
    padding: 40px;
}

.login-title h1 {
    font-size: 24px;
}

.login-title {
    margin-bottom: 2px;
}

.login-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.login-form input {
    height: 42px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
}

.alert {
    margin-bottom: 14px;
    padding: 10px 12px;
    border-radius: 6px;
}

.alert-danger {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: var(--danger);
}

.alert-success {
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: var(--success);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: #eef2f7;
    color: var(--muted);
    font-size: 12px;
}

.status-pill.is-warning {
    background: #fff7ed;
    color: var(--warning);
}

.status-pill.is-ok {
    background: #f0fdf4;
    color: var(--success);
}

.status-pill.is-danger {
    background: #fef2f2;
    color: #b91c1c;
}

.cc-aging-panel {
    margin-bottom: 14px;
}

.entity-form {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

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

.presupuesto-col-6 {
    grid-column: span 6;
}

.presupuesto-col-9 {
    grid-column: span 9;
}

.presupuesto-col-10 {
    grid-column: span 10;
}

.presupuesto-col-12 {
    grid-column: span 12;
}

.presupuesto-col-21 {
    grid-column: span 21;
}

.presupuesto-col-30 {
    grid-column: span 30;
}

.presupuesto-layout {
    display: grid;
    gap: 14px;
}

.presupuesto-row {
    display: grid;
    gap: 14px;
    align-items: end;
}

.presupuesto-row-40-40-20 {
    grid-template-columns: minmax(0, 2fr) minmax(0, 2fr) minmax(180px, 1fr);
}

.presupuesto-row-70-30 {
    grid-template-columns: minmax(0, 7fr) minmax(220px, 3fr);
}

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

.presupuesto-row-30-30-40 {
    grid-template-columns: minmax(0, 3fr) minmax(0, 3fr) minmax(0, 4fr);
}

.presupuesto-layout label,
.presupuesto-layout .form-field {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.presupuesto-layout input,
.presupuesto-layout select,
.presupuesto-layout textarea {
    width: 100%;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-weight: 400;
}

.select-filter-input {
    min-height: 34px !important;
    background: #f8fafc;
}

.select-filter-input.is-empty-filter {
    border-color: #f59e0b;
    background: #fffbeb;
}

.presupuesto-layout textarea {
    padding-top: 9px;
    resize: vertical;
}

.presupuesto-layout small {
    color: var(--danger);
}

.presupuesto-full {
    width: 100%;
}

.presupuesto-items-section {
    margin-top: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.form-grid.single-row {
    margin-top: 12px;
}

.form-section-title {
    display: flex;
    align-items: center;
    min-height: 32px;
    margin: 18px 0 10px;
    border-bottom: 1px solid var(--border);
}

.form-section-title h3 {
    font-size: 15px;
}

.article-main-grid {
    grid-template-columns: minmax(180px, 1fr) minmax(0, 2fr) minmax(180px, 1fr);
}

.article-pricing-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.form-grid label,
.form-field {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    width: 100%;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-weight: 400;
}

.form-grid textarea {
    padding-top: 9px;
    resize: vertical;
}

.form-grid small {
    color: var(--danger);
}

.inline-field-action {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.inline-field-action .row-remove {
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}

.form-grid .checkbox-label {
    align-content: start;
    grid-template-columns: auto 1fr;
    align-items: center;
    min-height: 38px;
}

.form-grid .checkbox-label input {
    width: 16px;
    height: 16px;
}

.items-editor {
    display: grid;
    gap: 10px;
}

.form-section {
    margin-top: 16px;
}

.items-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.items-editor-header strong {
    display: inline-flex;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e5e7eb;
    color: var(--muted);
    font-size: 12px;
}

.items-editor-header strong.is-warning {
    background: #fef3c7;
    color: #92400e;
}

.items-editor-header strong.is-danger {
    background: #fee2e2;
    color: #991b1b;
}

.items-editor-actions {
    display: inline-flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.items-table-wrap {
    overflow: visible;
}

.items-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.items-table th,
.items-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.items-table th:first-child,
.items-table td:first-child {
    width: 16%;
}

.items-table th:nth-child(2),
.items-table td:nth-child(2) {
    width: 40%;
}

.items-table th {
    color: var(--muted);
    font-size: 12px;
    text-align: left;
    background: #f8fafc;
}

.items-table tr:last-child td {
    border-bottom: 0;
}

.items-table tr.item-trace-row td {
    padding-top: 0;
    background: #f8fafc;
}

.items-table input,
.items-table select {
    width: 100%;
    min-height: 34px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0 8px;
}

.item-search-cell {
    position: relative;
    min-width: 150px;
}

.item-search-results {
    position: absolute;
    z-index: 20;
    top: 44px;
    left: 8px;
    width: min(620px, calc(100vw - 420px));
    min-width: 420px;
    max-height: 240px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .14);
}

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

.item-search-result {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: #ffffff;
    text-align: left;
    cursor: pointer;
}

.item-search-result strong {
    white-space: normal;
    line-height: 1.25;
}

.item-search-result:hover {
    background: #f8fafc;
}

.item-search-result span {
    color: var(--muted);
    font-size: 12px;
}

.item-search-result em {
    grid-row: span 2;
    align-self: center;
    color: var(--primary);
    font-style: normal;
    font-weight: 700;
}

.item-trace-panel {
    display: grid;
    grid-template-columns: auto minmax(190px, 1.2fr) minmax(170px, 1fr) minmax(120px, .8fr) minmax(120px, .8fr) minmax(150px, .8fr) auto;
    gap: 8px;
    align-items: end;
    padding: 8px;
    border: 1px dashed #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
}

.item-trace-panel strong {
    align-self: center;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.item-trace-panel small {
    align-self: center;
    color: var(--muted);
    line-height: 1.25;
}

.item-trace-panel label {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.item-trace-panel .row-remove {
    min-height: 34px;
    white-space: nowrap;
}

.contacts-editor-rows {
    display: grid;
    gap: 8px;
}

.item-row {
    display: grid;
    grid-template-columns: minmax(180px, 1.1fr) minmax(180px, 1.3fr) minmax(76px, .4fr) minmax(108px, .55fr) minmax(82px, .4fr) minmax(112px, .55fr) auto;
    gap: 8px;
    align-items: end;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.item-row-total {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.item-row-total strong,
.items-editor-total strong {
    color: var(--text);
    font-size: 14px;
}

.items-editor-total {
    display: grid;
    justify-content: end;
    gap: 6px;
    padding-top: 8px;
}

.items-editor-total p {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    min-width: 260px;
    margin: 0;
    color: var(--muted);
}

.items-grand-total {
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

.purchase-adjustments {
    display: grid;
    gap: 6px;
}

.purchase-adjustments[hidden],
.purchase-adjustment-row[hidden],
.purchase-adjustment-add[hidden] {
    display: none;
}

.purchase-adjustment-input {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.purchase-adjustment-input input {
    width: 120px;
    min-height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-align: right;
}

.purchase-adjustment-add {
    justify-self: end;
}

.payment-retentions {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.fixed-adjustments {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.fixed-adjustments-header {
    color: var(--muted);
    font-weight: 700;
}

.fixed-adjustments-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.payment-retention-rows {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.payment-retention-row[hidden],
[data-add-payment-retention][hidden] {
    display: none;
}

.payment-retention-input {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto;
    gap: 8px;
}

@media (max-width: 900px) {
    .fixed-adjustments-grid {
        grid-template-columns: 1fr;
    }
}

.quick-field {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}

.quick-dialog {
    width: min(560px, calc(100vw - 32px));
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.item-vat-display {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    color: var(--muted);
    font-weight: 700;
}

.quick-dialog::backdrop {
    background: rgba(15, 23, 42, .35);
}

.quick-dialog .entity-form {
    border: 0;
    padding: 0;
}

.trace-scanner {
    display: grid;
    gap: 18px;
}

.trace-scan-input,
.trace-json-field {
    width: 100%;
}

.trace-scan-input input {
    width: min(100%, 920px);
    font-family: Consolas, 'Courier New', monospace;
}

.trace-capture-status {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.trace-capture-status strong {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 26px;
    border-radius: 999px;
    background: #e2e8f0;
    color: var(--text);
}

.trace-capture-status em {
    font-style: normal;
    color: var(--text);
}

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

.scanner-result-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.scanner-result-grid > div {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    background: #f8fafc;
}

.scanner-result-grid span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 4px;
}

.scanner-result-grid strong {
    overflow-wrap: anywhere;
}

.scanner-result-grid.compact {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.scanner-panel,
.identifiers-editor {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.scan-field input {
    width: min(100%, 920px);
    font-family: Consolas, 'Courier New', monospace;
}

.identifier-rows {
    display: grid;
    gap: 8px;
}

.identifier-row {
    display: grid;
    grid-template-columns: 150px minmax(220px, 1fr) minmax(180px, 1fr) auto auto;
    gap: 8px;
    align-items: center;
}

.radio-inline {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    white-space: nowrap;
}

.scanner-warning {
    border: 1px solid #facc15;
    border-radius: 6px;
    background: #fefce8;
    color: #854d0e;
    padding: 10px 12px;
}

.trace-unit-scan {
    display: grid;
    gap: 6px;
    margin-bottom: 18px;
}

.trace-json-output {
    width: 100%;
    min-height: 520px;
    font-family: Consolas, 'Courier New', monospace;
}

.mono-cell {
    max-width: 420px;
    font-family: Consolas, 'Courier New', monospace;
    overflow-wrap: anywhere;
}

.context-field,
.nested-quick-create {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
}

.context-field span,
.nested-quick-create > span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.context-field strong {
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

.nested-quick-create {
    background: #ffffff;
}

.nested-quick-create .form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.is-hidden {
    display: none;
}

.contact-row {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(120px, .8fr) minmax(180px, 1fr) minmax(120px, .8fr) minmax(120px, .8fr) minmax(92px, .5fr) minmax(92px, .5fr) auto;
    gap: 8px;
    align-items: end;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.contact-row label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.contact-row input,
.contact-row select {
    width: 100%;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.data-table td small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.item-row .row-remove {
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--muted);
}

.span-2 {
    grid-column: span 2;
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
}

.checkbox-grid input {
    width: 16px;
    height: 16px;
}

.article-flags {
    margin-top: 0;
}

.form-actions a {
    color: var(--muted);
    text-decoration: none;
}

.form-actions button:not(.primary-button) {
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
}

.data-table td button {
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
}

.document-actions {
    align-items: center;
}

.document-action-panel {
    display: grid;
    gap: 8px;
    max-width: 980px;
    margin: -6px 0 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.document-action-panel .action-row {
    flex-wrap: wrap;
    justify-content: flex-start;
}

.document-sheet {
    max-width: 980px;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.document-top {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.document-number {
    text-align: right;
}

.document-number strong {
    display: block;
    margin: 4px 0;
    font-size: 24px;
}

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

.document-lines {
    margin-top: 4px;
}

.document-item-form {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.document-lines small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 14px 0 18px;
}

.summary-card {
    padding: 12px;
    border: 1px solid var(--border);
    border-left: 3px solid #f59e0b;
    border-radius: 8px;
    background: #fff7ed;
}

.summary-card.is-ok {
    border-left-color: #16a34a;
    background: #f0fdf4;
}

.summary-card span,
.summary-card small {
    display: block;
    color: var(--muted);
}

.summary-card strong {
    display: block;
    margin: 3px 0;
}

.is-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.document-notes {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.code-block {
    overflow-x: auto;
    margin: 8px 0 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    color: var(--text);
    font: 13px/1.5 Consolas, "Liberation Mono", monospace;
    white-space: pre-wrap;
}

.amount-column {
    text-align: right;
}

.print-page {
    min-height: 100vh;
    background: #e5e7eb;
}

.print-content {
    padding: 24px;
}

.print-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    width: min(100%, 210mm);
    margin: 0 auto 14px;
}

.print-sheet {
    width: min(100%, 210mm);
    min-height: 297mm;
    margin: 0 auto;
    padding: 18mm;
    border: 0;
    border-radius: 0;
    box-shadow: 0 20px 48px rgba(15, 23, 42, .16);
}

.print-document {
    width: min(100%, 297mm);
    margin: 0 auto;
    padding: 16mm;
    background: #ffffff;
    box-shadow: 0 20px 48px rgba(15, 23, 42, .16);
}

.print-header,
.print-meta {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.print-header span,
.print-meta {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.print-table th,
.print-table td {
    padding: 7px;
    border: 1px solid var(--border);
    text-align: left;
}

.print-table th {
    background: #f8fafc;
}

.print-total {
    display: flex;
    justify-content: flex-end;
    gap: 24px;
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 16px;
}

.print-total span {
    color: var(--muted);
    font-weight: 700;
}

.pdf-sheet {
    position: relative;
    width: min(100%, 210mm);
    min-height: 297mm;
    margin: 0 auto;
    padding: 12mm 12mm 14mm;
    box-sizing: border-box;
    background: #ffffff;
    color: #111827;
    box-shadow: 0 20px 48px rgba(15, 23, 42, .16);
    font-size: 12px;
}

.pdf-header {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 96px 1fr;
    min-height: 116px;
    border: 1px solid #111827;
}

.pdf-company,
.pdf-number {
    padding: 12px 14px;
}

.pdf-company {
    border-right: 1px solid #111827;
}

.pdf-number {
    border-left: 1px solid #111827;
}

.pdf-logo {
    display: block;
    max-width: 160px;
    max-height: 46px;
    object-fit: contain;
    margin-bottom: 6px;
}

.pdf-company h1,
.pdf-number h2 {
    margin: 0 0 8px;
    font-size: 18px;
    line-height: 1.1;
    text-transform: uppercase;
}

.pdf-company p,
.pdf-number p,
.pdf-customer p,
.pdf-notes p,
.pdf-cae p,
.preprinted-client p,
.preprinted-notes p {
    margin: 3px 0;
}

.pdf-letter {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 8px;
    text-align: center;
}

.pdf-letter strong {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    border: 1px solid #111827;
    font-size: 36px;
    line-height: 1;
}

.pdf-letter span {
    margin-top: 5px;
    font-size: 11px;
    font-weight: 700;
}

.pdf-invalid {
    max-width: 150px;
    color: #4b5563;
    font-weight: 700;
}

.pdf-customer {
    display: grid;
    grid-template-columns: 1.4fr .9fr 1fr;
    gap: 4px 16px;
    margin-top: 10px;
    padding: 8px 10px;
    border: 1px solid #111827;
}

.pdf-customer p:first-child,
.pdf-customer p:last-child {
    grid-column: span 2;
}

.pdf-table {
    width: 100%;
    margin-top: 12px;
    border-collapse: collapse;
    font-size: 11px;
}

.pdf-table th,
.pdf-table td {
    padding: 6px 7px;
    border: 1px solid #111827;
    vertical-align: top;
}

.pdf-table th {
    font-weight: 700;
    text-align: left;
}

.pdf-table small {
    display: block;
    margin-top: 2px;
    color: #374151;
}

.pdf-totals {
    width: 45%;
    margin: 14px 0 0 auto;
    border-top: 1px solid #111827;
}

.pdf-totals p {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin: 0;
    padding: 5px 0;
    border-bottom: 1px solid #d1d5db;
}

.pdf-total-final {
    font-size: 14px;
}

.pdf-cae,
.pdf-notes {
    margin-top: 14px;
    padding-top: 8px;
    border-top: 1px solid #111827;
}

.pdf-sheet-preprinted {
    padding: 47mm 13mm 12mm;
    box-shadow: 0 20px 48px rgba(15, 23, 42, .16);
}

.pdf-sheet-preprinted .preprinted-client {
    margin-left: 18mm;
    margin-bottom: 14mm;
    font-size: 12px;
}

.preprinted-items {
    margin-top: 0;
    font-size: 11px;
}

.preprinted-items th,
.preprinted-items td {
    border: 0;
    border-bottom: 1px solid #d1d5db;
    padding: 5px 4px;
}

.preprinted-items th:first-child,
.preprinted-items td:first-child {
    width: 20mm;
    text-align: center;
}

.preprinted-items th:nth-child(2),
.preprinted-items td:nth-child(2) {
    width: 28mm;
}

.preprinted-notes {
    margin-top: 12mm;
    font-size: 12px;
}

.document-logo {
    display: block;
    max-width: 180px;
    max-height: 72px;
    object-fit: contain;
    margin-bottom: 10px;
}

.shipment-table {
    margin-top: 10px;
}

.shipment-form {
    display: grid;
    grid-template-columns: 140px minmax(160px, 1fr) minmax(180px, 1.4fr) auto;
    gap: 8px;
    margin-top: 12px;
}

.shipment-form input,
.shipment-form select {
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
}

.route-signature {
    min-width: 120px;
    height: 38px;
}

@media print {
    .sidebar,
    .document-actions button,
    .document-actions .secondary-link,
    .print-toolbar,
    .no-print,
    .document-item-form {
        display: none;
    }

    @page {
        size: A4;
        margin: 0;
    }

    body,
    .print-page {
        background: #ffffff;
    }

    .app-shell {
        display: block;
    }

    .content,
    .print-content {
        padding: 0;
    }

    .document-sheet,
    .print-sheet,
    .pdf-sheet,
    .print-document {
        width: auto;
        min-height: 0;
        padding: 0;
        max-width: none;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .pdf-sheet {
        width: 210mm;
        min-height: 297mm;
        padding: 12mm 12mm 14mm;
    }

    .pdf-sheet-preprinted {
        padding: 37mm 0 0;
    }

    .data-table th,
    .data-table td {
        padding: 8px 10px;
    }
}

@media (max-width: 720px) {
    .auth-page {
        align-items: start;
        padding: 18px 0;
    }

    .login-panel {
        grid-template-columns: 1fr;
        min-height: 0;
    }

    .login-visual {
        min-height: 150px;
        padding: 24px;
    }

    .login-visual img {
        max-height: 56px;
    }

    .login-form {
        padding: 26px 22px 24px;
    }

    .form-grid,
    .article-main-grid,
    .article-pricing-grid,
    .article-stock-grid {
        grid-template-columns: 1fr;
    }

    .trace-analysis {
        grid-template-columns: 1fr;
    }

    .presupuesto-row,
    .presupuesto-row-40-40-20,
    .presupuesto-row-70-30,
    .presupuesto-row-thirds,
    .presupuesto-row-30-30-40 {
        grid-template-columns: 1fr;
    }

    .presupuesto-grid {
        grid-template-columns: 1fr;
    }

    .presupuesto-col-6,
    .presupuesto-col-9,
    .presupuesto-col-10,
    .presupuesto-col-12,
    .presupuesto-col-21,
    .presupuesto-col-30 {
        grid-column: span 1;
    }

    .document-top,
    .document-grid,
    .summary-grid {
        grid-template-columns: 1fr;
    }

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

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

    .shipment-form {
        grid-template-columns: 1fr;
    }

    .document-top {
        display: grid;
    }

    .document-number {
        text-align: left;
    }

    .span-2 {
        grid-column: span 1;
    }

    .checkbox-grid {
        grid-template-columns: 1fr;
    }
}
