/* ==========================================================================
   Ofsted Insights — Dashboard Stylesheet
   A professional, data-focused design for the analytics application.
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. CSS Custom Properties
   -------------------------------------------------------------------------- */

:root {
    /* Primary palette */
    --ia-primary: #1e3a5f;
    --ia-primary-dark: #152d4a;
    --ia-primary-light: #2a4f7a;
    --ia-secondary: #0ea5e9;
    --ia-secondary-dark: #0284c7;
    --ia-secondary-light: #38bdf8;

    /* Backgrounds */
    --ia-bg: #f0f4f8;
    --ia-card: #ffffff;

    /* Text */
    --ia-text: #1a202c;
    --ia-text-secondary: #4a5568;
    --ia-text-muted: #718096;

    /* Borders & shadows */
    --ia-border: rgba(30, 58, 95, 0.1);
    --ia-shadow: 0 1px 3px rgba(30, 58, 95, 0.08);
    --ia-shadow-md: 0 4px 12px rgba(30, 58, 95, 0.1);
    --ia-shadow-lg: 0 8px 24px rgba(30, 58, 95, 0.12);

    /* Radii */
    --ia-radius: 8px;
    --ia-radius-lg: 12px;
    --ia-radius-sm: 4px;
    --ia-radius-pill: 50rem;

    /* Transitions */
    --ia-transition: all 0.2s ease;
    --ia-transition-slow: all 0.35s ease;

    /* Semantic colours */
    --ia-success: #10b981;
    --ia-success-bg: rgba(16, 185, 129, 0.1);
    --ia-warning: #f59e0b;
    --ia-warning-bg: rgba(245, 158, 11, 0.1);
    --ia-danger: #ef4444;
    --ia-danger-bg: rgba(239, 68, 68, 0.1);
    --ia-info: #0ea5e9;
    --ia-info-bg: rgba(14, 165, 233, 0.1);

    /* Chart accent colours */
    --ia-chart-1: #0ea5e9;
    --ia-chart-2: #8b5cf6;
    --ia-chart-3: #10b981;
    --ia-chart-4: #f59e0b;
    --ia-chart-5: #ef4444;
}


/* --------------------------------------------------------------------------
   2. Base Typography & Layout
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
        "Segoe UI Emoji";
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--ia-text);
    background-color: var(--ia-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

main,
.main-content {
    flex: 1 0 auto;
    padding-top: 1.5rem;
    padding-bottom: 2rem;
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    color: var(--ia-text);
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 0.5em;
}

h1, .h1 { font-size: 1.75rem; }
h2, .h2 { font-size: 1.45rem; }
h3, .h3 { font-size: 1.2rem; }
h4, .h4 { font-size: 1.05rem; }
h5, .h5 { font-size: 0.95rem; }
h6, .h6 { font-size: 0.85rem; }

p {
    margin-bottom: 1rem;
    color: var(--ia-text-secondary);
}

small,
.small {
    font-size: 0.85rem;
}

.text-muted {
    color: var(--ia-text-muted) !important;
}

::selection {
    background-color: rgba(14, 165, 233, 0.2);
    color: var(--ia-text);
}


/* --------------------------------------------------------------------------
   3. Navbar
   -------------------------------------------------------------------------- */

.navbar {
    background-color: var(--ia-primary) !important;
    border: none;
    box-shadow: 0 2px 8px rgba(30, 58, 95, 0.15);
    padding: 0.6rem 1rem;
    z-index: 1030;
}

.navbar-brand {
    color: #ffffff !important;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--ia-transition);
}

.navbar-brand:hover {
    color: rgba(255, 255, 255, 0.9) !important;
}

.navbar-brand img {
    height: 32px;
    width: auto;
}

.navbar-dark .navbar-nav .nav-link,
.navbar .navbar-nav .nav-link {
    color: rgba(255, 255, 255, 0.85) !important;
    font-weight: 500;
    font-size: 0.9rem;
    padding: 0.45rem 0.9rem;
    border-radius: var(--ia-radius-pill);
    transition: var(--ia-transition);
    margin: 0 0.1rem;
}

.navbar-dark .navbar-nav .nav-link:hover,
.navbar .navbar-nav .nav-link:hover {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.1);
}

.navbar-dark .navbar-nav .nav-link.active,
.navbar .navbar-nav .nav-link.active,
.navbar-dark .navbar-nav .show > .nav-link,
.navbar .navbar-nav .show > .nav-link {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.15);
}

.navbar-dark .navbar-toggler,
.navbar .navbar-toggler {
    border-color: rgba(255, 255, 255, 0.35);
    padding: 0.35rem 0.6rem;
}

.navbar-dark .navbar-toggler-icon,
.navbar .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255,255,255,0.9%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* Navbar dropdowns */
.navbar .dropdown-menu {
    background-color: #ffffff;
    border: 1px solid var(--ia-border);
    border-radius: var(--ia-radius);
    box-shadow: var(--ia-shadow-md);
    padding: 0.4rem 0;
    margin-top: 0.35rem;
    min-width: 12rem;
}

.navbar .dropdown-item {
    color: var(--ia-text);
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    transition: var(--ia-transition);
}

.navbar .dropdown-item:hover,
.navbar .dropdown-item:focus {
    background-color: var(--ia-bg);
    color: var(--ia-primary);
}

.navbar .dropdown-item.active,
.navbar .dropdown-item:active {
    background-color: var(--ia-primary);
    color: #ffffff;
}

.navbar .dropdown-divider {
    border-top-color: var(--ia-border);
}


/* --------------------------------------------------------------------------
   4. Cards
   -------------------------------------------------------------------------- */

.card {
    background-color: var(--ia-card);
    border: 1px solid var(--ia-border);
    border-radius: var(--ia-radius-lg);
    box-shadow: var(--ia-shadow);
    transition: box-shadow 0.2s ease;
}

.card-header {
    background-color: #f8fafc;
    border-bottom: 1px solid var(--ia-border);
    padding: 0.75rem 1.1rem;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ia-text-secondary);
    border-radius: var(--ia-radius-lg) var(--ia-radius-lg) 0 0 !important;
}

.card-body {
    padding: 1.1rem;
}

.card-footer {
    background-color: #f8fafc;
    border-top: 1px solid var(--ia-border);
    padding: 0.75rem 1.1rem;
    border-radius: 0 0 var(--ia-radius-lg) var(--ia-radius-lg) !important;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--ia-text);
    margin-bottom: 0.5rem;
}

.card-subtitle {
    color: var(--ia-text-muted);
    font-size: 0.85rem;
}

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


/* --------------------------------------------------------------------------
   5. Buttons
   -------------------------------------------------------------------------- */

.btn {
    font-weight: 500;
    font-size: 0.9rem;
    border-radius: var(--ia-radius);
    padding: 0.45rem 1rem;
    transition: var(--ia-transition);
    border: none;
    cursor: pointer;
    line-height: 1.5;
}

.btn:focus,
.btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25);
    outline: none;
}

/* Primary */
.btn-primary {
    background-color: var(--ia-primary);
    color: #ffffff;
    border: 1px solid var(--ia-primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--ia-primary-light);
    border-color: var(--ia-primary-light);
    color: #ffffff;
}

.btn-primary:active {
    background-color: var(--ia-primary-dark);
    border-color: var(--ia-primary-dark);
}

/* Secondary */
.btn-secondary {
    background-color: var(--ia-secondary);
    color: #ffffff;
    border: 1px solid var(--ia-secondary);
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: var(--ia-secondary-dark);
    border-color: var(--ia-secondary-dark);
    color: #ffffff;
}

/* Outline Primary */
.btn-outline-primary {
    background-color: transparent;
    color: var(--ia-primary);
    border: 1px solid var(--ia-primary);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background-color: var(--ia-primary);
    color: #ffffff;
    border-color: var(--ia-primary);
}

/* Outline Secondary */
.btn-outline-secondary {
    background-color: transparent;
    color: var(--ia-secondary);
    border: 1px solid var(--ia-secondary);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background-color: var(--ia-secondary);
    color: #ffffff;
    border-color: var(--ia-secondary);
}

/* Success */
.btn-success {
    background-color: var(--ia-success);
    color: #ffffff;
    border: 1px solid var(--ia-success);
}

.btn-success:hover,
.btn-success:focus {
    background-color: #0d9668;
    border-color: #0d9668;
    color: #ffffff;
}

/* Danger */
.btn-danger {
    background-color: var(--ia-danger);
    color: #ffffff;
    border: 1px solid var(--ia-danger);
}

.btn-danger:hover,
.btn-danger:focus {
    background-color: #dc2626;
    border-color: #dc2626;
    color: #ffffff;
}

/* Warning */
.btn-warning {
    background-color: var(--ia-warning);
    color: #ffffff;
    border: 1px solid var(--ia-warning);
}

.btn-warning:hover,
.btn-warning:focus {
    background-color: #d97706;
    border-color: #d97706;
    color: #ffffff;
}

/* Info */
.btn-info {
    background-color: var(--ia-info);
    color: #ffffff;
    border: 1px solid var(--ia-info);
}

.btn-info:hover,
.btn-info:focus {
    background-color: var(--ia-secondary-dark);
    border-color: var(--ia-secondary-dark);
    color: #ffffff;
}

/* Light */
.btn-light {
    background-color: #f8fafc;
    color: var(--ia-text-secondary);
    border: 1px solid var(--ia-border);
}

.btn-light:hover,
.btn-light:focus {
    background-color: #edf2f7;
    color: var(--ia-text);
}

/* Link style button */
.btn-link {
    color: var(--ia-secondary);
    text-decoration: none;
    font-weight: 500;
}

.btn-link:hover {
    color: var(--ia-secondary-dark);
    text-decoration: underline;
}

/* Button sizes */
.btn-sm {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
}

.btn-lg {
    font-size: 1rem;
    padding: 0.6rem 1.4rem;
    border-radius: 10px;
}

/* Button groups */
.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child {
    border-radius: var(--ia-radius) 0 0 var(--ia-radius);
}

.btn-group .btn:last-child {
    border-radius: 0 var(--ia-radius) var(--ia-radius) 0;
}


/* --------------------------------------------------------------------------
   6. Tables
   -------------------------------------------------------------------------- */

.table {
    width: 100%;
    margin-bottom: 1rem;
    color: var(--ia-text);
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 0.65rem 0.85rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--ia-border);
}

.table thead th {
    background-color: var(--ia-primary);
    color: #ffffff;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--ia-primary-dark);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

.table tbody tr:hover {
    background-color: #edf2f7;
}

.table-bordered {
    border: 1px solid var(--ia-border);
}

.table-bordered th,
.table-bordered td {
    border: 1px solid var(--ia-border);
}

.table-bordered thead th {
    border-color: var(--ia-primary-dark);
}

.table-sm th,
.table-sm td {
    padding: 0.4rem 0.6rem;
}

/* Scrollable table wrapper */
.table-responsive {
    border-radius: var(--ia-radius);
    overflow: hidden;
}

.table-responsive .table {
    margin-bottom: 0;
}

/* Numeric cells: tabular figures */
.table td.numeric,
.table .text-numeric {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    text-align: right;
}


/* --------------------------------------------------------------------------
   7. Forms
   -------------------------------------------------------------------------- */

.form-control,
.form-select {
    border: 1px solid var(--ia-border);
    border-radius: var(--ia-radius);
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
    color: var(--ia-text);
    background-color: #ffffff;
    transition: var(--ia-transition);
    line-height: 1.5;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--ia-secondary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
    outline: none;
}

.form-control::placeholder {
    color: var(--ia-text-muted);
    opacity: 0.7;
}

.form-label,
label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ia-text-secondary);
    margin-bottom: 0.3rem;
}

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

.form-check-input:checked {
    background-color: var(--ia-secondary);
    border-color: var(--ia-secondary);
}

.form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
    border-color: var(--ia-secondary);
}

.input-group-text {
    background-color: #f8fafc;
    border: 1px solid var(--ia-border);
    color: var(--ia-text-secondary);
    font-size: 0.9rem;
}

/* Form control sizing */
.form-control-sm {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
}

.form-control-lg {
    font-size: 1rem;
    padding: 0.65rem 1rem;
    border-radius: 10px;
}

textarea.form-control {
    min-height: 80px;
}


/* --------------------------------------------------------------------------
   8. Alerts
   -------------------------------------------------------------------------- */

.alert {
    border-radius: var(--ia-radius);
    padding: 0.85rem 1.1rem;
    font-size: 0.9rem;
    border: none;
    font-weight: 500;
}

.alert-success {
    background-color: var(--ia-success-bg);
    color: #065f46;
    border-left: 4px solid var(--ia-success);
}

.alert-danger {
    background-color: var(--ia-danger-bg);
    color: #991b1b;
    border-left: 4px solid var(--ia-danger);
}

.alert-warning {
    background-color: var(--ia-warning-bg);
    color: #92400e;
    border-left: 4px solid var(--ia-warning);
}

.alert-info {
    background-color: var(--ia-info-bg);
    color: #0c4a6e;
    border-left: 4px solid var(--ia-info);
}

.alert-primary {
    background-color: rgba(30, 58, 95, 0.08);
    color: var(--ia-primary-dark);
    border-left: 4px solid var(--ia-primary);
}

.alert .btn-close {
    opacity: 0.5;
}

.alert .btn-close:hover {
    opacity: 0.8;
}


/* --------------------------------------------------------------------------
   9. Badges
   -------------------------------------------------------------------------- */

.badge {
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.3em 0.65em;
    border-radius: var(--ia-radius-sm);
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1;
    display: inline-block;
    vertical-align: middle;
}

.badge.bg-primary,
.badge-primary {
    background-color: var(--ia-primary) !important;
    color: #ffffff;
}

.badge.bg-secondary,
.badge-secondary {
    background-color: var(--ia-secondary) !important;
    color: #ffffff;
}

.badge.bg-success,
.badge-success {
    background-color: var(--ia-success) !important;
    color: #ffffff;
}

.badge.bg-danger,
.badge-danger {
    background-color: var(--ia-danger) !important;
    color: #ffffff;
}

.badge.bg-warning,
.badge-warning {
    background-color: var(--ia-warning) !important;
    color: #ffffff;
}

.badge.bg-info,
.badge-info {
    background-color: var(--ia-info) !important;
    color: #ffffff;
}

/* Ofsted rating badges */
.badge-exceptional,
.badge-outstanding {
    background-color: #ffd700;
    color: #1a202c;
}

.badge-strong,
.badge-good {
    background-color: var(--ia-success);
    color: #ffffff;
}

.badge-expected,
.badge-requires-improvement {
    background-color: var(--ia-secondary);
    color: #ffffff;
}

.badge-needs-attention {
    background-color: var(--ia-warning);
    color: #ffffff;
}

.badge-urgent,
.badge-inadequate {
    background-color: var(--ia-danger);
    color: #ffffff;
}

/* Badge pill variant */
.badge-pill,
.rounded-pill {
    border-radius: var(--ia-radius-pill);
}


/* --------------------------------------------------------------------------
   10. Insights Selector Bar
   -------------------------------------------------------------------------- */

.insights-selector-bar,
.selector-bar {
    background-color: var(--ia-card);
    border: 1px solid var(--ia-border);
    border-top: 3px solid var(--ia-secondary);
    border-radius: var(--ia-radius-lg);
    box-shadow: var(--ia-shadow);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

.insights-selector-bar .form-label,
.selector-bar .form-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ia-text-muted);
    font-weight: 600;
}

.insights-selector-bar .form-select,
.selector-bar .form-select {
    font-size: 0.88rem;
}


/* --------------------------------------------------------------------------
   11. KPI Cards
   -------------------------------------------------------------------------- */

.insights-kpi-card,
.kpi-card {
    background-color: var(--ia-card);
    border: 1px solid var(--ia-border);
    border-top: 3px solid var(--ia-secondary);
    border-radius: var(--ia-radius-lg);
    box-shadow: var(--ia-shadow);
    padding: 1.1rem;
    text-align: center;
    transition: var(--ia-transition);
}

.insights-kpi-card:hover,
.kpi-card:hover {
    box-shadow: var(--ia-shadow-md);
}

/* Colour variants for KPI top border */
.kpi-card--blue,
.insights-kpi-card--blue    { border-top-color: var(--ia-chart-1); }
.kpi-card--purple,
.insights-kpi-card--purple  { border-top-color: var(--ia-chart-2); }
.kpi-card--green,
.insights-kpi-card--green   { border-top-color: var(--ia-chart-3); }
.kpi-card--amber,
.insights-kpi-card--amber   { border-top-color: var(--ia-chart-4); }
.kpi-card--red,
.insights-kpi-card--red     { border-top-color: var(--ia-chart-5); }
.kpi-card--navy,
.insights-kpi-card--navy    { border-top-color: var(--ia-primary); }

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ia-text);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    margin-bottom: 0.25rem;
}

.kpi-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ia-text-muted);
    margin: 0;
}

.kpi-delta {
    font-size: 0.78rem;
    font-weight: 600;
    margin-top: 0.3rem;
}

.kpi-delta--up {
    color: var(--ia-success);
}

.kpi-delta--down {
    color: var(--ia-danger);
}

.kpi-delta--neutral {
    color: var(--ia-text-muted);
}


/* --------------------------------------------------------------------------
   12. Horizontal Bar Charts
   -------------------------------------------------------------------------- */

.chart-bar-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chart-bar-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0.5rem;
    border-radius: var(--ia-radius-sm);
    transition: var(--ia-transition);
}

.chart-bar-row:hover {
    background-color: #f8fafc;
}

.chart-bar-label {
    flex: 0 0 140px;
    font-size: 0.82rem;
    color: var(--ia-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
    font-weight: 500;
}

.chart-bar-track {
    flex: 1 1 auto;
    height: 22px;
    background-color: #e2e8f0;
    border-radius: var(--ia-radius-pill);
    overflow: hidden;
    position: relative;
}

.chart-bar-fill {
    height: 100%;
    border-radius: var(--ia-radius-pill);
    transition: width 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    min-width: 2px;
}

/* Chart bar colour variants */
.chart-bar-fill--blue   { background-color: var(--ia-chart-1); }
.chart-bar-fill--purple { background-color: var(--ia-chart-2); }
.chart-bar-fill--green  { background-color: var(--ia-chart-3); }
.chart-bar-fill--amber  { background-color: var(--ia-chart-4); }
.chart-bar-fill--red    { background-color: var(--ia-chart-5); }
.chart-bar-fill--navy   { background-color: var(--ia-primary); }

.chart-bar-value {
    flex: 0 0 55px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ia-text);
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

/* Trend delta badges (▲/▼/→) shown after the value in bar+trend charts */
.chart-trend-good,
.chart-trend-bad,
.chart-trend-stable {
    flex: 0 0 auto;
    font-size: 0.7rem;
    font-weight: 700;
    padding-left: 0.3rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.chart-trend-good   { color: #10b981; }
.chart-trend-bad    { color: #ef4444; }
.chart-trend-stable { color: #94a3b8; }

/* Fixed-width right column: latest value + trend badge + prior 2 years.
   Fixed width is the key to keeping all bars the same width regardless of
   how many digits the value contains. */
.chart-history-panel {
    flex: 0 0 105px;
    text-align: right;
    line-height: 1.35;
}

.chart-history-latest {
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
    gap: 0.3rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ia-text);
    font-variant-numeric: tabular-nums;
}

.chart-history-prev {
    font-size: 0.68rem;
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
}

.chart-history-year {
    opacity: 0.75;
}


/* --------------------------------------------------------------------------
   13. AI Narrative & School Highlights
   -------------------------------------------------------------------------- */

.narrative-section,
.ai-narrative {
    padding: 1rem 1.25rem;
}

.narrative-text p {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--ia-text-secondary);
    margin-bottom: 0.85rem;
}

.narrative-text p:last-child {
    margin-bottom: 0;
}

.narrative-text strong {
    color: var(--ia-text);
    font-weight: 600;
}

.narrative-text ul,
.narrative-text ol {
    padding-left: 1.25rem;
    margin-bottom: 0.85rem;
}

.narrative-text li {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--ia-text-secondary);
    margin-bottom: 0.3rem;
}

/* School highlight cards */
.school-highlight-card {
    background-color: var(--ia-card);
    border: 1px solid var(--ia-border);
    border-left: 3px solid var(--ia-secondary);
    border-radius: var(--ia-radius);
    padding: 0.85rem 1rem;
    margin-bottom: 0.6rem;
    transition: var(--ia-transition);
}

.school-highlight-card:hover {
    background-color: #f8fafc;
    box-shadow: var(--ia-shadow);
}

.school-highlight-card h6,
.school-highlight-card .school-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--ia-text);
    margin-bottom: 0.25rem;
}

.school-highlight-card .school-detail {
    font-size: 0.82rem;
    color: var(--ia-text-muted);
}

/* Highlight colour variants */
.school-highlight-card--success { border-left-color: var(--ia-success); }
.school-highlight-card--warning { border-left-color: var(--ia-warning); }
.school-highlight-card--danger  { border-left-color: var(--ia-danger); }

/* School Search result cards */
.school-result-card {
    border-left: 3px solid var(--ia-primary);
    transition: box-shadow 0.15s, border-color 0.15s;
}
.school-result-card:hover {
    box-shadow: 0 4px 12px rgba(30,58,95,0.18);
    border-left-color: var(--ia-secondary);
}
.school-result-card mark {
    background: #fef08a;
    padding: 0 2px;
    border-radius: 2px;
}


/* --------------------------------------------------------------------------
   14. Chat Interface
   -------------------------------------------------------------------------- */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-messages-container {
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem;
    background-color: #f8fafc;
    border: 1px solid var(--ia-border);
    border-radius: var(--ia-radius);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-msg {
    display: flex;
    gap: 0.5rem;
    max-width: 85%;
}

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

.chat-msg--assistant {
    align-self: flex-start;
}

.chat-msg-bubble {
    padding: 0.6rem 0.9rem;
    border-radius: var(--ia-radius-lg);
    font-size: 0.88rem;
    line-height: 1.55;
    word-wrap: break-word;
}

.chat-msg-bubble-user {
    background-color: var(--ia-primary);
    color: #ffffff;
    border-bottom-right-radius: var(--ia-radius-sm);
}

.chat-msg-bubble-assistant {
    background-color: #ffffff;
    color: var(--ia-text);
    border: 1px solid var(--ia-border);
    border-bottom-left-radius: var(--ia-radius-sm);
}

.chat-msg-bubble-assistant p {
    margin-bottom: 0.5rem;
    color: var(--ia-text-secondary);
}

.chat-msg-bubble-assistant p:last-child {
    margin-bottom: 0;
}

.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

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

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

/* Chat input area */
.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0;
}

.chat-input-area .form-control {
    flex: 1;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.6rem 0.9rem;
    background-color: #ffffff;
    border: 1px solid var(--ia-border);
    border-radius: var(--ia-radius-lg);
    border-bottom-left-radius: var(--ia-radius-sm);
    align-self: flex-start;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background-color: var(--ia-text-muted);
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}


/* --------------------------------------------------------------------------
   15. School Table (Insights View)
   -------------------------------------------------------------------------- */

#schoolTable {
    font-size: 0.85rem;
}

#schoolTable th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--ia-primary);
    color: #ffffff;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    white-space: nowrap;
    padding: 0.6rem 0.75rem;
}

#schoolTable td {
    padding: 0.55rem 0.75rem;
    vertical-align: middle;
}

/* Narrative cell truncation */
.narrative-cell {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
    transition: var(--ia-transition);
}

.narrative-cell:hover,
.narrative-cell.expanded {
    white-space: normal;
    overflow: visible;
    max-width: none;
}

/* Sortable column headers */
.sortable-header {
    cursor: pointer;
    user-select: none;
    transition: var(--ia-transition);
}

.sortable-header:hover {
    background-color: var(--ia-primary-light) !important;
}

.sortable-header::after {
    content: "\2195";
    margin-left: 0.3rem;
    opacity: 0.5;
    font-size: 0.65rem;
}

.sortable-header.sort-asc::after {
    content: "\2191";
    opacity: 1;
}

.sortable-header.sort-desc::after {
    content: "\2193";
    opacity: 1;
}


/* --------------------------------------------------------------------------
   16. Footer
   -------------------------------------------------------------------------- */

footer,
.site-footer {
    background-color: var(--ia-primary);
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.82rem;
    padding: 1rem 0;
    margin-top: auto;
    border-top: 2px solid var(--ia-primary-light);
    flex-shrink: 0;
}

footer a,
.site-footer a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    transition: var(--ia-transition);
}

footer a:hover,
.site-footer a:hover {
    color: #ffffff;
}

footer .text-muted,
.site-footer .text-muted {
    color: rgba(255, 255, 255, 0.55) !important;
}


/* --------------------------------------------------------------------------
   17. Progress Bars
   -------------------------------------------------------------------------- */

.progress {
    height: 10px;
    border-radius: var(--ia-radius-pill);
    background-color: #e2e8f0;
    overflow: hidden;
}

.progress-bar {
    background-color: var(--ia-secondary);
    border-radius: var(--ia-radius-pill);
    transition: width 0.6s ease;
}

.progress-bar-success,
.progress-bar.bg-success {
    background-color: var(--ia-success) !important;
}

.progress-bar-warning,
.progress-bar.bg-warning {
    background-color: var(--ia-warning) !important;
}

.progress-bar-danger,
.progress-bar.bg-danger {
    background-color: var(--ia-danger) !important;
}

.progress-bar-primary,
.progress-bar.bg-primary {
    background-color: var(--ia-primary) !important;
}

/* Stacked progress */
.progress-stacked .progress-bar {
    border-radius: 0;
}


/* --------------------------------------------------------------------------
   18. Links
   -------------------------------------------------------------------------- */

a {
    color: var(--ia-secondary);
    text-decoration: none;
    transition: var(--ia-transition);
}

a:hover {
    color: var(--ia-secondary-dark);
    text-decoration: underline;
}

a:focus-visible {
    outline: 2px solid var(--ia-secondary);
    outline-offset: 2px;
    border-radius: 2px;
}


/* --------------------------------------------------------------------------
   19. Responsive Adjustments
   -------------------------------------------------------------------------- */

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

    h1, .h1 { font-size: 1.4rem; }
    h2, .h2 { font-size: 1.2rem; }
    h3, .h3 { font-size: 1.05rem; }

    .card {
        border-radius: var(--ia-radius);
    }

    .card-header {
        border-radius: var(--ia-radius) var(--ia-radius) 0 0 !important;
        padding: 0.6rem 0.9rem;
    }

    .card-body {
        padding: 0.85rem;
    }

    .btn {
        padding: 0.4rem 0.85rem;
        font-size: 0.85rem;
    }

    .btn-lg {
        padding: 0.5rem 1.1rem;
        font-size: 0.95rem;
    }

    .insights-selector-bar,
    .selector-bar {
        padding: 0.85rem 1rem;
    }

    .kpi-value {
        font-size: 1.25rem;
    }

    .kpi-label {
        font-size: 0.65rem;
    }

    .chart-bar-label {
        flex: 0 0 100px;
        font-size: 0.75rem;
    }

    .chart-bar-value {
        flex: 0 0 45px;
        font-size: 0.75rem;
    }

    .chart-history-panel {
        flex: 0 0 90px;
    }

    .chart-history-latest {
        font-size: 0.75rem;
    }

    .chart-history-prev {
        font-size: 0.63rem;
    }

    .chat-messages-container {
        max-height: 300px;
    }

    .narrative-cell {
        max-width: 180px;
    }

    .navbar-brand {
        font-size: 1rem;
    }
}

@media (max-width: 576px) {
    main,
    .main-content {
        padding-top: 1rem;
        padding-bottom: 1.25rem;
    }

    .chart-bar-label {
        flex: 0 0 80px;
        font-size: 0.7rem;
    }

    .chart-bar-track {
        height: 18px;
    }

    .chart-history-panel {
        flex: 0 0 78px;
    }

    .chat-msg {
        max-width: 92%;
    }

    .insights-kpi-card,
    .kpi-card {
        padding: 0.85rem;
    }
}


/* --------------------------------------------------------------------------
   20. Scrollbar Styling (WebKit)
   -------------------------------------------------------------------------- */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #edf2f7;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(30, 58, 95, 0.25);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(30, 58, 95, 0.4);
}

/* Chat container scrollbar */
.chat-messages-container::-webkit-scrollbar {
    width: 6px;
}

.chat-messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages-container::-webkit-scrollbar-thumb {
    background: rgba(30, 58, 95, 0.15);
    border-radius: 3px;
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(30, 58, 95, 0.25) #edf2f7;
}


/* --------------------------------------------------------------------------
   21. Utility Classes & Bootstrap Overrides
   -------------------------------------------------------------------------- */

/* Section spacing */
.section-gap {
    margin-bottom: 1.5rem;
}

.section-gap-sm {
    margin-bottom: 0.75rem;
}

/* Truncated text */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Tabular numbers */
.tabular-nums,
.text-tabular {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

/* Accent borders */
.border-accent-blue   { border-left: 3px solid var(--ia-chart-1) !important; }
.border-accent-purple { border-left: 3px solid var(--ia-chart-2) !important; }
.border-accent-green  { border-left: 3px solid var(--ia-chart-3) !important; }
.border-accent-amber  { border-left: 3px solid var(--ia-chart-4) !important; }
.border-accent-red    { border-left: 3px solid var(--ia-chart-5) !important; }

/* Background fills */
.bg-ia-primary   { background-color: var(--ia-primary) !important; }
.bg-ia-secondary { background-color: var(--ia-secondary) !important; }
.bg-ia-success   { background-color: var(--ia-success) !important; }
.bg-ia-warning   { background-color: var(--ia-warning) !important; }
.bg-ia-danger    { background-color: var(--ia-danger) !important; }
.bg-ia-light     { background-color: #f8fafc !important; }
.bg-ia-bg        { background-color: var(--ia-bg) !important; }

/* Text colours */
.text-ia-primary   { color: var(--ia-primary) !important; }
.text-ia-secondary { color: var(--ia-secondary) !important; }
.text-ia-success   { color: var(--ia-success) !important; }
.text-ia-warning   { color: var(--ia-warning) !important; }
.text-ia-danger    { color: var(--ia-danger) !important; }

/* Fade-in animation */
.fade-in {
    animation: fadeIn 0.35s ease-in;
}

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

/* Loading spinner */
.spinner-ia {
    width: 28px;
    height: 28px;
    border: 3px solid var(--ia-border);
    border-top-color: var(--ia-secondary);
    border-radius: 50%;
    animation: spinnerRotate 0.7s linear infinite;
}

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

/* Divider */
.divider {
    height: 1px;
    background-color: var(--ia-border);
    margin: 1rem 0;
}

/* Tooltip overrides */
.tooltip-inner {
    background-color: var(--ia-primary);
    font-size: 0.78rem;
    padding: 0.35rem 0.65rem;
    border-radius: var(--ia-radius-sm);
}

.tooltip .tooltip-arrow::before {
    border-top-color: var(--ia-primary);
}

/* Modal overrides */
.modal-content {
    border: none;
    border-radius: var(--ia-radius-lg);
    box-shadow: var(--ia-shadow-lg);
}

.modal-header {
    background-color: #f8fafc;
    border-bottom: 1px solid var(--ia-border);
    border-radius: var(--ia-radius-lg) var(--ia-radius-lg) 0 0;
    padding: 0.85rem 1.1rem;
}

.modal-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--ia-text);
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    background-color: #f8fafc;
    border-top: 1px solid var(--ia-border);
    border-radius: 0 0 var(--ia-radius-lg) var(--ia-radius-lg);
    padding: 0.75rem 1.1rem;
}

/* Pagination overrides */
.page-link {
    color: var(--ia-primary);
    border-color: var(--ia-border);
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    transition: var(--ia-transition);
}

.page-link:hover {
    background-color: var(--ia-bg);
    color: var(--ia-primary-dark);
    border-color: var(--ia-border);
}

.page-item.active .page-link {
    background-color: var(--ia-primary);
    border-color: var(--ia-primary);
    color: #ffffff;
}

.page-item.disabled .page-link {
    color: var(--ia-text-muted);
    background-color: #f8fafc;
}

/* Breadcrumbs */
.breadcrumb {
    font-size: 0.82rem;
    margin-bottom: 1rem;
    background: transparent;
    padding: 0;
}

.breadcrumb-item a {
    color: var(--ia-secondary);
}

.breadcrumb-item.active {
    color: var(--ia-text-muted);
}

.breadcrumb-item + .breadcrumb-item::before {
    color: var(--ia-text-muted);
}

/* Accordion overrides */
.accordion-item {
    border: 1px solid var(--ia-border);
    border-radius: var(--ia-radius) !important;
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.accordion-button {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ia-text);
    background-color: #f8fafc;
    padding: 0.75rem 1rem;
}

.accordion-button:not(.collapsed) {
    background-color: rgba(14, 165, 233, 0.06);
    color: var(--ia-primary);
    box-shadow: none;
}

.accordion-button:focus {
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
    border-color: var(--ia-secondary);
}

.accordion-body {
    padding: 1rem;
    font-size: 0.9rem;
    color: var(--ia-text-secondary);
}

/* Nav tabs / pills overrides */
.nav-tabs .nav-link {
    color: var(--ia-text-secondary);
    font-weight: 500;
    font-size: 0.88rem;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.6rem 1rem;
    transition: var(--ia-transition);
}

.nav-tabs .nav-link:hover {
    color: var(--ia-primary);
    border-bottom-color: var(--ia-border);
}

.nav-tabs .nav-link.active {
    color: var(--ia-primary);
    border-bottom-color: var(--ia-secondary);
    background: transparent;
    font-weight: 600;
}

.nav-pills .nav-link {
    color: var(--ia-text-secondary);
    font-weight: 500;
    font-size: 0.88rem;
    border-radius: var(--ia-radius);
    padding: 0.45rem 0.9rem;
    transition: var(--ia-transition);
}

.nav-pills .nav-link.active {
    background-color: var(--ia-primary);
    color: #ffffff;
}

.nav-pills .nav-link:hover:not(.active) {
    background-color: rgba(30, 58, 95, 0.06);
    color: var(--ia-primary);
}

/* List group overrides */
.list-group-item {
    border-color: var(--ia-border);
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    color: var(--ia-text);
    transition: var(--ia-transition);
}

.list-group-item:hover {
    background-color: #f8fafc;
}

.list-group-item.active {
    background-color: var(--ia-primary);
    border-color: var(--ia-primary);
}

/* Print styles */
@media print {
    body {
        background: #ffffff;
        color: #000000;
        font-size: 11pt;
    }

    .navbar,
    footer,
    .site-footer,
    .btn,
    .chat-container,
    .chat-input-area {
        display: none !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .table thead th {
        background-color: #e2e8f0 !important;
        color: #000000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    a {
        color: #000000;
        text-decoration: underline;
    }
}
