:root {
    --foundation-green: #0a6e3d;
    --foundation-green-dark: #074e2b;
    --foundation-gold: #c9a227;
    --foundation-cream: #faf6ed;
    --foundation-red: #b71c1c;
    --soft-shadow: 0 6px 18px rgba(15, 30, 45, 0.06);
    --strong-shadow: 0 12px 36px rgba(15, 30, 45, 0.12);
}

* {
    font-family: 'Vazirmatn', 'Vazir', 'Tahoma', sans-serif !important;
}

body {
    background: linear-gradient(180deg, #f6f8fb 0%, #ffffff 100%);
    color: #1a2533;
    min-height: 100vh;
}

a {
    text-decoration: none;
}

/* ----- Navbar ----- */
.navbar-glass {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid #e9eef5;
}

/* Top navbar links + active (currently-open) item highlight */
.navbar-glass .navbar-nav .nav-link {
    border-radius: 10px;
    padding-inline: 0.7rem;
    color: #41506a;
    transition: background-color .15s ease, color .15s ease;
}

.navbar-glass .navbar-nav .nav-link:hover {
    color: var(--foundation-green-dark);
    background: rgba(10, 110, 61, 0.07);
}

.navbar-glass .navbar-nav .nav-link.active {
    color: var(--foundation-green-dark);
    background: rgba(10, 110, 61, 0.12);
    font-weight: 700;
    box-shadow: inset 0 -2px 0 var(--foundation-green);
}

.navbar-brand strong {
    font-weight: 700;
    color: var(--foundation-green-dark);
    font-size: 1.05rem;
}

.brand-emblem {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--foundation-green) 0%, var(--foundation-green-dark) 100%);
    color: #fff;
    border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 12px rgba(10, 110, 61, 0.25);
}

/* نشان بنیاد (تصویر لوگو) — بدون پلاک سبز پشت آن */
.brand-emblem--logo {
    background: none;
    border-radius: 0;
    box-shadow: none;
}

.brand-emblem img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.avatar-sm {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-initial {
    background: linear-gradient(135deg, var(--foundation-green), var(--foundation-gold));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

/* ----- Buttons ----- */
.btn-primary {
    background: linear-gradient(135deg, var(--foundation-green) 0%, var(--foundation-green-dark) 100%);
    border: none;
    box-shadow: 0 4px 12px rgba(10, 110, 61, 0.2);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--foundation-green-dark);
}
.btn-warning {
    background: var(--foundation-gold);
    border-color: var(--foundation-gold);
    color: #fff;
}
.btn-outline-primary {
    color: var(--foundation-green);
    border-color: var(--foundation-green);
}
.btn-outline-primary:hover {
    background: var(--foundation-green);
}

/* ----- Cards & UI ----- */
.card {
    border: 1px solid #eef1f6;
    border-radius: 14px;
    box-shadow: var(--soft-shadow);
    transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--strong-shadow);
}
.card-header {
    background: rgba(10, 110, 61, 0.05);
    border-bottom: 1px solid #e9eef5;
    font-weight: 600;
}

/* Hero on homepage */
.hero-shrine {
    background: linear-gradient(120deg, rgba(10, 110, 61, 0.95) 0%, rgba(7, 78, 43, 0.92) 100%),
                radial-gradient(circle at 20% 30%, rgba(201, 162, 39, 0.4), transparent 50%);
    color: #fff;
    padding: 4rem 1.5rem;
    border-radius: 18px;
    position: relative;
    overflow: hidden;
}

/* لوگوی بنیاد در بخش سرآمد صفحه خانه */
.hero-logo {
    width: 190px;
    max-width: 70%;
    height: auto;
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.35));
}

.hero-shrine h1 {
    font-weight: 800;
    font-size: 2.2rem;
}

/* KPI tiles */
.kpi-tile {
    background: linear-gradient(135deg, #ffffff 0%, #fbfdff 100%);
    border: 1px solid #eef1f6;
    border-radius: 16px;
    padding: 1.4rem;
    text-align: center;
}
.kpi-tile .kpi-icon {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: rgba(10, 110, 61, 0.1);
    color: var(--foundation-green-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 0.6rem;
}
.kpi-tile .kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--foundation-green-dark);
}
.kpi-tile .kpi-label {
    color: #6b7785;
    font-size: 0.85rem;
}
.kpi-tile.warning .kpi-icon { background: rgba(201, 162, 39, 0.12); color: var(--foundation-gold); }
.kpi-tile.warning .kpi-value { color: var(--foundation-gold); }
.kpi-tile.danger .kpi-icon { background: rgba(183, 28, 28, 0.1); color: var(--foundation-red); }
.kpi-tile.danger .kpi-value { color: var(--foundation-red); }
.kpi-tile.info .kpi-icon { background: rgba(13, 110, 253, 0.1); color: #0d6efd; }
.kpi-tile.info .kpi-value { color: #0d6efd; }

/* Chat bubbles */
.chat-pane {
    max-width: 100%;
    background: #fff;
    border-radius: 18px;
    box-shadow: var(--soft-shadow);
    overflow: hidden;
}
.chat-bubble {
    border-radius: 16px;
    padding: 1rem 1.2rem;
    margin-bottom: 0.6rem;
    line-height: 1.9;
}
.chat-bubble.user {
    background: linear-gradient(135deg, var(--foundation-green-dark), var(--foundation-green));
    color: #fff;
    align-self: flex-start;
    max-width: 80%;
}
.chat-bubble.assistant {
    background: var(--foundation-cream);
    border: 1px solid #ece4cf;
    color: #1a2533;
    max-width: 92%;
}
.chat-bubble.assistant.muted {
    background: #f4f6fa;
    border-color: #e5e9f0;
}

/* One question + its answer. `scroll-margin-top` keeps the turn clear of the
   sticky navbar when the page jumps to it after a follow-up question. */
.chat-turn {
    scroll-margin-top: 90px;
}
.chat-turn-latest > .chat-bubble.assistant {
    box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.18);
}

.source-card {
    background: #ffffff;
    border: 1px solid #e9eef5;
    border-right: 3px solid var(--foundation-gold);
    padding: 0.8rem 1rem;
    border-radius: 10px;
    margin-bottom: 0.6rem;
}
.source-card .source-title {
    font-weight: 600;
    color: var(--foundation-green-dark);
}
.source-card .source-snippet {
    color: #4a5563;
    font-size: 0.9rem;
}

/* Confidence */
.confidence-bar {
    height: 6px;
    border-radius: 3px;
    background: #e5e9f0;
    overflow: hidden;
}
.confidence-bar > div {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--foundation-red), var(--foundation-gold), var(--foundation-green));
}

/* Document tiles */
.doc-tile {
    border-radius: 14px;
    overflow: hidden;
    position: relative;
}
.doc-tile .doc-thumb {
    height: 140px;
    background: linear-gradient(135deg, #f4f6fa, #e7ecf3);
    display: flex; align-items: center; justify-content: center;
    color: #6b7785;
    font-size: 2.2rem;
}
.doc-tile .doc-thumb img {
    height: 100%;
    width: 100%;
    object-fit: cover;
}
.doc-tile .doc-body {
    padding: 0.9rem;
}
.doc-tile .doc-meta {
    color: #6b7785;
    font-size: 0.8rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Martyr cards */
/* «شهدای نام‌آور استان‌ها» — province page cards and the roll of honour. */
.province-card {
    border: 1px solid #e9edf3;
    border-radius: 16px;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.province-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--soft-shadow);
}
.province-card-image,
.province-hero {
    width: 100%;
    object-fit: cover;
}
.province-card-image { height: 150px; }
.province-hero { max-height: 280px; }

.notable-card { border: 1px solid #e9edf3; border-radius: 16px; }
.notable-photo {
    width: 84px;
    height: 104px;
    border-radius: 12px;
    background: var(--foundation-cream);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: #b9a97e;
    font-size: 1.8rem;
}
.notable-photo img { width: 100%; height: 100%; object-fit: cover; }

.martyr-card {
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    border: 1px solid #eef1f6;
    box-shadow: var(--soft-shadow);
    text-align: center;
    transition: transform 0.15s;
}
.martyr-card:hover { transform: translateY(-3px); }
.martyr-card .martyr-photo {
    height: 220px;
    background: #f4f6fa url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" viewBox="0 0 24 24" fill="none" stroke="%23b3bcc8" stroke-width="1.2"><circle cx="12" cy="9" r="3.5"/><path d="M5 21c0-3.866 3.134-7 7-7s7 3.134 7 7"/></svg>') center / 80px no-repeat;
}
.martyr-card .martyr-photo img {
    width: 100%; height: 100%; object-fit: cover;
}
.martyr-card .martyr-name {
    padding: 0.9rem 0.6rem 0.4rem;
    font-weight: 600;
    color: var(--foundation-green-dark);
}
.martyr-card .martyr-meta {
    padding: 0 0.6rem 0.9rem;
    color: #6b7785;
    font-size: 0.82rem;
}

/* Operation card */
.operation-card {
    background: #fff;
    border: 1px solid #eef1f6;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--soft-shadow);
}
.operation-card .op-banner {
    height: 100px;
    background: linear-gradient(120deg, var(--foundation-green-dark), var(--foundation-green));
    position: relative;
}
.operation-card .op-banner img {
    width: 100%; height: 100%; object-fit: cover; opacity: 0.7;
}
.operation-card .op-front {
    position: absolute; bottom: 8px; right: 12px;
    background: rgba(0,0,0,0.5);
    color: #fff;
    padding: 0.2rem 0.6rem;
    border-radius: 8px;
    font-size: 0.78rem;
}
.operation-card .op-body { padding: 1rem; }
.operation-card h5 a { color: var(--foundation-green-dark); }

/* Sidebar */
.sidebar {
    background: #fff;
    border-radius: 14px;
    box-shadow: var(--soft-shadow);
    padding: 1rem;
    position: sticky;
    top: 80px;
}
.sidebar .nav-link {
    color: #4a5563;
    border-radius: 10px;
    padding: 0.5rem 0.8rem;
    margin-bottom: 0.2rem;
}
.sidebar .nav-link:hover { background: #f4f6fa; }
.sidebar .nav-link.active {
    background: linear-gradient(135deg, var(--foundation-green-dark), var(--foundation-green));
    color: #fff;
}

/* Badges */
.badge-conf {
    font-size: 0.72rem;
    padding: 0.3rem 0.55rem;
    border-radius: 8px;
}

/* Forms */
.form-control, .form-select {
    border-radius: 10px;
    border-color: #dee4ec;
}
.form-control:focus, .form-select:focus {
    border-color: var(--foundation-green);
    box-shadow: 0 0 0 0.25rem rgba(10, 110, 61, 0.15);
}

/* Section heading */
.section-heading {
    font-weight: 700;
    color: var(--foundation-green-dark);
    border-right: 4px solid var(--foundation-gold);
    padding-right: 0.8rem;
    margin-bottom: 1.2rem;
}

/* Quick suggestion chips */
.suggest-chip {
    display: inline-block;
    background: #fff;
    border: 1px solid #d8dee7;
    color: #1a2533;
    padding: 0.4rem 0.9rem;
    border-radius: 30px;
    margin: 0.25rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}
.suggest-chip:hover {
    background: var(--foundation-cream);
    border-color: var(--foundation-gold);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7785;
}
.empty-state i {
    font-size: 3.5rem;
    color: #c3cbd6;
    margin-bottom: 0.8rem;
}

/* Tutorial steps */
.tutorial-step {
    background: #fff;
    border: 1px solid #eef1f6;
    border-radius: 14px;
    padding: 1.4rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
}
.tutorial-step .step-num {
    flex: 0 0 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--foundation-green-dark), var(--foundation-green));
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

/* Tables */
.table {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
}
.table thead th {
    background: rgba(10, 110, 61, 0.07);
    color: var(--foundation-green-dark);
    font-weight: 600;
    border: none;
}

/* Persian numerals */
.persian-num {
    font-variant-numeric: tabular-nums;
}

/* ===== Management dashboard ===== */
.dash-hero {
    background: linear-gradient(120deg, var(--foundation-green-dark) 0%, var(--foundation-green) 60%),
                radial-gradient(circle at 85% 20%, rgba(201, 162, 39, 0.45), transparent 55%);
    color: #fff;
    border-radius: 18px;
    padding: 1.8rem 2rem;
    position: relative;
    overflow: hidden;
    box-shadow: var(--strong-shadow);
}
.dash-hero h3 { font-weight: 800; }
.dash-hero .hero-meta { position: relative; z-index: 1; }
.dash-hero .hero-clock {
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 14px;
    padding: 0.8rem 1.2rem;
    backdrop-filter: blur(6px);
}

/* Gradient stat cards */
.stat-card {
    position: relative;
    border-radius: 16px;
    padding: 1.25rem 1.4rem;
    color: #fff;
    overflow: hidden;
    box-shadow: var(--soft-shadow);
    transition: transform 0.15s, box-shadow 0.15s;
    height: 100%;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--strong-shadow); }
.stat-card .stat-icon {
    position: absolute;
    left: 1rem;
    top: 1rem;
    font-size: 2.6rem;
    opacity: 0.28;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.stat-card .stat-label { font-size: 0.9rem; opacity: 0.92; }
.stat-card .stat-foot { font-size: 0.78rem; opacity: 0.85; margin-top: 0.4rem; }
.stat-green  { background: linear-gradient(135deg, #0a6e3d, #074e2b); }
.stat-gold   { background: linear-gradient(135deg, #d4af37, #b8860b); }
.stat-blue   { background: linear-gradient(135deg, #2563eb, #1e40af); }
.stat-red    { background: linear-gradient(135deg, #c0392b, #922020); }
.stat-purple { background: linear-gradient(135deg, #7c3aed, #5b21b6); }
.stat-teal   { background: linear-gradient(135deg, #0d9488, #0f766e); }

/* Mini metric chips */
.metric-chip {
    background: #fff;
    border: 1px solid #eef1f6;
    border-radius: 14px;
    padding: 0.9rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--soft-shadow);
    height: 100%;
}
.metric-chip .mc-icon {
    width: 42px; height: 42px;
    border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(10, 110, 61, 0.1);
    color: var(--foundation-green-dark);
    font-size: 1.15rem;
    flex: 0 0 42px;
}
.metric-chip .mc-value { font-size: 1.3rem; font-weight: 700; line-height: 1; }
.metric-chip .mc-label { font-size: 0.78rem; color: #6b7785; }

/* Dashboard panel cards */
.dash-panel {
    background: #fff;
    border: 1px solid #eef1f6;
    border-radius: 16px;
    box-shadow: var(--soft-shadow);
    padding: 1.2rem 1.3rem;
}
.dash-panel .panel-title {
    font-weight: 700;
    color: var(--foundation-green-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* ----- Resizable / collapsible dashboard grid ----- */
.dash-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1rem;
    align-items: start;
}
.dash-grid > .dash-panel { grid-column: span 6; margin: 0; }
.dash-grid > .dash-panel.span-4 { grid-column: span 4; }
.dash-grid > .dash-panel.span-8 { grid-column: span 8; }
.dash-grid > .dash-panel.span-12,
.dash-grid > .dash-panel.panel-wide { grid-column: 1 / -1; }
@media (max-width: 991.98px) {
    .dash-grid > .dash-panel { grid-column: 1 / -1 !important; }
}

.dash-panel .panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.dash-panel .panel-head .panel-title { margin-bottom: 0; }
.panel-tools { display: flex; gap: 0.25rem; }
.panel-btn {
    border: 1px solid #e9eef5;
    background: #fff;
    color: #6b7785;
    width: 30px; height: 30px;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all 0.14s;
    font-size: 0.85rem;
}
.panel-btn:hover {
    color: var(--foundation-green-dark);
    border-color: var(--foundation-green);
    background: rgba(10, 110, 61, 0.06);
}
.dash-panel.collapsed .panel-body { display: none; }
.dash-panel.collapsed { padding-bottom: 1.2rem; }
.dash-panel.collapsed .panel-btn[data-action="collapse"] i { transform: rotate(180deg); }
.panel-btn[data-action="collapse"] i { transition: transform 0.18s; }

/* ----- Global loading overlay ----- */
.app-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 30, 45, 0.45);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1080;
}
.app-loading-overlay.show { display: flex; }
.app-loading-card {
    background: #fff;
    border-radius: 16px;
    padding: 1.6rem 2.2rem;
    box-shadow: var(--strong-shadow);
    text-align: center;
    min-width: 220px;
}
.app-loading-card .spinner-ring {
    width: 48px; height: 48px;
    border: 4px solid #e5e9f0;
    border-top-color: var(--foundation-green);
    border-radius: 50%;
    margin: 0 auto 0.9rem;
    animation: app-spin 0.8s linear infinite;
}
.app-loading-card .load-text { font-weight: 600; color: var(--foundation-green-dark); }
@keyframes app-spin { to { transform: rotate(360deg); } }

/* Inline button spinner */
.btn .btn-spin {
    width: 1rem; height: 1rem;
    border: 2px solid rgba(255,255,255,0.5);
    border-top-color: #fff;
    border-radius: 50%;
    display: inline-block;
    vertical-align: -2px;
    animation: app-spin 0.7s linear infinite;
    margin-left: 0.4rem;
}
.btn-outline-primary .btn-spin, .btn-outline-secondary .btn-spin,
.btn-outline-danger .btn-spin, .btn-light .btn-spin {
    border-color: rgba(10,110,61,0.35);
    border-top-color: var(--foundation-green);
}
.activity-item {
    display: block;
    padding: 0.65rem 0.2rem;
    border-bottom: 1px dashed #eef1f6;
    text-decoration: none;
    transition: background 0.12s;
    border-radius: 8px;
}
.activity-item:hover { background: #f7faf8; }
.quick-action {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 0.9rem;
    border-radius: 12px;
    border: 1px solid #eef1f6;
    color: #1a2533;
    text-decoration: none;
    transition: all 0.14s;
    margin-bottom: 0.5rem;
}
.quick-action:hover {
    border-color: var(--foundation-green);
    background: rgba(10, 110, 61, 0.05);
    transform: translateX(-3px);
}
.quick-action .qa-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(10, 110, 61, 0.1);
    color: var(--foundation-green-dark);
}

/* Loader */
.loader-dots {
    display: inline-block;
}
.loader-dots span {
    display: inline-block;
    width: 8px; height: 8px; background: var(--foundation-green);
    border-radius: 50%;
    margin: 0 2px;
    animation: dot-pulse 1.2s infinite ease-in-out;
}
.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-pulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Rendered Markdown (assistant answers, studio output, suggested responses)
   The model writes headings, bold text, numbered reasoning and [۱] citations;
   `|markdown` turns that into the elements styled below.
   ========================================================================== */

.md-body {
    line-height: 2;
    /* A long URL or an untokenised Latin string must wrap, not widen the card. */
    overflow-wrap: anywhere;
    word-break: break-word;
}
.md-body > :first-child { margin-top: 0; }
.md-body > :last-child { margin-bottom: 0; }

.md-body p {
    margin-bottom: 0.85rem;
}

.md-body h3,
.md-body h4,
.md-body h5,
.md-body h6 {
    color: var(--foundation-green-dark);
    font-weight: 700;
    line-height: 1.7;
    margin: 1.4rem 0 0.6rem;
}
.md-body h3 { font-size: 1.2rem; }
.md-body h4 { font-size: 1.1rem; }
.md-body h5 { font-size: 1rem; }
.md-body h6 { font-size: 0.94rem; color: #41506a; }

/* A hairline under the top-level headings gives the answer visible structure
   without turning every section into a boxed card. */
.md-body h3,
.md-body h4 {
    padding-bottom: 0.35rem;
    border-bottom: 1px solid rgba(10, 110, 61, 0.14);
}

.md-body ul,
.md-body ol {
    margin: 0 0 0.9rem;
    padding-inline-start: 1.5rem;
}
.md-body li { margin-bottom: 0.4rem; }
.md-body li > ul,
.md-body li > ol { margin-top: 0.4rem; margin-bottom: 0.2rem; }
.md-body ol { list-style: decimal; }
.md-body ul { list-style: disc; }

.md-body strong { color: #12203a; font-weight: 700; }

.md-body hr {
    margin: 1.2rem 0;
    border-top: 1px dashed #d9e0ea;
    opacity: 1;
}

.md-quote {
    margin: 0 0 0.9rem;
    padding: 0.6rem 1rem;
    border-inline-start: 3px solid var(--foundation-gold);
    background: rgba(201, 162, 39, 0.07);
    border-radius: 0 10px 10px 0;
    color: #41506a;
}
.md-quote p:last-child { margin-bottom: 0; }

/* Code keeps LTR direction — an RTL container would scramble it. */
.md-body code {
    direction: ltr;
    unicode-bidi: isolate;
    background: #f1f4f8;
    border: 1px solid #e3e9f0;
    border-radius: 6px;
    padding: 0.05rem 0.35rem;
    font-size: 0.88em;
    color: #b5316b;
}
.md-pre {
    direction: ltr;
    text-align: left;
    background: #10233a;
    color: #e6edf5;
    border-radius: 12px;
    padding: 0.9rem 1rem;
    margin-bottom: 0.9rem;
    overflow-x: auto;
}
.md-pre code {
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
    font-size: 0.85rem;
}

/* Citation marker — mirrors the [۱] badge on the source cards below the answer. */
.md-cite {
    display: inline-block;
    background: rgba(10, 110, 61, 0.1);
    color: var(--foundation-green-dark);
    border-radius: 6px;
    padding: 0 0.3rem;
    margin: 0 0.12rem;
    font-size: 0.82em;
    font-weight: 600;
    vertical-align: baseline;
    white-space: nowrap;
}

.md-table {
    margin-bottom: 0;
    /* Below this the columns collapse into unreadable slivers; the wrapper
       scrolls instead. */
    min-width: 480px;
}
.md-table th {
    background: var(--foundation-cream);
    color: var(--foundation-green-dark);
    white-space: nowrap;
}

.md-body-lg { font-size: 1.05rem; line-height: 2.1; }

/* ==========================================================================
   Responsive behaviour
   Bootstrap handles the grid; these rules cover the custom components, which
   had no breakpoints of their own and overflowed on a phone.
   ========================================================================== */

/* Nothing may push the page sideways. Chart.js sizes its own canvas, so only
   the width ceiling is imposed — forcing its height would fight the library. */
img, svg, video, iframe { max-width: 100%; }
canvas { max-width: 100%; }

/* Any table wide enough to overflow scrolls inside its own box rather than
   stretching the page — the wrapper is `.table-responsive`. */
.table-responsive { -webkit-overflow-scrolling: touch; }

.chat-bubble,
.source-card,
.source-snippet {
    overflow-wrap: anywhere;
}

@media (max-width: 991.98px) {
    .chat-bubble.user { max-width: 92%; }
    .chat-bubble.assistant { max-width: 100%; }
}

@media (max-width: 767.98px) {
    body { font-size: 0.95rem; }

    /* The chat card carried `p-4` (1.5rem) on every side, which on a 360px
       screen spent a fifth of the width on padding. */
    .chat-pane { padding: 1rem !important; border-radius: 14px; }
    .chat-bubble {
        padding: 0.8rem 0.9rem;
        line-height: 1.85;
        border-radius: 14px;
    }
    .chat-bubble.user,
    .chat-bubble.assistant { max-width: 100%; }

    .md-body { line-height: 1.9; }
    .md-body-lg { font-size: 1rem; line-height: 1.95; }
    .md-body h3 { font-size: 1.08rem; }
    .md-body h4 { font-size: 1.02rem; }
    .md-body h5,
    .md-body h6 { font-size: 0.96rem; }
    .md-body ul,
    .md-body ol { padding-inline-start: 1.15rem; }

    /* Long action rows (save / feedback / new chat) stack instead of clipping. */
    .chat-pane .d-flex.gap-2.flex-wrap .btn { flex: 1 1 auto; }

    .source-card { padding: 0.7rem 0.8rem; }
    .card, .dash-panel { border-radius: 12px; }
    .kpi-tile .kpi-value { font-size: 1.35rem; }
    h1, .h1 { font-size: 1.6rem; }
    h2, .h2 { font-size: 1.4rem; }
    h3, .h3 { font-size: 1.2rem; }
}

@media (max-width: 575.98px) {
    .container, .container-fluid { padding-inline: 0.75rem; }
    /* Button rows wrap onto a second line instead of being squeezed or clipped. */
    main .d-flex.gap-2:not(.flex-nowrap) { flex-wrap: wrap; }
    .app-loading-card { min-width: 0; max-width: calc(100vw - 2rem); }
    .navbar-brand small { display: none; }
    .btn-sm { padding: 0.3rem 0.5rem; }
    .md-table { min-width: 380px; }
    .table > :not(caption) > * > * { padding: 0.4rem 0.5rem; }
}

/* Print: the studio and answer pages are routinely printed for archives. */
@media print {
    .navbar, footer, .app-loading-overlay,
    .btn, form, .no-print { display: none !important; }
    body { background: #fff; }
    .chat-pane, .card { box-shadow: none; border: 1px solid #ddd; }
    .md-body { line-height: 1.8; }
}
