/* ===== Variables ===== */
:root {
    --clr-primary:       #2563EB;
    --clr-primary-hover: #1D4ED8;
    --clr-primary-light: #EFF6FF;
    --clr-bg:            #F1F5F9;
    --clr-surface:       #FFFFFF;
    --clr-text:          #1E293B;
    --clr-muted:         #64748B;
    --clr-border:        #E2E8F0;
    --clr-success:       #10B981;
    --clr-error:         #EF4444;
    --radius:            12px;
    --radius-sm:         8px;
    --shadow:            0 1px 3px rgba(0,0,0,.07), 0 4px 14px rgba(0,0,0,.06);
    --transition:        0.18s ease;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--clr-bg);
    color: var(--clr-text);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

.visually-hidden { display: none !important; }

/* ===== Layout ===== */
.app-container {
    max-width: 920px;
    margin: 0 auto;
    padding: 0 16px 64px;
}

/* ===== Header ===== */
.app-header {
    padding: 32px 0 24px;
    border-bottom: 1px solid var(--clr-border);
    margin-bottom: 28px;
}
.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}
.app-subtitle {
    font-size: 13px;
    color: var(--clr-muted);
    margin-top: 3px;
}

/* ===== Tabs ===== */
.tab-nav {
    display: flex;
    gap: 4px;
    background: var(--clr-surface);
    padding: 6px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow-x: auto;
}

.tab-btn {
    flex: 1;
    min-width: 130px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--clr-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    white-space: nowrap;
}
.tab-btn:hover:not([disabled]) {
    background: var(--clr-primary-light);
    color: var(--clr-primary);
}
.tab-btn.active {
    background: var(--clr-primary);
    color: #fff;
}
.tab-btn--disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

/* ===== Tab Panels ===== */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== Cards ===== */
.card {
    background: var(--clr-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}
.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 20px;
}

/* ===== Forms ===== */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-group label {
    font-size: 13px;
    font-weight: 500;
}
.required { color: var(--clr-primary); }

.form-group input {
    padding: 10px 14px;
    border: 1.5px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--clr-text);
    background: var(--clr-bg);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.form-group input:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.13);
    background: #fff;
}
.form-group input::placeholder { color: #adb5bd; }
.form-group input.input-error,
.form-group select.input-error { border-color: var(--clr-error); }

.form-group select {
    padding: 10px 14px;
    border: 1.5px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--clr-text);
    background: var(--clr-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748B' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 14px center;
    appearance: none;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}
.form-group select:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.13);
    background-color: #fff;
}
.form-group select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

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

.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 24px;
}
.form-actions__right {
    display: flex;
    gap: 10px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.btn-primary {
    background: var(--clr-primary);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: var(--clr-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(37,99,235,.3);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--clr-bg);
    color: var(--clr-text);
    border: 1.5px solid var(--clr-border);
}
.btn-secondary:hover:not(:disabled) { background: var(--clr-border); }

.btn-danger {
    background: #FEE2E2;
    color: #B91C1C;
    border: 1.5px solid #FECACA;
}
.btn-danger:hover:not(:disabled) {
    background: var(--clr-error);
    color: #fff;
    border-color: var(--clr-error);
}

.btn:disabled { opacity: 0.58; cursor: not-allowed; }

/* ===== Search ===== */
.search-card { margin-bottom: 20px; }
.search-bar {
    display: flex;
    gap: 10px;
}
.search-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--clr-text);
    background: var(--clr-bg);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.search-bar input:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.13);
    background: #fff;
}
.search-bar input::placeholder { color: #adb5bd; }

/* ===== Results grid ===== */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 16px;
}

/* ===== Contact card ===== */
.contact-card {
    background: var(--clr-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-left: 4px solid var(--clr-primary);
    transition: transform var(--transition), box-shadow var(--transition);
}
.contact-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,.1);
}
.contact-card__business {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--clr-primary);
}
.contact-card__name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--clr-text);
}
.contact-card__details {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 2px;
}
.contact-detail {
    display: flex;
    gap: 8px;
    font-size: 13px;
    color: var(--clr-muted);
    align-items: baseline;
}
.contact-detail .lbl {
    font-weight: 600;
    color: var(--clr-text);
    min-width: 88px;
    flex-shrink: 0;
    font-size: 12px;
}
.contact-card .btn {
    align-self: flex-start;
    margin-top: 6px;
    padding: 8px 18px;
    font-size: 13px;
}

/* ===== Empty / loading states ===== */
.empty-state {
    grid-column: 1 / -1;
    background: var(--clr-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 52px 24px;
    text-align: center;
    color: var(--clr-muted);
}
.empty-state strong { display: block; font-size: 1rem; color: var(--clr-text); margin-bottom: 6px; }

/* ===== Coming soon ===== */
.coming-soon-card {
    text-align: center;
    padding: 72px 24px;
}
.coming-soon-icon { font-size: 3rem; margin-bottom: 16px; }
.coming-soon-card p { color: var(--clr-muted); margin-top: 8px; }

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,.48);
    backdrop-filter: blur(2px);
}
.modal-content {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 680px;
    max-height: 92vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.modal-header .card-title { margin-bottom: 20px; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--clr-muted);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
    transition: background var(--transition);
    margin-bottom: 16px;
}
.modal-close:hover { background: var(--clr-bg); }

/* ===== Spinner ===== */
.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: inline-block;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 13px 26px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    z-index: 200;
    box-shadow: 0 6px 24px rgba(0,0,0,.2);
    white-space: nowrap;
    animation: slideUp .22s ease;
}
.toast--success { background: var(--clr-success); }
.toast--error   { background: var(--clr-error); }
@keyframes slideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Header with logout ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-main { flex: 1; }
.btn-logout, .btn-theme {
    font-size: 13px;
    padding: 8px 16px;
}

/* ===== Header actions (theme + logout) ===== */
.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ===== Dark mode ===== */
[data-theme="dark"] {
    --clr-primary:       #3B82F6;
    --clr-primary-hover: #60A5FA;
    --clr-primary-light: #1E3A5F;
    --clr-bg:            #0F172A;
    --clr-surface:       #1E293B;
    --clr-text:          #F1F5F9;
    --clr-muted:         #94A3B8;
    --clr-border:        #334155;
    --shadow:            0 1px 3px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
}

[data-theme="dark"] .btn-danger {
    background: #450a0a;
    color: #FCA5A5;
    border-color: #7f1d1d;
}
[data-theme="dark"] .btn-danger:hover:not(:disabled) {
    background: #7f1d1d;
    color: #fff;
    border-color: #991b1b;
}

[data-theme="dark"] .btn-success {
    background: #064e3b;
    color: #6ee7b7;
    border-color: #065f46;
}
[data-theme="dark"] .btn-success:hover:not(:disabled) {
    background: #059669;
    color: #fff;
    border-color: #059669;
}

[data-theme="dark"] .badge--vendedor,
[data-theme="dark"] .badge--activo,
[data-theme="dark"] .badge--principal  { background: #052e16; color: #4ade80; }
[data-theme="dark"] .badge--inactivo   { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .badge--secundario { background: rgba(255,255,255,.05); border-color: var(--clr-border); }

[data-theme="dark"] .users-table tbody tr:hover td { background: rgba(255,255,255,.03); }

[data-theme="dark"] .filter-row select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394A3B8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
}
[data-theme="dark"] .filter-row select:focus { background-color: #1e3a5f; }

[data-theme="dark"] .form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394A3B8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
}

[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group select:focus,
[data-theme="dark"] .search-bar input:focus {
    background: #1e3a5f;
    box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}

/* ===== Card header row (título + botón lado a lado) ===== */
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.card-header-row .card-title { margin-bottom: 0; }

/* ===== Botón pequeño ===== */
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ===== Botón éxito ===== */
.btn-success {
    background: #d1fae5;
    color: #065f46;
    border: 1.5px solid #a7f3d0;
}
.btn-success:hover:not(:disabled) {
    background: var(--clr-success);
    color: #fff;
    border-color: var(--clr-success);
}

/* ===== Tabla de usuarios ===== */
.users-table-wrapper { overflow-x: auto; }
.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.users-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--clr-muted);
    border-bottom: 2px solid var(--clr-border);
    white-space: nowrap;
}
.users-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--clr-border);
    vertical-align: middle;
}
.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr:hover td { background: var(--clr-bg); }
.table-empty {
    text-align: center;
    padding: 40px;
    color: var(--clr-muted);
}
.table-actions { display: flex; gap: 6px; }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
}
.badge--admin      { background: var(--clr-primary-light); color: var(--clr-primary); }
.badge--vendedor   { background: #f0fdf4; color: #15803d; }
.badge--activo     { background: #f0fdf4; color: #15803d; }
.badge--inactivo   { background: #fef2f2; color: #b91c1c; }
.badge--principal  { background: #f0fdf4; color: #15803d; }
.badge--secundario { background: var(--clr-bg); color: var(--clr-muted); border: 1px solid var(--clr-border); }

/* ===== Hint de campo ===== */
.field-hint {
    font-size: 12px;
    color: var(--clr-muted);
    margin-top: 2px;
}

/* ===== Toggle switch ===== */
.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}
.toggle-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-track {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    background: var(--clr-border);
    border-radius: 12px;
    cursor: pointer;
    transition: background var(--transition);
    flex-shrink: 0;
}
.toggle-input:checked + .toggle-track {
    background: var(--clr-primary);
}
.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    pointer-events: none;
}
.toggle-input:checked + .toggle-track .toggle-thumb {
    transform: translateX(20px);
}
.toggle-text {
    font-size: 13px;
    color: var(--clr-muted);
    font-weight: 500;
    min-width: 18px;
}

/* ===== Login page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}
.login-container {
    width: 100%;
    max-width: 420px;
}
.login-card { padding: 36px 32px; }
.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo h1 { font-size: 1.4rem; font-weight: 700; }
.btn--full { width: 100%; }
.btn-theme--corner {
    position: fixed;
    top: 16px;
    right: 16px;
    font-size: 13px;
    padding: 8px 14px;
    z-index: 10;
}

/* ===== Modal de confirmación ===== */
.confirm-content {
    max-width: 440px;
}
.confirm-message {
    font-size: 14px;
    color: var(--clr-muted);
    line-height: 1.6;
    margin-bottom: 24px;
}

/* ===== Fila de filtros ===== */
.filter-row {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}
.filter-row select {
    flex: 1;
    min-width: 140px;
    padding: 8px 32px 8px 12px;
    border: 1.5px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--clr-text);
    background: var(--clr-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748B' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center;
    appearance: none;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.filter-row select:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.13);
    background-color: #fff;
}

/* ===== Tabla de contactos ===== */
.contacts-table-card { padding: 0; overflow: hidden; }
.tabla-info {
    padding: 10px 16px;
    font-size: 12px;
    color: var(--clr-muted);
    border-bottom: 1px solid var(--clr-border);
}

/* ===== Paginación ===== */
.paginacion {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
    flex-wrap: wrap;
}
.paginacion-ellipsis {
    padding: 0 4px;
    color: var(--clr-muted);
    font-size: 14px;
    user-select: none;
}

/* ===== Responsive — tablet (≤768px) ===== */
@media (max-width: 768px) {
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

/* ===== Responsive — móvil (≤580px) ===== */
@media (max-width: 580px) {
    /* Header: título arriba, botones abajo alineados a la derecha */
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 20px 0 16px;
    }
    .app-header h1 { font-size: 1.2rem; }
    .header-actions {
        width: 100%;
        justify-content: flex-end;
    }
    .btn-logout, .btn-theme { font-size: 12px; padding: 8px 12px; }

    /* Formularios */
    .card { padding: 20px 16px; }
    .form-grid { grid-template-columns: 1fr; }

    /* Búsqueda */
    .search-bar { flex-direction: column; }
    .search-bar input, .search-bar .btn { width: 100%; }

    /* Tabs */
    .tab-nav { gap: 2px; padding: 4px; }
    .tab-btn { font-size: 12px; padding: 9px 10px; min-width: 0; flex: 1; }

    /* Modal */
    .modal { padding: 8px; }
    .modal-content { max-height: 96vh; }
    .modal-header .card-title { font-size: 1rem; }

    /* Botones del modal: apilar en móvil */
    .form-actions { flex-direction: column; gap: 8px; }
    .form-actions__right { width: 100%; justify-content: flex-end; }
    .btn-danger { align-self: flex-start; }

    /* Toast */
    .toast { width: calc(100% - 32px); text-align: center; white-space: normal; }

    /* Login */
    .login-card { padding: 28px 20px; }
}
