:root {
    --bg-dark: #09090b;
    --bg-panel: rgba(24, 24, 27, 0.75);
    --border: rgba(255, 255, 255, 0.08);
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.5);
    --success: #10b981;
    --success-hover: #059669;
    --error: #ef4444;
    --epic: #8b5cf6;
    --feature: #ec4899;
    --pbi: #3b82f6;
    --task: #eab308;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-dark);
    background-image:
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, .12), transparent 30%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, .12), transparent 30%);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container {
    max-width: 1500px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    gap: 1.5rem;
}

/* Header */
.glass-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: rgba(24, 24, 27, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    margin-bottom: 1rem;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--primary), var(--epic));
    border-radius: 8px;
    box-shadow: 0 0 18px var(--primary-glow);
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    background: rgba(139, 92, 246, .2);
    color: #c4b5fd;
    font-size: .7rem;
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid rgba(139, 92, 246, .3);
}

/* Buttons */
.btn {
    padding: .55rem 1.1rem;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: all .2s;
}

.btn.primary {
    background: var(--primary);
    color: #fff;
}

.btn.primary:hover {
    background: var(--primary-hover);
}

.btn.primary.glow {
    box-shadow: 0 0 20px var(--primary-glow);
}

.btn.secondary {
    background: #27272a;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.secondary:hover {
    background: #3f3f46;
}

.btn.sm {
    padding: .35rem .75rem;
    font-size: .75rem;
    flex-shrink: 0;
}

.btn.success {
    background: var(--success);
    color: #fff;
}

.btn.success:hover {
    background: var(--success-hover);
}

.btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.4rem;
    cursor: pointer;
}

/* Main layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Section headers */
.section-header {
    margin-bottom: 1.2rem;
}

.section-header.flex-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: .35rem;
}

.subtitle {
    color: var(--muted);
    font-size: .82rem;
    line-height: 1.5;
}

/* Input area */
.input-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
}

textarea {
    flex: 1;
    background: rgba(0, 0, 0, .25);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 1rem;
    font-family: inherit;
    font-size: .9rem;
    line-height: 1.6;
    resize: none;
    transition: border-color .2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 1.5rem;
    text-align: center;
    color: var(--muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(59, 130, 246, .2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Tree container */
.tree-container {
    flex: 1;
    overflow-y: auto;
    background: rgba(0, 0, 0, .2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tree-container.empty {
    align-items: center;
    justify-content: center;
}

.empty-state {
    text-align: center;
    color: var(--muted);
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

/* Stats row */
.stats-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.stat {
    flex: 1;
    background: rgba(255, 255, 255, .04);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-num {
    font-size: 1.4rem;
    font-weight: 700;
}

.stat-label {
    font-size: .7rem;
    color: var(--muted);
}

/* Tree nodes */
.tree-node {
    border-radius: 6px;
    padding: 8px 10px;
    animation: fadeIn .2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
    }
}

.epic-node {
    background: rgba(139, 92, 246, .1);
    border: 1px solid rgba(139, 92, 246, .35);
}

.feature-node {
    background: rgba(236, 72, 153, .08);
    border: 1px solid rgba(236, 72, 153, .3);
    margin-left: 20px;
}

.pbi-node {
    background: rgba(59, 130, 246, .08);
    border: 1px solid rgba(59, 130, 246, .3);
    margin-left: 40px;
}

.task-node {
    background: rgba(234, 179, 8, .07);
    border: 1px solid rgba(234, 179, 8, .25);
    margin-left: 60px;
}

.node-badge {
    display: inline-block;
    font-size: .65rem;
    font-weight: 600;
    color: #fff;
    padding: 2px 7px;
    border-radius: 10px;
    margin-bottom: 4px;
}

.node-title {
    font-size: .9rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.node-meta {
    font-size: .78rem;
    color: var(--muted);
    margin-top: 2px;
}

.ac-list {
    font-size: .78rem;
    color: var(--muted);
    margin-top: 6px;
}

.ac-list ul {
    padding-left: 16px;
}

.ac-list li {
    margin-bottom: 2px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    width: 500px;
    max-width: 95%;
    padding: 2rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: .85rem;
    font-weight: 500;
}

.form-group input,
.form-group select {
    background: rgba(0, 0, 0, .3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: #fff;
    padding: .7rem;
    font-family: inherit;
    font-size: .875rem;
    width: 100%;
}

.form-group select option {
    background: #18181b;
    color: #fff;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.input-with-action {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-action input {
    flex: 1;
}

.form-group small {
    color: var(--muted);
    font-size: .72rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.optional-badge {
    color: var(--error);
    font-size: .68rem;
    border: 1px solid var(--error);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 6px;
}

.sensitive-badge {
    color: var(--success);
    font-size: .68rem;
    border: 1px solid var(--success);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 6px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: .75rem 1.5rem;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    z-index: 200;
    animation: slideUp .3s ease;
}

.toast.hidden {
    display: none;
}

.toast.success {
    background: #10b981;
    color: #fff;
}

.toast.error {
    background: #ef4444;
    color: #fff;
}

.toast.info {
    background: #3b82f6;
    color: #fff;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(20px);
    }

    to {
        transform: translateX(-50%);
    }
}

.hidden {
    display: none !important;
}

/* --- RESPONSIVE DESIGN --- */

/* Tablets and small laptops */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .app-container {
        padding: 1rem;
    }
}

/* Mobile Devices */
@media (max-width: 768px) {
    .app-container {
        padding: 0.75rem;
        gap: 1rem;
    }

    .glass-header {
        flex-direction: row; /* Mantener en una fila si es posible */
        flex-wrap: wrap;
        gap: 0.75rem;
        padding: 1rem;
        justify-content: center;
    }

    .logo {
        width: 100%;
        justify-content: center;
        margin-bottom: 0.25rem;
    }

    .header-actions {
        display: flex;
        width: 100%;
        gap: 0.5rem;
    }

    .header-actions .btn {
        flex: 1;
        font-size: 0.8rem;
        padding: 0.6rem 0.4rem;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
    }

    .main-content {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .glass-panel {
        padding: 1rem;
        border-radius: 16px;
    }

    .section-header h2 {
        font-size: 1rem;
    }

    .stats-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat {
        min-width: 0;
        padding: 8px;
    }

    .stat-num {
        font-size: 1.1rem;
    }

    /* Ajuste de nodos del árbol */
    .tree-node {
        padding: 8px;
    }
    .feature-node { margin-left: 8px; }
    .pbi-node { margin-left: 16px; }
    .task-node { margin-left: 24px; }
}

/* Small Mobile */
@media (max-width: 480px) {
    .logo h1 {
        font-size: 1rem;
    }

    .badge {
        display: none;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    .stat-num {
        font-size: 1.1rem;
    }
    
    .modal-content {
        padding: 1rem;
    }
}

/* --- PWA INSTALL PROMPT --- */
.pwa-prompt {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(59, 130, 246, 0.5);
    border-radius: 20px;
    padding: 16px;
    z-index: 1000;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    animation: slideUp 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.pwa-content {
    display: grid;
    grid-template-columns: 48px 1fr auto;
    align-items: center;
    gap: 12px;
}

.pwa-icon {
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--epic));
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
}

.pwa-text strong {
    display: block;
    font-size: 1rem;
    color: #fff;
    margin-bottom: 2px;
}

.pwa-text p {
    font-size: 0.8rem;
    color: #94a3b8;
    margin: 0;
}

#btn-pwa-install {
    background: var(--primary);
    border-radius: 12px;
    padding: 10px 20px;
    font-weight: 700;
    box-shadow: 0 4px 15px var(--primary-glow);
}

#btn-pwa-close {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.1);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

@media (max-width: 768px) {
    .pwa-prompt {
        bottom: 10px;
        left: 10px;
        right: 10px;
        padding: 10px;
    }
    
    .pwa-icon {
        font-size: 1.5rem;
        width: 40px;
        height: 40px;
    }
}
