/* ==========================================================================
   1. VARIABLES Y RESET GENERAL
   ========================================================================== */
:root {
    --bg-dark: #070f1a;
    --text-primary: #ffffff;
    --text-secondary: #8ba1b8;
    --glass-bg: rgba(18, 25, 43, 0.4);
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary-color: #0ea5e9;
    --primary-hover: #0284c7;
    --accent-red: #ef4444;
    --accent-green: #22c55e;
    --card-hover-bg: rgba(255, 255, 255, 0.03);

    --shadow-soft: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --gradient-1: linear-gradient(135deg, #0ea5e9 0%, #2dd4bf 100%);
    --gradient-2: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    /* NUEVO: Suavizado de fuentes para Dark Mode */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   2. FONDOS ANIMADOS Y ESTRUCTURA
   ========================================================================== */
.background-elements {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    filter: blur(80px);
    opacity: 0.5;
    border-radius: 50%;
    animation: float 20s infinite ease-in-out alternate;
}

.shape-1 {
    width: 500px;
    height: 500px;
    background: var(--gradient-1);
    top: -10%;
    left: -10%;
}

.shape-2 {
    width: 400px;
    height: 400px;
    background: var(--gradient-2);
    bottom: -10%;
    right: -5%;
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(100px, 50px) rotate(20deg); }
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

/* ==========================================================================
   3. CABECERA (HEADER) Y BOTONES
   ========================================================================== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--glass-border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
}

.logo i { color: var(--primary-color); font-size: 2rem; }
.logo span { color: var(--text-secondary); font-weight: 300; }

.header-actions { display: flex; align-items: center; gap: 0.8rem; }

/* Botones Principales */
.primary-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

/* NUEVO: Estilos de focus para accesibilidad */
.primary-btn:focus-visible,
.tab:focus-visible,
.secondary-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.secondary-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--glass-border);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.secondary-btn:hover {
    color: white;
    border-color: white;
    background: rgba(255, 255, 255, 0.05);
}

.danger-btn {
    background: var(--accent-red);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.danger-btn:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* Iconos interactivos en tarjetas */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    color: var(--accent-red);
    background: rgba(244, 63, 94, 0.1);
}

.icon-btn.visit-btn:hover,
.icon-btn.edit-btn:hover {
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

/* ==========================================================================
   4. FILTROS Y BÚSQUEDA
   ========================================================================== */
.filters-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 2.5rem;
    align-items: center;
}

.categories-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
    grid-column: span 1;
}

.category-tabs {
    display: flex;
    gap: 0.5rem;
    background: var(--glass-bg);
    padding: 0.5rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    overflow-x: auto;
    white-space: nowrap;
}

.category-tabs::-webkit-scrollbar { height: 6px; }
.category-tabs::-webkit-scrollbar-track { background: transparent; margin: 0 10px; }
.category-tabs::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }

.tab {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.tab:hover { color: white; }

.tab.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.search-bar {
    display: flex;
    align-items: center;
    height: 52px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0 1rem;
    width: 100%;
    backdrop-filter: blur(16px);
    transition: border-color 0.3s ease;
    flex-shrink: 0;
    box-sizing: border-box;
}

.search-bar:focus-within { border-color: var(--primary-color); }

.search-bar i {
    color: var(--text-secondary);
    font-size: 1.25rem;
    margin-right: 0.5rem;
}

.search-bar input {
    background: transparent;
    border: none;
    color: white;
    width: 100%;
    outline: none;
    font-size: 0.95rem;
}

/* ==========================================================================
   5. CUADRÍCULA DE TARJETAS (CARDS)
   ========================================================================== */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
}

.card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease, border-color 0.4s ease;
    animation: fadeIn 0.6s ease forwards;
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(30, 32, 40, 0.8);
}

.card-header-bg {
    height: 100px;
    width: 100%;
    background: linear-gradient(45deg, #111, #333);
    position: relative;
    opacity: 0.9;
}

.card-icon-wrapper {
    width: 48px;
    height: 48px;
    background: #1e2028;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: -24px;
    left: 1.5rem;
    font-size: 1.5rem;
    color: white;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    z-index: 2;
}

.card-content {
    padding: 2.5rem 1.5rem 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-category {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: white;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.card-footer-actions { display: flex; gap: 0.5rem; }

.visit-link {
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--text-secondary);
    padding: 0.5rem 0;
    transition: color 0.3s ease;
    flex-shrink: 0;
}

.visit-link i {
    font-size: 1.1rem;
    margin: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.visit-link:hover { color: var(--primary-color); }
.visit-link:hover i { transform: translateX(4px) translateY(-4px); }

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.empty-state i { font-size: 4rem; color: rgba(255, 255, 255, 0.1); }

/* ==========================================================================
   6. VENTANAS MODALES
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active { opacity: 1; pointer-events: all; }

.modal-content {
    width: 100%;
    max-width: 500px;
    padding: 2rem;
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal-content { transform: translateY(0); }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.close-btn:hover { background: var(--accent-red); }

/* Inputs y Formularios */
.input-group {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label { font-size: 0.9rem; color: var(--text-secondary); font-weight: 500; }

.input-group input,
.input-group select,
.input-group textarea {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

.input-group textarea { resize: none; }

.input-group input:focus,
.input-group select:focus,
.input-group textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 2rem; }

/* Modal de Confirmación */
.confirm-modal-content { max-width: 360px !important; text-align: center; padding: 2.5rem 2rem !important; }
.confirm-icon {
    width: 60px; height: 60px;
    background: rgba(239, 68, 68, 0.15);
    border: 2px solid rgba(239, 68, 68, 0.3);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1.25rem;
    font-size: 1.75rem;
    color: var(--accent-red);
}
.confirm-modal-content h3 { font-size: 1.2rem; margin-bottom: 0.5rem; color: white; }
.confirm-modal-content p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0; }
#confirmModal .danger-btn { min-width: 140px; justify-content: center; }
#confirmModal .danger-btn:not(:contains("Eliminar")) { background: var(--accent-red); }

#authError {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0; margin-bottom: 0;
    min-height: 0; max-height: 0; opacity: 0;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
#authError.show { margin-top: 0.75rem; margin-bottom: 0.25rem; max-height: 60px; opacity: 1; }

/* ==========================================================================
   7. COMPONENTES PERSONALIZADOS (Dropdown e Iconos)
   ========================================================================== */
.custom-select {
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
    min-height: 46px;
}

.custom-select:hover, .custom-select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.15);
}

.custom-select.open { border-color: var(--primary-color); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

.custom-select-text { color: white; font-size: 1rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-text.placeholder { color: rgba(139, 161, 184, 0.7); }
.custom-select-arrow { font-size: 1.2rem; color: var(--text-secondary); transition: transform 0.25s ease; flex-shrink: 0; }
.custom-select.open .custom-select-arrow { transform: rotate(180deg); }

.custom-dropdown {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    background: #0e1729;
    border: 1px solid var(--primary-color);
    border-top: none;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    z-index: 200;
    overflow: hidden;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.custom-dropdown.open { display: block; }

.custom-dropdown-search { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--glass-border); }
.custom-dropdown-search i { color: var(--text-secondary); font-size: 1.1rem; flex-shrink: 0; }
.custom-dropdown-search input { background: transparent; border: none; color: white; width: 100%; outline: none; font-size: 0.95rem; }

.custom-dropdown-list { max-height: 180px; overflow-y: auto; }
.custom-dropdown-list::-webkit-scrollbar { width: 5px; }
.custom-dropdown-list::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.1); }
.custom-dropdown-list::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }

.dropdown-item {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.65rem 1rem;
    cursor: pointer;
    transition: background 0.15s ease;
    color: var(--text-secondary);
    font-size: 0.95rem;
}
.dropdown-item i { font-size: 1.1rem; flex-shrink: 0; }
.dropdown-item span { flex: 1; }
.dropdown-item:hover, .dropdown-item.highlighted { background: rgba(255, 255, 255, 0.06); color: white; }
.dropdown-item.selected { color: var(--primary-color); background: rgba(14, 165, 233, 0.08); }

.custom-dropdown-new { border-top: 1px solid var(--glass-border); padding: 0.4rem 0.5rem; }
.dropdown-create-btn {
    display: flex; align-items: center; gap: 0.5rem; width: 100%;
    background: rgba(14, 165, 233, 0.1);
    border: 1px dashed rgba(14, 165, 233, 0.4);
    border-radius: 6px;
    color: var(--primary-color);
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem; font-weight: 500;
    transition: all 0.2s ease;
}
.dropdown-create-btn:hover { background: rgba(14, 165, 233, 0.2); border-color: var(--primary-color); }

/* Icon Picker */
.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 0.4rem;
    max-height: 185px;
    overflow-y: auto;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
}
.icon-picker-grid::-webkit-scrollbar { width: 5px; }
.icon-picker-grid::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.1); border-radius: 4px; }
.icon-picker-grid::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }

.icon-option {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0.45rem 0.25rem;
    transition: all 0.2s ease;
}
.icon-option i { font-size: 1.3rem; display: block; }
.icon-option span { font-size: 0.58rem; font-family: 'Inter', sans-serif; line-height: 1; text-align: center; color: var(--text-secondary); }
.icon-option:hover { background: rgba(14, 165, 233, 0.12); border-color: rgba(14, 165, 233, 0.4); color: white; transform: scale(1.05); }
.icon-option:hover span { color: white; }
.icon-option.selected { background: rgba(14, 165, 233, 0.2); border-color: var(--primary-color); color: var(--primary-color); box-shadow: 0 0 8px rgba(14, 165, 233, 0.3); }
.icon-option.selected span { color: var(--primary-color); }

/* ==========================================================================
   8. RESPONSIVE
   ========================================================================== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 1024px) { .categories-header { grid-column: 1 / span 2; } }

@media (max-width: 768px) {
    .app-container { padding: 1rem; }
    header { flex-direction: column; gap: 1.5rem; align-items: stretch; margin-bottom: 2rem; padding-bottom: 1.5rem; }
    .logo { justify-content: center; }
    .primary-btn { justify-content: center; }
    .header-actions { width: 100%; justify-content: space-between; }
    .filters-section { flex-direction: column; align-items: stretch; gap: 1rem; margin-bottom: 2rem; }
    .category-tabs { width: 100%; overflow-x: auto; padding-bottom: 0.5rem; -ms-overflow-style: none; scrollbar-width: none; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
    .category-tabs::-webkit-scrollbar { display: none; }
    .tab { white-space: nowrap; flex-shrink: 0; scroll-snap-align: start; }
    .search-bar { width: 100%; max-width: calc(100vw - 2rem); }
    .cards-grid { grid-template-columns: 1fr; gap: 1.5rem; }
    .modal-content { margin: 1rem; padding: 1.5rem; width: calc(100% - 2rem); }
    .modal-actions { flex-direction: column-reverse; gap: 0.75rem; }
    .modal-actions button { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
    .card-content { padding: 2.5rem 1.25rem 1.25rem; }
    .card-footer { flex-direction: row; align-items: center; justify-content: space-between; gap: 0; }
    .card-footer-actions { width: auto; }
    .shape-1 { width: 300px; height: 300px; }
    .shape-2 { width: 250px; height: 250px; }
    .icon-picker-grid { grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); max-height: 150px; }
}