.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 40px;
    padding: 0 var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface-2);
    transition: background var(--motion-fast), transform var(--motion-fast);
}

.btn:hover {
    background: var(--surface-3);
}

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

.btn-primary:hover svg,
.btn-primary:hover i {
    color: var(--color-primary);
    stroke: currentColor;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--text-inverse);
    border: 1px solid var(--color-primary);

    transition:
        background .18s ease,
        color .18s ease,
        border-color .18s ease,
        box-shadow .18s ease,
        transform .18s ease;
}

.btn-outline {
    background: transparent;
    border-color: var(--border-default);
}

.btn-outline:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

.btn-sm {
    min-height: 34px;
    padding: 0 var(--space-3);
    font-size: 0.875rem;
}

.card {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;

    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.card-header {
    min-width: 0;

    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);

    padding: var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
}

.card-body {
    min-width: 0;
    max-width: 100%;

    padding: var(--space-5);
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 650;
    color: var(--text-secondary);
    background: var(--surface-2);
    border: 1px solid var(--border-default);
}

.badge-success {
    color: var(--color-success);
    border-color: rgba(0, 255, 48, 0.28);
}

.badge-warning {
    color: var(--color-warning);
    border-color: rgba(244, 180, 0, 0.28);
}

.badge-error {
    color: var(--color-error);
    border-color: rgba(255, 77, 79, 0.28);
}

.table-wrap {
    width: 100%;
    max-width: 100%;

    overflow-x: auto;
    overflow-y: hidden;

    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    background: var(--surface-1);

    -webkit-overflow-scrolling: touch;
}

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

.table th,
.table td {
    padding: var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

.table th {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: var(--surface-2);
}

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

.grid,
.grid > * {
    min-width: 0;
}

.avatar {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border-radius: var(--radius-full);
    color: var(--text-inverse);
    background: var(--color-primary);
    font-weight: 700;
}

/* Login */

.login-body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: hidden;
    background:
        radial-gradient(circle at top center, rgba(0, 255, 48, 0.10), transparent 34%),
        linear-gradient(180deg, var(--surface-0), #030303);
    color: var(--text-primary);
}

.login-shell {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: min(100%, 560px);
    padding: 56px 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;

    background: var(--surface-1);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 32px;

    box-shadow:
        0 30px 80px rgba(0, 0, 0, .45),
        inset 0 1px rgba(255, 255, 255, .05);
}

.login-logo {
    margin-bottom: 34px;
}

.login-logo img {
    width: 310px;
    max-width: 100%;
    height: auto;
    filter: var(--logo-filter);
}

.login-content {
    max-width: 380px;
    margin-bottom: 42px;
}

.login-content p {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.12rem;
    font-weight: 600;
    line-height: 1.55;
}

.login-action {
    width: 100%;
    display: flex;
    justify-content: center;
}

.google-button-wrap {
    width: 100%;
    max-width: 360px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4px;
    border: 1px solid rgba(0, 255, 48, .55);
    border-radius: 999px;
    background: rgba(0, 255, 48, .035);
    box-shadow:
        0 0 0 1px rgba(0, 255, 48, .04),
        0 0 28px rgba(0, 255, 48, .10);
}

.google-button-wrap iframe {
    width: 100% !important;
    max-width: 340px !important;
    border-radius: 999px !important;
}

.login-note {
    width: 100%;
    max-width: 380px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-size: 0.9rem;
}

@media (max-width: 480px) {
    .login-body {
        padding: 18px;
    }

    .login-card {
        width: 100%;
        padding: 38px 24px;
        border-radius: 26px;
    }

    .login-logo img {
        width: 240px;
    }

    .login-content p {
        font-size: 1rem;
    }

    .google-button-wrap {
        max-width: 320px;
    }

    .google-button-wrap iframe {
        max-width: 300px !important;
    }
}

.chart-date {
    width: auto;
    min-width: 150px;
}

.chart-wrap {
    position: relative;
    width: 100%;
    min-height: 360px;
}

.chart-wrap canvas {
    width: 100% !important;
    height: 360px !important;
}

@media (max-width: 760px) {
    .chart-date {
        width: 100%;
    }

    .chart-wrap {
        min-height: 320px;
    }

    .chart-wrap canvas {
        height: 320px !important;
    }
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn.is-loading {
    opacity: 0.7;
    pointer-events: none;
}

@media (max-width: 760px) {
    .card-header,
    .card-body {
        padding: var(--space-4);
    }

    .table {
        min-width: 640px;
    }

    .table th,
    .table td {
        padding: 14px;
    }

    .table-wrap::after {
        content: "Desliza para ver más";
        display: block;
        padding: 10px 14px;
        color: var(--text-muted);
        font-size: 0.78rem;
        border-top: 1px solid var(--border-subtle);
    }
}

.crm-kanban {
    display: grid;
    grid-template-columns: repeat(7, minmax(240px, 1fr));
    gap: var(--space-4);
    overflow-x: auto;
    padding-bottom: var(--space-4);
}

.crm-column {
    min-width: 240px;
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.crm-column-header {
    min-height: 48px;
    padding: 0 var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
}

.crm-column-body {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
}

.crm-opportunity-card {
    display: grid;
    gap: 8px;
    padding: var(--space-4);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    color: var(--text-primary);
}

.crm-opportunity-card:hover {
    background: var(--surface-3);
}

.crm-opportunity-card span {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.crm-opportunity-meta {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    padding-top: 8px;
    border-top: 1px solid var(--border-subtle);
}

.crm-empty {
    padding: var(--space-4);
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
}

.crm-timeline {
    display: grid;
    gap: var(--space-5);
}

.crm-timeline-item {
    position: relative;
    display: grid;
    grid-template-columns: 18px 1fr;
    gap: var(--space-3);
}

.crm-timeline-dot {
    width: 10px;
    height: 10px;
    margin-top: 6px;
    border-radius: 999px;
    background: var(--color-primary);
}

.crm-timeline-dot.note{
    background:#3b82f6;
}

.crm-timeline-dot.call{
    background:#f59e0b;
}

.crm-timeline-dot.meeting{
    background:#8b5cf6;
}

.crm-timeline-dot.document{
    background:#10b981;
}

.crm-timeline-dot.system{
    background:#64748b;
}

.crm-timeline-dot.deleted{
    background:#ef4444;
    border-color:#ef4444;
    box-shadow:0 0 0 4px rgba(239,68,68,.15);
}

.btn-danger {
    color: var(--color-error);
    border-color: var(--color-error);
    margin-top: 6px;
}

.btn-danger:hover {
    color: var(--text-inverse);
    background: var(--color-error);
}

.danger-zone {
    border-color: color-mix(in srgb, var(--color-error) 35%, var(--border-default));
}

/* =========================
   Compact responsive tables
========================= */

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: var(--radius-lg);
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    min-width: 620px;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.table th,
.table td {
    padding: 10px 10px;
    line-height: 1;
    vertical-align: middle;
    white-space: nowrap;
}

.table th {
    font-size: 0.75rem;
    letter-spacing: 0.06em;
}

.table td {
    color: var(--text-secondary);
}

.table td a {
    color: var(--text-primary);
}

.table .btn,
.table .btn-sm {
    min-height: 30px;
    padding: 0 10px;
    font-size: 0.84rem;
}

/* Permite truncar nombres largos */
.table td {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Columnas de monto más compactas */
.table th:nth-child(n),
.table td:nth-child(n) {
    min-width: auto;
}

/* Cards con tablas */
.card-body .table-wrap {
    margin: 2;
}

/* Mobile */
@media (max-width: 760px) {
    .table {
        min-width: 560px;
        font-size: 0.6rem;
    }

    .table th,
    .table td {
        padding: 9px 10px;
    }

    .table th {
        font-size: 0.64rem;
    }

    .table td {
        max-width: 180px;
    }

    .table-wrap::after {
        content: "Desliza para ver más";
        display: block;
        padding: 8px 12px;
        color: var(--text-muted);
        font-size: 0.72rem;
        border-top: 1px solid var(--border-subtle);
    }
}

/* Very small phones */
@media (max-width: 420px) {
    .table {
        min-width: 520px;
        font-size: 0.74rem;
    }

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

    .table td {
        max-width: 150px;
    }
}

/* =========================
   Customer table filters
========================= */

.customer-filters {
    display: grid;
    grid-template-columns: minmax(240px, 1.4fr) repeat(5, minmax(130px, 0.8fr)) auto auto;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

.territory-filters {
    display: grid;
    grid-template-columns: minmax(260px, 1.6fr) repeat(3, minmax(150px, 0.8fr)) auto auto;
    gap: 10px;
    align-items: center;
}

.territory-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-4);
}

.territory-main-grid {
    align-items: stretch;
}

.territory-map-card,
.territory-breakdown-card {
    min-width: 0;
}

.territory-map-canvas {
    width: 100%;
    min-height: 420px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface-2);
}

.territory-map-placeholder {
    min-height: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: var(--space-6);
    color: var(--text-secondary);
    text-align: center;
}

.territory-map-placeholder i {
    width: 42px;
    height: 42px;
}

.territory-map-placeholder strong {
    color: var(--text-primary);
}

.territory-breakdown-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-5);
}

.territory-subtitle {
    margin: 0 0 var(--space-3);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.territory-table-scroll {
    max-height: 460px;
    overflow: auto;
}

.territory-info-window {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 220px;
    color: #111827;
}

.territory-info-window small,
.territory-info-window span {
    color: #4b5563;
}

.customer-location-preview {
    margin-top: var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface-2);
}

.customer-location-preview iframe {
    display: block;
    width: 100%;
    min-height: 240px;
    border: 0;
}

.customer-location-preview-meta {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 10px 12px;
    border-top: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.customer-count {
    margin-bottom: 12px;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.table-wrap-compact {
    overflow-x: auto;
}

.table-compact {
    min-width: 0;
    font-size: 0.78rem;
}

.table-compact th,
.table-compact td {
    padding: 8px 10px;
    line-height: 1.25;
}

.table-compact th {
    font-size: 0.62rem;
}

.table-customers {
    table-layout: fixed;
}

.table-customers th:nth-child(1),
.table-customers td:nth-child(1) {
    width: 22%;
}

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

.table-customers th:nth-child(3),
.table-customers td:nth-child(3) {
    width: 12%;
}

.table-customers th:nth-child(4),
.table-customers td:nth-child(4) {
    width: 15%;
}

.table-customers th:nth-child(5),
.table-customers td:nth-child(5) {
    width: 10%;
}

.table-customers th:nth-child(6),
.table-customers td:nth-child(6) {
    width: 9%;
}

.table-customers th:nth-child(7),
.table-customers td:nth-child(7) {
    width: 8%;
    text-align: right;
}

.table-customers td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-subtext {
    display: block;
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 0.7rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 1024px) {
    .customer-filters,
    .territory-filters {
        grid-template-columns: 1fr 1fr;
    }

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

    .territory-main-grid {
        grid-template-columns: 1fr;
    }

    .customer-filters .btn {
        width: 100%;
    }

    .table-compact {
        min-width: 760px;
    }
}

@media (max-width: 760px) {
    .customer-filters,
    .territory-filters,
    .territory-kpi-grid,
    .territory-breakdown-grid {
        grid-template-columns: 1fr;
    }

    .table-compact {
        min-width: 680px;
    }
}

.customer-autocomplete {
    position: relative;
}

.customer-results {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    left: 0;
    right: 0;

    display: grid;
    gap: 4px;

    max-height: 260px;
    overflow-y: auto;

    padding: 6px;
    
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.customer-results:empty {
    display: none;
}

.customer-result-item {
    width: 100%;
    display: grid;
    gap: 3px;

    padding: 10px 12px;

    text-align: left;
    color: var(--text-primary);
    background: transparent;
    border: 0;
    border-radius: var(--radius-md);
    
    cursor: pointer;
}
    
.customer-result-item:hover {
    background: var(--surface-2);
}
    
.customer-result-item strong {
    font-size: 0.9rem;
}

.customer-result-item span,
.customer-result-empty {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.customer-result-empty {
    padding: 10px 12px;
}

/* =========================
   Opportunity form
========================= */

.opportunity-form {
    display: grid;
    gap: var(--space-5);
}

.form-card {
    overflow: visible;
}

.form-card .card-body {
    padding: var(--space-5);
}

.form-grid {
    display: grid;
    gap: var(--space-4);
    align-items: start;
}

.form-grid-client {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
}

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

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

.form-inline-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-3);
    align-items: center;
}

.form-inline-control .btn {
    min-height: 48px;
    border-radius: 14px;
    white-space: nowrap;
}

.form-actions-card .card-body {
    padding-block: var(--space-4);
}

/* Autocomplete */
.customer-autocomplete {
    position: relative;
}

.customer-results {
    position: absolute;
    z-index: 50;
    top: calc(100% + 8px);
    left: 0;
    right: 0;

    display: grid;
    gap: 4px;

    max-height: 280px;
    overflow-y: auto;

    padding: 6px;

    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

.customer-results:empty {
    display: none;
}

.customer-result-item {
    width: 100%;

    display: grid;
    gap: 4px;

    padding: 11px 12px;

    text-align: left;
    color: var(--text-primary);
    background: transparent;
    border: 0;
    border-radius: 12px;

    cursor: pointer;
}

.customer-result-item:hover {
    background: var(--surface-2);
}

.customer-result-item strong {
    font-size: 0.9rem;
}

.customer-result-item span,
.customer-result-empty {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.customer-result-empty {
    padding: 10px 12px;
}

/* Responsive */
@media (max-width: 1180px) {
    .form-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .form-card .card-body {
        padding: var(--space-4);
    }

    .form-grid-client,
    .form-grid-4,
    .form-grid-2 {
        grid-template-columns: 1fr;
    }

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

    .form-inline-control .btn {
        width: 100%;
    }
}

.table-main-link {
    display: block;
    color: var(--text-primary);
    font-weight: 700;
}

.table-main-link:hover {
    color: var(--color-primary);
}

.table-actions {
    text-align: left;
}

.table-customers-simple th:nth-child(1),
.table-customers-simple td:nth-child(1) {
    width: 42%;
}

.table-customers-simple th:nth-child(2),
.table-customers-simple td:nth-child(2) {
    width: 18%;
}

.table-customers-simple th:nth-child(3),
.table-customers-simple td:nth-child(3) {
    width: 18%;
}

.table-customers-simple th:nth-child(4),
.table-customers-simple td:nth-child(4) {
    width: 14%;
}

.table-customers-simple th:nth-child(5),
.table-customers-simple td:nth-child(5) {
    width: 8%;
}

/* =========================
   Customers agenda
========================= */

.customers-card {
    overflow: hidden;
}

.customers-toolbar {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 240px auto auto;
    gap: 12px;
    align-items: center;
    margin-bottom: 18px;
}

.customers-search {
    min-height: 46px;
    display: grid;
    grid-template-columns: 20px 1fr;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border: 1px solid var(--border-default);
    border-radius: 14px;
    background: var(--surface-1);
}

.customers-search svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.customers-search input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.94rem;
}

.customers-city-filter {
    min-height: 46px;
    border-radius: 14px;
}

.customers-meta {
    margin-bottom: 12px;
    color: var(--text-muted);
    font-size: 0.86rem;
}

.customers-table-shell {
    max-height: calc(100vh - 360px);
    min-height: 360px;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid var(--border-default);
    border-radius: 18px;
    background: var(--surface-1);
}

.customers-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.88rem;
}

.customers-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    text-align: left;
    vertical-align: middle;
    padding: 12px 14px;
    color: var(--text-muted);
    background: var(--surface-2);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-subtle);
}

.customers-table tbody td {
    padding: 14px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    overflow: hidden;
}

.customers-table tbody tr:hover {
    background: color-mix(in srgb, var(--surface-2) 65%, transparent);
}

.customers-table th:nth-child(1),
.customers-table td:nth-child(1) {
    width: 46%;
}

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

.customers-table th:nth-child(3),
.customers-table td:nth-child(3) {
    width: 15%;
}

.customers-table th:nth-child(4),
.customers-table td:nth-child(4) {
    width: 14%;
}

.customers-table th:nth-child(5),
.customers-table td:nth-child(5) {
    width: 64px;
    min-width: 64px;
    max-width: 64px;
    text-align: center;
    padding-left: 8px;
    padding-right: 8px;
}

.customers-action {
    text-align: center;
    vertical-align: middle;
}

.customers-action .btn {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    gap: 0;
    border-radius: 999px;
    font-size: 0;

    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.customers-action .btn svg,
.customers-action svg {
    width: 17px;
    height: 17px;
}

.customers-table td:nth-child(2),
.customers-table td:nth-child(3),
.customers-table td:nth-child(4) {
    white-space: nowrap;
    text-overflow: ellipsis;
}

.customers-table td {
    overflow: hidden;
}

.customers-table th:nth-child(5),
.customers-table td:nth-child(5) {
    min-width: 110px;
}


.customer-cell {
    min-width: 0;

    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 12px;
    align-items: center;

    color: var(--text-primary);
}

.customer-cell:hover strong {
    color: var(--color-primary);
}

.customer-avatar-mini {
    width: 38px;
    height: 38px;

    display: inline-grid;
    place-items: center;

    border-radius: 999px;

    color: var(--text-inverse);
    background: var(--surface-inverse, #050505);

    font-size: 0.9rem;
    font-weight: 800;
}

.customer-cell-text {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.customer-cell-text strong,
.customer-cell-text small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.customer-cell-text strong {
    font-size: 0.92rem;
    font-weight: 750;
}

.customer-cell-text small {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.pill-muted {
    display: inline-flex;
    align-items: center;

    min-height: 24px;
    padding: 0 10px;

    border-radius: 999px;

    color: var(--text-muted);
    background: var(--surface-2);

    font-size: 0.76rem;
    font-weight: 650;
}

.customer-opps {
    color: var(--color-success);
    font-weight: 750;
}

.customer-opps.is-open {
    color: var(--color-warning);
}

/* Mobile: cards instead of dense table */
@media (max-width: 760px) {
    .customers-toolbar {
        grid-template-columns: 1fr;
    }

    .customers-card .card-body {
        padding: var(--space-4);
    }

    .customers-table-shell {
        max-height: none;
        min-height: 0;
        overflow: visible;
        border: 0;
        background: transparent;
    }

    .customers-table,
    .customers-table thead,
    .customers-table tbody,
    .customers-table th,
    .customers-table td,
    .customers-table tr {
        display: block;
        width: 100%;
    }

    .customers-table thead {
        display: none;
    }

    .customers-table tbody {
        display: grid;
        gap: 12px;
    }

    .customers-table tbody tr {
        display: grid;
        gap: 10px;

        padding: 14px;

        border: 1px solid var(--border-default);
        border-radius: 18px;
        background: var(--surface-1);
    }

    .customers-table tbody td {
        padding: 0;
        border: 0;
    }

    .customers-table td:nth-child(1),
    .customers-table td:nth-child(2),
    .customers-table td:nth-child(3),
    .customers-table td:nth-child(4),
    .customers-table td:nth-child(5) {
        width: 100%;
        text-align: left;
    }

    .customers-table td:nth-child(2)::before {
        content: "Ciudad";
        display: block;
        margin-bottom: 3px;
        color: var(--text-muted);
        font-size: 0.7rem;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .customers-table td:nth-child(3)::before {
        content: "Última compra";
        display: block;
        margin-bottom: 3px;
        color: var(--text-muted);
        font-size: 0.7rem;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .customers-table td:nth-child(4)::before {
        content: "Oportunidades";
        display: block;
        margin-bottom: 3px;
        color: var(--text-muted);
        font-size: 0.7rem;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .customers-action .btn {
        width: 100%;
        justify-content: center;
    }
}

/* =========================
   Opportunity edit/create form
========================= */

.page-header-compact {
    margin-bottom: var(--space-5);
}

.page-header-compact h1 {
    font-size: clamp(1.45rem, 2vw, 2rem);
}

.opportunity-form {
    display: grid;
    gap: var(--space-5);
}

.form-card {
    overflow: visible;
}

.form-card .card-body {
    padding: var(--space-5);
}

.form-card .card-header {
    padding: var(--space-5);
}

.form-grid {
    display: grid;
    gap: var(--space-4);
    align-items: start;
}

.form-grid-client {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

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

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

.form-inline-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-3);
    align-items: center;
}

.form-inline-control .btn {
    min-height: 48px;
    border-radius: 14px;
    white-space: nowrap;
}

.form-actions-card .card-body {
    padding-block: var(--space-4);
}

.danger-zone {
    border-color: color-mix(in srgb, var(--color-error) 42%, var(--border-default));
}

.danger-zone .card-header {
    border-bottom-color: color-mix(in srgb, var(--color-error) 25%, var(--border-subtle));
}

.btn-danger {
    color: var(--text-inverse);
    background: var(--color-error);
    border-color: var(--color-error);
}

.btn-danger:hover {
    filter: brightness(0.95);
}

#deleteOpportunityForm {
    display: none;
}

/* Responsive */
@media (max-width: 1180px) {
    .form-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .form-card .card-body,
    .form-card .card-header {
        padding: var(--space-4);
    }

    .form-grid-client,
    .form-grid-4,
    .form-grid-2 {
        grid-template-columns: 1fr;
    }

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

    .form-inline-control .btn {
        width: 100%;
    }

    .form-actions-card .cluster {
        display: grid;
        grid-template-columns: 1fr;
    }

    .form-actions-card .btn {
        width: 100%;
    }
}

/* ===========================
   Quick Actions
=========================== */

.quick-actions{
    display:grid;
    gap:14px;
}

.quick-action{
    display:grid;
    grid-template-columns:52px 1fr 20px;
    align-items:center;
    gap:14px;

    padding:16px;

    border:1px solid var(--border-default);
    border-radius:18px;

    background:var(--surface-1);
}

.quick-action:hover{
    transform:translateY(-2px);
    border-color:var(--color-primary);
    box-shadow:var(--shadow-md);
}

/* --- Componente Botón Primario --- */
.quick-action-primary {
    /* El fondo usa automáticamente el verde correspondiente a cada tema */
    background: var(--color-primary);
    
    /* El borde sigue al fondo */
    border: 1px solid var(--color-primary);
    
    /* En tema oscuro por defecto será negro, en tema claro será blanco (--text-inverse) */
    color: var(--text-inverse);
    
}

/* --- Estados Hover (Interacción) --- */
.quick-action-primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

/* --- Ajuste específico para Tema Oscuro --- */
/* Como en tu tema oscuro '--text-inverse' es #090909 (casi negro), */
/* si prefieres que sea negro puro (#000000), puedes forzarlo aquí: */
html[data-theme="dark"] .quick-action-primary {
    color: #000000; 
}

.quick-action-primary:hover{
    filter:brightness(.97);
}

.quick-action-icon{
    width:48px;
    height:48px;

    display:grid;
    place-items:center;

    border-radius:14px;

    background:rgba(255,255,255,.12);
}

.quick-action:not(.quick-action-primary) .quick-action-icon{
    background:var(--surface-2);
}

.quick-action-icon svg{
    width:22px;
    height:22px;
}

.quick-action-content{
    display:grid;
    gap:4px;
}

.quick-action-content strong{
    font-size:1rem;
    font-weight:700;
}

.quick-action-content small{
    color:inherit;
    opacity:.72;
    font-size:.80rem;
}

.quick-action-arrow{
    width:18px;
    height:18px;
    opacity:.7;
}
/* =========================
   CRM secondary forms
========================= */

.form-field-full {
    grid-column: 1 / -1;
}

.textarea-lg {
    min-height: 88px !important;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-5);
}

.form-actions .btn {
    min-height: 46px;
    border-radius: 14px;
}

.form-info-box {
    display: flex;
    align-items: center;
    gap: 12px;

    padding: 16px 18px;

    border: 1px solid color-mix(in srgb, var(--color-primary) 32%, var(--border-default));
    border-radius: 16px;

    color: var(--text-primary);
    background: color-mix(in srgb, var(--color-primary) 7%, var(--surface-1));
}

.form-info-box svg {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    color: var(--color-primary);
}

.form-info-box span {
    font-size: 0.92rem;
    line-height: 1.45;
}

.file-input {
    padding-top: 11px !important;
}

@media (max-width: 760px) {
    .form-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .form-actions .btn {
        width: 100%;
    }

    .form-info-box {
        align-items: flex-start;
    }
}

/* ===========================
   Customer Timeline
=========================== */

.crm-timeline-scroll{

    height:calc(100vh - 330px);
    min-height:100px;
    max-height:240px;

    overflow-y:auto;
    overflow-x:hidden;

    padding-right:10px;

}

/* Scroll moderno */

.crm-timeline-scroll::-webkit-scrollbar{
    width:8px;
}

.crm-timeline-scroll::-webkit-scrollbar-track{
    background:transparent;
}

.crm-timeline-scroll::-webkit-scrollbar-thumb{
    background:var(--border-default);
    border-radius:999px;
}

.crm-timeline-scroll::-webkit-scrollbar-thumb:hover{
    background:var(--text-muted);
}

/* Mantener el último elemento con aire */

.crm-timeline-item:last-child{
    margin-bottom:4px;
}

/* ===========================
   Scroll interno en tablas de ficha cliente
=========================== */

.table-scroll-y {
    height: 240px;
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-scroll-y .table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

/* Scrollbar consistente */
.table-scroll-y::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-scroll-y::-webkit-scrollbar-track {
    background: transparent;
}

.table-scroll-y::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 999px;
}

.table-scroll-y::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

@media (max-width: 760px) {
    .table-scroll-y {
        height: 180px;
    }
}

.admin-users-table th:last-child,
.admin-users-table td:last-child{
    width:120px;
    text-align:right;
}

/* =========================
   Dashboard scroll utilities
========================= */

.dashboard-card-sm,
.dashboard-card-md,
.dashboard-card-lg {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.dashboard-card-sm .card-body,
.dashboard-card-md .card-body,
.dashboard-card-lg .card-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.table-scroll-sm {
    height: 160px;
    overflow: auto;
}

.table-scroll-md {
    height: 360px;
    overflow: auto;
}

.table-scroll-lg {
    height: 520px;
    overflow: auto;
}

.table-scroll-sm .table thead th,
.table-scroll-md .table thead th,
.table-scroll-lg .table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

/* List scrolls */

.commercial-list-scroll-sm {
    height: 160px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 6px;
}

.commercial-list-scroll-md {
    height: 360px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 6px;
}

/* Consistent scrollbar */

.table-scroll-sm::-webkit-scrollbar,
.table-scroll-md::-webkit-scrollbar,
.table-scroll-lg::-webkit-scrollbar,
.commercial-list-scroll-sm::-webkit-scrollbar,
.commercial-list-scroll-md::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-scroll-sm::-webkit-scrollbar-track,
.table-scroll-md::-webkit-scrollbar-track,
.table-scroll-lg::-webkit-scrollbar-track,
.commercial-list-scroll-sm::-webkit-scrollbar-track,
.commercial-list-scroll-md::-webkit-scrollbar-track {
    background: transparent;
}

.table-scroll-sm::-webkit-scrollbar-thumb,
.table-scroll-md::-webkit-scrollbar-thumb,
.table-scroll-lg::-webkit-scrollbar-thumb,
.commercial-list-scroll-sm::-webkit-scrollbar-thumb,
.commercial-list-scroll-md::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 999px;
}

.table-scroll-sm::-webkit-scrollbar-thumb:hover,
.table-scroll-md::-webkit-scrollbar-thumb:hover,
.table-scroll-lg::-webkit-scrollbar-thumb:hover,
.commercial-list-scroll-sm::-webkit-scrollbar-thumb:hover,
.commercial-list-scroll-md::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

@media (max-width: 760px) {
    .table-scroll-sm,
    .commercial-list-scroll-sm {
        height: 300px;
    }

    .table-scroll-md,
    .commercial-list-scroll-md {
        height: 340px;
    }
}

.form-select{
    appearance:none;
    -webkit-appearance:none;
    -moz-appearance:none;

    width:100%;
    height:46px;

    padding:0 42px 0 16px;

    border:1px solid var(--border-color);
    border-radius:12px;

    background:
        var(--surface-1)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
        no-repeat right 14px center;

    font-size:15px;
    transition:.2s;
}

.form-select:hover{
    border-color:var(--color-primary);
}

.form-select:focus{
    outline:none;
    border-color:var(--color-primary);
    box-shadow:0 0 0 4px rgba(0,255,48,.08);
}

.metric-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
}

.metric-row span,
.metric-row strong,
.metric-value {
    min-width: 0;
}

.metric-value {
    max-width: 100%;
    text-align: right;
    overflow-wrap: anywhere;
    word-break: normal;
}

.metric-value {
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 650;
    line-height: 1.35;
    text-align: right;
    color: var(--text-primary);
    white-space: normal;
    overflow-wrap: anywhere;
}

.payment-badge {
    font-size: 0.75rem;
}

.payment-no_facturado {
    color: var(--text-muted);
}

.payment-por_cobrar {
    color: var(--color-warning);
}

.payment-pagado {
    color: var(--color-success);
}

.payment-atrasado,
.payment-incobrable {
    color: var(--color-error);
}

.sidebar-submenu {
    margin: 4px 0 8px 36px;
    padding-left: 12px;
    border-left: 2px solid var(--color-primary);
    display: grid;
    gap: 2px;
}

.sidebar-sublink {
    min-height: 32px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.92rem;
    text-decoration: none;
}

.sidebar-sublink:hover,
.sidebar-sublink.active {
    color: var(--color-primary);
    background: var(--surface-2);
    font-weight: 600;
}

/* =========================
   Form System
========================= */

.form-grid {
    display: grid;
    gap: var(--space-4);
    align-items: start;
}

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

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

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

.form-grid-client {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
}

.form-field {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.form-field-wide {
    grid-column: span 3;
}

.form-field-full {
    grid-column: 1 / -1;
}

/* Unified controls */
.form-control,
.input,
.select,
.textarea,
.form-field input:not([type="hidden"]),
.form-field select,
.form-field textarea {
    width: 100%;
    min-height: 46px;
    padding: 0 14px;

    border: 1px solid var(--border-default);
    border-radius: 14px;

    background-color: var(--surface-1);
    color: var(--text-primary);

    font-size: 0.94rem;
    font-family: inherit;
    line-height: 1.3;

    transition:
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        background-color 0.18s ease;
}

.form-control:hover,
.input:hover,
.select:hover,
.textarea:hover,
.form-field input:not([type="hidden"]):hover,
.form-field select:hover,
.form-field textarea:hover {
    border-color: var(--color-primary);
}

.form-control:focus,
.input:focus,
.select:focus,
.textarea:focus,
.form-field input:not([type="hidden"]):focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(0, 255, 48, 0.08);
}

/* Select */
.select,
.form-field select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;

    cursor: pointer;
    padding-right: 44px;

    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

/* Textarea */
.textarea,
.form-field textarea {
    min-height: 96px;
    padding: 14px;
    resize: vertical;
}

/* File input */
.form-field input[type="file"],
.file-input {
    padding-top: 11px;
}

/* Inline controls */
.form-inline-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-3);
    align-items: center;
}

.form-inline-control .btn {
    min-height: 46px;
    border-radius: 14px;
    white-space: nowrap;
}

/* Actions */
.form-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-5);
}

.form-actions .btn {
    min-height: 46px;
    border-radius: 14px;
}

/* Placeholder */
::placeholder {
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1180px) {
    .form-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .form-field-wide {
        grid-column: span 2;
    }
}

@media (max-width: 760px) {
    .form-grid-2,
    .form-grid-3,
    .form-grid-4,
    .form-grid-client {
        grid-template-columns: 1fr;
    }

    .form-field-wide {
        grid-column: span 1;
    }

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

    .form-inline-control .btn,
    .form-actions .btn {
        width: 100%;
    }

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

/* =========================
   Custom Select
========================= */

.custom-select {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    width: 100%;
    min-height: 46px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    padding: 0 14px;

    border: 1px solid var(--border-default);
    border-radius: 14px;

    background: var(--surface-1);
    color: var(--text-primary);

    font-size: 0.94rem;
    font-family: inherit;
    text-align: left;

    cursor: pointer;
}

.custom-select-trigger:hover,
.custom-select.is-open .custom-select-trigger {
    border-color: var(--color-primary);
}

.custom-select.is-open .custom-select-trigger {
    box-shadow: 0 0 0 4px rgba(0, 255, 48, 0.08);
}

.custom-select-trigger svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    transition: transform 0.18s ease;
}

.custom-select.is-open .custom-select-trigger svg {
    transform: rotate(180deg);
}

.custom-select-menu {
    position: absolute;
    z-index: 100;
    top: calc(100% + 8px);
    left: 0;
    right: 0;

    display: none;

    max-height: 260px;
    overflow-y: auto;

    padding: 6px;

    border: 1px solid var(--border-default);
    border-radius: 16px;

    background: var(--surface-1);
    box-shadow: var(--shadow-lg);
}

.custom-select.is-open .custom-select-menu {
    display: grid;
    gap: 4px;
}

.custom-select-option {
    width: 100%;

    padding: 11px 12px;

    border: 0;
    border-radius: 12px;

    background: transparent;
    color: var(--text-primary);

    font-size: 0.9rem;
    font-family: inherit;
    text-align: left;

    cursor: pointer;
}

.custom-select-option:hover {
    background: var(--surface-2);
}

.custom-select-option.is-selected {
    color: var(--color-primary);
    background: rgba(0, 255, 48, 0.08);
    font-weight: 700;
}

.btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary:disabled {
    background: var(--surface-3);
    color: var(--text-muted);
    border-color: var(--border-default);
}

.alert {
    padding: 16px 18px;
    margin-bottom: 24px;
    border-radius: 16px;
    border: 1px solid;
}

.alert strong {
    display: block;
    margin-bottom: 10px;
}

.alert ul {
    margin: 0;
    padding-left: 18px;
}

.alert-error {
    color: #ffb3b3;
    background: rgba(255, 60, 60, .08);
    border-color: rgba(255, 60, 60, .30);
}

/* =========================
   Field Validation
========================= */

.form-field.has-error .input,
.form-field.has-error .select,
.form-field.has-error .textarea,
.form-field.has-error .form-control,
.form-field.has-error input:not([type="hidden"]),
.form-field.has-error select,
.form-field.has-error textarea,
.form-field.has-error .custom-select-trigger {
    border-color: var(--color-error);
    box-shadow: 0 0 0 4px rgba(255, 60, 60, 0.08);
}

.field-error {
    color: var(--color-error);
    font-size: 0.78rem;
    line-height: 1.35;
}

.form-field.is-required .label::after {
    content: " *";
    color: var(--color-error);
}

/* ==========================================================================
   MODALES (Popups Generales)
   ========================================================================== */

.product-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal, 1050);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.product-modal-backdrop.show {
    opacity: 1;
}

.product-modal-box {
    background: var(--surface-1);
    width: 860px;
    max-width: min(95vw, calc(100vw - 48px));
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.2s ease;
}

.product-modal-backdrop.show .product-modal-box {
    transform: translateY(0);
}

.product-modal-header {
    padding: var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-shrink: 0;
}

.product-modal-body {
    padding: var(--space-5);
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.product-modal-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-0);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    width: 100%;
    flex-shrink: 0;
}

.modal-footer-actions-right {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: flex-end;
    flex: 1;
}

.btn-delete-mobile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 760px) {
    .product-modal-footer {
        flex-direction: row !important;
        justify-content: space-between !important;
        gap: 8px !important;
        padding: var(--space-3) var(--space-4) !important;
    }

    .btn-delete-mobile {
        padding: 0 !important;
        width: 42px !important;
        height: 42px !important;
    }

    .modal-footer-actions-right {
        gap: 8px !important;
    }

    .modal-footer-actions-right .btn {
        padding: 0 var(--space-3) !important;
        height: 42px !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
    }
}

/* P0.1b SPA modal stability: reglas base para modales reinyectados por SPA */
.product-modal-backdrop.show {
    display: flex;
}

.product-modal-box > form,
.product-modal-box .quote-view-layer,
.product-modal-box .opp-view-layer {
    min-height: 0;
}

@media (max-width: 760px) {
    .product-modal-backdrop {
        align-items: stretch;
        padding: 8px;
    }

    .product-modal-box {
        width: 100%;
        max-width: 100%;
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
    }
}

/* P4.2 - Customer location autocomplete */
.location-autocomplete-wrap {
    position: relative;
}
.location-suggest-menu {
    position: absolute;
    z-index: calc(var(--z-modal, 1050) + 20);
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    display: none;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-1);
    box-shadow: var(--shadow-lg);
    padding: 6px;
}
.location-suggest-menu.is-open {
    display: block;
}
.location-suggest-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.location-suggest-item:hover {
    background: var(--surface-2);
}
.location-suggest-item span {
    color: var(--text-secondary);
    font-size: 0.78rem;
}
.location-suggest-item.is-muted {
    cursor: default;
    color: var(--text-secondary);
}
.customer-map-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.82rem;
}

/* =========================
   Customer quick forms P4.5
========================= */
.customer-quick-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--space-4);
    align-items: start;
}

.customer-quick-grid .span-2 { grid-column: span 2; }
.customer-quick-grid .span-3 { grid-column: span 3; }
.customer-quick-grid .span-4 { grid-column: span 4; }
.customer-quick-grid .span-5 { grid-column: span 5; }
.customer-quick-grid .span-6 { grid-column: span 6; }
.customer-quick-grid .span-7 { grid-column: span 7; }
.customer-quick-grid .span-8 { grid-column: span 8; }
.customer-quick-grid .span-9 { grid-column: span 9; }
.customer-quick-grid .span-12 { grid-column: 1 / -1; }

.customer-phone-field {
    min-width: 280px;
}

.customer-phone-control {
    display: grid;
    grid-template-columns: 104px minmax(160px, 1fr);
    gap: 10px;
    align-items: stretch;
}

.customer-phone-control .input,
.customer-phone-control .select {
    width: 100%;
    min-width: 0;
}

.customer-phone-prefix {
    min-width: 0;
    padding-left: 8px !important;
    padding-right: 6px !important;
    appearance: auto;
}

.customer-location-note {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.35;
}

@media (max-width: 1180px) {
    .customer-quick-grid .span-2,
    .customer-quick-grid .span-3,
    .customer-quick-grid .span-4,
    .customer-quick-grid .span-5,
    .customer-quick-grid .span-6,
    .customer-quick-grid .span-7,
    .customer-quick-grid .span-8,
    .customer-quick-grid .span-9 {
        grid-column: span 6;
    }
}

@media (max-width: 760px) {
    .customer-quick-grid {
        grid-template-columns: 1fr;
    }

    .customer-phone-field {
        min-width: 0;
    }

    .customer-phone-control {
        grid-template-columns: minmax(92px, 0.36fr) minmax(0, 1fr);
    }

    .customer-quick-grid .span-2,
    .customer-quick-grid .span-3,
    .customer-quick-grid .span-4,
    .customer-quick-grid .span-5,
    .customer-quick-grid .span-6,
    .customer-quick-grid .span-7,
    .customer-quick-grid .span-8,
    .customer-quick-grid .span-9,
    .customer-quick-grid .span-12 {
        grid-column: 1 / -1;
    }
}

/* =========================================================
   P7.2 - Territory mobile UX and table correction
   ========================================================= */

#customers-territory-main .territory-country-code {
    display: none;
}

#customers-territory-main .territory-country-full {
    display: inline;
}

#customers-territory-main .territory-mobile-nav {
    display: none;
}

#customers-territory-main .territory-table-card {
    overflow: hidden;
}

#customers-territory-main .territory-table-scroll {
    max-height: 560px;
    overflow: auto;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

#customers-territory-main .territory-table {
    width: 100%;
    min-width: 1080px;
    table-layout: fixed;
}

#customers-territory-main .territory-table th,
#customers-territory-main .territory-table td {
    vertical-align: middle;
}

#customers-territory-main .territory-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    white-space: nowrap;
    background: var(--surface-2);
    box-shadow: 0 1px 0 var(--border-subtle);
}

#customers-territory-main .territory-col-client { width: 30%; }
#customers-territory-main .territory-col-country { width: 9%; }
#customers-territory-main .territory-col-region { width: 15%; }
#customers-territory-main .territory-col-city { width: 20%; }
#customers-territory-main .territory-col-geo { width: 12%; }
#customers-territory-main .territory-col-opportunities { width: 6%; }
#customers-territory-main .territory-col-action { width: 8%; }

#customers-territory-main .territory-customer-link {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
    color: inherit;
    text-decoration: none;
}

#customers-territory-main .territory-customer-link strong,
#customers-territory-main .territory-customer-link small,
#customers-territory-main .territory-cell-country,
#customers-territory-main .territory-cell-region,
#customers-territory-main .territory-cell-city {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#customers-territory-main .territory-customer-link strong {
    color: var(--text-primary);
    font-size: 0.92rem;
    font-weight: 800;
    line-height: 1.25;
}

#customers-territory-main .territory-customer-link small {
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.25;
}

#customers-territory-main .territory-cell-geo {
    white-space: nowrap;
}

#customers-territory-main .territory-geo-badge {
    max-width: 100%;
    justify-content: center;
    white-space: nowrap;
    font-size: 0.72rem;
    padding: 6px 10px;
}

#customers-territory-main .territory-cell-opportunities {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#customers-territory-main .territory-row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    white-space: nowrap;
}

#customers-territory-main .territory-icon-btn {
    width: 38px;
    min-width: 38px;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#customers-territory-main .territory-icon-btn svg {
    width: 18px;
    height: 18px;
}

#customers-territory-main .territory-action-label {
    display: none;
}

#customers-territory-main .territory-mobile-summary {
    display: none;
}

#customers-territory-main .territory-metric-list {
    display: grid;
    gap: 8px;
}

@media (max-width: 1180px) {
    #customers-territory-main .territory-table {
        min-width: 1040px;
    }
}

@media (max-width: 760px) {
    #customers-territory-main .content {
        padding-bottom: 88px;
    }

    #customers-territory-main .page-header {
        gap: 14px;
        margin-bottom: 12px;
    }

    #customers-territory-main .page-header-content p {
        display: none;
    }

    #customers-territory-main .territory-kpi-grid {
        display: none !important;
    }

    #customers-territory-main .territory-mobile-nav {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        gap: 8px;
        overflow-x: auto;
        margin: 0 calc(var(--space-4) * -1) 12px;
        padding: 8px var(--space-4) 10px;
        background: color-mix(in srgb, var(--surface-0) 92%, transparent);
        border-bottom: 1px solid var(--border-subtle);
        backdrop-filter: blur(14px);
        scrollbar-width: none;
    }

    #customers-territory-main .territory-mobile-nav::-webkit-scrollbar {
        display: none;
    }

    #customers-territory-main .territory-mobile-nav a {
        flex: 0 0 auto;
        min-height: 36px;
        padding: 0 14px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--border-default);
        border-radius: 999px;
        color: var(--text-primary);
        background: var(--surface-1);
        font-size: 0.82rem;
        font-weight: 750;
        text-decoration: none;
    }

    #customers-territory-main .territory-filters-card .card-body {
        padding: 14px;
    }

    #customers-territory-main .territory-filters {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    #customers-territory-main .territory-filters .btn,
    #customers-territory-main .territory-filters .select,
    #customers-territory-main .territory-filters .input {
        width: 100%;
        min-height: 42px;
    }

    #customers-territory-main .territory-main-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 14px;
    }

    #customers-territory-main .territory-map-card .card-header,
    #customers-territory-main .territory-breakdown-card .card-header,
    #customers-territory-main .territory-table-card .card-header {
        padding: 16px;
    }

    #customers-territory-main .territory-map-card .card-body,
    #customers-territory-main .territory-breakdown-card .card-body {
        padding: 14px;
    }

    #customers-territory-main .territory-map-canvas,
    #customers-territory-main .territory-map-placeholder {
        min-height: 280px;
    }

    #customers-territory-main .territory-map-placeholder {
        padding: 20px;
    }

    #customers-territory-main .territory-map-placeholder i {
        width: 32px;
        height: 32px;
    }

    #customers-territory-main .territory-breakdown-header {
        align-items: center;
    }

    #customers-territory-main .territory-mobile-summary {
        display: inline-flex;
        white-space: nowrap;
    }

    #customers-territory-main .territory-breakdown-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 14px;
    }

    #customers-territory-main .territory-subtitle {
        margin-bottom: 8px;
        font-size: 0.84rem;
    }

    #customers-territory-main .territory-metric-list {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 2px;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
    }

    #customers-territory-main .territory-metric-list::-webkit-scrollbar {
        display: none;
    }

    #customers-territory-main .territory-metric-card {
        flex: 0 0 164px;
        min-height: 56px;
        padding: 10px 12px;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 10px;
        border: 1px solid var(--border-default);
        border-radius: 16px;
        background: var(--surface-2);
        scroll-snap-align: start;
    }

    #customers-territory-main .territory-metric-card span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.82rem;
    }

    #customers-territory-main .territory-metric-card .metric-value {
        font-size: 0.95rem;
    }

    #customers-territory-main .territory-table-scroll {
        max-height: none;
        overflow: visible;
        border: 0;
        background: transparent;
    }

    #customers-territory-main .territory-table,
    #customers-territory-main .territory-table thead,
    #customers-territory-main .territory-table tbody,
    #customers-territory-main .territory-table th,
    #customers-territory-main .territory-table td,
    #customers-territory-main .territory-table tr {
        display: block;
        width: 100%;
        min-width: 0;
    }

    #customers-territory-main .territory-table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    #customers-territory-main .territory-table thead,
    #customers-territory-main .territory-table colgroup {
        display: none;
    }

    #customers-territory-main .territory-table tbody {
        display: grid;
        gap: 12px;
        padding: 0 14px 14px;
    }

    #customers-territory-main .territory-table tbody tr {
        display: grid;
        gap: 10px;
        padding: 14px;
        border: 1px solid var(--border-default);
        border-radius: 18px;
        background: var(--surface-1);
        box-shadow: var(--shadow-sm);
    }

    #customers-territory-main .territory-table tbody td {
        padding: 0;
        border: 0;
        max-width: none;
        overflow: visible;
        color: var(--text-secondary);
    }

    #customers-territory-main .territory-table tbody td:not(.territory-cell-client):not(.territory-cell-action) {
        display: grid;
        grid-template-columns: 116px minmax(0, 1fr);
        gap: 10px;
        align-items: center;
    }

    #customers-territory-main .territory-table tbody td:not(.territory-cell-client):not(.territory-cell-action)::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.68rem;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    #customers-territory-main .territory-cell-client {
        padding-bottom: 4px !important;
    }

    #customers-territory-main .territory-customer-link strong {
        white-space: normal;
        overflow: visible;
        font-size: 0.96rem;
    }

    #customers-territory-main .territory-customer-link small {
        white-space: nowrap;
    }

    #customers-territory-main .territory-cell-country,
    #customers-territory-main .territory-cell-region,
    #customers-territory-main .territory-cell-city {
        white-space: nowrap;
    }

    #customers-territory-main .territory-cell-opportunities {
        text-align: left !important;
    }

    #customers-territory-main .territory-row-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin-top: 4px;
    }

    #customers-territory-main .territory-icon-btn {
        width: 100%;
        min-width: 0;
        height: 40px;
        gap: 6px;
        border-radius: 999px;
        font-size: 0.82rem;
        font-weight: 750;
    }

    #customers-territory-main .territory-action-label {
        display: inline;
    }
}

/* =========================================================
   P7.2.1 - Territory mobile refinement
   - Removes internal mobile nav
   - Keeps customer list inside fixed-height scroll card
   - Converts segmentation to compact wrapping tags
   - Uses compact two-column filter layout on mobile
   ========================================================= */

#customers-territory-main .territory-mobile-nav {
    display: none !important;
}

#customers-territory-main .territory-mobile-location {
    display: none !important;
}

@media (max-width: 760px) {
    #customers-territory-main .content {
        padding-bottom: 16px;
    }

    #customers-territory-main .territory-kpi-grid {
        display: none !important;
    }

    #customers-territory-main .territory-filters-card {
        margin-bottom: 12px !important;
    }

    #customers-territory-main .territory-filters-card .card-body {
        padding: 12px;
    }

    #customers-territory-main .territory-filters {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px !important;
        align-items: stretch;
    }

    #customers-territory-main .territory-filters > * {
        min-width: 0;
    }

    #customers-territory-main .territory-filter-search {
        grid-column: 1 / -1;
    }

    #customers-territory-main .territory-filters .input,
    #customers-territory-main .territory-filters .select,
    #customers-territory-main .territory-filters .btn {
        width: 100%;
        min-height: 42px;
    }

    #customers-territory-main .territory-filters .select {
        padding-left: 11px;
        padding-right: 30px;
        font-size: 0.78rem;
    }

    #customers-territory-main .territory-filters.no-clear .territory-filter-submit {
        grid-column: 1 / -1;
    }

    #customers-territory-main .territory-filters.has-clear .territory-filter-submit,
    #customers-territory-main .territory-filters.has-clear .territory-filter-clear {
        grid-column: auto;
    }

    #customers-territory-main .territory-main-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    #customers-territory-main .territory-map-card .card-header,
    #customers-territory-main .territory-breakdown-card .card-header,
    #customers-territory-main .territory-table-card .card-header {
        padding: 14px;
    }

    #customers-territory-main .territory-map-card .card-body,
    #customers-territory-main .territory-breakdown-card .card-body {
        padding: 12px;
    }

    #customers-territory-main .territory-map-canvas,
    #customers-territory-main .territory-map-placeholder {
        min-height: 480px;
    }

    #customers-territory-main .territory-breakdown-header {
        align-items: center;
        gap: 10px;
    }

    #customers-territory-main .territory-mobile-summary {
        display: inline-flex;
        flex: 0 0 auto;
        white-space: nowrap;
        font-size: 0.72rem;
    }

    #customers-territory-main .territory-breakdown-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    #customers-territory-main .territory-breakdown-block {
        min-width: 0;
    }

    #customers-territory-main .territory-subtitle {
        margin: 0 0 7px;
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--text-muted);
    }

    #customers-territory-main .territory-metric-list {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        overflow: visible !important;
        padding: 0 !important;
        scroll-snap-type: none !important;
    }

    #customers-territory-main .territory-metric-list::-webkit-scrollbar {
        display: none;
    }

    #customers-territory-main .territory-metric-card {
        flex: 0 1 auto !important;
        min-height: 0 !important;
        max-width: 100%;
        padding: 5px 8px !important;
        display: inline-grid !important;
        grid-template-columns: minmax(0, auto) auto !important;
        align-items: center;
        gap: 6px !important;
        border: 1px solid var(--border-default);
        border-radius: 999px !important;
        background: var(--surface-2);
        scroll-snap-align: none !important;
    }

    #customers-territory-main .territory-metric-card span {
        max-width: 152px;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.72rem !important;
        line-height: 1.1;
    }

    #customers-territory-main .territory-metric-card .metric-value {
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        background: var(--surface-1);
        font-size: 0.72rem !important;
        font-variant-numeric: tabular-nums;
    }

    #customers-territory-main .territory-table-card {
        height: clamp(430px, 58dvh, 600px);
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        margin-top: 12px !important;
    }

    #customers-territory-main .territory-table-card .card-header {
        flex: 0 0 auto;
        border-bottom: 1px solid var(--border-subtle);
    }

    #customers-territory-main .territory-table-scroll {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        border: 0 !important;
        border-radius: 0 0 var(--radius-xl) var(--radius-xl) !important;
        background: var(--surface-1);
    }

    #customers-territory-main .territory-table,
    #customers-territory-main .territory-table thead,
    #customers-territory-main .territory-table tbody,
    #customers-territory-main .territory-table tr {
        width: 100% !important;
    }

    #customers-territory-main .territory-table {
        display: table !important;
        min-width: 0 !important;
        table-layout: fixed !important;
        border-collapse: collapse !important;
    }

    #customers-territory-main .territory-table colgroup {
        display: none !important;
    }

    #customers-territory-main .territory-table thead {
        display: table-header-group !important;
    }

    #customers-territory-main .territory-table tbody {
        display: table-row-group !important;
        padding: 0 !important;
    }

    #customers-territory-main .territory-table tr {
        display: table-row !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    #customers-territory-main .territory-table th,
    #customers-territory-main .territory-table td {
        display: table-cell !important;
        padding: 10px 10px !important;
        border-bottom: 1px solid var(--border-subtle) !important;
        vertical-align: middle !important;
        overflow: hidden !important;
    }

    #customers-territory-main .territory-table thead th {
        position: sticky;
        top: 0;
        z-index: 4;
        background: var(--surface-2);
        font-size: 0.66rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    #customers-territory-main .territory-head-region,
    #customers-territory-main .territory-head-city,
    #customers-territory-main .territory-head-geo,
    #customers-territory-main .territory-head-opportunities,
    #customers-territory-main .territory-cell-region,
    #customers-territory-main .territory-cell-city,
    #customers-territory-main .territory-cell-geo,
    #customers-territory-main .territory-cell-opportunities {
        display: none !important;
    }

    #customers-territory-main .territory-head-client,
    #customers-territory-main .territory-cell-client {
        width: 62% !important;
    }

    #customers-territory-main .territory-head-country,
    #customers-territory-main .territory-cell-country {
        width: 14% !important;
        text-align: center;
    }

    #customers-territory-main .territory-head-action,
    #customers-territory-main .territory-cell-action {
        width: 24% !important;
        text-align: right;
    }

    #customers-territory-main .territory-country-full {
        display: none !important;
    }

    #customers-territory-main .territory-country-code {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        min-width: 42px;
        height: 28px;
        padding: 0 8px;
        border: 1px solid var(--border-subtle);
        border-radius: 999px;
        background: var(--surface-1);
        color: var(--text-primary);
        font-size: 0.68rem;
        font-weight: 800;
        letter-spacing: 0.04em;
        line-height: 1;
    }

    #customers-territory-main .territory-table tbody td::before {
        content: none !important;
    }

    #customers-territory-main .territory-customer-link {
        gap: 2px;
    }

    #customers-territory-main .territory-customer-link strong {
        max-width: 100%;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        font-size: 0.88rem;
        line-height: 1.18;
    }

    #customers-territory-main .territory-customer-link small {
        max-width: 100%;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        font-size: 0.68rem;
        line-height: 1.15;
    }

    #customers-territory-main .territory-customer-link small:not(.territory-mobile-location) {
        color: var(--text-secondary);
    }

    #customers-territory-main .territory-mobile-location {
        display: block !important;
        color: var(--text-muted) !important;
    }

    #customers-territory-main .territory-geo-badge {
        max-width: 100%;
        padding: 4px 7px !important;
        font-size: 0.62rem !important;
        line-height: 1.1;
        white-space: nowrap;
    }

    #customers-territory-main .territory-row-actions {
        display: inline-flex !important;
        align-items: center;
        justify-content: flex-end;
        gap: 4px !important;
        margin-top: 0 !important;
        white-space: nowrap;
    }

    #customers-territory-main .territory-icon-btn {
        width: 32px !important;
        min-width: 32px !important;
        height: 32px !important;
        padding: 0 !important;
        border-radius: 11px !important;
    }

    #customers-territory-main .territory-icon-btn svg {
        width: 15px !important;
        height: 15px !important;
    }

    #customers-territory-main .territory-action-label {
        display: none !important;
    }
}

@media (max-width: 390px) {
    #customers-territory-main .territory-table-card {
        height: clamp(400px, 56dvh, 540px);
    }

    #customers-territory-main .territory-head-client,
    #customers-territory-main .territory-cell-client {
        width: 58% !important;
    }

    #customers-territory-main .territory-head-country,
    #customers-territory-main .territory-cell-country {
        width: 16% !important;
    }

    #customers-territory-main .territory-head-action,
    #customers-territory-main .territory-cell-action {
        width: 26% !important;
    }

    #customers-territory-main .territory-country-code {
        min-width: 38px;
        padding-left: 7px;
        padding-right: 7px;
        font-size: 0.64rem;
    }

    #customers-territory-main .territory-table th,
    #customers-territory-main .territory-table td {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }
}

/* =========================================================
   P7.2.3 - Territory mobile columns hard fix
   Mobile visible columns: Cliente | País | Acción
   ========================================================= */

#customers-territory-main .territory-country-code {
    display: none;
}

#customers-territory-main .territory-country-full {
    display: inline;
}

@media (max-width: 768px) {
    #customers-territory-main .territory-table-scroll {
        height: clamp(430px, 58dvh, 600px) !important;
        max-height: clamp(430px, 58dvh, 600px) !important;
        overflow: auto !important;
    }

    #customers-territory-main .territory-table {
        width: 100% !important;
        min-width: 0 !important;
        table-layout: fixed !important;
    }

    /*
       Oculta columnas móviles:
       3 Región
       4 Ciudad / Comuna
       5 Geo
       6 Ops.
    */
    #customers-territory-main .territory-table col:nth-child(3),
    #customers-territory-main .territory-table col:nth-child(4),
    #customers-territory-main .territory-table col:nth-child(5),
    #customers-territory-main .territory-table col:nth-child(6) {
        display: none !important;
        visibility: collapse !important;
        width: 0 !important;
    }

    #customers-territory-main .territory-table thead th:nth-child(3),
    #customers-territory-main .territory-table thead th:nth-child(4),
    #customers-territory-main .territory-table thead th:nth-child(5),
    #customers-territory-main .territory-table thead th:nth-child(6),
    #customers-territory-main .territory-table tbody td:nth-child(3),
    #customers-territory-main .territory-table tbody td:nth-child(4),
    #customers-territory-main .territory-table tbody td:nth-child(5),
    #customers-territory-main .territory-table tbody td:nth-child(6) {
        display: none !important;
        width: 0 !important;
        max-width: 0 !important;
        min-width: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        overflow: hidden !important;
        visibility: collapse !important;
    }

    /*
       Columnas visibles:
       1 Cliente
       2 País
       7 Acción
    */
    #customers-territory-main .territory-table col:nth-child(1) {
        width: auto !important;
    }

    #customers-territory-main .territory-table col:nth-child(2) {
        width: 58px !important;
    }

    #customers-territory-main .territory-table col:nth-child(7) {
        width: 86px !important;
    }

    #customers-territory-main .territory-table thead th:nth-child(1),
    #customers-territory-main .territory-table tbody td:nth-child(1) {
        width: auto !important;
        min-width: 0 !important;
    }

    #customers-territory-main .territory-table thead th:nth-child(2),
    #customers-territory-main .territory-table tbody td:nth-child(2) {
        width: 58px !important;
        max-width: 58px !important;
        text-align: center !important;
        padding-left: 6px !important;
        padding-right: 6px !important;
    }

    #customers-territory-main .territory-table thead th:nth-child(7),
    #customers-territory-main .territory-table tbody td:nth-child(7) {
        width: 86px !important;
        max-width: 86px !important;
        padding-left: 4px !important;
        padding-right: 8px !important;
    }

    #customers-territory-main .territory-table th,
    #customers-territory-main .territory-table td {
        height: 58px !important;
        vertical-align: middle !important;
    }

    #customers-territory-main .territory-cell-client,
    #customers-territory-main .territory-customer-link,
    #customers-territory-main .territory-customer-link strong,
    #customers-territory-main .territory-customer-link small {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    #customers-territory-main .territory-customer-link strong,
    #customers-territory-main .territory-customer-link small {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    #customers-territory-main .territory-country-full {
        display: none !important;
    }

    #customers-territory-main .territory-country-code {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 42px !important;
        height: 28px !important;
        padding: 0 7px !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 999px !important;
        background: var(--surface-muted) !important;
        color: var(--text-primary) !important;
        font-size: 0.7rem !important;
        font-weight: 800 !important;
        letter-spacing: 0.04em !important;
        line-height: 1 !important;
    }

    #customers-territory-main .territory-row-actions {
        display: flex !important;
        justify-content: flex-end !important;
        align-items: center !important;
        gap: 4px !important;
        white-space: nowrap !important;
    }

    #customers-territory-main .territory-icon-btn {
        width: 34px !important;
        height: 34px !important;
        min-width: 34px !important;
        padding: 0 !important;
        border-radius: 12px !important;
    }

    #customers-territory-main .territory-icon-btn svg {
        width: 17px !important;
        height: 17px !important;
    }
}

/* =========================================================
   P7.2.4 - Territory back button alignment
   ========================================================= */

#customers-territory-main .territory-page-header {
    position: relative;
}

#customers-territory-main .territory-header-actions {
    margin-left: auto;
    align-self: flex-start;
}

#customers-territory-main .territory-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

#customers-territory-main .territory-back-btn svg {
    width: 18px;
    height: 18px;
}

@media (max-width: 768px) {
    #customers-territory-main .territory-page-header {
        position: relative;
        display: block;
        padding-right: 52px;
        margin-bottom: 16px;
    }

    #customers-territory-main .territory-page-header .page-header-content {
        min-width: 0;
    }

    #customers-territory-main .territory-page-header h1 {
        padding-right: 4px;
    }

    #customers-territory-main .territory-header-actions {
        position: absolute;
        top: 0;
        right: 0;
        margin: 0;
        z-index: 3;
    }

    #customers-territory-main .territory-back-btn {
        width: 42px;
        height: 42px;
        min-width: 42px;
        padding: 0;
        border-radius: 14px;
    }

    #customers-territory-main .territory-back-label {
        display: none !important;
    }

    #customers-territory-main .territory-back-btn svg {
        width: 20px;
        height: 20px;
    }
}
/* =========================================================
   P8 - Mobile UX commercial stabilization
   ========================================================= */

/* Territory: filters by commercial profile, compact chips and map touch isolation */
#customers-territory-main .territory-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow: visible;
}

#customers-territory-main .territory-chip-card {
    width: auto;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

#customers-territory-main .territory-chip-card span {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

#customers-territory-main .territory-map-card,
#customers-territory-main .territory-map-canvas {
    position: relative;
    z-index: 2;
}

#customers-territory-main .territory-map-canvas {
    touch-action: pan-x pan-y;
    overscroll-behavior: contain;
}

#customers-territory-main .territory-info-window small {
    display: block;
    margin-top: 3px;
    color: #536b8f;
}

@media (max-width: 768px) {
    #customers-territory-main .territory-filters {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
        gap: 8px !important;
    }

    #customers-territory-main .territory-filter-search {
        grid-column: 1 / -1 !important;
    }

    #customers-territory-main .territory-filters .form-field {
        min-width: 0 !important;
    }

    #customers-territory-main .territory-filters .select,
    #customers-territory-main .territory-filters .input,
    #customers-territory-main .territory-filters .btn {
        min-width: 0 !important;
        width: 100% !important;
        height: 42px !important;
        font-size: 0.78rem !important;
    }

    #customers-territory-main .territory-filters.no-clear .territory-filter-submit {
        grid-column: 1 / -1 !important;
    }

    #customers-territory-main .territory-filters.has-clear .territory-filter-submit,
    #customers-territory-main .territory-filters.has-clear .territory-filter-clear {
        grid-column: span 1 !important;
    }

    #customers-territory-main .territory-breakdown-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    #customers-territory-main .territory-chip-list {
        overflow: visible !important;
        max-width: 100% !important;
    }

    #customers-territory-main .territory-chip-card {
        flex: 0 1 auto !important;
        max-width: 100% !important;
        padding: 6px 9px !important;
        font-size: 0.74rem !important;
    }

    #customers-territory-main .territory-chip-card span {
        max-width: 150px !important;
    }
}

/* Customers index: mobile collapsible filters and more vertical room for list */
#customers-main .customer-filters-compact {
    display: grid;
    gap: 12px;
}

#customers-main .customer-filter-main-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: stretch;
}

#customers-main .customer-filter-search-field {
    min-width: 0;
}

#customers-main .customer-filter-toggle {
    white-space: nowrap;
}

#customers-main .customer-filter-toggle strong {
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--color-primary);
    color: #020202;
    font-size: 0.72rem;
    font-weight: 900;
}

#customers-main .customer-filter-panel {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto auto;
    gap: 10px;
    align-items: stretch;
}

#customers-main .customer-filter-panel .form-field {
    min-width: 0;
}

@media (min-width: 761px) {
    #customers-main .customer-filter-toggle {
        display: none !important;
    }
}

@media (max-width: 760px) {
    #customers-main .content {
        padding-top: 14px !important;
        padding-bottom: 12px !important;
    }

    #customers-main .page-header {
        margin-bottom: 12px !important;
    }

    #customers-main .page-header-content p {
        display: none !important;
    }

    #customers-main .customer-filter-card {
        margin-bottom: 10px !important;
    }

    #customers-main .customer-filter-card .card-body {
        padding: 10px !important;
    }

    #customers-main .customer-filter-main-row {
        grid-template-columns: minmax(0, 1fr) 44px !important;
        gap: 8px !important;
    }

    #customers-main .customer-filter-toggle {
        width: 44px !important;
        min-width: 44px !important;
        height: 42px !important;
        padding: 0 !important;
        justify-content: center !important;
    }

    #customers-main .customer-filter-toggle span,
    #customers-main .customer-filter-toggle strong {
        display: none !important;
    }

    #customers-main .customer-filter-panel {
        display: none !important;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
        gap: 8px !important;
        padding-top: 10px !important;
        border-top: 1px solid var(--border-subtle) !important;
    }

    #customers-main .customer-filters-compact.is-expanded .customer-filter-panel {
        display: grid !important;
    }

    #customers-main .customer-filter-panel .form-field,
    #customers-main .customer-filter-panel .customer-filter-apply,
    #customers-main .customer-filter-panel .customer-filter-clear {
        min-width: 0 !important;
        width: 100% !important;
    }

    #customers-main .customer-filter-panel .select,
    #customers-main .customer-filter-panel .btn,
    #customers-main .customer-filter-main-row .input {
        height: 40px !important;
        min-height: 40px !important;
        font-size: 0.78rem !important;
    }

    #customers-main .card-table-container {
        flex: 1 1 auto !important;
        min-height: 58dvh !important;
    }

    #customers-main .table-container-scroll {
        min-height: 0 !important;
        height: 100% !important;
    }
}

/* Quotes: make mobile search/date filters reliable and creation-date based */
#quotesMain #quoteSearch,
#quotesMain #quoteStatusFilter,
#quotesMain #quoteCreatedFrom,
#quotesMain #quoteCreatedTo {
    position: relative;
    z-index: 2;
    pointer-events: auto;
}

@media (max-width: 980px), (hover: none) and (pointer: coarse) {
    #quotesMain .quotes-filter-bar {
        position: relative !important;
        z-index: 5 !important;
    }

    #quotesMain #quoteSearch,
    #quotesMain #quoteStatusFilter {
        touch-action: manipulation !important;
    }

    #quotesMain .quote-filter-date-group input {
        touch-action: manipulation !important;
        -webkit-user-select: auto !important;
        user-select: auto !important;
    }
}
