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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --card-bg: #ffffff;
    --text-primary: #1f2937;
    --text-main: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --bg-page: #f3f4f6;
    --bg-secondary: #f9fafb;
    --border: #e5e7eb;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

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

/* Sidebar Layout */
.sidebar-layout {
    display: flex;
    flex-direction: column;
}

.banner {
    background: linear-gradient(90deg, #1e293b 0%, #334155 100%);
    color: white;
    padding: 0.75rem 2rem;
    height: 3.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.banner-title {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.banner-powered-by {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-left: 1rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.banner-powered-by-text {
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

.banner-powered-by-logo {
    height: 18px;
    width: auto;
    opacity: 0.9;
    filter: brightness(0) invert(1); /* Force white for corporate look if needed */
}

.sidebar-container {
    display: flex;
    min-height: calc(100vh - 3.5rem);
}

.sidebar {
    width: 260px;
    background: white;
    border-right: 2px solid var(--border);
    padding: 1.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: sticky;
    top: 3.5rem;
    height: calc(100vh - 3.5rem);
    overflow-y: auto;
    scrollbar-width: thin;
}

.sidebar-footer {
    margin-top: auto;
    padding: 1rem 0.5rem 1rem 0.5rem;
    border-top: 1px solid var(--border);
    background: white;
    position: sticky;
    bottom: 0;
    z-index: 10;
    flex-shrink: 0;
}

.powered-by-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.powered-by-container:hover {
    opacity: 1;
}

.powered-by-text {
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.powered-by-logo-img {
    height: 14px;
    width: auto;
    filter: grayscale(1) contrast(1.2);
}

.sidebar-link {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-link:hover {
    background: #f9fafb;
    color: var(--primary);
}

.sidebar-link.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.sidebar-sub-link {
    font-size: 0.9rem;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
}

.sidebar-folder {
    margin-bottom: 0.25rem;
}

.sidebar-folder-name {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    color: #4b5563;
    /* slightly darker but distinct */
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s ease;
    user-select: none;
    list-style: none;
    /* Hide default arrow */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-folder-name > * {
    pointer-events: none;
}

.sidebar-folder-name::-webkit-details-marker {
    display: none;
}

.folder-arrow {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    border-radius: 4px;
}

.folder-arrow:hover {
    background: rgba(0, 0, 0, 0.05);
}

.sidebar-folder[open] .folder-arrow {
    transform: rotate(180deg);
}

.sidebar-folder-name:hover {
    background: #f9fafb;
    color: var(--primary);
}

.sidebar-sub-links {
    padding-left: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-top: 0.25rem;
}

.sidebar-sub-link {
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
}

.main-content {
    flex: 1;
    padding: 2rem;
    background: #f3f4f6;
}

.container-sidebar {
    max-width: 1400px;
    margin: 0 auto;
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
}

.card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section {
    margin-bottom: 2rem;
}

.section h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    margin-bottom: 0;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.95rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: white;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

input::placeholder {
    color: var(--text-muted);
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-secondary:hover {
    background: var(--primary);
    color: white;
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border);
}

/* Cost Driver Styles */
.cost-driver {
    background: #f9fafb;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    position: relative;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.driver-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.driver-number {
    font-weight: 600;
    color: var(--primary);
    font-size: 1.1rem;
}

.remove-driver {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 1.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: 5px;
    transition: all 0.2s ease;
}

.remove-driver:hover {
    background: rgba(239, 68, 68, 0.1);
}

.remove-market-btn {
    background: white;
    border: 1px solid var(--error);
    color: var(--error);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.remove-market-btn:hover {
    background: var(--error);
    color: white;
    box-shadow: 0 2px 5px rgba(239, 68, 68, 0.2);
}

/* Delete Confirmation Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-content-card {
    max-width: 450px;
    width: 90%;
    text-align: center;
}

.modal-content-card h3 {
    font-size: 1.3rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.modal-content-card p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.modal-actions .btn {
    min-width: 100px;
}

.driver-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.driver-fields .form-group {
    margin-bottom: 0;
}

/* Notification Styles */
.notification {
    position: fixed;
    top: 5rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    transform: translateX(calc(100% + 2rem + 50px));
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    z-index: 2000;
    max-width: 400px;
}

.notification.show {
    transform: translateX(0);
    opacity: 1;
}

.notification.success {
    background: var(--success);
    color: white;
}

.notification.error {
    background: var(--error);
    color: white;
}

/* Responsive Design */
@media (max-width: 768px) {
    .card {
        padding: 1.5rem;
    }

    .form-row,
    .driver-fields {
        grid-template-columns: 1fr;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

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

    .btn {
        width: 100%;
        justify-content: center;
    }

    header h1 {
        font-size: 2rem;
    }
}

/* Loading State */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-sm {
    padding: 0.4rem 0.9rem;
    font-size: 0.875rem;
}

.btn.loading::after {
    content: "...";
    animation: dots 1.5s infinite;
}

@keyframes dots {

    0%,
    20% {
        content: ".";
    }

    40% {
        content: "..";
    }

    60%,
    100% {
        content: "...";
    }
}

/* Navigation Menu */
.nav-menu {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.nav-link {
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    text-decoration: none;
    color: white;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    font-weight: 500;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.nav-link.active {
    background: white;
    color: var(--primary);
}

/* Product Selector Styling */
.form-control,
.product-selector {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: white;
    cursor: pointer;
    line-height: 1.5;
    height: 3rem;
    /* Force consistent height */
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select {
    height: 3rem;
    /* Force consistent height for all form elements */
    line-height: 1.5;
}

/* Info Grid */
.info-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
}

.info-item {
    background: #f9fafb;
    padding: 1.25rem;
    border-radius: 10px;
    border: 2px solid var(--border);
    flex: 0 1 calc(33.333% - 1rem);
    min-width: 200px;
}

.info-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.info-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Table Styles */
.table-container {
    overflow-x: auto;
    border-radius: 10px;
    border: 2px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

thead {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

th {
    padding: 0.6rem 0.5rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
}

td {
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: #f9fafb;
}

.no-data {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

/* Type Badge */
.type-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.type-fixed {
    background: #dbeafe;
    color: #1e40af;
}

.type-variable {
    background: #fef3c7;
    color: #92400e;
}

/* Market Code */
.market-code {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border-radius: 5px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 400px;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 10px;
    border: 2px solid var(--border);
}

/* Hidden State */
.hidden {
    display: none !important;
}

/* Responsive Updates */
@media (max-width: 768px) {
    .nav-menu {
        flex-direction: column;
    }

    .nav-link {
        text-align: center;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .chart-container {
        height: 300px;
    }

    table {
        font-size: 0.9rem;
    }

    th,
    td {
        padding: 0.75rem 0.5rem;
    }
}

/* File Input */
input[type="file"] {
    padding: 0.5rem;
    border: 2px dashed var(--border);
    border-radius: 10px;
    cursor: pointer;
}

input[type="file"]:hover {
    border-color: var(--primary);
}

/* Help Text */
.help-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-style: italic;
}

/* Large Chart Container */
.chart-container-large {
    position: relative;
    height: 350px;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 10px;
    border: 2px solid var(--border);
}

.chart-container-half {
    position: relative;
    height: 250px;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 10px;
    border: 2px solid var(--border);
}

.chart-container-small {
    position: relative;
    height: 180px;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 10px;
    border: 2px solid var(--border);
}

@media (max-width: 768px) {
    .chart-container-large {
        height: 350px;
    }
}

/* Side-by-Side Chart Grid */
.chart-row-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 1024px) {
    .chart-row-grid {
        grid-template-columns: 1fr;
    }
}

.chart-row-grid .section {
    margin-bottom: 0;
    /* Let the grid handle the spacing */
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chart-row-grid .chart-container-large,
.chart-row-grid .chart-container-centered {
    flex: 1;
    height: 450px !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Standardize header heights in grid */
.chart-row-grid .section-header {
    min-height: 60px;
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

/* Toggle Group Styles */
.toggle-group {
    display: flex;
    background: #f3f4f6;
    padding: 3px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Centered Chart Container */
.chart-container-centered {
    position: relative;
    height: 400px;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 10px;
    border: 2px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
}

.chart-container-centered canvas {
    max-width: 100% !important;
    max-height: 100% !important;
}

/* Bookmark Specific Refinements */
.bookmark-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.bookmark-card {
    background: white;
    border-radius: 16px;
    padding: 1.25rem;
    border: 1px solid var(--border);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.bookmark-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.bookmark-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.bookmark-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.bookmark-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.bookmark-footer {
    margin-top: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.75rem;
    border-top: 1px solid #f3f4f6;
}

.details-link {
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.details-link:hover {
    color: var(--primary-dark);
}

.details-link .arrow {
    display: inline-block;
    transition: transform 0.3s ease;
}

.bookmark-card:hover .details-link .arrow {
    animation: slideArrow 0.8s infinite alternate ease-in-out;
}

@keyframes slideArrow {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(6px);
    }
}

/* Inline Chart Styles */
.inline-chart-row td {
    padding: 0;
    border-bottom: 2px solid var(--primary);
    background: #fdfdfd !important;
}

.inline-chart-container {
    padding: 1.5rem;
    position: relative;
    animation: slideDown 0.3s ease-out;
}

.inline-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.inline-chart-header h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
}

.close-chart-btn {
    background: #f3f4f6;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.close-chart-btn:hover {
    background: var(--error);
    color: white;
    border-color: var(--error);
    transform: rotate(90deg);
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.3);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Driver Changes Cards */
.driver-changes-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    align-items: stretch;
    margin-bottom: 1.5rem;
}

.driver-change-card {
    background: white;
    border-radius: 14px;
    padding: 1.25rem;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1 1 250px;
    min-width: 250px;
    max-width: 300px; /* Limit size for 4-in-a-row on large screens */
}

.driver-change-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
    border-color: var(--primary);
}

.dc-card-header {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    flex-wrap: wrap;
    min-height: 2.2rem;
}

.dc-commodity {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-primary);
}

.dc-country {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.dc-country::before {
    content: "(";
}

.dc-country::after {
    content: ")";
}

.dc-share {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.dc-main-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    border-top: 1px solid #f3f4f6;
}

.dc-change {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 1.5rem;
    font-weight: 800;
    flex-shrink: 0;
}

.dc-change-icon {
    font-size: 0.9rem;
}

.dc-values {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    margin-left: auto;
}

.dc-val {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.dc-val-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.dc-val-num {
    font-size: 0.9rem;
    font-weight: 600;
}

.dc-arrow {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.dc-card-footer {
    padding-top: 0.5rem;
    border-top: 1px solid #f3f4f6;
}

@media (max-width: 768px) {
    .driver-change-card {
        max-width: 100%;
    }
}

/* News Module Styles */
.news-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.news-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: row;
    gap: 1.25rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    text-decoration: none;
    color: inherit;
    min-height: 180px;
}

.news-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    border-color: var(--primary);
}

.news-card h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1.15rem;
    line-height: 1.4;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.news-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1.5rem;
    flex-grow: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
}

.read-more-btn {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.news-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.news-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.news-thumbnail {
    width: 140px;
    height: 140px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f3f4f6;
    border: 1px solid var(--border);
}

.loading-text {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    grid-column: 1 / -1;
}

/* News Filter Bar Redesign */
.news-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    padding: 0.75rem 1.25rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

.news-filter-bar label {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    font-size: 0.9rem;
}

.compact-select {
    max-width: 250px;
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
    height: auto;
}

@media (max-width: 600px) {
    .news-card {
        flex-direction: column;
        gap: 0.75rem;
    }

    .news-thumbnail {
        width: 100%;
        height: 180px;
    }

    .news-grid {
        grid-template-columns: 1fr;
    }

    .news-filter-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }


    .compact-select {
        max-width: 100%;
    }
}

/* ─── Market Dashboard ────────────────────────────────────────────── */

/* Empty state */
.mdb-empty-state {
    text-align: center;
    padding: 5rem 2rem;
    color: var(--text-secondary);
}

.mdb-empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.mdb-empty-state h2 {
    font-size: 1.4rem;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.mdb-empty-state p {
    font-size: 0.95rem;
}

/* Charts grid – 2-column responsive */
.mdb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
    gap: 1.5rem;
}

/* Individual chart card */
.mdb-chart-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.mdb-chart-card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.09);
    transform: translateY(-2px);
}

.mdb-chart-card-header {
    display: flex;
    align-items: flex-start;
    padding: 1rem 1.25rem 0.5rem;
    gap: 0.5rem;
}

.mdb-chart-card-title {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    /* allows flex item to shrink below content width */
    overflow: visible;
}

.mdb-chart-card-subtitle {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.mdb-remove-btn {
    background: transparent;
    border: none;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
    border-radius: 4px;
    flex-shrink: 0;
}

.mdb-remove-btn:hover {
    background: var(--error);
    color: #fff;
}

.mdb-chart-card-body {
    padding: 0.5rem 1.25rem 1.25rem;
    height: 220px;
    position: relative;
}

.mdb-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
    flex-shrink: 0;
}

.mdb-source-badge {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    opacity: 0.85;
}

.mdb-chart-card-body canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Modal overlay */
.mdb-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.mdb-modal-overlay.hidden {
    display: none;
}

.mdb-modal-box {
    background: #fff;
    border-radius: 16px;
    width: 560px;
    max-width: 95vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: mdbFadeIn 0.18s ease;
}

@keyframes mdbFadeIn {
    from {
        opacity: 0;
        transform: scale(0.96);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.mdb-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.mdb-modal-header h2 {
    font-size: 1.1rem;
    margin: 0;
}

.mdb-modal-close {
    border: none;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background 0.15s;
}

.mdb-modal-close:hover {
    background: rgba(0, 0, 0, 0.12);
}

.mdb-modal-search {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.mdb-modal-search input {
    width: 100%;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.mdb-modal-search input:focus {
    border-color: var(--primary);
}

.mdb-modal-list {
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem 0.75rem;
}

/* Modal market item */
.mdb-modal-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 0.75rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
}

.mdb-modal-item:hover {
    background: #f5f6ff;
}

.mdb-modal-item--disabled {
    opacity: 0.5;
    cursor: default;
}

.mdb-modal-item--disabled:hover {
    background: transparent;
}

.mdb-modal-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.mdb-modal-code {
    font-weight: 700;
    color: var(--primary);
    font-size: 0.9rem;
}

.mdb-modal-name {
    font-size: 0.88rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mdb-modal-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.mdb-add-pin-btn {
    border: 1.5px solid var(--primary);
    background: transparent;
    color: var(--primary);
    border-radius: 8px;
    padding: 0.35rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.mdb-add-pin-btn:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
}

.mdb-add-pin-btn:disabled {
    border-color: #d1d5db;
    color: var(--text-muted);
    cursor: default;
}

/* ─── Drag & Drop ────────────────────────────────────────────────── */

/* Drag handle icon in card header */
/* Timeframe selector */
.mdb-tf-group {
    display: flex;
    gap: 2px;
    margin-left: auto;
    /* push to the right, before the ✕ */
    margin-right: 0.25rem;
    background: #f0f1f8;
    border-radius: 8px;
    padding: 2px;
    flex-shrink: 0;
}

.mdb-tf-btn {
    border: none;
    background: transparent;
    border-radius: 6px;
    padding: 0.2rem 0.45rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    line-height: 1.4;
}

.mdb-tf-btn:hover {
    background: #fff;
    color: var(--primary);
}

.mdb-tf-btn.mdb-tf-active {
    background: var(--primary);
    color: #fff;
}

.mdb-drag-handle {
    font-size: 1.1rem;
    color: #c4c8d8;
    cursor: grab;
    line-height: 1;
    padding: 0 0.25rem;
    flex-shrink: 0;
    transition: color 0.15s;
    user-select: none;
    letter-spacing: 0.5px;
}

.mdb-drag-handle:hover {
    color: var(--primary);
}

.mdb-drag-handle:active {
    cursor: grabbing;
}

/* Card being dragged — fade it so the gap is clear */
.mdb-chart-card.mdb-dragging {
    opacity: 0.35;
    border-style: dashed;
    border-color: var(--primary);
}

/* Card that the dragged card is hovering over */
.mdb-chart-card.mdb-drop-target {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
    transform: translateY(-3px);
    transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
}
/* Tabs Interface */
.tabs-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.tab-btn {
    padding: 1rem 2rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: -2px; /* Pull down to overlap border */
}

.tab-btn:hover {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    animation: fadeIn 0.4s ease-out;
}

/* Admin Hub Tiles */
.admin-hub-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.admin-hub-tile:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.admin-hub-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.admin-hub-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

/* Manage Market Codes Badges */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-ecb {
    background: #e0e7ff;
    color: #4338ca;
}
.badge-manual {
    background: var(--bg-page);
    color: var(--text-secondary);
}
.badge-eurostat {
    background: #dbeafe;
    color: #1e40af;
}
.badge-fred {
    background: #fef3c7;
    color: #b45309;
}

/* Manage Markets Action Icons */
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.3rem;
    border-radius: 6px;
    transition: background 0.2s;
}
.btn-icon:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.delete-btn:hover {
    background: #fee2e2;
}
.spinning {
    display: inline-block;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Utility classes for compact tables */
.truncate-text {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.period-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

#marketsTable th:nth-child(1) { width: 140px; } /* Code */
#marketsTable th:nth-child(2) { width: auto; }  /* Name */
#marketsTable th:nth-child(3) { width: 110px; } /* Source */
#marketsTable th:nth-child(4) { width: 110px; } /* Commodity */
#marketsTable th:nth-child(5) { width: 110px; } /* Country */
#marketsTable th:nth-child(6) { width: 150px; } /* Period */

/* Highlight Animation */
@keyframes highlightFlash {
    0% { background-color: rgba(79, 70, 229, 0.2); }
    100% { background-color: transparent; }
}

.highlight-flash {
    animation: highlightFlash 1s ease-out;
}

/* Home page layout: 2-col, 2-row grid */
.home-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: auto auto;
    gap: 1.5rem;
    align-items: start;
}

.home-panel-bookmarks {
    grid-column: 1;
    grid-row: 1;
}

.home-panel-pdfs {
    grid-column: 1;
    grid-row: 2;
}

.home-panel-notes {
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: stretch;
}

.home-panel-bookmarks .bookmark-grid {
    grid-template-columns: repeat(2, 1fr);
}

/* Notes panel */
.notes-card {
    height: 100%;
    box-sizing: border-box;
}

.notes-add-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.notes-textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
    background: var(--bg-secondary, #f9fafb);
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.notes-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.notes-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.note-item {
    background: var(--bg-secondary, #f9fafb);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.note-content {
    font-size: 0.9rem;
    color: var(--text-primary, #111827);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.note-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.note-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    line-height: 1;
}

.note-delete-btn:hover {
    color: var(--error, #ef4444);
    background: rgba(239, 68, 68, 0.08);
}

/* PDF filter input — overrides the global input[type="text"] width: 100% */
.pdf-filter-input {
    width: 200px !important;
    flex-shrink: 0;
    padding: 0.4rem 0.75rem !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.pdf-filter-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: none !important;
}

/* PDF grid */
.pdf-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin-top: 1rem;
}

/* PDF card */
.pdf-card {
    background: white;
    border-radius: 14px;
    border: 1px solid var(--border);
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px -1px rgba(0,0,0,0.04);
}

.pdf-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.pdf-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.pdf-card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary, #111827);
    line-height: 1.3;
}

.pdf-card-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.pdf-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.25rem;
}

.pdf-card-footer {
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid #f3f4f6;
}

/* Keyword pill — shared between home page and manage_pdfs table */
.keyword-tag {
    display: inline-block;
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary, #6366f1);
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

@media (max-width: 900px) {
    .home-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .home-panel-bookmarks,
    .home-panel-pdfs,
    .home-panel-notes {
        grid-column: 1;
        grid-row: auto;
        align-self: auto;
    }

    .notes-card {
        height: auto;
    }

    .pdf-grid {
        grid-template-columns: 1fr;
    }
}

/* Data attribution footer */
.data-attribution-footer {
    margin-top: 2rem;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
}

.data-attribution-footer a {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.data-attribution-footer a:hover {
    color: var(--text-primary);
}

/* --- Claros IQ analyst chat ------------------------------------------- */
.analyst-chat {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

/* Header bar */
.analyst-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 1rem 1.25rem;
    background: var(--bg-gradient);
    color: #fff;
}

.analyst-avatar {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    backdrop-filter: blur(4px);
}

.analyst-id {
    flex: 1;
    min-width: 0;
}

.analyst-name {
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.2;
}

.analyst-tagline {
    font-size: 0.8rem;
    opacity: 0.85;
}

.chat-new-btn {
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-new-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Message scroll area */
.chat-window {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    height: 58vh;
    min-height: 340px;
    overflow-y: auto;
    padding: 1.5rem 1.25rem;
    background: var(--bg-secondary);
    scroll-behavior: smooth;
}

/* One message row = avatar + bubble */
.chat-msg {
    display: flex;
    gap: 0.7rem;
    max-width: 88%;
    align-items: flex-start;
}

.chat-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    font-size: 0.95rem;
    margin-top: 2px;
}

.chat-msg-user .chat-msg-avatar {
    background: var(--primary);
    color: #fff;
}

.chat-msg-assistant .chat-msg-avatar {
    background: #ede9fe;
    color: var(--secondary);
}

.chat-msg-main {
    min-width: 0;
}

.chat-bubble {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-md);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: 1.55;
    font-size: 0.93rem;
}

.chat-msg-user .chat-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.chat-msg-assistant .chat-bubble {
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.chat-bubble-error {
    border-color: var(--error) !important;
    color: var(--error);
}

/* Markdown inside assistant bubbles */
.chat-bubble > *:first-child { margin-top: 0; }
.chat-bubble > *:last-child { margin-bottom: 0; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3, .chat-bubble h4 {
    margin: 0.8em 0 0.4em;
    line-height: 1.25;
}
.chat-bubble h1 { font-size: 1.2rem; }
.chat-bubble h2 { font-size: 1.1rem; }
.chat-bubble h3 { font-size: 1rem; }
.chat-bubble h4 { font-size: 0.95rem; }
.chat-bubble p { margin: 0.5em 0; }
.chat-bubble ul, .chat-bubble ol { margin: 0.5em 0; padding-left: 1.3em; }
.chat-bubble li { margin: 0.2em 0; }
.chat-bubble a { color: var(--primary-dark); text-decoration: underline; }
.chat-bubble strong { font-weight: 700; }
.chat-bubble code {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1em 0.35em;
    font-size: 0.85em;
    font-family: 'SFMono-Regular', Consolas, monospace;
}
.chat-bubble pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 0.8rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.6em 0;
}
.chat-bubble pre code { background: none; border: none; color: inherit; padding: 0; }
.chat-bubble blockquote {
    border-left: 3px solid var(--primary);
    margin: 0.6em 0;
    padding: 0.1em 0.9em;
    color: var(--text-secondary);
}
.chat-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6em 0;
    font-size: 0.85rem;
}
.chat-bubble th, .chat-bubble td {
    border: 1px solid var(--border);
    padding: 0.4rem 0.6rem;
    text-align: left;
}
.chat-bubble th { background: var(--bg-secondary); font-weight: 600; }
.chat-bubble hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }

/* Meta row (timestamp + copy) */
.chat-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.3rem;
    font-size: 0.72rem;
    color: var(--text-muted);
}
.chat-msg-user .chat-meta { justify-content: flex-end; }
.chat-copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.72rem;
    padding: 0;
}
.chat-copy-btn:hover { color: var(--primary); }

/* Typing indicator */
.chat-typing { display: inline-flex; gap: 4px; padding: 0.2rem 0; }
.chat-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-muted);
    animation: chat-bounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Welcome empty-state */
.chat-welcome {
    margin: auto;
    text-align: center;
    max-width: 540px;
    padding: 1rem;
}
.chat-welcome-icon { font-size: 2.6rem; }
.chat-welcome h2 { margin: 0.5rem 0 0.3rem; font-size: 1.2rem; color: var(--text-primary); }
.chat-welcome p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 1.2rem; }
.chat-chips { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; }
.chat-chip {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.5rem 0.95rem;
    font-size: 0.83rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.1s ease;
    text-align: left;
}
.chat-chip:hover { border-color: var(--primary); transform: translateY(-1px); }

/* Status line */
.chat-status {
    min-height: 1.1rem;
    padding: 0 1.25rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.chat-status:not(:empty) { padding-top: 0.5rem; }
.chat-tool-flag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: #ede9fe;
    color: var(--secondary);
    border-radius: 999px;
    padding: 0.15rem 0.6rem;
    font-weight: 600;
}

/* Composer */
.chat-form {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    padding: 0.9rem 1.25rem 1.1rem;
    border-top: 1px solid var(--border);
    background: var(--card-bg);
}
.chat-input {
    flex: 1;
    resize: none;
    max-height: 160px;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font: inherit;
    font-size: 0.93rem;
    line-height: 1.4;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.chat-send {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.15s ease, transform 0.1s ease;
}
.chat-send:hover:not(:disabled) { background: var(--primary-dark); transform: scale(1.05); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Two-column layout: conversations rail + chat */
.analyst-layout {
    display: flex;
    gap: 1.25rem;
    align-items: stretch;
}
.analyst-rail {
    flex: 0 0 250px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
}
.analyst-chat { flex: 1; min-width: 0; }

.conv-new-btn {
    width: 100%;
    padding: 0.65rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}
.conv-new-btn:hover { background: var(--primary-dark); }

.conv-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    overflow-y: auto;
}
.conv-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0.7rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.conv-item:hover { border-color: var(--primary); }
.conv-item.active { border-color: var(--primary); background: #eef2ff; }
.conv-item-title {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item-del {
    flex: 0 0 auto;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    padding: 2px 4px;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease;
}
.conv-item:hover .conv-item-del { opacity: 1; }
.conv-item-del:hover { color: var(--error); }
.conv-empty {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding: 1rem 0.5rem;
}
@media (max-width: 860px) {
    .analyst-layout { flex-direction: column; }
    .analyst-rail { flex: none; }
    .conv-list { max-height: 180px; }
}
