:root {
    --crm-primary: #0d9488;
    --crm-primary-dark: #0f766e;
    --crm-accent: #2563eb;
    --crm-bg: #f3f6fb;
    --crm-text: #0f172a;
    --crm-muted: #64748b;
    --crm-border: rgba(148, 163, 184, .28);
    --crm-surface: rgba(255, 255, 255, .88);
    --crm-surface-solid: #ffffff;
    --crm-shadow: 0 18px 48px rgba(15, 23, 42, .10);
    --crm-shadow-sm: 0 10px 26px rgba(15, 23, 42, .07);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body.crm-body,
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, Helvetica, sans-serif;
    color: var(--crm-text);
    background:
        radial-gradient(circle at 12% -8%, rgba(37, 99, 235, .13), transparent 32%),
        radial-gradient(circle at 96% 2%, rgba(13, 148, 136, .12), transparent 34%),
        linear-gradient(180deg, #f8fbff 0%, var(--crm-bg) 100%);
}

a { color: inherit; text-decoration: none; }
a:hover { color: inherit; }

/* Shell con navegación superior: libera el ancho del chat */
.crm-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.crm-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    min-height: 68px;
    display: grid;
    grid-template-columns: auto minmax(320px, 1fr) auto;
    align-items: center;
    gap: 18px;
    padding: 10px 18px;
    background: rgba(255, 255, 255, .90);
    border-bottom: 1px solid rgba(226, 232, 240, .86);
    backdrop-filter: blur(18px);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .05);
}

.crm-topbar-brand { min-width: 0; }
.crm-brand-horizontal {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.crm-brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 15px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #00a884, #2563eb);
    box-shadow: 0 14px 30px rgba(0, 168, 132, .22);
    color: #fff;
    font-size: 24px;
    flex: 0 0 auto;
}

.crm-brand-text strong {
    display: block;
    font-size: 16px;
    letter-spacing: -.03em;
    line-height: 1.1;
}

.crm-brand-text small {
    display: block;
    margin-top: 2px;
    color: var(--crm-muted);
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
}

.crm-nav-horizontal {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.crm-nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 14px;
    color: #475569;
    border-radius: 999px;
    font-weight: 900;
    font-size: 13px;
    border: 1px solid transparent;
    transition: background .18s ease, color .18s ease, transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.crm-nav-link i { font-size: 20px; opacity: .92; }
.crm-nav-link:hover {
    color: #0f172a;
    background: rgba(15, 23, 42, .05);
    border-color: rgba(148, 163, 184, .22);
    transform: translateY(-1px);
}
.crm-nav-link.active {
    color: #fff;
    background: linear-gradient(135deg, rgba(13, 148, 136, .98), rgba(37, 99, 235, .98));
    box-shadow: 0 14px 28px rgba(37, 99, 235, .18);
}

.crm-header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}

.crm-user-mini {
    display: inline-grid;
    grid-template-columns: 36px minmax(0, 120px);
    gap: 9px;
    align-items: center;
    padding: 5px 9px 5px 5px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid rgba(148, 163, 184, .25);
    box-shadow: 0 8px 18px rgba(15, 23, 42, .04);
}

.crm-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    background: #0f172a;
    color: #fff;
    font-weight: 950;
}

.crm-user-name strong,
.crm-user-name small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.crm-user-name strong { font-size: 12px; line-height: 1.1; }
.crm-user-name small { color: var(--crm-muted); font-size: 10px; margin-top: 2px; }

.crm-menu-toggle,
.crm-logout-btn {
    border: 1px solid rgba(148, 163, 184, .28);
    background: rgba(255, 255, 255, .92);
    color: #334155;
    border-radius: 14px;
    min-height: 42px;
    padding: 0 13px;
    font-weight: 900;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.crm-menu-toggle { display: none; width: 42px; padding: 0; font-size: 22px; }
.crm-logout-btn:hover,
.crm-menu-toggle:hover {
    transform: translateY(-1px);
    border-color: rgba(13, 148, 136, .35);
    box-shadow: var(--crm-shadow-sm);
}

.crm-online {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 12px;
    border-radius: 999px;
    background: #ecfdf5;
    color: #047857;
    font-size: 12px;
    font-weight: 950;
    border: 1px solid #bbf7d0;
}
.crm-online i { font-size: 9px; color: #22c55e; }
.crm-logout-form { margin: 0; }

.crm-mobile-nav {
    display: none;
    padding: 8px 12px 12px;
    background: rgba(255,255,255,.94);
    border-bottom: 1px solid rgba(226,232,240,.86);
}

.page-container {
    flex: 1;
    padding: 12px 18px 18px;
    min-width: 0;
}

.crm-page-title {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 12px;
}
.crm-page-title span {
    display: block;
    color: var(--crm-muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.crm-page-title h1 {
    margin: 2px 0 0;
    font-size: 24px;
    font-weight: 950;
    letter-spacing: -.04em;
    line-height: 1.05;
}

.page-conversations .page-container { padding: 10px 12px 12px; }
.page-conversations .crm-page-title { display: none; }

/* Compatibilidad con vistas actuales */
.topbar { display: none; }
.grid { display: grid; gap: 18px; }
.cards-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.card {
    background: var(--crm-surface);
    border: 1px solid rgba(255, 255, 255, .82);
    border-radius: 22px;
    box-shadow: var(--crm-shadow);
    backdrop-filter: blur(16px);
}
.stat {
    position: relative;
    overflow: hidden;
    min-height: 132px;
    padding: 18px;
}
.stat::after {
    content: "";
    position: absolute;
    right: -32px;
    bottom: -35px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(13,148,136,.13), rgba(37,99,235,.15));
}
.stat-title { color: var(--crm-muted); margin-bottom: 8px; font-weight: 800; font-size: 13px; }
.stat-value { font-size: 36px; font-weight: 950; letter-spacing: -.05em; color: var(--crm-text); }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; font-weight: 800; color: #334155; }
.input, textarea, select, .form-control {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid #dbe3ef;
    border-radius: 13px;
    background: #fff;
    color: var(--crm-text);
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease;
}
.input:focus, textarea:focus, select:focus, .form-control:focus {
    border-color: rgba(13, 148, 136, .55);
    box-shadow: 0 0 0 4px rgba(13, 148, 136, .12);
}

.btn-primary, .btn {
    border: 0;
    border-radius: 13px;
    padding: 10px 15px;
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-accent));
    color: #fff;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(37, 99, 235, .18);
    transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}
.btn-primary:hover, .btn:hover {
    color: #fff;
    transform: translateY(-1px);
    filter: brightness(1.03);
    box-shadow: 0 16px 30px rgba(37, 99, 235, .22);
}

.alert {
    margin: 12px 0;
    padding: 11px 13px;
    border-radius: 14px;
    background: #fff7ed;
    color: #9a3412;
    border: 1px solid #fed7aa;
}
.text-danger { color: #dc2626; font-size: 12px; }
.admin-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-bottom: 18px; }
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
}
.table th,
.table td {
    padding: 12px 10px;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: middle;
}
.table th {
    color: #475569;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: #f8fafc;
}
.table tbody tr:hover { background: rgba(13, 148, 136, .04); }
hr { border: 0; border-top: 1px solid var(--crm-border); margin: 18px 0; }

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(380px, .95fr);
    background:
        radial-gradient(circle at 18% 10%, rgba(13, 148, 136, .22), transparent 30%),
        radial-gradient(circle at 88% 10%, rgba(37, 99, 235, .20), transparent 30%),
        linear-gradient(135deg, #0f172a, #172554 54%, #0f766e);
    color: #fff;
}
.login-hero {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: clamp(28px, 6vw, 78px);
}
.login-logo {
    width: 64px;
    height: 64px;
    border-radius: 22px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #00a884, #2563eb);
    font-size: 34px;
    box-shadow: 0 20px 42px rgba(0,0,0,.22);
    margin-bottom: 24px;
}
.login-hero h1 {
    font-size: clamp(36px, 6vw, 66px);
    line-height: .95;
    margin: 0 0 18px;
    letter-spacing: -.06em;
    font-weight: 950;
}
.login-hero p {
    max-width: 650px;
    margin: 0;
    color: rgba(255,255,255,.74);
    font-size: 18px;
    line-height: 1.55;
}
.login-features {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 28px;
}
.login-feature {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255,255,255,.13);
    background: rgba(255,255,255,.08);
    border-radius: 999px;
    padding: 9px 12px;
    color: rgba(255,255,255,.86);
    font-weight: 800;
    font-size: 13px;
}
.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: rgba(255,255,255,.06);
    backdrop-filter: blur(18px);
}
.login-card {
    width: min(440px, 100%);
    background: rgba(255,255,255,.95);
    color: var(--crm-text);
    border: 1px solid rgba(255,255,255,.75);
    border-radius: 28px;
    box-shadow: 0 28px 70px rgba(0,0,0,.22);
    padding: 32px;
}
.login-card h2 {
    margin: 0;
    font-size: 28px;
    font-weight: 950;
    letter-spacing: -.04em;
}
.login-card .login-subtitle {
    margin: 6px 0 22px;
    color: var(--crm-muted);
}
.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
    color: #475569;
    font-size: 14px;
}
.btn-login {
    width: 100%;
    min-height: 46px;
    border: 0;
    border-radius: 15px;
    padding: 12px 14px;
    font-size: 15px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-accent));
    color: #fff;
    cursor: pointer;
    box-shadow: 0 14px 28px rgba(37, 99, 235, .22);
}
.btn-login:hover { filter: brightness(1.03); }
.validation-summary-errors,
.text-danger { color: #b91c1c; font-size: 13px; }
.validation-summary-errors ul { margin: 0 0 16px; padding-left: 18px; }

@media (max-width: 1180px) {
    .crm-topbar {
        grid-template-columns: auto auto 1fr;
        gap: 10px;
    }
    .crm-menu-toggle { display: inline-flex; order: 2; }
    .crm-nav-horizontal { display: none; }
    .crm-header-right { order: 3; }
    .crm-mobile-nav {
        display: none;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }
    .crm-shell.mobile-nav-open .crm-mobile-nav { display: grid; }
    .crm-brand-text small { display: none; }
}

@media (max-width: 960px) {
    .crm-topbar { padding: 9px 12px; }
    .crm-online { display: none; }
    .crm-user-mini { grid-template-columns: 36px; padding-right: 5px; }
    .crm-user-name { display: none; }
    .page-container { padding: 12px; }
    .admin-grid { grid-template-columns: 1fr; }
    .login-page { grid-template-columns: 1fr; }
    .login-hero { min-height: 36vh; padding-bottom: 20px; }
    .login-panel { align-items: flex-start; }
}

@media (max-width: 560px) {
    .crm-brand-text { display: none; }
    .crm-logout-btn span { display: none; }
    .crm-header-right { gap: 6px; }
    .crm-mobile-nav { grid-template-columns: 1fr; }
    .crm-mobile-nav .crm-nav-link { justify-content: flex-start; }
    .cards-4 { grid-template-columns: 1fr; }
    .login-card { padding: 24px; border-radius: 22px; }
}

/* Dashboard */
.dashboard-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 22px;
    margin-bottom: 18px;
    overflow: hidden;
    position: relative;
}
.dashboard-hero::after {
    content: "";
    position: absolute;
    right: -95px;
    top: -95px;
    width: 240px;
    height: 240px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(13,148,136,.15), rgba(37,99,235,.16));
}
.dashboard-hero > * { position: relative; z-index: 1; }
.dashboard-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #0f766e;
    background: #ccfbf1;
    border-radius: 999px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 900;
    margin-bottom: 12px;
}
.dashboard-hero h2 {
    margin: 0;
    font-weight: 950;
    letter-spacing: -.045em;
    font-size: clamp(26px, 4vw, 38px);
}
.dashboard-hero p { margin: 8px 0 0; color: var(--crm-muted); }
.dashboard-action { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.dashboard-grid .stat { display: flex; flex-direction: column; justify-content: space-between; }
.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 15px;
    display: grid;
    place-items: center;
    margin-bottom: 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-accent));
    box-shadow: 0 12px 22px rgba(37,99,235,.18);
    font-size: 23px;
}
.stat-accent-teal .stat-icon { background: linear-gradient(135deg, #0d9488, #14b8a6); }
.stat-accent-blue .stat-icon { background: linear-gradient(135deg, #2563eb, #38bdf8); }
.stat-accent-slate .stat-icon { background: linear-gradient(135deg, #334155, #64748b); }
.stat-accent-indigo .stat-icon { background: linear-gradient(135deg, #4f46e5, #2563eb); }
.stat-accent-green .stat-icon { background: linear-gradient(135deg, #16a34a, #0d9488); }
.stat-accent-orange .stat-icon { background: linear-gradient(135deg, #f97316, #f59e0b); }
.stat-accent-purple .stat-icon { background: linear-gradient(135deg, #7c3aed, #2563eb); }
@media (max-width: 720px) {
    .dashboard-hero { align-items: flex-start; flex-direction: column; }
    .dashboard-action { width: 100%; justify-content: center; }
}

/* Administración */
.admin-hero {
    padding: 22px;
    margin-bottom: 18px;
}
.admin-hero h2 {
    margin: 0;
    font-size: clamp(26px, 4vw, 38px);
    font-weight: 950;
    letter-spacing: -.045em;
}
.admin-hero p { margin: 8px 0 0; color: var(--crm-muted); }
.admin-card { padding: 18px; overflow: hidden; }
.card-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.card-title-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-accent));
    color: #fff;
    box-shadow: 0 12px 22px rgba(37,99,235,.18);
    font-size: 23px;
    flex: 0 0 auto;
}
.card-title-row h2,
.subsection-title {
    margin: 0;
    font-size: 18px;
    font-weight: 950;
    letter-spacing: -.02em;
}
.card-title-row p { margin: 3px 0 0; color: var(--crm-muted); font-size: 13px; }
.full-btn { width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.table-responsive-soft { overflow-x: auto; border-radius: 16px; border: 1px solid #e5e7eb; }
.role-pill,
.group-pill,
.status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
}
.role-pill { color: #3730a3; background: #eef2ff; }
.group-pill { color: #0f766e; background: #ccfbf1; }
.status-pill.ok { color: #166534; background: #dcfce7; }
.status-pill.off { color: #991b1b; background: #fee2e2; }
