/* FundaMetriq Stock Screener - Template Styling */

:root {
    /* EXACT Template Colors - DO NOT CHANGE */
    --bg-main: #f3f4f6;              /* Light grey main background */
    --bg-sidebar: #1e293b;           /* Dark blue-grey sidebar */
    --bg-card-header: #1e293b;       /* Dark blue-grey card headers */
    --bg-card-body: #ffffff;         /* White card content */

    /* Text Colors */
    --text-on-dark: #ffffff;         /* White text on dark backgrounds */
    --text-primary: #1f2937;         /* Dark grey for main text */
    --text-secondary: #6b7280;       /* Medium grey for secondary text */

    /* Accent */
    --accent-primary: #3b82f6;       /* Blue for active states */
    --accent-hover: #334155;         /* Lighter bg for hover on sidebar */

    /* Spacing & Sizing */
    --sidebar-width: 280px;
    --sidebar-padding: 24px;
    --menu-item-height: 44px;
    --menu-item-gap: 4px;

    /* Cards/Widgets */
    --card-border-radius: 12px;
    --card-header-padding: 16px;
    --card-body-padding: 20px;
    --card-gap: 24px;

    /* Shadows */
    --shadow-card: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-card-hover: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* App Container - Sidebar Layout */
.app-container {
    display: flex;
    height: 100vh; /* Fixed height, no scroll */
    overflow: hidden; /* Prevent page scroll */
}

/* ========== SIDEBAR (280px) ========== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    z-index: 100;
    padding: var(--sidebar-padding);
}

.sidebar-header {
    margin-bottom: 32px;
}

.app-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-on-dark);
    margin: 0;
}

/* Navigation Menu */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: var(--menu-item-gap);
}

.nav-item {
    height: var(--menu-item-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-on-dark);
    text-decoration: none;
    border-radius: 8px;
    transition: all var(--transition-fast);
    background: transparent;
    border-left: 4px solid transparent;
}

.nav-item:hover {
    background: var(--accent-hover);
}

.nav-item.active {
    background: var(--accent-hover);
    border-left-color: var(--accent-primary);
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-text {
    font-size: 14px;
    font-weight: 400;
}

/* ========== MAIN WRAPPER ========== */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh; /* Fixed height */
    background: var(--bg-main);
    overflow: hidden; /* No scroll on wrapper */
}

/* ========== MAIN CONTENT ========== */
.main-content {
    padding: 32px;
    flex: 1;
    background: var(--bg-main);
    height: 100vh; /* Fixed height instead of min-height */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent page scroll - only table scrolls */
}

/* Search Bar in Main Content */
.search-container-main {
    margin-bottom: var(--card-gap);
}

.search-box {
    width: 100%;
    max-width: 600px;
    padding: 12px 16px;
    background: var(--bg-card-body);
    border: 1px solid #d1d5db;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-card);
}

.search-box:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-box::placeholder {
    color: var(--text-secondary);
}

/* ========== CARDS ========== */
.card {
    background: var(--bg-card-body);
    border-radius: var(--card-border-radius);
    box-shadow: var(--shadow-card);
    margin-bottom: var(--card-gap);
    overflow: hidden;
    transition: box-shadow var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-card-hover);
}

.card-header {
    background: var(--bg-card-header);
    padding: var(--card-header-padding);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-on-dark);
}

.card-title h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    color: var(--text-on-dark);
}

.title-icon {
    font-size: 18px;
}

.badge {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-on-dark);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    min-width: 24px;
    text-align: center;
}

.card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-on-dark);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.btn-text:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-icon-sm {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-on-dark);
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-sm:hover {
    background: rgba(255, 255, 255, 0.2);
}

.card-body {
    padding: var(--card-body-padding);
    background: var(--bg-card-body);
    transition: all var(--transition-base);
    max-height: 2000px;
    overflow: hidden;
}

.card-body.collapsed {
    max-height: 0;
    padding: 0 var(--card-body-padding);
}

/* ========== FILTERS ========== */
.filter-group {
    margin-bottom: 20px;
}

.filter-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.filter-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.pill-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill {
    padding: 8px 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.pill:hover {
    background: #f3f4f6;
    border-color: var(--accent-primary);
}

.pill.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.range-filter {
    display: flex;
    align-items: center;
    gap: 8px;
}

.range-input {
    flex: 1;
    padding: 8px 12px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition-fast);
}

.range-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.range-separator {
    color: var(--text-secondary);
    font-weight: 500;
}

/* ========== RESULTS BAR ========== */
.results-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg-card-body);
    border-radius: var(--card-border-radius);
    box-shadow: var(--shadow-card);
    margin-bottom: var(--card-gap);
}

.results-info {
    display: flex;
    gap: 8px;
    align-items: baseline;
}

.results-count {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-primary);
}

.results-text {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.results-actions {
    display: flex;
    gap: 12px;
}

.select-box {
    padding: 8px 12px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.select-box:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.btn-secondary {
    padding: 8px 16px;
    background: var(--accent-primary);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-card);
}

.btn-secondary:hover {
    background: #2563eb;
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

/* ========== TABLE ========== */
.table-card {
    box-shadow: var(--shadow-card);
    flex: 1; /* Grow to fill available space */
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex child to shrink */
    max-height: 100%; /* Don't exceed parent height */
    overflow: hidden; /* Contain the table within the card border */
    border: 2px solid #2d3e50; /* Donkerblauwgrijs kader zoals menubar */
    background: white;
}

.table-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    background: white;
    min-height: 300px; /* Minimum table height */
    border-radius: 0 0 var(--card-border-radius) var(--card-border-radius); /* Rounded bottom corners */
}

.table-container::-webkit-scrollbar {
    width: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: #f9fafb;
}

.table-container::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.stock-table {
    width: 100%;
    border-collapse: collapse;
}

.stock-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-card-header);
}

.stock-table th {
    padding: 8px 12px; /* Reduced from 16px */
    text-align: left;
    font-weight: 600;
    font-size: 11px; /* Reduced from 12px */
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-on-dark);
    cursor: pointer;
    user-select: none;
    transition: all var(--transition-fast);
    background: var(--bg-card-header);
    white-space: nowrap;
}

.stock-table th:hover {
    background: rgba(255, 255, 255, 0.05);
}

.sort-icon {
    margin-left: 4px;
    opacity: 0.6;
    font-size: 10px;
}

.stock-table th:hover .sort-icon {
    opacity: 1;
}

.stock-table tbody tr {
    border-bottom: 1px solid #e5e7eb;
    transition: all var(--transition-fast);
    cursor: pointer;
    background: white;
}

.stock-table tbody tr:hover {
    background: #f9fafb;
}

.stock-table tbody tr:nth-child(even) {
    background: #fafbfc; /* Subtle zebra striping like ShareScope */
}

.stock-table tbody tr:nth-child(even):hover {
    background: #f3f4f6;
}

.stock-table td {
    padding: 6px 12px; /* Reduced from 16px - more compact! */
    color: var(--text-primary);
    font-size: 13px; /* Reduced from 14px */
    line-height: 1.4;
    white-space: nowrap;
}

.stock-table td strong {
    color: var(--text-primary);
    font-weight: 600;
}

.loading-cell {
    text-align: center;
    padding: var(--spacing-xl) !important;
    color: var(--text-secondary);
}

/* ========== LOADING ========== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(236, 240, 241, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--spacing-md);
    z-index: 1000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-spinner.large {
    width: 60px;
    height: 60px;
    border-width: 5px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========== MODAL ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--card-border-radius);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    background: var(--bg-card-header);
    color: var(--text-on-dark);
    padding: var(--card-header-padding);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--card-border-radius) var(--card-border-radius) 0 0;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.modal-body {
    padding: var(--card-body-padding);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: var(--card-header-padding);
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.column-config-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.column-config-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    background: #f9fafb;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.column-config-item:hover {
    background: #f3f4f6;
}

.column-config-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.column-config-item label {
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    flex: 1;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1024px) {
    .sidebar {
        width: 70px;
    }

    .sidebar-header {
        padding: var(--spacing-md);
    }

    .logo {
        font-size: 16px;
        writing-mode: vertical-rl;
        text-orientation: mixed;
    }

    .nav-text {
        display: none;
    }

    .nav-item {
        justify-content: center;
    }

    .main-wrapper {
        margin-left: 70px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }

    .main-wrapper {
        margin-left: 60px;
    }

    .results-bar {
        flex-direction: column;
        gap: var(--spacing-md);
        align-items: stretch;
    }

    .results-actions {
        flex-direction: column;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }
}
