/* css/app.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-gradient: linear-gradient(135deg, #f0f4ff 0%, #e0e7ff 100%);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --sidebar-width: 280px;
    --header-height: 70px;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--glass-shadow);
}

.glass-button {
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    transition: all 0.2s ease;
}

.glass-button:hover {
    background: rgba(255, 255, 255, 0.8);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* Toolbar Buttons (for analysis actions like Create Net, Top 2 Box, etc.) */
.toolbar-btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toolbar-btn:hover {
    background: white;
    border-color: #cbd5e1;
    color: #1e293b;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.toolbar-btn.primary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-color: transparent;
    color: white;
}

.toolbar-btn.primary:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Inline Export Buttons (below tables) */
.inline-export-btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s ease;
}

.inline-export-btn:hover {
    background: white;
    border-color: #cbd5e1;
    color: #1e293b;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Chart Display Toggle */
.chart-display-toggle {
    display: inline-flex;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 2px;
    margin-right: 0.5rem;
}

.toggle-mode-btn {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    color: #64748b;
}

.toggle-mode-btn.active {
    background: #3b82f6;
    color: white;
}

.toggle-mode-btn:hover:not(.active) {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.toggle-mode-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Layout */
.app-shell {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    /* Slightly more opaque for contrast */
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.6);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    box-sizing: border-box;
    z-index: 20;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-blue);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
}

.user-profile {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* Main Content */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.top-bar {
    height: var(--header-height);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.content-area {
    flex: 1;
    padding: 0 2rem 2rem 2rem;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Variable List (in Sidebar) */
.search-box {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    background: rgba(255, 255, 255, 0.6);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
}

.search-box:focus {
    background: white;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.var-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.var-item {
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.25rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}

.var-item:hover {
    background: rgba(255, 255, 255, 0.6);
}

.var-item.active {
    background: white;
    border-color: var(--accent-blue);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.var-id {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: monospace;
    opacity: 0.7;
}

.var-label {
    font-size: 0.85rem;
    font-weight: 500;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Cards & Panels */
.card {
    background: rgba(255, 255, 255, 0.6);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    margin-bottom: 2rem;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    margin-top: 0;
    margin-bottom: 1.5rem;
}

/* File Upload Button (Hero) */
.upload-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
}

.upload-btn-lg {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    padding: 1rem 2.5rem;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.25);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.upload-btn-lg:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 15px 35px rgba(59, 130, 246, 0.35);
}

/* Tables */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    text-align: left;
    padding: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

td {
    padding: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    color: var(--text-main);
}

tr:last-child td {
    border-bottom: none;
}

/* Loading Spinner */
.spinner {
    border: 3px solid rgba(59, 130, 246, 0.1);
    border-top: 3px solid var(--accent-blue);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}


/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: fadeIn 0.2s forwards;
    pointer-events: auto;
    /* Ensure clicks are captured */
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.modal {
    background: #ffffff;
    /* Solid background for legibility */
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    transform: scale(0.95);
    animation: scaleUp 0.2s forwards;
}

@keyframes scaleUp {
    to {
        transform: scale(1);
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    background: #f8fafc;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
    box-sizing: border-box;
}

.form-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-main);
}

/* Recode Rules */
.recode-rule {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

/* Pending Edits */
.pending-edit-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.pending-edit-description {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
}

.pending-edit-type {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: #3b82f6;
    color: white;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.pending-edit-remove {
    padding: 0.25rem 0.75rem;
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.pending-edit-remove:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #dc2626;
}

/* Report Builder */
.report-item-card {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 1.5rem;
    transition: all 0.2s ease;
    cursor: default;
}

.report-item-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.report-item-card.dragging {
    opacity: 0.5;
    border: 2px dashed #3b82f6;
}

.report-item-number {
    width: 28px;
    height: 28px;
    background: #3b82f6;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.ai-summary-card {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.ai-summary-card .summary-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #1e40af;
}

.ai-summary-loading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.report-chart-preview {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.report-chart-preview img {
    max-width: 100%;
    height: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.report-table-content {
    max-height: 400px;
    overflow-y: auto;
}