:root {
    --erp-primary: #003b71;
    --erp-primary-deep: #001f3d;
    --erp-primary-light: #0b5cab;
    --erp-accent: #10b981;
    --erp-accent-soft: #6ee7b7;
    --erp-danger: #dc2626;
    --erp-bg: #eef4fb;
    --erp-card: #ffffff;
    --erp-text: #0f2744;
    --erp-muted: #64748b;
    --erp-border: #e2e8f0;
    --erp-sidebar-w: 292px;
    --erp-sidebar-w-collapsed: 76px;
    --erp-radius: 20px;
    --erp-shadow: 0 20px 50px rgba(15, 39, 68, 0.1);
    --erp-shadow-lg: 0 28px 60px rgba(15, 39, 68, 0.14);
    --erp-glass: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

body.erp-body {
    margin: 0;
    font-family: "Segoe UI", "Inter", system-ui, sans-serif;
    background: var(--erp-bg);
    color: var(--erp-text);
    -webkit-font-smoothing: antialiased;
}

/* ========== LAYOUT ========== */
.erp-layout {
    display: flex;
    min-height: 100vh;
}

.erp-main {
    flex: 1;
    margin-left: var(--erp-sidebar-w);
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.erp-topbar {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--erp-border);
    padding: 20px 32px;
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 16px;
}

.erp-sidebar-toggle {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border: 1px solid var(--erp-border);
    border-radius: 12px;
    background: #fff;
    color: var(--erp-primary);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.erp-sidebar-toggle:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.erp-topbar-title h1 {
    margin: 0;
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--erp-primary);
    letter-spacing: -0.02em;
}

.erp-topbar-sub {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: var(--erp-muted);
}

.erp-content {
    padding: 28px 32px 40px;
    flex: 1;
}

/* ========== SIDEBAR GLOBAL ========== */
.erp-sidebar {
    width: var(--erp-sidebar-w);
    background: linear-gradient(165deg, #004a8f 0%, var(--erp-primary-deep) 45%, #001528 100%);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 8px 0 40px rgba(0, 31, 61, 0.35);
}

.erp-sidebar-glow {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 120% 80% at 0% 0%, rgba(56, 189, 248, 0.22), transparent 50%),
        radial-gradient(ellipse 80% 60% at 100% 100%, rgba(16, 185, 129, 0.15), transparent 45%);
    pointer-events: none;
}

.erp-sidebar-brand {
    position: relative;
    padding: 28px 22px 20px;
    text-align: center;
    border-bottom: 1px solid var(--erp-glass);
}

.erp-logo {
    max-width: 168px;
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25));
}

.erp-brand-tag {
    display: block;
    margin-top: 10px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    opacity: 0.65;
    font-weight: 600;
}

.erp-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px 16px;
    position: relative;
}

.erp-sidebar-nav::-webkit-scrollbar {
    width: 5px;
}

.erp-sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.erp-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.erp-menu .menu-section {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 700;
    opacity: 0.55;
    padding: 18px 10px 8px;
    margin-top: 4px;
}

.menu-section-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent, #38bdf8);
    box-shadow: 0 0 10px var(--accent, #38bdf8);
}

.erp-menu-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    margin-bottom: 6px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    border-radius: 14px;
    border: 1px solid transparent;
    transition: transform 0.2s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.erp-menu-link:hover {
    background: var(--erp-glass);
    border-color: rgba(255, 255, 255, 0.12);
    transform: translateX(4px);
    color: #fff;
}

.erp-menu-link.active {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.erp-menu-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    background: color-mix(in srgb, var(--item-accent, #38bdf8) 35%, transparent);
    border: 1px solid color-mix(in srgb, var(--item-accent, #38bdf8) 50%, transparent);
    flex-shrink: 0;
}

.erp-menu-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.erp-menu-text strong {
    font-size: 0.92rem;
    font-weight: 700;
}

.erp-menu-text small {
    font-size: 0.72rem;
    opacity: 0.7;
    margin-top: 2px;
}

/* Sidebar colapsado (por defecto) */
html.erp-sidebar-collapsed {
    --erp-sidebar-w: var(--erp-sidebar-w-collapsed);
}

html.erp-sidebar-collapsed .erp-sidebar-brand {
    padding: 20px 10px 14px;
}

html.erp-sidebar-collapsed .erp-logo {
    max-width: 44px;
}

html.erp-sidebar-collapsed .erp-brand-tag,
html.erp-sidebar-collapsed .erp-menu-text,
html.erp-sidebar-collapsed .erp-menu .menu-section,
html.erp-sidebar-collapsed .erp-user-info,
html.erp-sidebar-collapsed .erp-user-logout {
    display: none;
}

html.erp-sidebar-collapsed .erp-menu-link {
    justify-content: center;
    padding: 10px;
}

html.erp-sidebar-collapsed .erp-menu-link:hover {
    transform: none;
}

html.erp-sidebar-collapsed .erp-user-card {
    justify-content: center;
    padding: 10px;
}

html.erp-sidebar-collapsed .erp-sidebar-nav {
    padding: 12px 8px;
}

/* Usuario al pie del menú */
.erp-sidebar-user {
    position: relative;
    padding: 16px 14px 20px;
    border-top: 1px solid var(--erp-glass);
    background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.2));
}

.erp-user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 14px;
    background: var(--erp-glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 10px;
}

.erp-user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #38bdf8, #10b981);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.erp-user-info {
    min-width: 0;
    line-height: 1.3;
}

.erp-user-info strong {
    display: block;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.erp-user-info span {
    font-size: 0.72rem;
    opacity: 0.75;
}

.erp-user-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px;
    border-radius: 12px;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.88rem;
    background: rgba(220, 38, 38, 0.25);
    border: 1px solid rgba(248, 113, 113, 0.35);
    transition: 0.2s;
}

.erp-user-logout:hover {
    background: rgba(220, 38, 38, 0.45);
    color: #fff;
}

/* ========== TARJETAS Y PANEL DE SERVICIOS ========== */
.erp-card {
    background: var(--erp-card);
    border-radius: var(--erp-radius);
    box-shadow: var(--erp-shadow);
    padding: 24px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.erp-services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 22px;
}

.erp-service-card {
    position: relative;
    overflow: hidden;
    border-radius: 24px;
    padding: 28px 24px;
    min-height: 280px;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    background: #fff;
    border: 1px solid var(--erp-border);
    box-shadow: var(--erp-shadow);
    transition: transform 0.3s, box-shadow 0.3s;
}

.erp-service-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: var(--service-color, var(--erp-primary));
}

.erp-service-card::after {
    content: "";
    position: absolute;
    top: -40%;
    right: -30%;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--service-color, #003b71) 12%, transparent);
    pointer-events: none;
}

.erp-service-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--erp-shadow-lg);
}

.erp-service-icon {
    width: 58px;
    height: 58px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #fff;
    background: linear-gradient(135deg, var(--service-color), color-mix(in srgb, var(--service-color) 70%, #000));
    margin-bottom: 18px;
    position: relative;
    z-index: 1;
}

.erp-service-card h3 {
    margin: 0 0 10px;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--erp-primary);
    position: relative;
    z-index: 1;
}

.erp-service-card p {
    flex: 1;
    margin: 0 0 20px;
    color: var(--erp-muted);
    line-height: 1.65;
    font-size: 0.95rem;
    position: relative;
    z-index: 1;
}

.erp-service-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    color: var(--service-color);
    position: relative;
    z-index: 1;
}

.erp-service-cta i {
    transition: transform 0.2s;
}

.erp-service-card:hover .erp-service-cta i {
    transform: translateX(4px);
}

/* Legacy grid */
.erp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.erp-module-card { text-align: center; padding: 36px 28px; transition: 0.25s; }
.erp-module-card:hover { transform: translateY(-6px); }
.erp-module-card .icon { font-size: 3.5rem; margin-bottom: 16px; }
.erp-module-card h3 { margin: 0 0 10px; color: var(--erp-primary); font-size: 1.4rem; }
.erp-module-card p { color: var(--erp-muted); min-height: 72px; line-height: 1.6; }

/* Botones */
.erp-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 12px;
    border: none;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: 0.2s;
}

.erp-btn-primary { background: var(--erp-primary); color: #fff; }
.erp-btn-success { background: var(--erp-accent); color: #fff; }
.erp-btn-outline { background: #fff; color: var(--erp-primary); border: 2px solid var(--erp-border); }
.erp-btn-danger { background: var(--erp-danger); color: #fff; }
.erp-btn:hover { transform: translateY(-1px); opacity: 0.95; }

.erp-alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; }
.erp-alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.erp-alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }

.erp-form-group { margin-bottom: 18px; }
.erp-form-group label { display: block; margin-bottom: 6px; font-weight: 600; }
.erp-form-group input,
.erp-form-group select,
.erp-form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--erp-border);
    border-radius: 12px;
    font-size: 1rem;
}

.erp-table { width: 100%; border-collapse: collapse; }
.erp-table th, .erp-table td { padding: 12px; border-bottom: 1px solid var(--erp-border); text-align: left; }
.erp-table th { background: #f8fafc; color: var(--erp-primary); }

.erp-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.erp-tabs a {
    padding: 10px 16px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--erp-muted);
    font-weight: 600;
    background: #fff;
    border: 1px solid var(--erp-border);
}
.erp-tabs a.active { background: var(--erp-primary); color: #fff; border-color: var(--erp-primary); }

/* Barra herramientas módulo (cotizador, etc.) */
.erp-module-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.erp-module-toolbar a {
    padding: 10px 16px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    background: #fff;
    color: var(--erp-primary);
    border: 1px solid var(--erp-border);
    transition: 0.2s;
}

.erp-module-toolbar a:hover {
    background: var(--erp-primary);
    color: #fff;
    border-color: var(--erp-primary);
}

.erp-cotizador-content .container {
    max-width: 100%;
    margin: 0 auto 24px;
    box-shadow: var(--erp-shadow);
}

.erp-farmavet-embed .welcome-panel,
.erp-farmavet-embed .info-panel {
    border-radius: var(--erp-radius);
}

.erp-farmavet-embed .main-content {
    padding: 0;
    margin: 0;
    width: 100%;
}

/* ========== LOGIN ERP ========== */
.erp-login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background-color: var(--erp-primary-deep);
    background-image: linear-gradient(135deg, rgba(0, 59, 113, 0.88), rgba(0, 21, 40, 0.92)), var(--erp-login-bg);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

.erp-login-card {
    width: 100%;
    max-width: 440px;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(16px);
    padding: 44px 40px;
    border-radius: 28px;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.erp-login-logo {
    display: block;
    max-width: 200px;
    margin: 0 auto 24px;
}

.erp-login-card h1 {
    margin: 0 0 6px;
    text-align: center;
    color: var(--erp-primary);
    font-size: 1.5rem;
    font-weight: 800;
}

.erp-login-card .erp-login-sub {
    text-align: center;
    color: var(--erp-muted);
    margin-bottom: 28px;
}

.erp-login-card a {
    color: var(--erp-primary-light);
    font-weight: 600;
}

.erp-login-portal {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--erp-border);
    text-align: center;
}

.erp-login-portal-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 16px 24px;
    border-radius: 16px;
    background: linear-gradient(135deg, #eff6ff 0%, #e0f2fe 100%);
    border: 2px solid #93c5fd;
    color: var(--erp-primary) !important;
    font-size: 1.05rem;
    font-weight: 800;
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.erp-login-portal-link:hover {
    background: linear-gradient(135deg, #dbeafe 0%, #bae6fd 100%);
    box-shadow: 0 8px 24px rgba(0, 59, 113, 0.15);
    transform: translateY(-2px);
    color: var(--erp-primary-deep) !important;
}

.erp-login-portal-link i {
    font-size: 1.35rem;
}

.erp-login-portal-hint {
    margin: 12px 0 0;
    font-size: 0.82rem;
    color: var(--erp-muted);
    line-height: 1.4;
}

/* ========== PORTAL EMPLEADO ========== */
.erp-portal-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background-color: #0a2540;
    background-image: linear-gradient(160deg, rgba(0, 59, 113, 0.75), rgba(16, 185, 129, 0.35)), var(--erp-portal-bg);
    background-size: cover;
    background-position: center;
}

.erp-portal-card {
    width: 100%;
    max-width: 480px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
    padding: 48px 40px;
    border-radius: 28px;
    box-shadow: var(--erp-shadow-lg);
}

.erp-portal-card .erp-portal-logo {
    max-width: 180px;
    display: block;
    margin: 0 auto 20px;
}

.erp-portal-card h1 {
    margin: 0 0 8px;
    text-align: center;
    color: var(--erp-primary);
    font-size: 1.45rem;
}

.erp-portal-card .portal-desc {
    text-align: center;
    color: var(--erp-muted);
    margin-bottom: 28px;
    line-height: 1.6;
}

.erp-portal-result {
    margin-top: 28px;
    text-align: left;
}

.erp-portal-validacion {
    margin-bottom: 20px;
}

.erp-portal-validacion span {
    display: block;
    margin-top: 4px;
    font-weight: 500;
    opacity: 0.9;
}

.erp-portal-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.erp-portal-info-card {
    background: #f8fafc;
    border: 1px solid var(--erp-border);
    border-radius: 14px;
    padding: 16px 18px;
}

.erp-portal-info-card span {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--erp-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.erp-portal-info-card strong {
    font-size: 1rem;
    color: var(--erp-text);
    word-break: break-word;
}

.erp-portal-estado {
    color: #16a34a;
}

.erp-portal-cupo-card {
    display: inline-block;
    max-width: 100%;
    margin: 8px 0 24px;
    padding: 22px 28px;
    border-radius: 16px;
    background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
    border: 1px solid #93c5fd;
}

.erp-portal-cupo-card span {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--erp-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
}

.erp-portal-cupo-card strong {
    display: block;
    font-size: 1.65rem;
    color: #1769ff;
    line-height: 1.2;
}

.erp-portal-cert-btn {
    display: inline-flex;
    width: auto;
    min-width: 220px;
}

@media (max-width: 960px) {
    .erp-sidebar {
        width: 100%;
        position: relative;
        max-height: none;
    }
    .erp-main { margin-left: 0; }
    .erp-layout { flex-direction: column; }
    .erp-sidebar-nav { max-height: 50vh; }
}
