/* Base HTML and Body Styles */
html {
    font-size: 16px; /* Set a comfortable base font size for the whole site. */
}

/* General Body Styles */
body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    background-color: #f4f7f6;
    color: #333;
    line-height: 1.6;
}

/* Main Container */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* Navbar */
.navbar {
    background-color: #ffffff;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-bottom: 3px solid #0056b3;
}

.navbar-brand a {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0056b3;
    text-decoration: none;
}

.navbar-nav {
    display: flex;
    align-items: center;
    flex-direction: row; /* Ensure horizontal layout */
    gap: 1.5rem; /* Add space between items like the user group and logout button */
}

.nav-user {
    margin-right: 1.5rem;
    color: #555;
}

.nav-link-button {
    background-color: #007bff;
    color: #ffffff;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    text-decoration: none;
    transition: background-color 0.3s ease;
}

.nav-link-button:hover {
    background-color: #0056b3;
}

.user-nav-group {
    display: flex;
    align-items: center;
    gap: 1rem; /* Creates space between "Welcome", "Settings" */
}

/* Dashboard Content */
.dashboard-title {
    text-align: center;
    margin-bottom: 2rem;
    color: #2c3e50;
    font-weight: 300;
    font-size: 2.5rem;
}

/* Tool Grid */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.tool-card {
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
    padding: 2rem;
    text-align: center;
    text-decoration: none;
    color: inherit;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.tool-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.1);
}

.card-icon {
    font-size: 3rem;
    color: #007bff;
    margin-bottom: 1rem;
}

.card-title {
    margin: 0.5rem 0;
    color: #2c3e50;
    font-weight: 500;
}

.card-description {
    font-size: 0.9rem;
    color: #666;
    flex-grow: 1;
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 2rem 0;
    margin-top: 3rem;
    background-color: #e9ecef;
    color: #6c757d;
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
    }
    .navbar-nav {
        margin-top: 1rem;
    }
}

/* Login Prompt on Index Page */
.login-prompt {
    text-align: center;
    padding: 4rem 0;
}

/* Overriding card-description specifically for the login prompt for larger text */
.login-prompt .card-description {
    font-size: 1.2rem;
    margin-bottom: 2rem;
}

/* In static/style.css */

.forecaster-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 2rem;
    margin-top: 2rem;
}

.forecaster-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background-color: #f9f9f9;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.forecaster-controls label {
    font-weight: 500;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.forecaster-controls .button-primary {
    margin-top: 1.5rem;
}

.forecaster-graph {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Performance Tool Table Styles */
.stale-row {
    color: #999; /* Lighter text color for stale data */
    font-style: italic;
}

.data-freshness-note {
    background-color: #eef2f7;
    border-left: 4px solid #007bff;
    padding: 0.75rem 1.25rem;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* ==========================================================================
   Tool Page Styles (Forms, Tables, etc.)
   ========================================================================== */

.page-title {
    text-align: center;
    margin-bottom: 0.5rem;
    color: #2c3e50;
    font-weight: 300;
    font-size: 2.5rem;
}

.page-description {
    text-align: center;
    margin-bottom: 2.5rem;
    color: #666;
    font-size: 1.1rem;
}

.filter-form {
    background-color: #ffffff;
    padding: 1.5rem 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
    margin-bottom: 2rem;
}

/* This class is used in the new regression tool form */
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.form-group {
    flex: 1 1 200px; /* Flex-grow, flex-shrink, basis */
    display: flex;
    flex-direction: column;
}

.form-group-checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    flex-basis: 300px; /* Give it some space */
}

.form-group-checkbox input {
    width: auto; /* Let checkbox size itself */
}

.form-group-full-width {
    flex-basis: 100%;
}

.form-group label {
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

.form-group select,
.form-group input {
    padding: 0.6rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1rem;
}

.form-actions {
    text-align: right;
    margin-top: 1.5rem;
}

.button-primary {
    background-color: #007bff;
    color: #ffffff;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.button-secondary {
    background-color: #6c757d;
    color: #ffffff;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.button-primary:hover {
    background-color: #0056b3;
}

.results-section {
    margin-top: 2.5rem;
}

.results-section h2 {
    font-weight: 400;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Data Tables & Charts
   ========================================================================== */

.table-container,
.chart-container {
    overflow-x: auto; /* Allows horizontal scrolling on small screens */
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
    margin-bottom: 2rem;
}

.chart-subtitle {
    font-size: 1.2rem;
    font-weight: 500;
    color: #495057;
    margin-bottom: -1rem; /* Pull the chart container up slightly */
    margin-top: 2rem;
}
.chart-container {
    padding: 1rem;
}

.performance-summary-table,
.daily-perf-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.performance-summary-table th, .performance-summary-table td,
.daily-perf-table th, .daily-perf-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
    white-space: nowrap; /* Prevent wrapping for most columns */
}

.performance-summary-table tbody tr:last-child td,
.daily-perf-table tbody tr:last-child td {
    border-bottom: none;
}

.performance-summary-table thead th,
.daily-perf-table thead th {
    background-color: #f8f9fa;
    font-weight: 500;
    color: #495057;
    text-align: center;
    vertical-align: middle;
    border-bottom: 2px solid #dee2e6;
}

/* Column Specific Styles */
.col-product-name {
    text-align: left !important;
    white-space: normal !important; /* Allow product names to wrap */
    min-width: 250px;
    font-weight: 500;
}

.col-date {
    text-align: center;
    width: 110px;
}

.col-perf, .col-rank {
    font-family: 'Roboto Mono', monospace;
    text-align: right !important;
    width: 90px;
}

.col-rank {
    font-weight: 500;
    color: #495057;
    width: 60px;
}

/* Positive/Negative coloring for performance numbers */
.col-perf.positive {
    color: #28a745;
}

.col-perf.negative {
    color: #dc3545;
}

/* A box for displaying messages (e.g., errors, warnings) to the user */
.message-box {
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
    color: #856404;
    padding: 1rem;
    border-radius: 5px;
    margin: 2rem 0;
}
/* --- Regression Results Table --- */
.regression-results-table {
    font-size: 0.9rem;
    border-collapse: separate;
    border-spacing: 0;
}

.regression-results-table th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    white-space: nowrap;
    vertical-align: bottom;
    padding: 0.75rem;
}

.regression-results-table td {
    padding: 0.5rem 0.75rem;
}

.regression-results-table .col-product-name {
    font-weight: 500;
      text-align: left !important;
    white-space: normal !important;
    min-width: 250px;
    /* Make the first column sticky so it stays in view on horizontal scroll */
    position: sticky;
    left: 0;
    background-color: #ffffff; /* A background is needed to hide content scrolling behind it */
    z-index: 5;
    border-right: 1px solid #dee2e6;
}

/* Ensure the sticky header for the product name column is above other sticky headers */
.regression-results-table th.col-product-name {
    z-index: 15;
}

.regression-results-table .col-metric {
    font-family: 'Roboto Mono', monospace;
    text-align: right !important;
    white-space: nowrap;
    min-width: 120px;
}

.col-actions {
    text-align: center !important;
    white-space: nowrap;
}

.button-details {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.significance-legend {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: #6c757d;
    text-align: right;
}

/* Grid for laying out analysis charts */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr; /* Stack charts vertically by default */
    gap: 2.5rem;
}

/* For wider screens, use a two-column layout for charts */
@media (min-width: 1200px) {
    .chart-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Kalman Filter Summary Table */
.kalman-summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1rem; /* Normal font size */
    margin-bottom: 20px;
}

.kalman-summary-table th,
.kalman-summary-table td {
    padding: 8px 12px;
    border: 1px solid #ddd;
    text-align: left;
    word-wrap: break-word;
}

.kalman-summary-table th {
    background-color: #f2f2f2;
    font-weight: bold;
    text-align: center;
    vertical-align: bottom;
    height: 150px;
    position: relative;
}

.kalman-summary-table th > div {
    transform: rotate(-90deg);
    transform-origin: left bottom;
    position: absolute;
    bottom: 5px;
    left: 5px;
    white-space: nowrap;
    font-size: 1rem; /* Normal font size */
    padding-right: 10px;
}

/* First column not rotated */
.kalman-summary-table th:first-child {
    height: auto;
    white-space: normal;
}

.kalman-summary-table th:first-child > div {
    transform: none;
    position: static;
    white-space: normal;
}

.kalman-summary-table td:first-child {
    text-align: left;
    white-space: normal;
}

/* Align percentage columns to the right */
.kalman-summary-table td:not(:first-child) {
    text-align: right;
}

/* Styles for the Market Factor header with toggle switch */
.factor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem; /* Same as form-group label */
}

.toggle-switch-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 400;
    color: #495057;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px; /* smaller width */
    height: 24px; /* smaller height */
}

.toggle-switch input { display: none; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px; /* height */
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px; /* smaller circle */
    width: 18px;  /* smaller circle */
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider { background-color: #28a745; } /* Green for 'on' */
input:checked + .slider:before { transform: translateX(20px); }

/* Style for the 'Settings' text link in the navbar */
.navbar-nav .nav-link {
    color: #0056b3 !important; /* Use the brand blue and ensure it is not overridden */
    text-decoration: none; /* Remove default underline */
    padding: 0.5rem 0;
    transition: color 0.2s;
}

.navbar-nav .nav-link:hover {
    color: #003d80 !important; /* A darker shade for hover */
    text-decoration: underline; /* Add underline on hover for clickability */
}
