@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ===== CSS VARIABLES ===== */
:root {
    --bg-page: #f5f6fa;
    --bg-white: #ffffff;
    --bg-hover: #f0f2f8;
    --bg-input: #f7f8fc;
    --border-light: #e8eaef;
    --border-medium: #dcdfe6;
    --text-dark: #1a1d2e;
    --text-body: #4a4d5e;
    --text-muted: #8b8fa3;
    --text-label: #9a9db0;
    --accent-red: #e63946;
    --accent-blue: #3b82f6;
    --accent-blue-dark: #2563eb;
    --accent-green: #10b981;
    --success: #10b981;
    --error: #ef4444;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --sidebar-width: 260px;
    --transition: all 0.25s ease;
}

/* ===== RESET ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-page);
    color: var(--text-dark);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.18); }

/* ===== APP CONTAINER ===== */
#app-container {
    display: none;
    height: 100vh;
}

#app-container.active {
    display: flex;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-white);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
    transition: var(--transition);
    z-index: 10;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

/* ===== SIDEBAR RESIZER ===== */
.sidebar-resizer {
    width: 6px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    z-index: 15;
    flex-shrink: 0;
    transition: background 0.15s ease;
    margin-left: -3px;
    margin-right: -3px;
}

.sidebar-resizer:hover,
.sidebar-resizer.active,
body.is-resizing-sidebar .sidebar-resizer {
    background: var(--accent-blue);
    box-shadow: 0 0 6px rgba(59, 130, 246, 0.4);
}

.sidebar-resizer::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -4px;
    right: -4px;
}

body.is-resizing-sidebar {
    cursor: col-resize !important;
    user-select: none !important;
    -webkit-user-select: none !important;
}

body.is-resizing-sidebar .sidebar {
    transition: none !important;
}

.sidebar-top {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1.5rem;
}

.sidebar-logo {
    width: 32px;
    height: auto;
    object-fit: contain;
}

.sidebar-brand-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-dark);
    letter-spacing: 1.5px;
}

.sidebar-brand-tag {
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--accent-red);
    letter-spacing: 2px;
}

.new-query-btn {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 1.5rem;
}

.new-query-btn span {
    font-size: 1.1rem;
    font-weight: 300;
}

.new-query-btn:hover { background: var(--accent-blue-dark); }

.available-tables-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-label);
    letter-spacing: 1.5px;
    margin-bottom: 0.75rem;
}

.available-tables-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.available-table-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-body);
    border: 1px solid var(--border-light);
    background: var(--bg-page);
    width: 100%;
    text-align: left;
    font-family: 'Inter', sans-serif;
}

.table-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    color: var(--accent-blue);
}

.table-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

/* Sidebar bottom — user profile */
.sidebar-bottom {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-light);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }

.sidebar-user-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== CHAT MAIN ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-page);
}

/* --- Top Bar --- */
.chat-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.85rem 1.5rem;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.hamburger-btn {
    background: none;
    border: none;
    color: var(--text-body);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    transition: var(--transition);
}

.topbar-hamburger {
    display: none;
}

.sidebar.collapsed + .chat-main .topbar-hamburger {
    display: flex !important;
}

.hamburger-btn:hover { background: var(--bg-hover); }

.chat-topbar-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
}

.chat-topbar-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--accent-green);
    letter-spacing: 0.5px;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* --- Messages --- */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* --- Message Bubbles --- */
.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
    animation: msgIn 0.3s ease-out;
    position: relative;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--accent-blue);
    color: white;
    font-weight: 600;
    font-size: 0.7rem;
}

.message.assistant .message-avatar {
    background: var(--accent-red);
    color: white;
}

.message-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; overflow: hidden; }

.message-content {
    padding: 0.9rem 1.15rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .message-content {
    background: var(--accent-blue);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    color: var(--text-body);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-label {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--accent-red);
    letter-spacing: 0.5px;
    padding-left: 4px;
}

/* Markdown */
.message-content h1,.message-content h2,.message-content h3,
.message-content h4,.message-content h5,.message-content h6 {
    font-size: 0.92rem; font-weight: 600; margin: 0.7rem 0 0.3rem; color: var(--text-dark);
}
.message-content h1 { font-size: 1.05rem; font-weight: 700; }
.message-content p { margin: 0.25rem 0; }
.message-content ul,.message-content ol { padding-left: 1.2rem; margin: 0.3rem 0; }
.message-content li { margin: 0.15rem 0; }
.message-content strong { color: var(--text-dark); font-weight: 600; }
.message-content code {
    background: #f0f2f8; padding: 2px 6px; border-radius: 4px;
    font-size: 0.8rem; color: var(--accent-red);
}
.message-content pre {
    background: #f6f8fa; border: 1px solid var(--border-light);
    border-radius: var(--radius-sm); padding: 0.7rem; overflow-x: auto; margin: 0.5rem 0;
}
.message-content pre code { background: none; padding: 0; color: var(--text-body); }
.message-content hr {
    border: none; border-top: 1px solid var(--border-light); margin: 0.75rem 0;
}
.message-content blockquote {
    border-left: 4px solid var(--accent-blue);
    background: #f8fafc;
    margin: 10px 0;
    padding: 10px 15px;
    border-radius: 0 8px 8px 0;
    color: var(--text-body);
}

/* Tables */
.message-content table { width: 100%; border-collapse: collapse; margin: 0.6rem 0; font-size: 0.8rem; }
.message-content th {
    background: #f0f4ff; color: var(--accent-blue); font-weight: 600;
    text-align: left; padding: 8px 10px; border: 1px solid var(--border-light); white-space: nowrap;
}
.message-content td { padding: 6px 10px; border: 1px solid var(--border-light); color: var(--text-body); }
.message-content tr:hover td { background: #f9fafb; }

/* Charts */
.chart-wrapper {
    margin: 0.6rem 0; padding: 1rem; background: var(--bg-white);
    border: 1px solid var(--border-light); border-radius: var(--radius-md);
    max-width: 100%; box-shadow: var(--shadow-sm);
}
.chart-wrapper canvas { max-height: 370px; min-height: 250px; display: block; width: 100% !important; }
.chart-title { font-size: 0.85rem; font-weight: 600; color: var(--text-dark); margin-bottom: 0.6rem; text-align: center; }

/* Typing */
.typing-indicator {
    display: flex; align-items: center; gap: 10px;
    padding: 0.85rem 1.15rem; background: var(--bg-white);
    border: 1px solid var(--border-light); border-radius: var(--radius-md);
    border-bottom-left-radius: 4px; box-shadow: var(--shadow-sm);
}
.typing-dots { display: flex; gap: 4px; }
.typing-dots span {
    width: 7px; height: 7px; background: var(--accent-blue);
    border-radius: 50%; animation: bounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%,60%,100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-8px); opacity: 1; }
}
.typing-text { color: var(--text-muted); font-size: 0.8rem; }

/* Suggestions */
.suggestions-container {
    display: flex; flex-wrap: wrap; gap: 8px;
    padding: 0.6rem 2rem; flex-shrink: 0;
}
.suggestion-chip {
    background: var(--bg-white); border: 1px solid var(--border-medium);
    border-radius: 20px; padding: 7px 16px; font-size: 0.78rem;
    color: var(--text-body); cursor: pointer; font-family: 'Inter', sans-serif;
    transition: var(--transition); white-space: nowrap;
}
.suggestion-chip:hover {
    background: #eff6ff; border-color: var(--accent-blue);
    color: var(--accent-blue); transform: translateY(-1px);
}

/* Input */
.input-area {
    padding: 0.75rem 2rem 1.25rem;
    flex-shrink: 0;
}
.input-wrapper {
    display: flex; align-items: center; gap: 0;
    background: var(--bg-white); border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl); padding: 0.25rem 0.5rem 0.25rem 1.25rem;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}
.input-wrapper:focus-within {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.08);
}
.chat-input {
    flex: 1; background: none; border: none;
    padding: 0.65rem 0; font-size: 0.88rem;
    font-family: 'Inter', sans-serif; color: var(--text-dark);
    outline: none; resize: none; max-height: 100px; min-height: 40px; line-height: 1.5;
}
.chat-input::placeholder { color: var(--text-muted); }
.send-btn {
    width: 38px; height: 38px; border-radius: 50%;
    background: none; border: none; color: var(--accent-blue);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: var(--transition); flex-shrink: 0;
}
.send-btn:hover { background: #eff6ff; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; }

/* Welcome */
.welcome-container {
    display: flex; flex-direction: column; align-items: flex-start;
    gap: 4px; animation: msgIn 0.3s ease-out;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed; left: 0; top: 0; height: 100vh;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-width)); box-shadow: none; }
    .messages-container { padding: 1rem; }
    .message { max-width: 95%; }
    .input-area { padding: 0.5rem 1rem 1rem; }
}

/* ===== SIDEBAR FILTERS (ACCORDION & CHECKBOXES) ===== */
.filter-accordion-card {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    background: var(--bg-white);
    overflow: hidden;
    margin-bottom: 4px;
}

.filter-header {
    cursor: pointer;
    position: relative;
    padding: 0.7rem 0.75rem;
    user-select: none;
    transition: var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter-header:hover {
    background: var(--bg-hover);
}

.filter-header-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-dark);
}

.filter-dropdown {
    display: none;
    padding: 6px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-page);
}

.filter-search {
    width: 100%;
    padding: 6px 10px;
    margin-bottom: 6px;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: 'Inter', sans-serif;
    outline: none;
}
.filter-search:focus {
    border-color: var(--accent-blue);
}

.filter-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-height: 200px;
    overflow-y: auto;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    cursor: pointer;
}
.filter-item:hover {
    background: #e9ecef;
    border-radius: 4px;
}

.filter-item input[type="checkbox"] {
    cursor: pointer;
}

.filter-item label {
    font-size: 0.78rem;
    color: var(--text-body);
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.apply-filters-btn {
    width: 100%;
    padding: 0.6rem;
    background: var(--bg-white);
    color: var(--accent-blue);
    border: 1px solid var(--accent-blue);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    margin-top: 4px;
}
.apply-filters-btn:hover {
    background: var(--accent-blue);
    color: white;
}

/* Force Markdown tables to align left */
.message-content table th, 
.message-content table td {
    text-align: left !important;
}

/* Feedback */
.feedback-row { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.feedback-btn {
    background: none; border: 1px solid transparent; border-radius: 6px;
    padding: 3px 8px; font-size: 0.85rem; cursor: pointer; transition: var(--transition); opacity: 0.35;
}
.feedback-btn:hover { opacity: 1; background: var(--bg-hover); border-color: var(--border-medium); }
.feedback-btn.selected { opacity: 1; background: #eff6ff; border-color: var(--accent-blue); }
.feedback-btn.disabled { pointer-events: none; }

/* ===== LOGIN SCREEN ===== */
#login-screen {
    display: flex;
    height: 100vh;
}

/* --- Left Red Brand Panel --- */
.login-left {
    width: 42%;
    background: #e63946;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 2.5rem;
    flex-shrink: 0;
    overflow: hidden;
}

.login-left-content {
    text-align: center;
    color: white;
    max-width: 300px;
    animation: slideUp 0.5s ease-out;
}

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

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

.login-brand-icon {
    width: 96px;
    height: 96px;
    background: white;
    border-radius: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    flex-shrink: 0;
}

.login-brand-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    display: block;
}

.login-brand-name {
    font-size: 2rem;
    font-weight: 800;
    color: white;
    letter-spacing: 5px;
    margin-bottom: 6px;
}

.login-brand-sub {
    font-size: 0.68rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 3px;
    margin-bottom: 2rem;
}

.login-brand-desc {
    font-size: 0.83rem;
    color: rgba(255, 255, 255, 0.78);
    line-height: 1.75;
}

/* --- Right White Login Panel --- */
.login-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    padding: 3rem;
}

.login-form-card {
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    animation: slideUp 0.5s ease-out;
}

.login-heading {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-dark);
    text-align: center;
    letter-spacing: -0.3px;
}

.login-subtext {
    color: var(--text-muted);
    font-size: 0.87rem;
    text-align: center;
    line-height: 1.55;
    margin-top: -0.4rem;
}

.login-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 0.85rem 2rem;
    background: white;
    color: var(--text-dark);
    border: 1.5px solid var(--border-medium);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.login-btn:hover {
    border-color: var(--accent-blue);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.12);
    transform: translateY(-1px);
}

.login-btn:active {
    transform: translateY(0);
}

.login-provider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 1.5px;
}

.login-disclaimer {
    border-top: 1px solid var(--border-light);
    padding-top: 1.2rem;
    margin-top: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.login-disclaimer p {
    font-size: 0.71rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.65;
    text-align: center;
}

.login-secure {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--text-label);
    letter-spacing: 1.5px;
}

/* Responsive: stack panels on mobile */
@media (max-width: 640px) {
    #login-screen {
        flex-direction: column;
    }

    .login-left {
        width: 100%;
        padding: 2rem;
        min-height: 220px;
    }

    .login-right {
        padding: 2rem 1.5rem;
    }
}

/* ===== PDF DOWNLOAD BUTTON (Option 33 — White bg, Red border chip) ===== */
.pdf-download-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    color: var(--accent-red);
    background: #ffffff;
    border: 1px solid var(--accent-red);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.18s ease, color 0.18s ease;
    z-index: 10;
    white-space: nowrap;
    letter-spacing: 0.2px;
}

.message:hover .pdf-download-btn {
    opacity: 1;
}

.pdf-download-btn:hover {
    background: var(--accent-red);
    color: #fff;
}

.pdf-download-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: #f5f6fa;
    color: var(--text-muted);
    border-color: var(--border-light);
}

/* ===== PRINT STYLES — Only the .print-target message is visible ===== */
@media print {
    /* Reset everything */
    *, *::before, *::after {
        visibility: hidden;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    /* Remove all layout constraints from body and every ancestor */
    html, body {
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        overflow: visible !important;
    }

    /* Force all containers in the chain to be full-width and visible */
    body,
    .app-container,
    .main-content,
    .messages-area,
    .messages-container,
    .message,
    .message-body,
    .message-content {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        visibility: visible !important;
        background: white !important;
        border: none !important;
        float: none !important;
        flex: none !important;
    }

    /* Hide all UI chrome */
    .sidebar,
    .topbar,
    .chat-input-bar,
    .pdf-download-btn,
    .feedback-row,
    .follow-up-bar,
    .message-avatar,
    .suggested-prompts,
    nav, header, footer {
        display: none !important;
    }

    /* Hide ALL messages by default */
    .message {
        display: none !important;
    }

    /* Show ONLY the message that contains a .print-target */
    .message:has(.print-target) {
        display: block !important;
        visibility: visible !important;
    }

    /* Make the print-target and all its children fully visible */
    .print-target,
    .print-target * {
        visibility: visible !important;
        color: #1a1d2e !important;
    }

    .print-target {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 12px !important;
        line-height: 1.65 !important;
        background: white !important;
    }

    /* Tables: clean, full width */
    .print-target table {
        width: 100% !important;
        table-layout: fixed !important;
        word-break: break-word !important;
        font-size: 11px !important;
        border-collapse: collapse !important;
    }

    .print-target th,
    .print-target td {
        padding: 5px 8px !important;
        border: 1px solid #ccc !important;
        background: white !important;
    }

    .print-target th {
        background: #f5f6fa !important;
        font-weight: 700 !important;
    }

    /* Prevent page-break inside charts, tables, sections */
    .print-target .chart-wrapper,
    .print-target table,
    .print-target blockquote,
    .print-target h3,
    .print-target h4 {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Chart images inserted by JS for print */
    .print-chart-img {
        display: block !important;
        visibility: visible !important;
        width: 100% !important;
        min-height: 250px !important;
        max-height: 400px !important;
        object-fit: contain !important;
        page-break-inside: avoid !important;
    }

    /* Hide live canvases (replaced by static images) */
    .print-target canvas {
        display: none !important;
    }

    /* Keep chart wrapper containers sized properly */
    .print-target .chart-wrapper {
        visibility: visible !important;
        display: block !important;
        width: 100% !important;
        min-height: 280px !important;
        height: auto !important;
        overflow: visible !important;
        page-break-inside: avoid !important;
    }

    /* Each major section is wrapped by JS in a .print-section div */
    .print-section {
        page-break-before: always !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* First section stays on page 1 */
    .print-section:first-of-type {
        page-break-before: auto !important;
    }

    /* Headings no longer need to force page breaks, the wrapper does it */
    .print-target h3 {
        padding-top: 8px !important;
        page-break-after: avoid !important;
        break-after: avoid !important;
    }

    /* Page setup */
    @page {
        size: A4 portrait;
        margin: 15mm 12mm;
    }
}
