:root { color-scheme: light; font-family: Arial, Helvetica, sans-serif; color: #1f2933; background: #f4f6f8; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
.login-page { display: grid; place-items: center; padding: 24px; }
.login-panel, .panel { background: #fff; border-radius: 8px; box-shadow: 0 12px 26px rgba(15,23,42,.08); }
.login-panel { width: min(420px,100%); padding: 32px; border-top: 5px solid #16a34a; }
.brand-logo { display: block; max-width: 250px; max-height: 64px; margin: 0 0 26px; }
h1, h2, p { margin-top: 0; } h1 { font-size: 1.35rem; margin-bottom: 8px; } h2 { font-size: 1.1rem; }
.muted, .meta { color: #52616f; }
.login-form { display: grid; gap: 9px; margin-top: 24px; }
label { font-weight: 700; font-size: .9rem; }
input { width: 100%; min-height: 42px; border: 1px solid #b8c2cc; border-radius: 6px; padding: 9px 11px; font: inherit; }
input:focus { border-color: #16a34a; outline: 3px solid rgba(22,163,74,.16); }
button, .button { min-height: 40px; border: 0; border-radius: 6px; padding: 0 14px; background: #0f172a; color: #fff; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.login-form button { margin-top: 10px; background: #16a34a; }
.alert { margin: 20px 0 0; padding: 10px 12px; border-radius: 6px; color: #9f1239; background: #fff1f2; font-weight: 700; }
.app { padding: 24px; }.app-header { display:flex; align-items:center; justify-content:space-between; gap:18px; width:min(1400px,100%); margin:0 auto 22px; }.app-header .brand-logo { margin:0; max-width:210px; }.header-user { display:flex; align-items:center; gap:14px; }.logout { background:#fff; color:#0f172a; border:1px solid #b8c2cc; }.dashboard { width:min(1400px,100%); margin:auto; display:grid; gap:20px; }.panel { padding:22px; overflow:auto; }.summary { display:grid; grid-template-columns:repeat(3,minmax(160px,1fr)); gap:14px; }.summary-card { padding:16px; border-left:4px solid #16a34a; background:#f8fafc; }.summary-card strong { display:block; margin-top:6px; font-size:1.35rem; }.table { width:100%; border-collapse:collapse; min-width:700px; }.table th,.table td { padding:11px 10px; border-bottom:1px solid #e5e7eb; text-align:left; }.table th { color:#52616f; font-size:.78rem; text-transform:uppercase; }.table td.number,.table th.number { text-align:right; white-space:nowrap; }.table tr.total { font-weight:700; background:#f8fafc; }.detail-header { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:20px; }.back { color:#0f172a; font-weight:700; text-decoration:none; }.empty { padding:22px 0 4px; color:#52616f; }
@media (max-width:680px) { .app { padding:14px; }.app-header { align-items:flex-start; flex-direction:column; }.header-user { width:100%; justify-content:space-between; }.summary { grid-template-columns:1fr; }.panel { padding:16px; } }
.sales-history{padding-bottom:14px}.chart-heading{display:flex;justify-content:space-between;gap:16px;align-items:center}.chart-heading h2{margin:0}.chart-legend{display:flex;gap:16px;color:#52616f}.chart-legend span:before{content:"";display:inline-block;width:10px;height:10px;border-radius:50%;margin-right:6px}.legend-sales:before{background:#008000}.legend-commission:before{background:#0000ff}.chart-scroll{overflow-x:auto;margin-top:14px}.sales-chart{display:block;width:100%;min-width:720px}.chart-grid{stroke:#ccc}.chart-axis{stroke:#444}.chart-line{fill:none;stroke-width:2.5;stroke-linejoin:round}.chart-line-sales{stroke:#008000}.chart-line-commission{stroke:#0000ff}.chart-point{stroke:#fff}.chart-point-sales{fill:#008000}.chart-point-commission{fill:#0000ff}.chart-y-label,.chart-x-label{fill:#444;font:12px Arial}.chart-y-label{text-anchor:end}.chart-x-label{text-anchor:middle}
.chart-filters{padding:14px 22px}.range-form{display:flex;align-items:end;gap:12px;flex-wrap:wrap}.range-form label{display:grid;gap:5px}.range-form input,.range-form select{min-width:150px}.range-form .button{background:#fff;color:#0f172a;border:1px solid #b8c2cc}
.customers-range{text-align:center;color:#52616f;font-weight:700;margin:0 0 16px}
#customers-table th:last-child,#customers-table td:last-child{display:none}.customer-row-selectable{cursor:pointer}.customer-row-selectable:hover{background:#f1f5f9}.customers-pagination{display:flex;justify-content:center;align-items:center;gap:12px;padding-top:16px}.customers-pagination button{min-height:34px}
/* Tabla dinámica y selector temporal del portal externo. */
.range-form { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.range-slider { position: relative; width: min(620px, 100%); height: 42px; padding-top: 4px; }
.range-slider::before { content: ''; position: absolute; top: 12px; left: 0; right: 0; height: 4px; background: #cfd9df; border-radius: 4px; }
.range-slider input[type=range] { position: absolute; top: 0; left: 0; width: 100%; pointer-events: none; appearance: none; background: transparent; }
.range-slider input[type=range]::-webkit-slider-thumb { pointer-events: auto; appearance: none; width: 15px; height: 15px; border: 2px solid #fff; border-radius: 50%; background: #00a89c; box-shadow: 0 0 0 1px #008d84; }
.range-slider input[type=range]::-moz-range-thumb { pointer-events: auto; width: 13px; height: 13px; border: 2px solid #fff; border-radius: 50%; background: #00a89c; }
.range-slider strong { position: absolute; top: 25px; width: 100%; text-align: center; color: #556774; font-size: 13px; }
#customers-table th:last-child, #customers-table td:last-child { display: none; }
#customers-table .clickable-row { cursor: pointer; }
#customers-table .clickable-row:hover { background: #eaf8f6; }
.pagination { display: flex; justify-content: flex-end; gap: 5px; padding-top: 14px; }
.pagination button { padding: 6px 10px; background: #eef3f6; color: #29465d; }
.pagination button.active { background: #00a89c; color: #fff; }


/* Interfaz equivalente al controlador GTMComAgent original. */
.app { padding: 0; background: #fff; }
.app-header { width: 100%; max-width: none; min-height: 0; padding: 10px 80px; margin: 0; background: #fff; border-bottom: 1px solid #eee; }
.dashboard { width: 100%; max-width: none; display: block; margin: 0; padding: 0 80px 60px; background: #fff; }
.dashboard > .panel { box-shadow: none; border: 0; border-radius: 0; padding: 0; overflow: visible; }
.dashboard > .chart-filters { height: 70px; display: flex; align-items: center; }
.range-form label { font-family: Arial, sans-serif; font-size: 25px; font-weight: 400; color: #000; }
.range-form select { margin-left: 10px; font-size: 15px; min-width: 180px; }
.sales-history { margin: 0; }
.chart-heading { height: 50px; justify-content: center; }
.chart-heading h2 { font-size: 19px; font-weight: 400; color: #000; }
.chart-legend { position: absolute; right: 80px; font-size: 13px; }
.chart-scroll { margin: 0; overflow: hidden; }
body.app:has(.legacy-back) .chart-scroll { overflow-x: hidden !important; overflow-y: hidden !important; scrollbar-width: none; }
body.app:has(.legacy-back) .chart-scroll::-webkit-scrollbar { display: none; }
.legacy-echart { width: 100%; height: 320px; }
.detail-header { min-height: 50px; margin: 15px 0 0; justify-content: center; font-size: 19px; font-weight: 400; }
.detail-header h2 { font-size: 19px; font-weight: 400; color: #000; }
.customers-range { margin: 0 0 12px; text-align: center; }
.table { min-width: 900px; }
.table th { color: #202020; background: #f6f6f6; text-transform: none; font-size: 13px; }
.table td, .table th { border: 1px solid #ddd; }
.legacy-row { cursor: pointer; }
.legacy-row:hover { background: #f5f5f5; }
.legacy-download { width: 25px; height: auto; cursor: pointer; object-fit: contain; }
.legacy-back { display: inline-flex; align-items: center; min-height: 24px; padding-left: 30px; background: url('../assets/images/back.png') left center / auto 20px no-repeat; }
.legacy-pagination { display: flex; justify-content: flex-end; gap: 5px; padding: 14px 0; }
.legacy-pagination button { min-height: 30px; padding: 0 10px; border-radius: 0; background: #eee; color: #222; }
.legacy-pagination button.active { color: #fff; background: #009900; }
#customers-table th:last-child, #customers-table td:last-child { display: none; }
@media (max-width: 900px) {
    .app-header, .dashboard { padding-left: 18px; padding-right: 18px; }
    .chart-legend { right: 18px; }}

/* Selector temporal e icono XLS del controlador original. */
.legacy-echart { height: 340px; }
.detail-header { position: relative; }
.detail-header .legacy-download { position: absolute; right: 0; top: 50%; transform: translateY(-50%); }

#orders-table tbody tr:first-child td { border-top: 2px solid #999; }
#orders-table tbody tr { background:#fff; }

#orders-table .order-group td { font-weight:700; background:#f4f4f4; }

.detail-header { justify-content:flex-start; }
.detail-header .legacy-back { background:none; padding-left:0; color:#000; font-size:19px; }
.detail-header .legacy-back img { width:20px; margin-right:10px; vertical-align:middle; }
.range-form label { display:flex; align-items:center; gap:10px; }
.range-form select { margin-left:0; }
.legacy-pagination { justify-content:flex-end; border-top:1px solid #ddd; }

.legacy-back img { width:36px !important; height:36px; margin-right:16px !important; }
#orders-table { font-family:Arial,sans-serif; font-size:13px; }
#orders-table th { font-size:13px; font-weight:400; }
#orders-table td { font-size:13px; font-weight:400; }
#orders-table + .legacy-pagination, .legacy-pagination { min-height:42px; background:#eee; padding:6px 12px; align-items:center; gap:6px; }
.legacy-pagination span { margin-right:2px; font-size:13px; }
.legacy-pagination select { height:28px; min-width:58px; font-size:13px; }
.legacy-pagination button { min-height:28px; background:transparent; border:0; color:#333; font-size:13px; font-weight:400; padding:4px 7px; }
.legacy-pagination button.active { background:#ddd; color:#000; border-radius:2px; }
.detail-header > h2 { width:100%; text-align:center; font-weight:400; }

/* Ajustes finales de tablas y paginación. */
.detail-header:has(#orders-table) { justify-content:center; }
.detail-header > h2 { margin:0 auto; text-align:center; font-size:19px; font-weight:400; }
.legacy-back img { width:46px !important; height:46px; margin-right:7px !important; }
#customers-table, #orders-table { font-family:Arial,sans-serif; font-size:13px; }
#customers-table th, #orders-table th { font-size:13px; font-weight:400; line-height:1.25; }
#customers-table td, #orders-table td { font-size:13px; font-weight:400; line-height:1.25; }
.legacy-pagination span { font-weight:700; }
.legacy-pagination button { border:1px solid #c7c7c7; border-radius:5px; background:#fff; min-width:30px; }
.legacy-pagination button:hover { background:#f3f3f3; }
.legacy-pagination button:disabled { opacity:.45; background:#eee; }
.legacy-pagination button.active { border-color:#999; border-radius:5px; background:#ddd; }

/* Tablas equivalentes a las plantillas GTM. */
#orders-table { margin-top:0; }
#orders-table::before { content:''; }
.panel:has(#orders-table) > h2 { display:block; width:100%; text-align:center; font-family:Arial,sans-serif; font-size:19px; font-weight:400; color:#000; margin:0 0 14px; }
.table { border-collapse:separate; border-spacing:0; background:#fff; }
.table th { background:#f1f1f1; color:#000; font-family:Arial,sans-serif; font-size:13px; font-weight:400; padding:10px; border-top:1px solid #ccc; border-bottom:1px solid #ccc; }
.table td { color:#000; font-family:Arial,sans-serif; font-size:13px; font-weight:400; padding:9px 10px; border-bottom:1px solid #ddd; }
.table tbody tr:nth-child(even):not(.total):not(.order-group) { background:#fafafa; }
.table tbody tr:hover:not(.total):not(.order-group) { background:#f2f2f2; }
.table .total, #orders-table .order-group { background:#eee; font-weight:700; }
.table .total td, #orders-table .order-group td { font-weight:700; }

#orders-table tbody tr:not(.order-group):hover { background:#e9e9e9; }
#customers-table tbody tr:nth-child(odd):not(.total), #orders-table tbody tr:nth-child(odd):not(.order-group) { background:#f0f0f0; }
.table th { cursor:pointer; }
.table th::after { content:' ▴'; font-size:10px; color:#777; }
.order-group::before { content:'▾'; display:table-cell; padding:8px; color:#555; cursor:pointer; }
.order-group.collapsed::before { content:'▸'; }

.table th::after { content:none; }
#customers-table th:nth-child(-n+8)::after, #orders-table th:nth-child(1)::after, #orders-table th:nth-child(5)::after, #orders-table th:nth-child(6)::after, #orders-table th:nth-child(7)::after { content:'▴'; display:inline-block; margin-left:7px; font-size:16px; line-height:10px; color:#555; }
.table th { background:#d9d9d9; }
#orders-table .order-group { background:#e4e4e4; }
#orders-table tbody tr:nth-child(odd):not(.order-group) { background:#f5f5f5; }
.order-group::before { font-size:18px; padding-right:4px; }

.order-group::before { content:none; }
.order-toggle { font-size:18px; margin-right:7px; cursor:pointer; }

#orders-table .order-group::before { display:none !important; content:none !important; }
#orders-table .order-toggle { display:inline-block; width:18px; margin-right:4px; }

.legacy-pagination { display:none !important; }

.tabulator .tabulator-footer .tabulator-page { color:#000; }
.tabulator .tabulator-footer .tabulator-page:disabled { color:#666; }

/* Tabulator tables */
.tabulator-host, #orders-tabulator, #customers-tabulator { width: 100%; margin-top: 12px; }
.tabulator { border: 1px solid #ccc; font-family: Arial, sans-serif; font-size: 13px; }
.tabulator .tabulator-header { background: #d9d9d9; border-bottom: 1px solid #bbb; }
.tabulator .tabulator-header .tabulator-col { background: transparent; border-right: 1px solid #bbb; }
.tabulator .tabulator-row { cursor: pointer; }
.tabulator .tabulator-row:nth-child(even) { background: #f5f5f5; }
.tabulator .tabulator-group { background: #e4e4e4; color: #000; font-weight: 700; padding: 10px; }
.tabulator-group-totals { float: right; font-weight: 400; }
.tabulator-row-detail { display: flex; gap: 18px; padding: 10px 18px; background: #eef6f6; border-bottom: 1px solid #c9dddd; font-size: 12px; }
.tabulator .tabulator-footer { background: #eee; border-top: 1px solid #ccc; }
.tabulator .tabulator-calcs-holder { background: #eee; font-weight: 700; }

.chart-legend { display: none; }
.legacy-download { width: 34px; }

.panel > h2 { width: 100%; margin: 0 0 14px; text-align: center; font-size: 19px; font-weight: 400; }
.tabulator .tabulator-group { display: grid; grid-template-columns: 105px 120px minmax(220px, 1fr) 110px 140px 130px 130px; align-items: center; color: #000; }
.tabulator-group-label { grid-column: 1 / 5; }
.tabulator-group-total { text-align: right; color: #000; font-weight: 400; }

.tabulator .tabulator-group { display: block; color: #000; font-weight: 400; }
.tabulator .tabulator-group .tabulator-arrow { display: inline-block; }
.tabulator-group-label { display: inline-block; width: calc(100% - 410px); color: #000; font-weight: 400; }
.tabulator-group-total { display: inline-block; width: 130px; text-align: right; color: #000; font-weight: 400; }

.tabulator .tabulator-footer .tabulator-paginator { display: flex; align-items: center; justify-content: flex-end; gap: 3px; }
.tabulator .tabulator-footer .tabulator-page { min-width: 26px; height: 28px; padding: 3px 5px; font-size: 13px; line-height: 20px; }
.tabulator .tabulator-footer .tabulator-page-size { height: 28px; margin: 0 4px 0 0; font-size: 13px; }
.tabulator-group-label + .tabulator-group-total { width: 140px; }

#orders-tabulator .tabulator-group, #orders-tabulator .tabulator-group * { color: #000 !important; }
#orders-tabulator .tabulator-group .tabulator-arrow { border-left-color: #000; }
#orders-tabulator .tabulator-group-label { width: calc(100% - 422px); }

#orders-tabulator .tabulator-group { display: flex; align-items: center; padding: 10px; background: #e4e4e4 !important; }
#orders-tabulator .tabulator-group .tabulator-arrow { flex: 0 0 16px; border-left-color: #666; }
#orders-tabulator .tabulator-group-label { flex: 1 1 auto; width: auto; }
#orders-tabulator .tabulator-group-total { flex: 0 0 130px; }
#orders-tabulator .tabulator-group-label + .tabulator-group-total { flex-basis: 140px; }
.tabulator .tabulator-footer .tabulator-page { width: 58px; min-width: 58px; }

.tabulator .tabulator-footer .tabulator-page { width: auto; min-width: 0; height: 28px; padding: 3px 7px; }
#orders-tabulator .tabulator-group .tabulator-arrow { width: 16px; height: 16px; border: 0 !important; }
#orders-tabulator .tabulator-group .tabulator-arrow::before { content: '▾'; color: #000; font-size: 17px; line-height: 16px; }
#orders-tabulator .tabulator-group.tabulator-group-closed .tabulator-arrow::before { content: '▸'; }
#orders-tabulator .tabulator-group-total { transform: translateX(10px); }

#orders-tabulator .tabulator-group .tabulator-arrow::before { content: '\25BE'; }
#orders-tabulator .tabulator-group.tabulator-group-closed .tabulator-arrow::before { content: '\25B8'; }

#orders-tabulator .tabulator-group { display: block; position: relative; min-height: 38px; }
#orders-tabulator .tabulator-group-total { position: absolute; top: 10px; transform: none; text-align: right; }
#orders-tabulator .tabulator-group .tabulator-arrow { width: 0; height: 0; border: inherit; }
#orders-tabulator .tabulator-group .tabulator-arrow::before { content: none; }
.tabulator .tabulator-footer .tabulator-page { width: auto; min-width: 0; }

#orders-tabulator .tabulator-group .tabulator-arrow { display: inline-block; flex: 0 0 16px; width: 16px; height: 16px; border: 0 !important; }
#orders-tabulator .tabulator-group .tabulator-arrow::before { content: '\25BE'; color: #000; font-size: 17px; line-height: 16px; }
#orders-tabulator .tabulator-group.salesagents-group-collapsed .tabulator-arrow::before { content: '\25B8'; }

.tabulator .tabulator-footer .tabulator-page, .tabulator .tabulator-footer .tabulator-page-size { height: 28px !important; min-height: 28px !important; box-sizing: border-box; }
.tabulator .tabulator-footer .tabulator-page { width: auto !important; min-width: 0 !important; padding: 4px 7px; }
#orders-tabulator .tabulator-group .tabulator-arrow { display: none !important; }
#orders-tabulator .order-toggle { display: inline-block; width: 20px; margin-right: 4px; color: #000; font-size: 22px; line-height: 18px; }
#orders-tabulator .tabulator-group-total { padding-right: 14px; }
#orders-tabulator .tabulator-tableholder { overflow-x: hidden !important; }
#orders-tabulator .tabulator-group { width: 100%; }

/* Clientes: el desplazamiento horizontal pertenece a la ventana, no a Tabulator. */
html { overflow-x: auto !important; }
body.app { overflow-x: visible !important; }
#customers-tabulator .tabulator,
#customers-tabulator .tabulator-tableholder { overflow: visible !important; }
/* El scroll horizontal pertenece a la ventana cuando una tabla no cabe. */
#customers-tabulator,
#customers-tabulator .tabulator { min-width: 1198px; }
#orders-tabulator,
#orders-tabulator .tabulator,
#orders-empty-table { min-width: 1105px; }
#orders-tabulator .tabulator-tableholder { overflow: visible !important; }
/* Cabecera equivalente a Sala Verde, limitada al espacio situado junto al logo. */
.app-header { align-items: stretch; gap: 24px; }
.app-header .brand-logo { align-self: center; flex: 0 0 auto; }
.app-header .header-user { display: flex; flex: 1 1 auto; align-items: center; justify-content: space-between; min-height: 80px; padding: 20px 24px; background: #0f172a; color: #ffffff; border-radius: 8px; box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08); }
.app-header .portal-header-copy h1, .app-header .portal-header-copy p { margin: 0; }
.app-header .portal-header-copy h1 { font-size: 1.2rem; font-weight: 700; color: #ffffff; }
.app-header .portal-header-copy p { margin-top: 4px; color: #cbd5e1; font-size: 0.92rem; }
.app-header .header-user form { margin: 0; }
.app-header .header-user .logout { min-height: 38px; padding: 0 12px; background: #ffffff; color: #0f172a; border: 0; border-radius: 6px; font-weight: 700; white-space: nowrap; }
/* Panel de presentación del acceso de comisionistas. */
.login-portal-intro { margin: 0 -32px 24px; padding: 20px 24px; background: #0f172a; color: #ffffff; }
.login-portal-intro h1, .login-portal-intro p { margin: 0; }
.login-portal-intro h1 { font-size: 1.2rem; color: #ffffff; }
.login-portal-intro .muted { margin-top: 4px; color: #cbd5e1; font-size: 0.92rem; }.login-page .login-portal-intro { display: block; width: calc(100% + 64px); margin: 0 -32px 24px; padding: 20px 24px; background: #0f172a !important; color: #ffffff; }
.login-page .login-form button[type="submit"] { background: #0f172a !important; }/* Cabecera visible de la tarjeta de acceso. */
.login-page .login-panel { border-top: 0; overflow: hidden; }
.login-page .login-portal-intro { display: block !important; width: calc(100% + 64px) !important; min-height: 80px; margin: 0 -32px 24px !important; padding: 20px 24px !important; background: #0f172a !important; color: #ffffff !important; border-radius: 0 !important; }
.login-page .brand-logo { margin-bottom: 16px; }
/* Tarjeta de acceso: misma composición que las salas del portal de referencia. */
.login-page .login-card { padding: 0; border: 2px solid #0f172a; overflow: hidden; }
.login-page .login-card .brand-logo { margin: 32px 32px 24px; }
.login-page .login-card-header { display: flex; align-items: center; min-height: 80px; padding: 18px 24px; background: #0f172a; color: #ffffff; }
.login-page .login-card-header h1 { margin: 0; color: #ffffff; font-size: 1.2rem; line-height: 1.25; }
.login-page .login-card-header p { margin: 4px 0 0; color: #cbd5e1; font-size: .92rem; }
.login-page .login-card-body { padding: 0 32px 32px; }
.login-page .login-card-body .login-form { margin-top: 24px; }

/* La cabecera autenticada forma un único bloque con el logo. */
.app-header { padding: 10px 80px; background: #ffffff; }
.app-header .header-user { width: 100%; gap: 24px; padding: 10px 24px 10px 10px; }
.app-header .header-logo { display: flex; align-items: center; align-self: stretch; padding: 10px 14px; background: #ffffff; border-radius: 6px; }
.app-header .header-logo .brand-logo { display: block; max-width: 210px; max-height: 64px; margin: 0; }
.app-header .portal-header-copy { margin-right: auto; }

.orders-export-heading { justify-content: center; }

/* Filas de albarán compactas, con totales centrados verticalmente. */
#orders-tabulator .tabulator-group { min-height: 30px; padding-top: 5px; padding-bottom: 5px; }
#orders-tabulator .tabulator-group-total { top: 50%; transform: translateY(-50%); }

/* Selector de comisionista con tamaño fijo en escritorio y móvil. */
.range-form select[name='agent'] { flex: 0 0 270px; width: 270px; min-width: 270px; max-width: 270px; height: 28px; }

/* Acceso al SQL aplicado, igual que en Global Insight. */
.chart-heading { position: relative; }
.chart-heading .sql-modal-trigger { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: inline-grid; box-sizing: border-box; width: 24px; min-width: 24px; height: 24px; min-height: 0; place-items: center; border: 1px solid #cbd5e1; border-radius: 5px; padding: 3px; background: #fff; cursor: pointer; }
.chart-heading .sql-modal-trigger:hover { background: #f8fafc; }
.chart-heading .sql-modal-trigger img { display: block; width: 16px; height: 16px; }
.sql-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 24px; background: rgba(15, 23, 42, .48); }
.sql-modal[hidden] { display: none; }
.sql-modal-panel { display: grid; width: min(1100px, calc(100vw - 48px)); max-height: min(720px, calc(100vh - 48px)); grid-template-rows: auto 1fr; overflow: hidden; border-radius: 8px; background: #fff; box-shadow: 0 24px 60px rgba(15, 23, 42, .28); }
.sql-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; border-bottom: 1px solid #e5e7eb; }
.sql-modal-header h3 { margin: 0; font-size: 1rem; }
.sql-modal-actions { display: flex; gap: 8px; align-items: center; }
.sql-modal-actions button { display: inline-grid; min-width: 28px; height: 28px; place-items: center; border: 0; border-radius: 5px; padding: 0 8px; background: #f1f5f9; color: #334155; cursor: pointer; font: inherit; font-weight: 700; }
.sql-modal-actions button:hover { background: #e2e8f0; color: #0f172a; }
.sql-modal-actions button.is-copied { background: #dcfce7; }
.sql-modal pre { margin: 0; overflow: auto; padding: 14px; background: #0f172a; color: #e5e7eb; font: 12px Consolas, 'Courier New', monospace; line-height: 1.45; white-space: pre; }
body.modal-open { overflow: hidden; }
/* Evita mostrar el SVG de respaldo antes de que ECharts dibuje el gráfico final. */
.chart-scroll { min-height: 340px; }
.chart-scroll > .sales-chart { visibility: hidden; }
.sql-modal-actions img { display: block; width: 16px; height: 16px; }

/* Estado vacío del detalle de Pedidos. */
#orders-empty-table .orders-empty { text-align: center; color: #555; background: #e4e4e4; font-size: 16px; padding: 18px 10px; }

/* Ajustes de presentación del panel de clientes. */
.app-header { border-bottom: 0; }
.range-form label { font-size: 17px; }
.legacy-echart { height: 340px; }

/* Filtros compactos en la cabecera de Clientes. */
#customers-tabulator .tabulator-header-filter input { height: 28px; min-height: 28px; padding: 2px 6px; }

/* Logos específicos de acceso y cabecera autenticada. */
.app-header .header-user { min-height: 60px; gap: 18px; padding: 8px 18px 8px 12px; }
.app-header .header-logo { align-self: center; padding: 0; background: transparent; border-radius: 0; }
.app-header .header-logo .brand-logo { max-width: 210px; max-height: 42px; margin: 0; }

/* Ajuste fino de la cabecera autenticada. */
.app-header .header-user { padding-left: 18px; }
.app-header .portal-header-copy h1 { font-size: 1.08rem; }
.app-header .header-user .logout { min-height: 32px; padding: 0 9px; }
.app-header { position: relative; display: flex; }
.data-refresh-row { position: absolute; top: 100%; right: 80px; z-index: 2; display: flex; min-height: 18px; justify-content: flex-end; }
.data-refresh { display: inline-flex; height: 18px; min-height: 18px; align-items: center; gap: 4px; padding: 0 5px; border: 1px solid #b8c2cc; border-radius: 3px; background: #fff; color: #334155; font: 10px Arial, sans-serif; line-height: 1; text-decoration: none; white-space: nowrap; }
.data-refresh-icon { font-size: 16px; font-weight: 700; line-height: 1; }

/* Móvil: se adapta la interfaz; las tablas conservan su estructura y usan el scroll de la ventana. */
@media (max-width: 900px) {
    .app-header { padding: 8px 12px; }
    .data-refresh-row { right: 12px; }
    .app-header .header-user { min-height: 54px; gap: 12px; padding: 8px 10px; border-radius: 6px; }
    .app-header .header-logo .brand-logo { max-width: 108px; max-height: 32px; }
    .app-header .portal-header-copy { min-width: 0; }
    .app-header .portal-header-copy h1 { overflow: hidden; font-size: .9rem; text-overflow: ellipsis; white-space: nowrap; }
    .app-header .portal-header-copy p { overflow: hidden; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
    .app-header .header-user .logout { min-height: 30px; padding: 0 8px; font-size: .85rem; }

    /* El contenido general ocupa todo el ancho visible; solo las tablas desbordan. */
    .dashboard { padding: 0 0 36px; }
    .dashboard > .chart-filters { display: block; height: auto; min-height: 0; padding: 10px 0; }
    .range-form { align-items: center; gap: 8px; }
    .range-form label { width: 100%; gap: 7px; font-size: 15px; }
    .range-form select[name='agent'] { flex: 0 0 270px; width: 270px; min-width: 270px; max-width: 270px; height: 28px; }

    .chart-heading { min-height: 44px; padding: 0 34px 0 4px; }
    .chart-heading h2, .detail-header h2, .panel > h2 { font-size: 17px; }
    .chart-heading .sql-modal-trigger { right: 0; }
    .legacy-echart, .chart-scroll { height: 300px; min-height: 300px; }
    .detail-header { min-height: 44px; margin-top: 10px; font-size: 16px; }
    .detail-header .legacy-back { font-size: 16px; }
    .legacy-back img { width: 36px !important; height: 36px; margin-right: 8px !important; }
    .detail-header .legacy-download { right: 0; width: 30px; }

    .sql-modal { padding: 12px; }
    .sql-modal-panel { width: calc(100vw - 24px); max-height: calc(100vh - 24px); }
    .sql-modal-header { padding: 10px 12px; }
    .sql-modal pre { padding: 12px; font-size: 11px; }


    /* Sin responsive ni scroll interno: el desplazamiento horizontal es el de la ventana. */
    /* Franja real visible tras el borde derecho de Tabulator. */
    #customers-tabulator,
    #orders-tabulator { box-sizing: content-box !important; margin: 0; padding: 0 12px 0 0; background: #f4f6f8; }
    #orders-empty-table { margin-left: 0; margin-right: 12px; padding-left: 0; }

    #orders-tabulator,
    #orders-tabulator .tabulator,
    #orders-empty-table { width: 1355px !important; min-width: 1355px !important; max-width: none !important; }
    #customers-tabulator .tabulator-tableholder,
    #orders-tabulator .tabulator-tableholder { overflow: visible !important; }
}
/* Escritorio: el contenido conserva una base legible; la ventana aporta el scroll horizontal. */
@media (hover: hover) and (pointer: fine) {
    body.app { min-width: 1024px; }
    .customers-table-panel { overflow: visible; }
    #customers-tabulator,
    #customers-tabulator .tabulator { min-width: 1345px !important; }
    #orders-tabulator,
    #orders-tabulator .tabulator,
    #orders-empty-table { width: 100% !important; min-width: 1105px !important; max-width: none !important; }
}

/* Escritorio estrecho o con zoom: reflujo aislado; no se aplica al móvil táctil. */
@media (max-width: 900px) and (hover: hover) and (pointer: fine) {
    .app-header { flex-direction: column; align-items: stretch; gap: 5px; }
    .app-header .header-user { width: 100%; }
    .data-refresh-row { position: static; width: 100%; flex: 0 0 auto; }
    .dashboard > .chart-filters { padding-left: 12px; padding-right: 12px; }
    .dashboard > .panel:has(.legacy-back) { padding-left: 12px; padding-right: 12px; }
    .chart-heading .sql-modal-trigger,
    .detail-header .legacy-download { right: 12px; }
    .chart-scroll { height: auto; min-height: 340px; overflow-x: hidden; overflow-y: hidden; }
    .legacy-echart { min-width: 1024px; min-height: 340px; height: 340px; }
    #customers-tabulator,
    #orders-tabulator { box-sizing: border-box !important; padding-right: 0; background: transparent; }
    #orders-empty-table { margin-right: 0; }
}

@media (max-width: 640px) and (hover: hover) and (pointer: fine) {
    .app-header .header-user {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "logo logout"
            "copy copy";
        row-gap: 8px;
    }
    .app-header .header-logo { grid-area: logo; }
    .app-header .portal-header-copy { grid-area: copy; margin-right: 0; }
    .app-header .header-user form { grid-area: logout; }
    .app-header .portal-header-copy h1,
    .app-header .portal-header-copy p { overflow: visible; text-overflow: clip; white-space: normal; }
    .range-form label { width: 100%; flex-direction: column; align-items: flex-start; gap: 6px; }
    .range-form select[name='agent'] { flex: 0 0 28px; min-height: 28px; max-height: 28px; }
}
.range-form select[name='agent'].touch-agent-select-native { display: none; }

.touch-agent-select {
    position: relative;
    width: 270px;
    font-family: Arial, sans-serif;
    font-weight: 400;
}

.touch-agent-select-button {
    width: 270px;
    min-height: 28px;
    height: 28px;
    justify-content: space-between;
    border: 1px solid #767676;
    border-radius: 2px;
    padding: 0 7px;
    background: #fff;
    color: #000;
    font-size: 15px;
    font-weight: 400;
}

.touch-agent-select-button::after { content: '▾'; }

.touch-agent-select-options {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    z-index: 1000;
    box-sizing: border-box;
    width: 270px;
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid #767676;
    border-radius: 2px;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}

.touch-agent-select-options[hidden] { display: none; }

.touch-agent-select-option {
    display: block;
    width: 100%;
    min-height: 28px;
    border: 0;
    border-radius: 0;
    padding: 4px 8px;
    background: #fff;
    color: #000;
    font-size: 15px;
    font-weight: 400;
    line-height: 20px;
    text-align: left;
    white-space: nowrap;
}

.touch-agent-select-option + .touch-agent-select-option { border-top: 1px solid #e5e7eb; }
.touch-agent-select-option:hover { background: #e9e9e9; }

/* Móvil táctil: formulario completo a ancho fijo, reducido por el viewport y ampliable con zoom. */
@media (hover: none) and (pointer: coarse) {
    body.app {
        min-width: 1440px;
        background: #fff;
        -webkit-tap-highlight-color: rgba(203, 213, 225, .65);
    }

    .app-header,
    .dashboard {
        width: 1434px;
        max-width: none;
        margin-left: auto;
        margin-right: auto;
    }

    /* Clientes replica el margen lateral centrado que ya usa Pedidos. */
    body.app:not(:has(.legacy-back)) .app-header,
    body.app:not(:has(.legacy-back)) .dashboard { width: 1355px; }

    #customers-tabulator .tabulator-header .tabulator-col:is(
        [tabulator-field="sales"],
        [tabulator-field="commission"],
        [tabulator-field="previousSales"],
        [tabulator-field="previousCommission"],
        [tabulator-field="currentSales"],
        [tabulator-field="currentCommission"]
    ) .tabulator-col-content {
        display: flex;
        height: 100%;
        align-items: center;
    }

    #customers-tabulator .tabulator-header .tabulator-col:is(
        [tabulator-field="sales"],
        [tabulator-field="commission"],
        [tabulator-field="previousSales"],
        [tabulator-field="previousCommission"],
        [tabulator-field="currentSales"],
        [tabulator-field="currentCommission"]
    ) .tabulator-col-title-holder {
        flex: 1 1 auto;
        width: 100%;
        min-width: 0;
    }

    #customers-tabulator .tabulator-header .tabulator-col:is(
        [tabulator-field="sales"],
        [tabulator-field="commission"],
        [tabulator-field="previousSales"],
        [tabulator-field="previousCommission"],
        [tabulator-field="currentSales"],
        [tabulator-field="currentCommission"]
    ) .tabulator-col-sorter {
        right: 4px;
    }

    #customers-tabulator .tabulator-header .tabulator-col:is(
        [tabulator-field="sales"],
        [tabulator-field="commission"],
        [tabulator-field="previousSales"],
        [tabulator-field="previousCommission"],
        [tabulator-field="currentSales"],
        [tabulator-field="currentCommission"]
    ) .tabulator-col-title {
        line-height: 1.2;
        white-space: normal;
    }

    .app-header { padding: 10px 0; }
    .data-refresh-row { right: 0; }
    .dashboard { padding: 0 0 60px; }

    .touch-agent-select {
        position: relative;
        width: 270px;
        font-family: Arial, sans-serif;
        font-weight: 400;
    }

    .touch-agent-select-button {
        width: 270px;
        min-height: 28px;
        height: 28px;
        justify-content: space-between;
        border: 1px solid #767676;
        border-radius: 2px;
        padding: 0 7px;
        background: #fff;
        color: #000;
        font-size: 15px;
        font-weight: 400;
    }

    .touch-agent-select-button::after { content: '▾'; }

    .touch-agent-select-options {
        position: absolute;
        top: calc(100% + 2px);
        left: 0;
        z-index: 1000;
        box-sizing: border-box;
        width: max-content;
        min-width: 270px;
        max-height: none;
        overflow-y: visible;
        border: 1px solid #767676;
        border-radius: 2px;
        background: #fff;
        box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
    }

    .touch-agent-select-options[hidden] { display: none; }

    .touch-agent-select-option {
        display: block;
        width: 100%;
        min-height: 40px;
        border: 0;
        border-radius: 0;
        padding: 5px 8px;
        background: #fff;
        color: #000;
        font-size: 25px;
        font-weight: 400;
        line-height: 30px;
        text-align: left;
        white-space: nowrap;
    }

    .touch-agent-select-option + .touch-agent-select-option { border-top: 1px solid #e5e7eb; }
    .touch-agent-select-option:active { background: #e5e7eb; }

    /* Pedidos conserva su ancho fijo propio. */
    body.app:has(.legacy-back) .app-header,
    body.app:has(.legacy-back) .dashboard { width: 1355px; }
}

/* Móvil vertical: conserva completa la barra temporal y elimina la antigua franja lateral. */
@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
    .legacy-echart,
    .chart-scroll {
        height: 340px;
        min-height: 340px;
    }

    #customers-tabulator,
    #orders-tabulator {
        box-sizing: border-box !important;
        padding-right: 0;
        background: transparent;
    }

    #orders-empty-table { margin-right: 0; }
}
