:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --bg-app: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --border-radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.6;
}

.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

/* HEADER */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 24px 30px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
}

.app-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: white;
    margin: 0;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    backdrop-filter: blur(10px);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.btn-editing {
    background-color: #10b981;
    color: white;
}

.btn-editing:hover {
    background-color: #059669;
}

/* PORTFOLIO SECTION */
.portfolio-section {
    margin-bottom: 30px;
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.portfolio-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--border-color);
}

.portfolio-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

.add-ticker-form {
    display: flex;
    gap: 10px;
}

.add-ticker-form input {
    padding: 10px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    min-width: 150px;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.add-ticker-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.add-ticker-form button {
    padding: 10px 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
}

.add-ticker-form button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.add-ticker-form button:active {
    transform: translateY(0);
}

/* PORTFOLIO LIST */
.portfolio-list {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding: 10px 0;
    list-style: none;
    scroll-behavior: smooth;
}

.portfolio-list::-webkit-scrollbar {
    height: 8px;
}

.portfolio-list::-webkit-scrollbar-track {
    background: var(--bg-app);
    border-radius: 4px;
}

.portfolio-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.portfolio-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* PORTFOLIO CARDS */
.portfolio-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 280px;
    max-width: 280px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    cursor: pointer;
}

.portfolio-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
}

.portfolio-card.loading-card {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stock-ticker {
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stock-name {
    font-size: 0.9rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stock-price {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 4px;
}

.view-btn {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    width: 100%;
    margin-top: auto;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.view-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.view-btn:active {
    transform: translateY(0);
}

.remove-btn {
    background: transparent;
    color: #ef4444;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
    transition: all 0.2s ease;
    border-radius: 4px;
}

.remove-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    transform: scale(1.1);
}

/* GRIDSTACK & CARDS */
.grid-stack {
    margin-bottom: 40px;
}

.grid-stack-item-content {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    padding: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all 0.2s ease;
}

.grid-stack-item-content:hover {
    box-shadow: var(--shadow-lg);
}

.card {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.card h3 {
    margin-top: 0;
    margin-bottom: 16px;
    flex-shrink: 0;
    color: var(--text-main);
    font-size: 1.1rem;
    font-weight: 600;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.chart-container {
    flex-grow: 1;
    position: relative;
    min-height: 0;
}

.widget-content {
    flex-grow: 1;
    width: 100%;
    height: 100%;
}

/* CHART CONTROLS */
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.chart-header h3 {
    margin: 0;
    padding: 0;
    border: none;
}

.chart-controls {
    display: flex;
    gap: 6px;
    background: var(--bg-app);
    padding: 4px;
    border-radius: 8px;
}

.period-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.period-btn:hover {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.period-btn.active {
    background: var(--primary);
    color: white;
}

.time-range-controls {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.time-range-btn {
    padding: 5px 10px;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.time-range-btn:hover {
    background: var(--bg-app);
    border-color: var(--primary);
    color: var(--primary);
}

.time-range-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* DCF Calculator Styles */
.dcf-calc-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 100%;
}

.dcf-result {
    text-align: center;
    padding: 1.25rem;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(5, 150, 105, 0.1) 100%);
    border-radius: 0.75rem;
    border: 2px solid rgba(16, 185, 129, 0.3);
}

.dcf-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.dcf-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: #10b981;
}

.dcf-result-sub {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-app);
    border-radius: 0.5rem;
    font-size: 0.9rem;
}

.dcf-label-sub {
    color: var(--text-secondary);
    font-weight: 500;
}

.dcf-value-sub {
    font-weight: 600;
    color: var(--text-main);
}

.dcf-inputs {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.two-column-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.dcf-inputs .input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0;
    border: none;
    padding: 0;
}

.input-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.input-row label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.input-row input {
    background: var(--bg-app);
    border: 2px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.5rem;
    color: var(--text-main);
    font-size: 0.875rem;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.input-row input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toggle-row label {
    font-size: 0.875rem;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.toggle-row input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
}

/* Projection Table */
.dcf-projection-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.dcf-projection-table th,
.dcf-projection-table td {
    padding: 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.dcf-projection-table th:first-child,
.dcf-projection-table td:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--bg-card);
    z-index: 1;
    font-weight: 600;
}

.dcf-projection-table th {
    color: var(--text-secondary);
    font-weight: 600;
    background: var(--bg-app);
}

.dcf-projection-table .proj-col {
    background: rgba(59, 130, 246, 0.08);
}

.dcf-projection-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.03);
}

/* Data Tables */
.table-responsive {
    overflow-x: auto;
    /* height: 100%; ELIMINADA para evitar doble scroll */
    /* overflow-y: auto; ELIMINADA para evitar doble scroll */
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: var(--bg-app);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table tr:hover {
    background-color: rgba(37, 99, 235, 0.03);
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* Loading & Error States */
.loading {
    text-align: center;
    padding: 60px 40px;
    font-size: 1.2rem;
    color: var(--text-muted);
}

.error {
    color: #ef4444;
    text-align: center;
    padding: 20px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.placeholder-text {
    text-align: center;
    color: var(--text-muted);
    margin-top: 60px;
    font-size: 1.2rem;
    padding: 40px;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 2px dashed var(--border-color);
}

/* Gridstack Interaction */
.grid-stack-item-content {
    cursor: grab;
}

.grid-stack-item-content:active {
    cursor: grabbing;
}

.grid-stack-item-content canvas,
.grid-stack-item-content .table-responsive,
.grid-stack-item-content .dcf-calc-container {
    cursor: default;
}

/* Utility Classes */
.text-green {
    color: #10b981 !important;
}

.text-red {
    color: #ef4444 !important;
}

/* Spinner for loading cards */
.spinner {
    width: 40px;
    height: 40px;
    margin: 20px auto;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    .portfolio-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .add-ticker-form {
        width: 100%;
    }

    .add-ticker-form input {
        flex: 1;
    }

    .two-column-grid {
        grid-template-columns: 1fr;
    }

    .portfolio-card {
        min-width: 240px;
        max-width: 240px;
    }
}