* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: #f3f6fb;
    color: #172b4d;
}

a {
    color: inherit;
    text-decoration: none;
}

.crm-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top bar */
.crm-topbar {
    height: 58px;
    background: #ffffff;
    border-bottom: 1px solid #d8dde6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.crm-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: #032d60;
    font-size: 18px;
}

.crm-logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #0176d3;
    color: white;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.crm-top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #3e4e63;
    font-size: 14px;
}

.crm-search {
    width: 340px;
    max-width: 40vw;
    padding: 10px 14px;
    border: 1px solid #c9d3e0;
    border-radius: 999px;
    background: #f8fafc;
}

/* Layout */
.crm-layout {
    display: flex;
    flex: 1;
}

.crm-sidebar {
    width: 230px;
    background: #ffffff;
    border-right: 1px solid #d8dde6;
    padding: 18px 12px;
}

.crm-nav-title {
    font-size: 11px;
    text-transform: uppercase;
    color: #6b778c;
    margin: 14px 12px 8px;
    font-weight: 700;
}

.crm-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 8px;
    color: #243b53;
    font-size: 14px;
    margin-bottom: 4px;
}

.crm-nav a:hover,
.crm-nav a.active {
    background: #eaf4ff;
    color: #0176d3;
    font-weight: 700;
}

.crm-main {
    flex: 1;
    padding: 26px;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
}

.page-title h1 {
    margin: 0;
    font-size: 26px;
    color: #032d60;
}

.page-title p {
    margin: 6px 0 0;
    color: #5f6f89;
    font-size: 14px;
}

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.card {
    background: #ffffff;
    border: 1px solid #d8dde6;
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 2px 6px rgba(9, 30, 66, 0.04);
}

.card-label {
    font-size: 13px;
    color: #6b778c;
    margin-bottom: 8px;
}

.card-value {
    font-size: 28px;
    font-weight: 700;
    color: #032d60;
}

.panel {
    background: #ffffff;
    border: 1px solid #d8dde6;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(9, 30, 66, 0.04);
}

.panel-header {
    padding: 16px 18px;
    border-bottom: 1px solid #e5e9f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    margin: 0;
    font-size: 18px;
    color: #032d60;
}

.panel-body {
    padding: 18px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
}

.btn-primary {
    background: #0176d3;
    color: #ffffff;
}

.btn-primary:hover {
    background: #0b5cab;
}

.btn-secondary {
    background: #ffffff;
    border-color: #c9d3e0;
    color: #032d60;
}

.btn-danger {
    background: #ba0517;
    color: #ffffff;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    text-align: left;
    padding: 13px 14px;
    border-bottom: 1px solid #e5e9f0;
    font-size: 14px;
}

.table th {
    background: #f8fafc;
    color: #3e4e63;
    font-size: 12px;
    text-transform: uppercase;
}

.table tr:hover td {
    background: #f8fbff;
}

.badge {
    display: inline-flex;
    padding: 4px 9px;
    border-radius: 999px;
    background: #eaf4ff;
    color: #0176d3;
    font-size: 12px;
    font-weight: 700;
}

.badge.badge-active {
    background: #e8f5e9;
    color: #1b5e20;
}

.badge.badge-lead {
    background: #eaf4ff;
    color: #0176d3;
}

.badge.badge-inactive {
    background: #eef1f5;
    color: #5f6f89;
}

.badge.badge-archived {
    background: #fff7e6;
    color: #7a4b00;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full {
    grid-column: 1 / -1;
}

label {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
    color: #3e4e63;
}

input,
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #c9d3e0;
    border-radius: 8px;
    font-size: 14px;
    background: #ffffff;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.form-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #032d60, #0176d3);
}

.login-box {
    width: 100%;
    max-width: 390px;
    background: #ffffff;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.18);
}

.login-box h1 {
    margin: 0 0 8px;
    color: #032d60;
}

.login-box p {
    margin: 0 0 20px;
    color: #5f6f89;
}

.error {
    background: #fdecee;
    color: #ba0517;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 14px;
}

/* Responsive */
@media (max-width: 900px) {
    .crm-layout {
        flex-direction: column;
    }

    .crm-sidebar {
        width: 100%;
        border-right: 0;
        border-bottom: 1px solid #d8dde6;
    }

    .crm-nav {
        display: flex;
        overflow-x: auto;
        gap: 6px;
    }

    .crm-nav a {
        white-space: nowrap;
    }

    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .crm-search {
        display: none;
    }
}

.table td {
    vertical-align: top;
}

.table td a {
    color: #0176d3;
    font-weight: 600;
}

.table td a:hover {
    text-decoration: underline;
}

.card-link {
    display: block;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.card-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(9, 30, 66, 0.10);
    border-color: #0176d3;
    text-decoration: none;
}

.crm-footer {
    margin-top: 32px;
    padding: 18px 4px 4px;
    color: #5f6f89;
    font-size: 13px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* =========================
   Dark mode - Hostinger-like
   ========================= */

body.theme-dark {
    background: #111820;
    color: #d7e0ea;
}

body.theme-dark .crm-topbar {
    background: #141d26;
    border-bottom: 1px solid #2d3a45;
}

body.theme-dark .crm-sidebar {
    background: #111820;
    border-right: 1px solid #2d3a45;
}

body.theme-dark .crm-main {
    background: #111820;
}

body.theme-dark .crm-brand span,
body.theme-dark .page-title h1,
body.theme-dark .panel-header h2,
body.theme-dark h1,
body.theme-dark h2,
body.theme-dark h3,
body.theme-dark label {
    color: #f3f7fb;
}

body.theme-dark .page-title p,
body.theme-dark .crm-footer,
body.theme-dark .crm-nav-title {
    color: #8ea0b2;
}

body.theme-dark .panel,
body.theme-dark .card,
body.theme-dark .stat-card,
body.theme-dark .login-box {
    background: #1b252e;
    border-color: #2d3a45;
    box-shadow: none;
}

body.theme-dark .panel-header {
    border-bottom: 1px solid #2d3a45;
}

body.theme-dark .table th {
    background: #18222b;
    color: #c8d4df;
    border-bottom: 1px solid #2d3a45;
}

body.theme-dark .table td {
    color: #d7e0ea;
    border-bottom: 1px solid #2d3a45;
}

body.theme-dark input,
body.theme-dark select,
body.theme-dark textarea {
    background: #111820;
    color: #d7e0ea;
    border-color: #3a4a57;
}

body.theme-dark input::placeholder,
body.theme-dark textarea::placeholder {
    color: #7f91a3;
}

body.theme-dark input:focus,
body.theme-dark select:focus,
body.theme-dark textarea:focus {
    border-color: #2d9bf0;
    box-shadow: 0 0 0 3px rgba(45, 155, 240, 0.16);
}

body.theme-dark .crm-nav a {
    color: #c8d4df;
}

body.theme-dark .crm-nav a:hover {
    background: #1b252e;
    color: #ffffff;
}

body.theme-dark .crm-nav a.active {
    background: #213142;
    color: #4db3ff;
}

body.theme-dark .btn-primary {
    background: #0b7bd3;
    border-color: #0b7bd3;
    color: #ffffff;
}

body.theme-dark .btn-primary:hover {
    background: #0969b4;
    border-color: #0969b4;
}

body.theme-dark .btn-secondary {
    background: #18222b;
    border-color: #3a4a57;
    color: #d7e0ea;
}

body.theme-dark .btn-secondary:hover {
    background: #22303b;
}

body.theme-dark .btn-danger {
    background: #c1121f;
    border-color: #c1121f;
    color: #ffffff;
}

body.theme-dark .badge {
    background: #243244;
    color: #d7e0ea;
}

body.theme-dark .badge-active {
    background: #163d2a;
    color: #7ee2a8;
}

body.theme-dark .badge-inactive {
    background: #29313a;
    color: #b9c5d0;
}

body.theme-dark .badge-lead {
    background: #143456;
    color: #7fc5ff;
}

body.theme-dark .badge-archived {
    background: #4a3516;
    color: #ffd48a;
}

body.theme-dark .error {
    background: #3a1d22;
    color: #ffb8c0;
    border-color: #6b2b36;
}

body.theme-dark .error[style*="background:#e8f5e9"] {
    background: #173823 !important;
    color: #8be0a4 !important;
}

body.theme-dark details {
    background: #18222b !important;
    border-color: #2d3a45 !important;
}

body.theme-dark summary {
    color: #d7e0ea !important;
}

body.theme-dark pre {
    background: #111820 !important;
    border-color: #2d3a45 !important;
    color: #d7e0ea !important;
}

body.theme-dark a {
    color: #4db3ff;
}

body.theme-dark .crm-logo {
    background: #0b7bd3;
    color: #ffffff;
}

/* Dark mode - table hover fix */
body.theme-dark .table tbody tr:hover {
    background: #22303b;
}

body.theme-dark .table tbody tr:hover td {
    color: #f3f7fb;
}

body.theme-dark .table tbody tr:hover a {
    color: #4db3ff;
}

body.theme-dark .table tbody tr:hover .badge {
    color: inherit;
}

/* Dark mode - definitive table hover override */
body.theme-dark table.table tbody tr:hover,
body.theme-dark .table tbody tr:hover {
    background-color: #22303b !important;
}

body.theme-dark table.table tbody tr:hover td,
body.theme-dark .table tbody tr:hover td {
    background-color: #22303b !important;
    color: #f3f7fb !important;
}

body.theme-dark table.table tbody tr:hover a,
body.theme-dark .table tbody tr:hover a {
    color: #4db3ff !important;
}

body.theme-dark table.table tbody tr:hover .badge,
body.theme-dark .table tbody tr:hover .badge {
    color: #ffffff !important;
}

/* Dark mode - login */
body.login-page.theme-dark {
    background: #111820 !important;
    color: #d7e0ea;
}

body.login-page.theme-dark .login-box {
    background: #1b252e !important;
    border: 1px solid #2d3a45;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

body.login-page.theme-dark .login-box h1 {
    color: #f3f7fb;
}

body.login-page.theme-dark .login-box p {
    color: #8ea0b2;
}

body.login-page.theme-dark .login-box label {
    color: #d7e0ea;
}

body.login-page.theme-dark .login-box input {
    background: #111820;
    color: #f3f7fb;
    border-color: #3a4a57;
}

body.login-page.theme-dark .login-box input:focus {
    border-color: #2d9bf0;
    box-shadow: 0 0 0 3px rgba(45, 155, 240, 0.16);
}

body.login-page.theme-dark .btn-primary {
    background: #0b7bd3;
    border-color: #0b7bd3;
}

/* =========================================
   Mejorar visibilidad de textos azules
   en modo oscuro
========================================= */

body.theme-dark {
    --accent-blue-strong: #2ea8ff;
    --accent-blue-hover: #59bbff;
}

/* Números de tarjetas del panel */
body.theme-dark .stat-card strong,
body.theme-dark .stat-card .stat-value,
body.theme-dark .stat-card .number,
body.theme-dark .card strong,
body.theme-dark .card .value {
    color: var(--accent-blue-strong) !important;
}

/* Links de clientes, teléfonos, emails */
body.theme-dark .table a,
body.theme-dark td a,
body.theme-dark .client-link,
body.theme-dark .phone-link,
body.theme-dark .email-link,
body.theme-dark .panel a:not(.btn),
body.theme-dark .crm-main a:not(.btn),
body.theme-dark .card a:not(.btn) {
    color: var(--accent-blue-strong) !important;
    text-decoration: none;
}

/* Hover/focus para que también se vea bien */
body.theme-dark .table a:hover,
body.theme-dark td a:hover,
body.theme-dark .client-link:hover,
body.theme-dark .phone-link:hover,
body.theme-dark .email-link:hover,
body.theme-dark .panel a:not(.btn):hover,
body.theme-dark .crm-main a:not(.btn):hover,
body.theme-dark .card a:not(.btn):hover {
    color: var(--accent-blue-hover) !important;
    text-decoration: underline;
}

/* Si algunos teléfonos/emails no son enlaces sino texto normal */
body.theme-dark .client-phone,
body.theme-dark .client-email,
body.theme-dark .client-name,
body.theme-dark .contact-value,
body.theme-dark .info-value {
    color: var(--accent-blue-strong) !important;
}

/* =========================================
   Dark mode - stronger blue contrast
   ========================================= */

body.theme-dark {
    --crm-blue-visible: #2ea8ff;
    --crm-blue-visible-hover: #6bc6ff;
}

/* Números grandes del panel */
body.theme-dark .stat-card,
body.theme-dark .stat-card * {
    color: #8ea0b2;
}

body.theme-dark .stat-card strong,
body.theme-dark .stat-card b,
body.theme-dark .stat-card div:last-child,
body.theme-dark .stat-card span:last-child,
body.theme-dark .stat-card .stat-number,
body.theme-dark .stat-card .stat-value {
    color: var(--crm-blue-visible) !important;
}

/* Enlaces dentro del contenido principal */
body.theme-dark .crm-main a:not(.btn),
body.theme-dark .crm-main table a:not(.btn),
body.theme-dark .crm-main td a:not(.btn),
body.theme-dark .crm-main .panel a:not(.btn) {
    color: var(--crm-blue-visible) !important;
    font-weight: 600;
}

/* Teléfonos y emails dentro de tablas, aunque no sean enlaces */
body.theme-dark .crm-main table td {
    color: #f3f7fb !important;
}

body.theme-dark .crm-main table td a {
    color: var(--crm-blue-visible) !important;
}

/* Texto de datos en fichas/cards */
body.theme-dark .crm-main .card,
body.theme-dark .crm-main .panel,
body.theme-dark .crm-main .stat-card {
    color: #f3f7fb;
}

body.theme-dark .crm-main .card a,
body.theme-dark .crm-main .panel a,
body.theme-dark .crm-main .stat-card a {
    color: var(--crm-blue-visible) !important;
}

/* Hover */
body.theme-dark .crm-main a:not(.btn):hover,
body.theme-dark .crm-main table a:not(.btn):hover {
    color: var(--crm-blue-visible-hover) !important;
    text-decoration: underline;
}

body.theme-dark .dashboard-card strong,
body.theme-dark .dashboard-card b,
body.theme-dark .dashboard-card .number,
body.theme-dark .dashboard-card .value,
body.theme-dark .summary-card strong,
body.theme-dark .summary-card b,
body.theme-dark .summary-card .number,
body.theme-dark .summary-card .value,
body.theme-dark .card-number,
body.theme-dark .card-value {
    color: #2ea8ff !important;
}

.crm-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.crm-logo {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    overflow: hidden;
    background: transparent;
    flex-shrink: 0;
}

.crm-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.login-brand {
    margin-bottom: 18px;
}

.login-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    overflow: hidden;
    background: transparent;
}

.login-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Logo dentro del CRM (barra superior) */
.crm-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.crm-logo {
    background: none !important;
    width: auto !important;
    height: auto !important;
    padding: 0 !important;
}

.crm-logo img,
.crm-logo-img {
    height: 34px;
    width: auto;
    display: block;
}

/* Logo en login */
.login-logo-img {
    height: 80px;
    width: auto;
    display: block;
    margin: 0 auto 16px auto;
}

/* =========================================
   Logo MyCRM - ajuste final
   ========================================= */

/* Contenedor del logo en la barra superior */
.crm-brand {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
}

/* Elimina el cuadro/fondo antiguo del logo */
.crm-logo {
    width: auto !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;

    background: transparent !important;
    background-color: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
}

/* Imagen del logo dentro del CRM */
.crm-logo img,
.crm-logo-img {
    height: 34px !important;
    width: auto !important;
    max-width: none !important;

    display: block !important;
    object-fit: contain !important;

    background: transparent !important;
    background-color: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* Nombre del CRM junto al logo */
.crm-brand span {
    color: inherit;
    font-weight: 700;
}

/* Logo en login */
.login-logo,
.login-logo-img {
    background: transparent !important;
    background-color: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
}

.login-logo-img {
    height: 72px !important;
    width: auto !important;
    display: block !important;
    object-fit: contain !important;
    margin: 0 auto 16px auto !important;
}

/* =========================================
   Login logo - tamaño correcto junto al título
   ========================================= */

.login-brand {
    margin-bottom: 20px !important;
}

.login-title-row {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    margin-bottom: 6px !important;
}

.login-title-row h1 {
    margin: 0 !important;
    line-height: 1.1 !important;
}

.login-logo-img {
    width: 42px !important;
    height: 42px !important;
    max-width: 42px !important;
    max-height: 42px !important;
    object-fit: contain !important;
    display: block !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    flex-shrink: 0 !important;
}

.login-brand p {
    margin: 0 !important;
}

/* =========================================
   Login brand igual que cabecera CRM
   ========================================= */

.login-brand {
    margin-bottom: 20px !important;
    text-align: left !important;
}

.login-brand-row {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 10px !important;
    margin: 0 0 8px 0 !important;
}

.login-brand-logo {
    width: 28px !important;
    height: 28px !important;
    max-width: 28px !important;
    max-height: 28px !important;
    object-fit: contain !important;
    display: block !important;
    flex: 0 0 28px !important;

    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.login-brand-row h1 {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    font-size: 30px !important;
    font-weight: 800 !important;
}

.login-brand p {
    margin: 0 !important;
    padding: 0 !important;
}