/* ========================================
   RESET
======================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

/* ========================================
   DESIGN TOKENS
======================================== */
:root {
    --color-bg:           #F8F9FA;
    --color-bg-2:         #ECEEF2;
    --color-surface:      #FFFFFF;
    --color-surface-2:    #F0F2F6;
    --color-primary:      #0F2952;
    --color-primary-dark: #0A1E3D;
    --color-sky:          #1E73C3;
    --color-accent:       #F5C518;
    --color-green:        #16a34a;
    --color-red:          #dc2626;
    --color-text:         #1A1A2E;
    --color-text-muted:   #4A5568;
    --color-text-dim:     #718096;
    --color-border:       rgba(15, 41, 82, 0.1);
    --color-border-hover: rgba(15, 41, 82, 0.28);

    --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;

    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  16px;
    --radius-xl:  24px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
}

/* ========================================
   BASE
======================================== */
body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ========================================
   SCROLL ANIMATIONS
======================================== */
.aos {
    opacity: 0;
    transform: translateY(22px);
    transition: opacity 0.55s ease, transform 0.55s ease;
    transition-delay: var(--delay, 0s);
}

.aos.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   AUTH PAGES
======================================== */
.auth-container {
    max-width: 420px;
    margin: 5rem auto;
    background: var(--color-surface);
    padding: 2.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
}

.auth-container h1 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
}

.auth-container input {
    display: block;
    width: 100%;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.85rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    transition: border-color 0.2s;
    outline: none;
}

.auth-container input:focus {
    border-color: var(--color-primary);
}

.auth-container input::placeholder {
    color: var(--color-text-dim);
}

.auth-container button {
    width: 100%;
    padding: 0.75rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    transition: background 0.2s, transform 0.15s;
}

.auth-container button:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
}

.auth-container a {
    display: block;
    margin-top: 1.1rem;
    text-align: center;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    transition: color 0.2s;
}

.auth-container a:hover { color: var(--color-primary); }

.error-msg {
    color: var(--color-red);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* ========================================
   AUTH LAYOUT (nuevo diseño)
======================================== */
.auth-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
    background-image: radial-gradient(circle, rgba(15,41,82,0.12) 1px, transparent 1px);
    background-size: 22px 22px;
    padding: 7rem 1.5rem 3rem;
}

.auth-wrap {
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: var(--color-text);
}

.auth-brand__name {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.auth-card {
    width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2.25rem;
    box-shadow: var(--shadow-lg);
    animation: fadeUp 0.45s ease both;
}

.auth-card__header {
    margin-bottom: 1.75rem;
}

.auth-card__title {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--color-text);
}

.auth-card__subtitle {
    font-size: 0.88rem;
    color: var(--color-text-muted);
    margin-top: 0.35rem;
    line-height: 1.5;
}

.auth-submit {
    width: 100%;
    justify-content: center;
    margin-top: 0.5rem;
    padding: 0.7rem 1.25rem;
    font-size: 0.95rem;
    border: none;
    cursor: pointer;
}

.auth-footer-link {
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: 1.25rem;
}

.auth-footer-link a {
    color: var(--color-sky);
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.15s;
}

.auth-footer-link a:hover { opacity: 0.75; }

/* ========================================
   APP LAYOUT
======================================== */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ========================================
   APP NAVBAR (pill flotante, estilo landing)
======================================== */
.app-nav {
    position: fixed;
    top: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    width: calc(100% - 4rem);
    max-width: 1100px;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--color-border);
    border-radius: 100px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.07);
    transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

.app-nav.is-scrolled {
    background: rgba(255, 255, 255, 0.75);
    border-color: rgba(15, 41, 82, 0.18);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.1);
}

.app-nav__logo {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: var(--color-text);
}

.app-nav__logo-name {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.app-nav__links {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.app-nav__link {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: color 0.2s;
}

.app-nav__link:hover { color: var(--color-text); }

.app-nav__logout {
    display: inline-flex;
    align-items: center;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
}

.app-nav__logout:hover {
    color: var(--color-red);
    background: rgba(220, 38, 38, 0.06);
}

/* ========================================
   DASHBOARD BODY
======================================== */
.dashboard-body {
    flex: 1;
    background: var(--color-bg);
    background-image: radial-gradient(circle, rgba(15,41,82,0.12) 1px, transparent 1px);
    background-size: 22px 22px;
}

.dashboard-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 5.5rem 1.5rem 4rem;
    animation: fadeUp 0.6s ease both;
}

/* ========================================
   DASHBOARD HEADER
======================================== */
.dashboard-header {
    margin-bottom: 2rem;
    margin-top: 2rem;
}

.dashboard-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--color-text);
    line-height: 1.2;
}

.dashboard-subtitle {
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-top: 0.3rem;
}

/* ========================================
   STAT CARDS
======================================== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
    animation: fadeUp 0.45s ease both;
}

.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.12s; }
.stat-card:nth-child(3) { animation-delay: 0.19s; }

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-sky));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card__icon {
    width: 38px;
    height: 38px;
    background: rgba(15, 41, 82, 0.07);
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.35rem;
    flex-shrink: 0;
}

.stat-card__icon svg {
    width: 18px;
    height: 18px;
    color: var(--color-primary);
    stroke: currentColor;
    fill: none;
}

.stat-card__label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--color-text-dim);
}

.stat-card__value {
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.04em;
    color: var(--color-text);
    line-height: 1;
}

.stat-card__sub {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin-top: 0.1rem;
}

.stat-card__value-row {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.stat-card__badge {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    background: rgba(15, 41, 82, 0.06);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 0.12rem 0.5rem;
    white-space: nowrap;
}

.stat-card--warning::before { background: linear-gradient(90deg, #f59e0b, #fcd34d); }
.stat-card--warning .stat-card__value { color: #92400e; }
.stat-card--warning .stat-card__icon { background: rgba(245,158,11,0.1); }
.stat-card--warning .stat-card__icon svg { color: #d97706; }

.stat-card--danger::before { background: linear-gradient(90deg, var(--color-red), #f87171); }
.stat-card--danger .stat-card__value { color: var(--color-red); }
.stat-card--danger .stat-card__icon { background: rgba(220,38,38,0.08); }
.stat-card--danger .stat-card__icon svg { color: var(--color-red); }

/* ========================================
   DASHBOARD SECTIONS
======================================== */
.dashboard-section {
    margin-bottom: 2.5rem;
    animation: fadeUp 0.45s ease both;
    animation-delay: 0.25s;
}

.dashboard-section:nth-of-type(2) { animation-delay: 0.35s; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    letter-spacing: -0.01em;
}

.section-title::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 1em;
    background: var(--color-accent);
    border-radius: 2px;
    flex-shrink: 0;
}

/* ========================================
   BUTTONS
======================================== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.25rem;
    background: var(--color-primary);
    color: white;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(15,41,82,0.2);
}

.btn-primary:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(15,41,82,0.28);
}

.btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 1rem;
    border: 1px solid var(--color-border-hover);
    color: var(--color-text-muted);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-outline:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: rgba(15,41,82,0.03);
}

/* ========================================
   DATA TABLE
======================================== */
.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    background: var(--color-bg);
    padding: 0.75rem 1.25rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--color-text-dim);
    border-bottom: 1px solid var(--color-border);
}

.data-table td {
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    vertical-align: middle;
}

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

.data-table tbody tr {
    transition: background 0.12s;
}

.data-table tbody tr:hover td {
    background: rgba(15, 41, 82, 0.025);
}

.td-mono {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--color-text-muted);
}

.td-muted { color: var(--color-text-dim); font-size: 0.82rem; }

/* ========================================
   BADGES
======================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.65rem;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.badge::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge--completed  { background: #dcfce7; color: #15803d; }
.badge--completed::before  { background: #16a34a; }

.badge--failed     { background: #fee2e2; color: #b91c1c; }
.badge--failed::before     { background: #dc2626; }

.badge--processing { background: #dbeafe; color: #1d4ed8; }
.badge--processing::before { background: #2563eb; animation: dotpulse 1.4s ease-in-out infinite; }

.badge--pending    { background: var(--color-bg-2); color: var(--color-text-dim); }
.badge--pending::before    { background: var(--color-text-dim); }

.badge--active   { background: #dcfce7; color: #15803d; }
.badge--active::before   { background: #16a34a; }

.badge--inactive { background: var(--color-bg-2); color: var(--color-text-dim); }
.badge--inactive::before { background: var(--color-text-dim); }

.badge--neutral { background: var(--color-bg-2); color: var(--color-text-muted); }
.badge--neutral::before { background: var(--color-text-muted); }

/* Origen de la operación bulk: web / API / catálogo */
.badge--origin-web     { background: var(--color-bg-2); color: var(--color-text-muted); }
.badge--origin-web::before     { background: var(--color-text-muted); }

.badge--origin-api     { background: #ede9fe; color: #6d28d9; }
.badge--origin-api::before     { background: #7c3aed; }

.badge--origin-catalog { background: #fef3c7; color: #b45309; }
.badge--origin-catalog::before { background: #d97706; }

/* ── Scope tooltip ── */
.scope-wrap {
    position: relative;
    display: inline-block;
}

.scope-restricted-badge {
    cursor: default;
}

.scope-tooltip {
    display: none;
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    z-index: 100;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.10);
    white-space: nowrap;
    flex-direction: column;
    gap: 0.25rem;
    min-width: max-content;
}

.scope-tooltip__item {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--color-text-muted);
    line-height: 1.4;
}

.scope-wrap:hover .scope-tooltip {
    display: flex;
}

@keyframes dotpulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.3; transform: scale(0.7); }
}

/* ========================================
   EMPTY STATE
======================================== */
.empty-state {
    background: var(--color-surface);
    border: 1.5px dashed var(--color-border-hover);
    border-radius: var(--radius-lg);
    padding: 3.5rem 2rem;
    text-align: center;
    color: var(--color-text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
}

.empty-state__icon {
    width: 52px;
    height: 52px;
    background: var(--color-bg-2);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-dim);
}

.empty-state__icon svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
}

.empty-state p {
    font-size: 0.925rem;
}

/* ========================================
   ACTION CARDS
======================================== */
.action-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.action-card {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.4rem;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.action-card::after {
    content: '→';
    position: absolute;
    bottom: 1.1rem;
    right: 1.25rem;
    font-size: 0.95rem;
    color: var(--color-border-hover);
    transition: color 0.2s, transform 0.2s;
}

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

.action-card:hover::after {
    color: var(--color-sky);
    transform: translateX(4px);
}

.action-card__icon {
    width: 40px;
    height: 40px;
    background: rgba(15, 41, 82, 0.07);
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.action-card:hover .action-card__icon {
    background: rgba(30, 115, 195, 0.12);
}

.action-card__icon svg {
    width: 20px;
    height: 20px;
    stroke: var(--color-primary);
    fill: none;
    transition: stroke 0.2s;
}

.action-card:hover .action-card__icon svg {
    stroke: var(--color-sky);
}

.action-card__body {
    flex: 1;
    padding-right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.action-card__title {
    font-size: 0.925rem;
    font-weight: 600;
    color: var(--color-text);
}

.action-card__desc {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.45;
}

/* ========================================
   DASHBOARD BACK LINK
======================================== */
.dashboard-back {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--color-text-dim);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 0.6rem;
    transition: color 0.15s;
}

.dashboard-back svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}

.dashboard-back:hover { color: var(--color-primary); }

/* ========================================
   ONBOARDING CARD (0 clientes)
======================================== */
.onboarding-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    background: var(--color-surface);
    border: 1.5px dashed var(--color-border-hover);
    border-radius: var(--radius-lg);
    padding: 1.75rem 2rem;
    margin-bottom: 2rem;
    animation: fadeUp 0.4s ease both;
}

.onboarding-card__icon {
    width: 52px;
    height: 52px;
    background: rgba(15,41,82,0.07);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--color-primary);
}

.onboarding-card__icon svg {
    width: 26px;
    height: 26px;
}

.onboarding-card__body {
    flex: 1;
}

.onboarding-card__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.25rem;
}

.onboarding-card__desc {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    line-height: 1.45;
}

/* ========================================
   SETUP GUIDE
======================================== */
.setup-guide {
    animation: fadeUp 0.45s ease both;
    animation-delay: 0.1s;
}

.setup-guide__title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--color-text-dim);
    margin-bottom: 1rem;
}

.setup-steps {
    display: flex;
    align-items: flex-start;
    gap: 0;
}

.setup-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    flex: 1;
    padding: 1.5rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    position: relative;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.setup-step--active {
    opacity: 1;
    border-color: rgba(15,41,82,0.2);
    box-shadow: var(--shadow-sm);
}

.setup-step--active .setup-step__num {
    background: var(--color-primary);
    color: white;
}

.setup-step--active .setup-step__icon {
    background: rgba(15,41,82,0.08);
    color: var(--color-primary);
}

.setup-step__num {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--color-bg-2);
    color: var(--color-text-dim);
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-surface);
}

.setup-step__icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--color-bg-2);
    color: var(--color-text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.5rem;
}

.setup-step__icon svg {
    width: 20px;
    height: 20px;
}

.setup-step__label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
}

.setup-step__desc {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    line-height: 1.45;
}

.setup-step__connector {
    width: 2rem;
    height: 1px;
    background: var(--color-border);
    flex-shrink: 0;
    margin-top: 3.5rem;
    position: relative;
}

.setup-step__connector::after {
    content: '';
    position: absolute;
    right: -3px;
    top: -3px;
    width: 6px;
    height: 6px;
    border-top: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    transform: rotate(45deg);
}

@media (max-width: 600px) {
    .setup-steps {
        flex-direction: column;
        gap: 0.5rem;
    }
    .setup-step__connector {
        width: 1px;
        height: 1.5rem;
        margin: 0 auto;
    }
    .setup-step__connector::after {
        right: -3px;
        top: auto;
        bottom: -3px;
        border-top: none;
        border-bottom: 1px solid var(--color-border);
    }
}

/* ========================================
   CLIENT PICKER
======================================== */
.client-picker-grid {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-width: 640px;
    animation: fadeUp 0.4s ease both;
}

.client-picker-card {
    display: flex;
    align-items: center;
    gap: 1.1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.4rem;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.18s, box-shadow 0.18s, transform 0.15s;
}

.client-picker-card:hover {
    border-color: var(--color-sky);
    box-shadow: var(--shadow-md);
    transform: translateX(4px);
}

.client-picker-card__avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-sky));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.client-picker-card__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.client-picker-card__avatar span {
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.client-picker-card__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.client-picker-card__name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text);
}

.client-picker-card__meta {
    font-size: 0.8rem;
    color: var(--color-text-dim);
}

.client-picker-card__arrow {
    width: 18px;
    height: 18px;
    color: var(--color-border-hover);
    flex-shrink: 0;
    transition: color 0.18s, transform 0.18s;
}

.client-picker-card:hover .client-picker-card__arrow {
    color: var(--color-sky);
    transform: translateX(3px);
}

/* ========================================
   CLIENTS TABLE
======================================== */
.page-header-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.app-nav__link--active {
    color: var(--color-text) !important;
    font-weight: 700;
}

.clients-table .td-center { text-align: center; }

.client-cell {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    text-decoration: none;
    color: inherit;
}

.client-cell__avatar {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-sky));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.client-cell__avatar--sm {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
}

.client-cell__avatar img,
.client-cell__avatar--sm img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.client-cell__avatar span,
.client-cell__avatar--sm span {
    color: white;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.client-cell__name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

.client-row:hover td { background: rgba(15, 41, 82, 0.03); }

.client-row--inactive td { opacity: 0.55; }
.client-row--inactive .row-actions { opacity: 1; }

/* Row action buttons */
.row-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    justify-content: flex-end;
}

.btn-ghost {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text-dim);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}

.btn-ghost svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
}

.token-preview-btn {
    width: auto;
    height: auto;
    padding: 0.2rem 0.4rem;
}

.btn-ghost:hover {
    background: var(--color-bg-2);
    color: var(--color-text);
}

.btn-ghost--danger:hover {
    background: rgba(220, 38, 38, 0.08);
    color: var(--color-red);
}

/* Inline edit row */
.client-row--editing td {
    padding: 0.75rem 1.25rem;
    background: rgba(30, 115, 195, 0.03);
}

.row-edit-form {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
}

.row-edit-field {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex: 1;
    min-width: 200px;
}

.row-edit-input {
    max-width: 360px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.row-edit-error {
    flex-basis: 100%;
    margin: 0;
    font-size: 0.8rem;
}

.row-edit-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.btn-sm {
    padding: 0.42rem 0.9rem;
    font-size: 0.8rem;
}

/* ========================================
   FORM CARD (crear / editar entidades)
======================================== */
.form-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem 2.25rem;
    max-width: 560px;
    box-shadow: var(--shadow-sm);
    animation: fadeUp 0.4s ease both;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-bottom: 1.35rem;
}

.form-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-muted);
    letter-spacing: 0.01em;
}

.form-required {
    color: var(--color-red);
    margin-left: 0.15rem;
}

.form-input {
    width: 100%;
    padding: 0.65rem 0.9rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    border-color: var(--color-sky);
    box-shadow: 0 0 0 3px rgba(30, 115, 195, 0.1);
}

.form-input::placeholder { color: var(--color-text-dim); }

.file-input {
    width: 100%;
    padding: 0.35rem 0.6rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-dim);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    cursor: pointer;
    line-height: 1.5;
}

.file-input::file-selector-button {
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.28rem 0.75rem;
    font-size: 0.78rem;
    font-family: var(--font-sans);
    font-weight: 600;
    cursor: pointer;
    margin-right: 0.65rem;
    transition: background 0.15s;
}

.file-input::file-selector-button:hover {
    background: var(--color-sky);
}

.file-input--sm {
    font-size: 0.8rem;
    padding: 0.22rem 0.45rem;
}

.file-input--sm::file-selector-button {
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    margin-right: 0.5rem;
}

.form-input-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.form-input-row .form-input { flex: 1; }

.form-avatar-preview {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-sky));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.form-avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.form-avatar-preview span {
    color: white;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.form-hint {
    font-size: 0.78rem;
    color: var(--color-text-dim);
    line-height: 1.4;
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.75rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

.btn-primary:disabled,
.btn-primary.htmx-request {
    opacity: 0.65;
    cursor: not-allowed;
    pointer-events: none;
}

/* ========================================
   API KEY CARDS
======================================== */
.apikey-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.apikey-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.9rem 1.25rem;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.apikey-card--inactive {
    opacity: 0.55;
}

.apikey-card__info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 120px;
    flex-shrink: 0;
}

.apikey-card__name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
}

.apikey-card__meta {
    font-size: 0.75rem;
    color: var(--color-text-dim);
}

.apikey-card__key-wrap {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.apikey-value {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.6rem;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.04em;
    user-select: all;
}

.apikey-card__actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

/* ========================================
   MODAL
======================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 41, 82, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    /* visibility permite transición suave; display:none no */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, visibility 0.18s ease;
    /* Promueve el blur a una capa GPU propia para evitar repaint */
    transform: translateZ(0);
    will-change: opacity;
}

.modal-overlay:not([aria-hidden="true"]) {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-box {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    padding: 1.75rem 2rem;
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

/* Animación solo al abrir — no en página cargada ni al cerrar */
.modal-overlay:not([aria-hidden="true"]) .modal-box {
    animation: modalSlideUp 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)     scale(1);    }
}

.modal-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.modal-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: rgba(220, 38, 38, 0.08);
    color: var(--color-red);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-icon--neutral {
    background: rgba(15, 41, 82, 0.07);
    color: var(--color-primary);
}

.modal-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.01em;
}

.modal-subtitle {
    font-size: 0.8rem;
    color: var(--color-text-dim);
    margin-top: 0.15rem;
}

.modal-desc {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
    margin-top: 0.25rem;
}

.btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.25rem;
    background: var(--color-red);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, opacity 0.15s;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}

.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.35);
}

.btn-danger:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

/* ========================================
   CLIENT DETAIL PAGE
======================================== */
.client-detail-identity {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

.client-detail-avatar {
    width: 80px;
    height: 80px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-sky));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.client-detail-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.client-detail-avatar span {
    color: white;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.client-detail-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

/* Tab navigation */
.detail-tabs-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.detail-tabs {
    display: flex;
    gap: 0.3rem;
    background: var(--color-bg-2);
    border-radius: var(--radius-md);
    padding: 0.3rem;
    width: fit-content;
    margin-bottom: 1.25rem;
}

.detail-tab {
    padding: 0.55rem 1.25rem;
    border-radius: calc(var(--radius-md) - 2px);
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.detail-tab:hover:not(.detail-tab--active) {
    background: rgba(15, 41, 82, 0.06);
    color: var(--color-text);
}

.detail-tab--active {
    background: var(--color-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

/* Offers container */
.offers-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.supply-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.section-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.section-label::before,
.section-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

/* Offer grid */
.offer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    align-items: start;
}

@media (max-width: 640px) {
    .offer-grid { grid-template-columns: 1fr; }
}

/* Offer card */
.offer-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}

.offer-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.offer-card__company {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.company-logo-sm {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: contain;
    border: 1px solid var(--color-border);
    flex-shrink: 0;
}

.company-avatar-sm {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-sky));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
}

.offer-card__company-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.offer-card__badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    flex-shrink: 0;
}

.offer-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.55rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.offer-badge--tariff {
    background: rgba(15, 41, 82, 0.08);
    color: var(--color-primary);
}

.offer-badge--indexed {
    background: rgba(245, 197, 24, 0.18);
    color: #7a5c00;
}

.offer-badge--solar {
    background: rgba(22, 163, 74, 0.1);
    color: var(--color-green);
}

.offer-badge--inactive {
    background: rgba(100, 116, 139, 0.14);
    color: var(--color-text-dim);
}

.offer-card__name-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem 0.75rem;
    min-width: 0;
}

.offer-card__name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.01em;
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Territory badges */
.territory-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    padding: 0 1.25rem 0.75rem;
}

.terr-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    background: var(--color-bg-2);
    color: var(--color-text-dim);
    font-size: 0.7rem;
    font-weight: 600;
}

/* Price sections */
.price-section {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--color-border);
}

.price-section__label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--color-text-dim);
    margin-bottom: 0.45rem;
}

.price-table {
    width: 100%;
    border-collapse: collapse;
}

.price-table tr + tr td { padding-top: 0.2rem; }

.price-period {
    color: var(--color-text-muted);
    padding-right: 1rem;
    white-space: nowrap;
    font-size: 0.82rem;
}

.price-value {
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 500;
    text-align: right;
}

/* Sparkline */
.sparkline-wrap {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sparkline-chart {
    flex: 1;
    min-width: 80px;
    display: flex;
    flex-direction: column;
}

.sparkline-svg {
    width: 100%;
    height: 40px;
    display: block;
}

.sparkline-months {
    position: relative;
    height: 14px;
    overflow: hidden;
}

.sparkline-months span {
    position: absolute;
    transform: translateX(-50%);
    font-size: 0.58rem;
    color: var(--color-text-dim);
    opacity: 0.6;
    white-space: nowrap;
}

.btn-history {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--color-sky);
    font-weight: 600;
    width: auto;
    height: auto;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-sm);
    background: rgba(30, 115, 195, 0.07);
    transition: background 0.15s;
    cursor: pointer;
    border: none;
    font-family: var(--font-sans);
}

.btn-history:hover {
    background: rgba(30, 115, 195, 0.14);
    color: var(--color-primary);
}

/* History section */
.history-table-wrap {
    padding: 0.5rem 1.25rem 1rem;
    border-top: 1px solid var(--color-border);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.history-table th {
    text-align: center;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-text-dim);
    padding: 0.25rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.history-table th:first-child { text-align: left; }

.history-table .col-e   { background: rgba(59, 130, 246, 0.04); }
.history-table .col-p   { background: rgba(16, 185, 129, 0.04); }
.history-table .col-p-start { border-left: 1px solid var(--color-border); }

.history-legend {
    font-size: 0.72rem;
    color: var(--color-text-dim);
    margin: 0 0 0.5rem;
}

.history-table td {
    text-align: right;
    padding: 0.3rem 0.5rem;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 0.76rem;
    border-bottom: 1px solid rgba(15, 41, 82, 0.04);
}

.history-table td:first-child {
    text-align: left;
    color: var(--color-text);
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.82rem;
}

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

.history-edit-bar {
    display: flex;
    justify-content: flex-end;
    padding: 0.5rem 0 0;
}

.btn-history-edit {
    font-size: 0.75rem;
    color: var(--color-text-dim);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.65rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.btn-history-edit:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.history-edit-form {
    padding: 0 0 0.5rem;
}

.history-edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0 0.75rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.5rem;
}

.history-edit-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-add-month {
    font-size: 0.75rem;
    color: var(--color-sky);
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 600;
    padding: 0;
}

.btn-add-month:hover { text-decoration: underline; }

.history-rows { display: flex; flex-direction: column; gap: 0.4rem; }

.history-edit-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
}

.history-row__header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.history-row__header input[type="month"] { flex: 1; }

.history-row__group {
    display: flex;
    align-items: flex-end;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.history-row__glabel {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--color-text-muted);
    min-width: 1rem;
    padding-bottom: 0.3rem;
}

.labeled-input {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    align-items: center;
}

.labeled-input::before {
    content: attr(data-label);
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--color-text-dim);
    line-height: 1;
}

.history-row__group .edit-input--price {
    width: 100px;
}

.edit-input--month {
    width: 7.5rem;
    flex-shrink: 0;
}

/* Offer notes */
.offer-notes {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.83rem;
    color: var(--color-text-muted);
}

.offer-notes summary {
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-dim);
    list-style: none;
    user-select: none;
}

.offer-notes[open] summary { margin-bottom: 0.5rem; }

.offer-notes p {
    line-height: 1.5;
    font-size: 0.83rem;
}

/* Empty state for offers (distinct from page-level .empty-state) */
.empty-offers {
    padding: 2rem;
    text-align: center;
    color: var(--color-text-dim);
    font-size: 0.875rem;
    background: var(--color-surface);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-md);
}

.tab-loading {
    padding: 3rem;
    text-align: center;
    color: var(--color-text-dim);
    font-size: 0.875rem;
}

/* ========================================
   DRILL-DOWN: COMPANY PILLS + TARIFF TABS
======================================== */

/* Buscador de comercializadora */
.company-search-wrap {
    position: relative;
    max-width: 300px;
    margin-bottom: 1rem;
}

.company-search__icon {
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--color-text-dim);
    pointer-events: none;
}

.company-search {
    width: 100%;
    padding: 0.55rem 0.75rem 0.55rem 2.1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.company-search:focus {
    border-color: var(--color-sky);
    box-shadow: 0 0 0 3px rgba(30, 115, 195, 0.1);
}

.company-search::placeholder { color: var(--color-text-dim); }

/* Selector de comercializadora */
.company-selector {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.75rem;
    margin-bottom: 1.75rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.company-selector::-webkit-scrollbar {
    height: 4px;
}

.company-selector::-webkit-scrollbar-track {
    background: transparent;
}

.company-selector::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.company-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem 0.45rem;
    width: 150px;
    min-height: 130px;
    flex-shrink: 0;
    border-radius: var(--radius-lg);
    border: 2px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    line-height: 1.3;
    transition: border-color 0.15s, color 0.15s, box-shadow 0.15s, background 0.15s;
    box-shadow: var(--shadow-sm);
}

.company-pill:hover:not(.is-active) {
    border-color: var(--color-border-hover);
    color: var(--color-text);
    box-shadow: var(--shadow-md);
}

.company-pill.is-active {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: rgba(15, 41, 82, 0.03);
    box-shadow: 0 0 0 3px rgba(15, 41, 82, 0.08), var(--shadow-sm);
}

.company-pill__avatar {
    width: 96px;
    height: 96px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-sky));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.25rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.company-pill__logo {
    width: 96px;
    height: 96px;
    border-radius: 18px;
    object-fit: contain;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
    padding: 4px;
    background: white;
}

/* El lápiz de editar se monta sobre el logo: lo mostramos como chip flotante solo
   al hover o en la comercializadora activa, para que en reposo el logo se vea entero */
.company-pill .company-pill__edit {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text-muted);
    box-shadow: var(--shadow-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.company-pill:hover .company-pill__edit,
.company-pill:focus-within .company-pill__edit,
.company-pill.is-active .company-pill__edit {
    opacity: 1;
    pointer-events: auto;
}

.company-pill .company-pill__edit:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.company-pill span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

/* Barra de filtros */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.filter-group {
    display: flex;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.filter-group .filter-chip {
    border: none;
    border-radius: 0;
    box-shadow: none;
    border-right: 1px solid var(--color-border);
}

.filter-group .filter-chip:last-child {
    border-right: none;
}

.filter-group .filter-chip.is-active {
    box-shadow: none;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-md);
    border: 2px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    white-space: nowrap;
}

.filter-chip:hover:not(.is-active) {
    border-color: var(--color-border-hover);
    color: var(--color-text);
}

.filter-chip.is-active {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: rgba(15, 41, 82, 0.05);
}

.filter-chip input[type="radio"],
.filter-chip input[type="checkbox"] {
    display: none;
}

.filter-select {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    border: 2px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s;
    appearance: auto;
}

.filter-select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-md);
    border: 2px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
    margin-left: auto;
}

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

.empty-offers--filtered {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    padding: 2rem 0;
}

/* Panels (show/hide) */
.company-panel.is-hidden,
.tariff-panel.is-hidden {
    display: none;
}

/* ── Modo "Todas": todas las comercializadoras apiladas como secciones ── */
/* Cabecera de sección y etiqueta de tarifa solo se ven en modo "Todas" */
.company-panel__header,
.tariff-panel__label {
    display: none;
}

/* Revela todos los paneles ocultos (4 clases → gana a .company-panel.is-hidden sin !important) */
.offers-container.offers-all .company-panel.is-hidden,
.offers-container.offers-all .tariff-panel.is-hidden {
    display: block;
}

.offers-container.offers-all .tariff-tabs {
    display: none;
}

.offers-container.offers-all .company-panel__header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.offers-container.offers-all .tariff-panel__label {
    display: flex;
    margin: 1.25rem 0 1rem;
}

/* Separación entre secciones de comercializadora (solo entre paneles consecutivos,
   nunca encima del primero — :first-of-type no sirve porque el primer div del
   contenedor es .offers-toolbar, no un .company-panel) */
.offers-container.offers-all .company-panel + .company-panel {
    padding-top: 1.75rem;
    margin-top: 1.75rem;
    border-top: 1px solid var(--color-border);
}

.company-panel__logo,
.company-panel__avatar {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: contain;
    flex-shrink: 0;
}

.company-panel__logo {
    border: 1px solid var(--color-border);
    padding: 4px;
    background: white;
}

.company-panel__avatar {
    background: linear-gradient(135deg, var(--color-primary), var(--color-sky));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.4rem;
}

.company-panel__name {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--color-text);
}

/* En "Todas": cada subsección de ofertas es una tira horizontal scrolleable,
   para que las secciones de comercializadora no crezcan en vertical. */
.offers-container.offers-all .offer-grid {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 1.25rem;
    overflow-x: auto;
    padding: 0.25rem 0 0.5rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
    /* Fade en el borde derecho como pista de que hay más ofertas */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}

.offers-container.offers-all .offer-grid > .offer-card {
    flex: 0 0 300px;
}

.offers-container.offers-all .offer-grid::-webkit-scrollbar { height: 6px; }
.offers-container.offers-all .offer-grid::-webkit-scrollbar-track { background: transparent; }
.offers-container.offers-all .offer-grid::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

/* Tariff type tabs */
.tariff-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.tariff-tab {
    padding: 0.5rem 1.1rem;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: transparent;
    color: var(--color-text-dim);
    font-family: var(--font-sans);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    letter-spacing: 0.01em;
}

.tariff-tab:hover:not(.is-active) {
    color: var(--color-text);
}

.tariff-tab.is-active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* ========================================
   ENTRANCE ANIMATION
======================================== */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ========================================
   RESPONSIVE
======================================== */
@media (max-width: 768px) {
    .app-nav {
        width: calc(100% - 2rem);
        top: 0.75rem;
    }

    .app-nav__links { display: none; }

    .stat-grid,
    .action-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-wrap { padding-top: 5rem; }
}

@media (max-width: 480px) {
    .stat-grid,
    .action-grid {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   DASHBOARD (legacy stub — kept for backward compat)
======================================== */
.dashboard {
    max-width: 1100px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* ========================================
   UPLOAD PAGE
======================================== */

.upload-form-card {
    max-width: 560px;
}

/* Dropzone */
.upload-dropzone {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg);
    padding: 2rem 1.5rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    min-height: 120px;
}

.upload-dropzone:hover,
.upload-dropzone:focus-visible {
    border-color: var(--color-sky);
    background: rgba(30, 115, 195, 0.04);
    outline: none;
}

.upload-dropzone.is-active {
    border-color: var(--color-sky);
    background: rgba(30, 115, 195, 0.06);
}

.upload-dropzone.has-file {
    border-style: solid;
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.04);
}

.upload-dropzone__input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

.upload-dropzone__body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    text-align: center;
}

.upload-dropzone__icon {
    width: 2rem;
    height: 2rem;
    color: var(--color-text-muted);
    transition: color 0.2s;
}

.upload-dropzone.is-active .upload-dropzone__icon,
.upload-dropzone:hover .upload-dropzone__icon {
    color: var(--color-sky);
}

.upload-dropzone.has-file .upload-dropzone__icon {
    color: #22c55e;
}

.upload-dropzone__label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.upload-dropzone__filename {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-sky);
    word-break: break-all;
    display: none;
}

.upload-dropzone.has-file .upload-dropzone__filename {
    display: block;
}

/* Upload spinner inside btn */
.upload-spinner {
    display: none;
    align-items: center;
}

.upload-spinner.htmx-request {
    display: inline-flex;
}

.upload-spinner__icon {
    width: 1rem;
    height: 1rem;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.upload-result-area {
    max-width: 560px;
    margin-top: 1rem;
}

/* Upload result fragments returned by HTMX */
.upload-result {
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    font-size: 0.9rem;
    animation: fadeUp 0.3s ease both;
}

.upload-result--ok {
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-left: 4px solid #22c55e;
    color: var(--color-text);
}

.upload-result--ok p {
    margin: 0 0 0.35rem;
}

.upload-result--ok p:last-child {
    margin-bottom: 0;
}

.upload-result--ok details {
    margin-top: 0.75rem;
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.upload-result--ok details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--color-text);
}

.upload-result--ok details ul {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Inline error messages returned by HTMX */
p.error {
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    background: rgba(239, 68, 68, 0.07);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-left: 4px solid var(--color-red);
    color: var(--color-text);
    font-size: 0.9rem;
    margin: 0;
    animation: fadeUp 0.3s ease both;
}

/* ========================================
   UPLOAD ACTIVITY TABLE — expandable rows
======================================== */

.upload-row {
    cursor: pointer;
    transition: background 0.15s;
}

.upload-row:hover {
    background: var(--color-bg);
}

.upload-detail-row {
    background: var(--color-bg);
}

.upload-detail-row:not(:has(> td)),
.upload-row:not(.is-open) + .upload-detail-row {
    display: none;
}

.upload-detail-cell {
    padding: 0 !important;
    border-top: none !important;
}

.upload-detail {
    padding: 0.9rem 1.25rem;
    border-top: 1px solid var(--color-border);
    animation: fadeUp 0.2s ease both;
}

.upload-detail__stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.25rem;
    font-size: 0.84rem;
    color: var(--color-text-muted);
}

.upload-detail__stat strong {
    color: var(--color-text);
    font-weight: 600;
}

.upload-detail__stat--dim {
    color: var(--color-text-dim);
    font-style: italic;
}

.upload-detail__origin {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.6rem;
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.upload-detail__actor strong {
    color: var(--color-text);
    font-weight: 600;
}

.upload-detail__errors {
    margin-top: 0.65rem;
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.upload-detail__errors summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--color-text);
    user-select: none;
}

.upload-detail__errors ul {
    margin: 0.4rem 0 0;
    padding-left: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.upload-detail__error {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--color-red);
    font-size: 0.84rem;
    margin: 0;
}

.upload-detail__empty {
    color: var(--color-text-dim);
    font-size: 0.84rem;
    margin: 0;
    font-style: italic;
}

/* ========================================
   OFFER DRAWER
======================================== */

#offer-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 199;
}
#offer-drawer-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

#offer-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 600px;
    max-width: 100%;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#offer-drawer.is-open {
    transform: translateX(0);
}

#offer-drawer.offer-drawer--wide {
    width: 820px;
}

.offer-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.offer-drawer__title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-width: 0;
}

.offer-drawer__title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.offer-drawer__close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text-muted);
    transition: background 0.15s, color 0.15s;
}
.offer-drawer__close:hover {
    background: var(--color-bg-2);
    color: var(--color-text);
}

.offer-drawer__body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.drawer-loading {
    color: var(--color-text-dim);
    font-size: 0.85rem;
    padding: 1rem 0;
}

.offer-detail__name-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.6rem;
}

.offer-detail__name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.01em;
}

.drawer-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.drawer-actions {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border);
}
.drawer-actions--edit {
    display: flex;
    gap: 0.75rem;
}

.btn-drawer-edit {
    width: 100%;
    padding: 0.65rem 1.25rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-drawer-edit:hover { opacity: 0.88; }

.btn-drawer-save {
    flex: 1;
    padding: 0.65rem 1.25rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-drawer-save:hover { opacity: 0.88; }

.btn-drawer-cancel {
    padding: 0.65rem 1.25rem;
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.btn-drawer-cancel:hover {
    border-color: var(--color-border-hover);
    color: var(--color-text);
}

/* Offer card — clickable */
.offer-card {
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.offer-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
}


.offer-card__footer {
    padding: 0.6rem 1.25rem 0.75rem;
    border-top: 1px solid var(--color-border);
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.offer-card__updated {
    font-size: 0.7rem;
    color: var(--color-text-muted);
}
.offer-card__details-hint {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-sky);
    letter-spacing: 0.01em;
}

/* Edit form */
.offer-edit-form {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.edit-section {
    padding-bottom: 1.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--color-border);
}
.edit-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
}
.edit-section__label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--color-text-dim);
    margin-bottom: 0.75rem;
}

.edit-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.65rem;
}
.edit-field:last-child { margin-bottom: 0; }

.edit-field--inline {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.edit-field__name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.edit-input {
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-text);
    background: var(--color-bg);
    width: 100%;
    transition: border-color 0.15s;
}
.edit-input:focus {
    outline: none;
    border-color: var(--color-primary);
}
.edit-input--price {
    width: 130px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    text-align: right;
}
.edit-input--textarea {
    resize: vertical;
    min-height: 72px;
}

.edit-price-grid {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.edit-section__label--row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.edit-section__unit {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--color-text-dim);
    margin-left: 0.25rem;
}

.tier-rows {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.tier-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 72px 1.75rem;
    gap: 0.35rem;
    align-items: center;
}

.edit-input--select-sm {
    padding: 0.28rem 0.3rem;
    font-size: 0.8rem;
    width: 100%;
    min-width: 0;
}

.btn-add-tier {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    color: var(--color-text-dim);
    white-space: nowrap;
}

.btn-add-tier:hover {
    background: var(--color-surface-hover, rgba(0,0,0,0.04));
}

.btn-remove-tier {
    font-size: 0.8rem;
    padding: 0.15rem 0.4rem;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--color-text-dim);
    line-height: 1;
}

.btn-remove-tier:hover {
    color: #e53e3e;
}

.ccaa-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.3rem;
}

.ccaa-badge {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    background: var(--color-surface-alt, #f3f4f6);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}

.ccaa-checkboxes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem 0.5rem;
}

.edit-hint {
    font-size: 0.78rem;
    color: var(--color-text-dim);
    margin: 0 0 0.5rem;
}

.edit-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.5rem;
}
.edit-checkbox {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.83rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
}
.edit-checkbox--disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.edit-checkbox--disabled input {
    cursor: not-allowed;
}

.edit-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.form-error-banner {
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: var(--radius-sm);
    color: #dc2626;
    font-size: 0.83rem;
    font-weight: 600;
    padding: 0.6rem 0.85rem;
    margin-bottom: 1rem;
}

@media (max-width: 640px) {
    #offer-drawer { width: 100%; }
}

/* ========================================
   UPLOAD PAGE — two-column layout + guide
======================================== */
.upload-page-grid {
    display: grid;
    grid-template-columns: minmax(0, 560px) minmax(0, 420px);
    gap: 2rem;
    align-items: start;
}

.upload-form-card {
    max-width: none;
}

/* Guide aside */
.upload-guide {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    animation: fadeUp 0.45s ease both;
    animation-delay: 0.08s;
}

.upload-guide__header {
    padding: 1.25rem 1.5rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

.upload-guide__eyebrow {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-sky);
    margin-bottom: 0.3rem;
}

.upload-guide__title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
    margin-bottom: 0.3rem;
}

.upload-guide__intro {
    font-size: 0.8rem;
    color: var(--color-text-dim);
    line-height: 1.5;
}

/* Accordion */
.upload-guide__accordion {
    display: flex;
    flex-direction: column;
}

.ug-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.ug-row:hover { background: var(--color-bg); }

.ug-row[aria-expanded="true"] { background: var(--color-bg); }

.ug-row__left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.ug-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.ug-dot--blue   { background: var(--color-sky); }
.ug-dot--purple { background: #7c3aed; }
.ug-dot--teal   { background: #0d9488; }
.ug-dot--red    { background: var(--color-red); }

.ug-row__name {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
}

.ug-row__right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ug-row__op {
    font-size: 0.72rem;
    color: var(--color-text-dim);
    white-space: nowrap;
}

.ug-row__chevron {
    width: 14px;
    height: 14px;
    color: var(--color-text-dim);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.ug-row[aria-expanded="true"] .ug-row__chevron {
    transform: rotate(180deg);
}

/* Body */
.ug-body {
    padding: 0.9rem 1.5rem 1rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    overflow: hidden;
}

.ug-body--closed {
    display: none;
}

.ug-body__desc {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    margin-bottom: 0.65rem;
}

.ug-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.ug-table tr + tr td {
    border-top: 1px solid var(--color-border);
}

.ug-table td {
    padding: 0.3rem 0;
    vertical-align: baseline;
    color: var(--color-text-dim);
    line-height: 1.4;
}

.ug-table__col {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    color: var(--color-primary);
    white-space: nowrap;
    padding-right: 0.75rem;
    width: 1%;
}

.ug-table td code {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    color: var(--color-primary);
    background: rgba(15,41,82,0.06);
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
}

/* Footer note */
.upload-guide__footer {
    padding: 0.75rem 1.5rem;
    font-size: 0.75rem;
    color: var(--color-text-dim);
    text-align: center;
}

.sample-download-hint {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(30, 115, 195, 0.07);
    border: 1px solid rgba(30, 115, 195, 0.2);
    border-radius: 8px;
    margin-top: 0.5rem;
}

.sample-download-hint__icon {
    flex-shrink: 0;
    color: var(--color-sky);
    margin-top: 1px;
}

.sample-download-hint__body {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sample-download-hint__label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
}

.sample-download-hint__link {
    color: var(--color-sky);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
}

.sample-download-hint__link:hover {
    text-decoration: underline;
}

.sample-download-hint__link[data-disabled] {
    color: var(--color-text-dim);
    cursor: default;
    text-decoration: none;
}

.sample-download-hint__sub {
    font-size: 0.75rem;
    color: var(--color-text-dim);
}

@media (max-width: 1000px) {
    .upload-page-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Comercializadoras grid ── */
.co-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.co-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    padding: 1.5rem 1.25rem 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    transition: border-color 0.15s, box-shadow 0.15s;
    text-align: center;
}

.co-card:hover {
    border-color: var(--color-border-hover);
    box-shadow: var(--shadow-md);
}

.co-card__avatar {
    width: 96px;
    height: 96px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-sky));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

/* Con logo, fondo blanco (el degradado azul es solo para la inicial de respaldo). */
.co-card__avatar:has(img) {
    background: #fff;
    border: 1px solid var(--color-border);
    padding: 6px;
}

.co-card__avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 12px;
}

.co-card__body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
}

.co-card__name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
}

.co-card__url {
    font-size: 0.72rem;
    color: var(--color-text-dim);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.co-card__edit {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.co-card:hover .co-card__edit {
    opacity: 1;
}

/* Edit mode */
.co-card--editing {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    padding: 1.25rem;
    gap: 0;
}

.co-card__edit-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.co-card--editing .co-card__avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.co-card__edit-form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
}

.co-card__input-row {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.co-card__input {
    flex: 1;
    font-size: 0.85rem;
    padding: 0.45rem 0.75rem;
}

.co-card__file-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    padding: 0.28rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color 0.15s;
}

.co-card__file-label:hover {
    border-color: var(--color-primary);
}

.co-card__file-name {
    font-size: 0.78rem;
    color: var(--color-text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.co-card__file-name.has-file {
    color: var(--color-text);
    font-weight: 500;
}

.co-card__edit-actions {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.co-card__edit-actions .btn-primary,
.co-card__edit-actions .btn-outline {
    flex: 1;
    justify-content: center;
}

@media (max-width: 600px) {
    .co-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

/* ========================================
   CATÁLOGO — alta de comercializadora
======================================== */
.catalog-new-company-wrap {
    margin-bottom: 2rem;
}

.catalog-new-company-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 560px;
}

.catalog-new-company-form .form-input {
    flex: 1;
    min-width: 0;
}

.catalog-new-company-form .btn-primary {
    flex-shrink: 0;
    white-space: nowrap;
}

#catalog-new-company-error:not(:empty) {
    margin-top: 0.6rem;
}

@media (max-width: 600px) {
    .catalog-new-company-form {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ========================================
   CATÁLOGO — suscripciones del cliente
======================================== */
.offer-badge--catalog {
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
}

.company-pill__catalog-tag {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
    white-space: nowrap;
}

.btn-add-catalog {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-md);
    border: 2px solid var(--color-primary);
    background: var(--color-primary);
    color: white;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
}

.btn-add-catalog:hover { opacity: 0.88; }

.offer-card__catalog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem 0.75rem;
    border-top: 1px dashed var(--color-border);
}

.offer-card__catalog-link {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-dim);
    text-decoration: none;
}

.offer-card__catalog-link:hover { color: var(--color-primary); }

.offer-card__unsub {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-dim);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.offer-card__unsub:hover {
    border-color: var(--color-red);
    color: var(--color-red);
}

.offer-card--inactive {
    opacity: 0.6;
    border-style: dashed;
}

.offer-card--inactive:hover {
    opacity: 1;
}

.offer-card__inactive-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem 0.75rem;
    border-top: 1px dashed var(--color-border);
}

.offer-card__inactive-note {
    font-size: 0.72rem;
    color: var(--color-text-dim);
}

.offer-card__reactivate {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-dim);
    font-family: var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, color 0.15s;
}

.offer-card__reactivate:hover {
    border-color: var(--color-green);
    color: var(--color-green);
}

.btn-drawer-edit--danger {
    background: var(--color-red);
}

.drawer-actions--split {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
}

.drawer-actions--split .btn-drawer-cancel,
.drawer-actions--split .btn-drawer-edit {
    flex: 1;
    width: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-decoration: none;
}

/* Modal de suscripción */
.subscribe-modal-box {
    max-width: 640px;
    max-height: 82vh;
    overflow-y: auto;
}

.subscribe-modal-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.subscribe-group__company {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.subscribe-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: 0.4rem;
}

.subscribe-row__info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-width: 0;
}

.subscribe-row__name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
}

.btn-subscribe {
    padding: 0.3rem 0.85rem;
    border: none;
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: white;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
}

.btn-subscribe:hover { opacity: 0.88; }
