/* ============================================================
   AllSeeingOfsted CSS
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&family=Source+Sans+3:wght@400;500;600&display=swap');

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

:root {
    --sidebar-w:   220px;
    --navy:        #1a1f36;
    --navy-light:  #2d3352;
    --navy-muted:  #8b95c9;
    --accent:      #c5922e;
    --accent-hover:#b38326;
    --bg:          #f7f8fa;
    --surface:     #ffffff;
    --border:      #e4e7ec;
    --text:        #2e3444;
    --muted:       #6b7280;
    --grade-5:     #20529a;
    --grade-4:     #204f29;
    --grade-3:     #43972a;
    --grade-2:     #c46222;
    --grade-1:     #b02418;
    --grade-5-bg:  #d5e3f5;
    --grade-4-bg:  #d3e8d6;
    --grade-3-bg:  #def0d6;
    --grade-2-bg:  #faeee3;
    --grade-1-bg:  #f5dddb;
    --shadow-sm:   0 1px 3px rgba(26,31,54,.06);
    --shadow-md:   0 4px 12px rgba(26,31,54,.08);
    --radius:      10px;
}

body {
    font-family: 'Source Sans 3', 'DM Sans', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--navy);
    position: fixed;
    top: 0; left: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;  /* inner .sidebar-nav handles the scroll */
}

.sidebar-logo {
    height: 72px;
    padding: 0 16px;
    display: flex; align-items: center;
    border-bottom: 1px solid rgba(255,255,255,.08);
    background: var(--surface);
    flex-shrink: 0;
}
.sidebar-logo a {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: var(--navy);
}
.sidebar-logo img { width: 32px; height: 32px; }
.sidebar-logo-text { font-family: 'DM Sans', sans-serif; font-weight: 700; font-size: 13px; line-height: 1.2; color: var(--navy); }
.sidebar-logo-sub  { font-size: 10px; color: var(--muted); font-weight: 400; }

.sidebar-nav { flex: 1 1 auto; padding: 4px 0 12px; overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch; }

.nav-section-label {
    font-size: 8px; font-weight: 600; color: var(--navy-muted);
    text-transform: uppercase; letter-spacing: 0.08em;
    padding: 5px 16px 0;
}

.nav-item {
    display: flex; align-items: center; gap: 7px;
    padding: 3px 16px;
    font-size: 11.5px; color: rgba(255,255,255,.65);
    text-decoration: none;
    transition: background 0.1s, color 0.1s;
    border-left: 3px solid transparent;
}
.nav-item:hover {
    background: rgba(255,255,255,.06);
    color: #fff;
}
.nav-item.active {
    background: rgba(197,146,46,.12);
    color: var(--accent);
    font-weight: 600;
    border-left-color: var(--accent);
}
.nav-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 16px; height: 16px; display: block; }

/* ── Main area ───────────────────────────────────────────── */

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }

.topbar {
    height: 72px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: var(--shadow-sm);
}
.topbar h1 {
    font-family: 'DM Sans', sans-serif;
    font-size: 18px; font-weight: 700;
    color: var(--navy);
}
.topbar-meta { font-size: 13px; color: var(--muted); }

.content { padding: 24px 28px; }

/* ── Cards ───────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
.card-title { font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 600; color: var(--navy); margin-bottom: 3px; }
.card-sub   { font-size: 12px; color: var(--muted); margin-bottom: 16px; }

/* ── Grade tiles ─────────────────────────────────────────── */

.grade-tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.grade-tile  {
    background: #fff;
    border: 1px solid #e8edf3;
    border-radius: var(--radius);
    padding: 14px 16px 12px;
    position: relative;
    overflow: hidden;
}
.grade-tile::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
}
.grade-tile-5::before { background: var(--grade-5); }
.grade-tile-4::before { background: var(--grade-4); }
.grade-tile-3::before { background: var(--grade-3); }
.grade-tile-2::before { background: var(--grade-2); }
.grade-tile-1::before { background: var(--grade-1); }
.grade-tile-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #94a3b8; margin-bottom: 6px; }
.grade-tile-count { font-size: 32px; font-weight: 800; line-height: 1; margin-bottom: 10px; }
.grade-tile-5 .grade-tile-count { color: var(--grade-5); }
.grade-tile-4 .grade-tile-count { color: var(--grade-4); }
.grade-tile-3 .grade-tile-count { color: var(--grade-3); }
.grade-tile-2 .grade-tile-count { color: var(--grade-2); }
.grade-tile-1 .grade-tile-count { color: var(--grade-1); }
.grade-tile-track {
    height: 4px;
    background: #f1f5f9;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 5px;
}
.grade-tile-fill { height: 100%; border-radius: 2px; }
.grade-tile-5 .grade-tile-fill { background: var(--grade-5); }
.grade-tile-4 .grade-tile-fill { background: var(--grade-4); }
.grade-tile-3 .grade-tile-fill { background: var(--grade-3); }
.grade-tile-2 .grade-tile-fill { background: var(--grade-2); }
.grade-tile-1 .grade-tile-fill { background: var(--grade-1); }
.grade-tile-pct { font-size: 11px; font-weight: 600; color: #64748b; }

.grade-bar { height: 10px; border-radius: 5px; overflow: hidden; display: flex; margin-bottom: 20px; }
.grade-bar-seg { height: 100%; transition: width 0.3s; }

/* ── Inspection list (latest-updates) ────────────────────── */

.insp-list { display: flex; flex-direction: column; gap: 5px; margin-bottom: 20px; }
.insp-row {
    background: #fff;
    border: 1px solid #e8edf3;
    border-left: 4px solid #e8edf3;
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: box-shadow .12s, border-color .12s;
    text-decoration: none;
}
.insp-row:hover { box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.insp-row-info { flex: 1; min-width: 0; }
.insp-row-name { font-size: 13px; font-weight: 600; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insp-row-meta { font-size: 11px; color: #94a3b8; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insp-row-meta a { color: #1d4ed8; text-decoration: none; }
.insp-row-meta a:hover { text-decoration: underline; }
.insp-row-chips { display: flex; gap: 5px; align-items: flex-end; flex-shrink: 0; }
.grade-chip { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.grade-chip-abbr { font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #94a3b8; }
.grade-chip-bar { width: 30px; height: 18px; border-radius: 3px; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 800; color: #fff; }
.grade-chip-sg { width: 30px; height: 18px; border-radius: 3px; display: flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 700; color: #fff; }
.grade-chip-sg.sg-met { background: #1d4ed8; }
.grade-chip-sg.sg-not { background: #b02418; }

/* ── Inspection archive table ────────────────────────────── */

.archive-wrap {
    background: #fff;
    border: 1px solid #e8edf3;
    border-radius: 10px;
    overflow: hidden;
}
.archive-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
.archive-table thead th {
    background: var(--navy);
    color: rgba(255,255,255,.75);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .05em;
    padding: 11px 10px;
    text-align: left;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}
.archive-table thead th.ar-grade,
.archive-table thead th.ar-fw,
.archive-table thead th.ar-sg { text-align: center; }
.archive-table tbody tr {
    cursor: pointer;
    transition: background .12s;
    border-bottom: 1px solid #f1f5f9;
}
.archive-table tbody tr:nth-child(even) { background: #fafbfc; }
.archive-table tbody tr:hover { background: #eff6ff; }
.archive-table tbody td {
    padding: 9px 10px;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
}
.archive-table tbody tr:last-child td { border-bottom: none; }
.archive-table tbody td.ar-date {
    border-left: 3px solid transparent;
    padding-left: 13px;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
}
.archive-table .ar-loc-name { font-size: 13px; font-weight: 600; color: #0f172a; line-height: 1.2; }
.archive-table .ar-loc-sub  { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.archive-table .ar-type { font-size: 11px; color: #64748b; white-space: nowrap; }
.archive-table .ar-insp { font-size: 12px; white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.archive-table .ar-insp a { color: #1d4ed8; text-decoration: none; }
.archive-table .ar-insp a:hover { text-decoration: underline; }
.archive-table .ar-fw { text-align: center; }
.archive-table .ar-grades-col { min-width: 180px; }
.archive-table .ar-grades-col .grades-cell { display: flex; gap: 4px; flex-wrap: wrap; align-items: flex-end; }
.archive-table .ar-sg { width: 36px; text-align: center; }
.archive-table .ar-empty { color: #cbd5e1; font-size: 11px; }
.fw-pill {
    display: inline-block;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 2px 7px;
    border-radius: 4px;
    white-space: nowrap;
}
.fw-pill.fw-new { background: #dbeafe; color: #1d4ed8; }
.fw-pill.fw-old { background: #f1f5f9; color: #64748b; }
.ar-chip {
    width: 24px;
    height: 22px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    color: #fff;
}
.ar-oldjud { text-align: center; padding: 6px 3px; }
.ar-oldjud-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    padding: 4px 12px;
    border-radius: 4px;
    white-space: nowrap;
    letter-spacing: .02em;
}
.sg-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
    color: #fff;
}
.sg-dot.sg-met { background: #1d4ed8; }
.sg-dot.sg-not { background: #b02418; }

@media (max-width: 1100px) {
    .archive-table .ar-insp { display: none; }
    .archive-table thead th.ar-insp { display: none; }
}
@media (max-width: 900px) {
    .archive-table .ar-type,
    .archive-table thead th.ar-type { display: none; }
    .archive-table thead th,
    .archive-table tbody td { padding: 8px 6px; }
}

/* ── Forms / filters ─────────────────────────────────────── */

.filter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-row label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.main select, .main input[type="text"], .main input[type="search"], .main input[type="tel"] {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    font-family: inherit;
    transition: border-color .15s;
}
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(197,146,46,.12); }

/* ── Tables ──────────────────────────────────────────────── */

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
    background: var(--navy);
    color: #fff;
    padding: 10px 14px;
    text-align: left;
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafafa; }

/* ── Grade badges ────────────────────────────────────────── */

.grade-badge {
    display: inline-block; padding: 3px 8px; border-radius: 5px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.grade-5 { background: var(--grade-5-bg); color: var(--grade-5); }
.grade-4 { background: var(--grade-4-bg); color: var(--grade-4); }
.grade-3 { background: var(--grade-3-bg); color: var(--grade-3); }
.grade-2 { background: var(--grade-2-bg); color: var(--grade-2); }
.grade-1 { background: var(--grade-1-bg); color: var(--grade-1); }
.grade-met     { background: #dcfce7; color: #15803d; }
.grade-not-met { background: var(--grade-1-bg); color: var(--grade-1); }

/* ── Inspection cards ────────────────────────────────────── */

.inspection-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.inspection-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; position: relative;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .15s;
}
.inspection-card:hover { box-shadow: var(--shadow-md); }
.inspection-card-title { font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 700; margin-bottom: 4px; color: var(--navy); }
.inspection-card-meta {
    font-size: 12px; color: var(--muted); margin-bottom: 10px;
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.inspection-card-meta a { color: var(--accent); text-decoration: none; }
.inspection-card-meta a:hover { text-decoration: underline; }
.grade-area-row { display: flex; align-items: center; gap: 7px; padding: 3px 0; font-size: 12.5px; }
.grade-area-icon  { font-size: 13px; }
.grade-area-label { flex: 1; color: var(--text); }
.grade-corner { position: absolute; top: 14px; right: 14px; font-size: 18px; }
.safeguarding-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 10px; padding-top: 10px;
    border-top: 1px solid var(--border); font-size: 12.5px;
}

/* ── Date group headers ──────────────────────────────────── */

.date-group-header { display: flex; align-items: center; gap: 10px; margin: 22px 0 12px; }
.date-group-header h3 { font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 600; color: var(--navy); }
.date-group-count {
    background: var(--bg); border: 1px solid var(--border); border-radius: 20px;
    padding: 2px 10px; font-size: 12px; color: var(--muted);
}

/* ── Search / filter bar ─────────────────────────────────── */

.search-filters {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px;
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}
.search-input-wrap { flex: 1; min-width: 220px; position: relative; }
.search-input-wrap input { width: 100%; padding: 7px 12px 7px 32px !important; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; }

/* ── Stat tiles ──────────────────────────────────────────── */

.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-tile {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
    display: flex; align-items: flex-start; justify-content: space-between;
    box-shadow: var(--shadow-sm);
}
.stat-tile-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.stat-tile-value { font-family: 'DM Sans', sans-serif; font-size: 26px; font-weight: 700; color: var(--navy); }

/* ── Charts ──────────────────────────────────────────────── */

.chart-wrap      { position: relative; height: 260px; }
.chart-wrap-tall { height: 340px; }

/* ── Pagination ──────────────────────────────────────────── */

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 0; font-size: 13px; color: var(--muted); }
.pagination-btns { display: flex; gap: 4px; }
.pagination-btns a, .pagination-btns span {
    display: inline-block; padding: 5px 10px;
    border: 1px solid var(--border); border-radius: 5px;
    font-size: 13px; color: var(--text); text-decoration: none;
    background: var(--surface);
}
.pagination-btns a:hover { background: var(--bg); }
.pagination-btns .active { background: var(--navy); color: #fff; border-color: var(--navy); }
.pagination-btns .disabled { color: var(--muted); pointer-events: none; }

/* ── Map fullscreen ──────────────────────────────────────── */

.map-fullscreen {
    position: relative;
    height: calc(100vh - 72px);
    overflow: hidden;
    isolation: isolate;
}
#monitor-map { width: 100%; height: 100%; }

.map-panel {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 1000;
    width: 230px;
    max-height: calc(100% - 28px);
    overflow-y: auto;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(6px);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,.14);
    padding: 16px;
    scrollbar-width: thin;
}
.mp-section-label {
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #94a3b8;
    margin-bottom: 10px;
}
.mp-field { margin-bottom: 10px; }
.mp-field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 4px;
}
.mp-field select {
    width: 100%;
    font-size: 12px;
    padding: 5px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    color: #0f172a;
    cursor: pointer;
}
.mp-divider { height: 1px; background: #f1f5f9; margin: 12px -16px; }
.mp-legend-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 5px 0;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: opacity .15s;
}
.mp-legend-dot {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    flex-shrink: 0;
}
.mp-legend-label { font-size: 12px; font-weight: 500; color: #0f172a; flex: 1; }
.mp-legend-count { font-size: 11px; color: #94a3b8; }

.map-badge-count {
    position: absolute;
    bottom: 14px;
    right: 14px;
    z-index: 1000;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(4px);
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,.12);
    padding: 8px 14px;
    font-size: 12px;
    color: #475569;
}
.map-badge-count strong { color: #0f172a; }

/* ── Trend / status indicators ───────────────────────────── */

.trend-up    { color: var(--grade-4); }
.trend-down  { color: var(--grade-1); }
.trend-flat  { color: var(--grade-3); }
.check-green { color: var(--grade-4); }
.check-warn  { color: var(--grade-2); }
.check-bad   { color: var(--grade-1); }

/* ── Tags ────────────────────────────────────────────────── */

.tag {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 500;
    background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
.tag-blue  { background: #dbeafe; color: #1d4ed8; border-color: #bfdbfe; }
.tag-green { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.tag-gold  { background: #fef3c7; color: #92400e; border-color: #fde68a; }

/* ── Utilities ───────────────────────────────────────────── */

.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 14px; }
.two-col   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.mb-14 { margin-bottom: 14px; }
.mb-20 { margin-bottom: 20px; }
.mt-20 { margin-top: 20px; }

/* ── Mobile overrides for inline grid styles ────────────── */
@media (max-width: 600px) {
    /* Hero stats strips (4-col inline grids) */
    [style*="grid-template-columns:repeat(4"] ,
    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    /* Performers panels (2-col inline grids) */
    [style*="grid-template-columns:1fr 1fr;"][style*="gap:16px"] {
        grid-template-columns: 1fr !important;
    }
    /* Plan cards (3-col) */
    .plan-grid { grid-template-columns: 1fr !important; }
    /* Cookie banner */
    #cookie-banner { flex-direction: column !important; text-align: center; padding: 12px 16px !important; }
}

/* ── Responsive ──────────────────────────────────────────── */

/* ── Tablet (481–900px) ──────────────────────────────────── */
@media (max-width: 900px) {
    .mobile-menu-btn { display: flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 1000;
    }
    .sidebar.sidebar-open {
        transform: translateX(0);
    }
    .main { margin-left: 0; padding-top: 0; overflow-x: hidden; }
    body { overflow-x: hidden; }
    .topbar { padding: 0 16px 0 60px; height: auto; min-height: 56px; flex-wrap: wrap; gap: 8px; }
    .topbar h1 { font-size: 16px; }
    .content { padding: 16px; }
    .inspection-grid { grid-template-columns: 1fr 1fr; }
    .grade-tiles { grid-template-columns: repeat(3, 1fr); }
    .stat-tiles  { grid-template-columns: 1fr 1fr; }
    .search-filters { gap: 6px; }
    .search-input-wrap { min-width: 180px; }
    .insp-row { flex-direction: column; align-items: flex-start; gap: 8px; }
    .insp-row-chips { flex-wrap: wrap; }
    .insp-row-name { white-space: normal; }
    .insp-row-meta { white-space: normal !important; line-height: 1.6; }
    .map-panel {
        width: 160px !important;
        padding: 10px !important;
        font-size: 11px;
        border-radius: 8px;
        top: 8px !important;
        left: 8px !important;
        z-index: 800 !important;
    }
    .map-panel.collapsed {
        width: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }
    .map-panel.collapsed .mp-panel-body { display: none; }
    .map-panel.collapsed .mp-toggle-icon { transform: rotate(180deg); }
    .mp-toggle-btn {
        display: flex !important;
        align-items: center; gap: 4px;
        background: none; border: none; cursor: pointer;
        font-size: 10px; font-weight: 700; color: #475569;
        font-family: inherit; padding: 0; margin-bottom: 6px;
        text-transform: uppercase; letter-spacing: .06em;
    }
    .mp-toggle-icon { transition: transform .2s; font-size: 8px; }
    .mp-section-label { font-size: 8px; margin-bottom: 6px; }
    .mp-field { margin-bottom: 6px; }
    .mp-field label { font-size: 10px; margin-bottom: 2px; }
    .mp-field select { font-size: 11px; padding: 3px 6px; }
    .mp-divider { margin: 8px -10px; }
    .mp-legend-btn { padding: 3px 0; }
    .mp-legend-dot { width: 8px; height: 8px; }
    .mp-legend-label { font-size: 10px; }
    .mp-legend-count { font-size: 9px; }
    .map-badge-count { font-size: 10px; padding: 5px 10px; bottom: 8px; right: 8px; }
    .leaflet-popup { z-index: 900 !important; }
    .leaflet-popup-content-wrapper { max-width: 220px !important; font-size: 12px !important; }
    .leaflet-popup-content { margin: 10px !important; max-width: 200px !important; word-wrap: break-word; }
    .leaflet-popup-content a { font-size: 12px !important; }
    .leaflet-popup-content .grade-badge { font-size: 10px !important; padding: 2px 6px !important; }
    .pagination-btns a, .pagination-btns span { padding: 6px 11px; }
    .two-col { grid-template-columns: 1fr; }
    .three-col { grid-template-columns: 1fr; }
    /* Force all inline grids to stack */
    [style*="grid-template-columns:repeat(4"] ,
    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    [style*="grid-template-columns:repeat(3"] ,
    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns:1fr 260px"],
    [style*="grid-template-columns: 1fr 260px"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns:auto 1fr"],
    [style*="grid-template-columns: auto 1fr"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns:1fr 1fr;"] {
        grid-template-columns: 1fr !important;
    }
}

/* ── Mobile (≤600px) ────────────────────────────────────── */
@media (max-width: 600px) {
    .topbar { height: auto; min-height: 52px; padding: 10px 14px 10px 60px; flex-direction: column; align-items: flex-start; gap: 4px; }
    .topbar h1 { font-size: 15px; }
    .topbar-meta { font-size: 11px; }
    .content { padding: 10px; }
    .card { padding: 12px; }
    .inspection-grid { grid-template-columns: 1fr; }
    .grade-tiles { grid-template-columns: 1fr 1fr; }
    .grade-tile { padding: 10px 12px 8px; }
    .grade-tile-count { font-size: 24px; }
    .stat-tiles { grid-template-columns: 1fr; }
    .search-filters { flex-direction: column; align-items: stretch; }
    .search-filters select { width: 100%; }
    .search-input-wrap { min-width: 100%; }
    .insp-row-chips .grade-chip-bar,
    .insp-row-chips .grade-chip-sg { width: 26px; height: 16px; font-size: 8px; }
    .archive-wrap { border-radius: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .archive-table { min-width: 580px; }
    .three-col { grid-template-columns: 1fr; }
    .two-col { grid-template-columns: 1fr; }
    /* All inline grids single column */
    [style*="grid-template-columns:repeat(4"] ,
    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: 1fr 1fr !important;
    }
    [style*="grid-template-columns:repeat(3"] ,
    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns:1fr 260px"],
    [style*="grid-template-columns: 1fr 260px"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns:auto 1fr"],
    [style*="grid-template-columns: auto 1fr"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns:1fr 1fr;"] {
        grid-template-columns: 1fr !important;
    }
    /* Prevent iOS zoom on inputs */
    select, input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea {
        font-size: 16px !important;
    }
    /* Prevent horizontal scroll */
    .main { overflow-x: hidden; }
    body { overflow-x: hidden; }
    /* National overview hero */
    .no-hero-count { min-width: 0 !important; }
    .no-hero-number { font-size: 36px !important; }
    .no-hero-grades { min-width: 0 !important; width: 100% !important; flex: none !important; }
    .no-hero-strip { flex-direction: column !important; gap: 16px !important; padding: 20px 16px !important; align-items: stretch !important; }
    .no-bar-pct { display: none !important; }
    .no-type-pills { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 5px !important; }
    .no-type-pills a { text-align: center; }
    /* Assessment area table — hide columns, show stacked */
    .assessment-area-table { min-width: 0 !important; }
    .assessment-area-table thead { display: none; }
    .assessment-area-table tbody tr {
        display: block;
        padding: 10px 0;
        border-bottom: 1px solid var(--border);
    }
    .assessment-area-table tbody td {
        display: inline-block;
        padding: 2px 6px !important;
        border-bottom: none !important;
        font-size: 12px;
    }
    .assessment-area-table tbody td:first-child {
        display: block;
        font-size: 13px;
        padding: 0 0 6px 0 !important;
    }
}

/* ── Trend arrows ────────────────────────────────────────── */
.trend-arrow { font-size: 13px; font-weight: 700; margin-left: 4px; }
.trend-arrow.up   { color: #43972a; }
.trend-arrow.down { color: #b02418; }
.trend-arrow.flat { color: #6b7280; }

/* ── Auth pages (login/register/verify — standalone) ─────── */
.auth-page {
    min-height: 100vh;
    background: #f7f8fa;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 16px 40px;
    font-family: 'Source Sans 3', 'DM Sans', sans-serif;
}
.auth-card {
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 12px;
    padding: 36px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 4px 24px rgba(26,31,54,.08);
}
.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}
.auth-logo img { width: 40px; height: 40px; }
.auth-logo-name { font-family: 'DM Sans', sans-serif; font-weight: 700; font-size: 16px; color: #1a1f36; margin-top: 6px; }
.auth-logo-sub  { font-size: 12px; color: #6b7280; }
.auth-title { font-family: 'DM Sans', sans-serif; font-size: 20px; font-weight: 700; color: #1a1f36; margin-bottom: 4px; }
.auth-sub   { font-size: 13px; color: #6b7280; margin-bottom: 24px; }
.auth-field { margin-bottom: 16px; }
.auth-field label { display: block; font-size: 13px; font-weight: 600; color: #2e3444; margin-bottom: 5px; }
.auth-field input {
    width: 100%;
    border: 1px solid #e4e7ec;
    border-radius: 7px;
    padding: 9px 12px;
    font-size: 14px;
    color: #2e3444;
    background: #fff;
    outline: none;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
.auth-field input:focus { border-color: #c5922e; box-shadow: 0 0 0 3px rgba(197,146,46,.12); }
.auth-field input.error { border-color: #b02418; }
.auth-field-error { font-size: 12px; color: #b02418; margin-top: 4px; }
.auth-btn {
    width: 100%;
    background: #c5922e;
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 11px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s;
    margin-top: 4px;
}
.auth-btn:hover { background: #b38326; }
.auth-links { text-align: center; margin-top: 18px; font-size: 13px; color: #6b7280; }
.auth-links a { color: #1d4ed8; text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
.auth-alert {
    padding: 10px 14px;
    border-radius: 7px;
    font-size: 13px;
    margin-bottom: 16px;
}
.auth-alert.error   { background: #f5dddb; color: #b02418; border: 1px solid #fca5a5; }
.auth-alert.success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.auth-alert.info    { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ── Account page sections ───────────────────────────────── */
.account-section { margin-bottom: 20px; }
.account-section .card-title { font-size: 15px; margin-bottom: 14px; }
.plan-cards { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-top: 14px; }
.plan-card {
    border: 2px solid #e4e7ec;
    border-radius: 10px;
    padding: 18px 14px;
    text-align: center;
    transition: border-color .15s;
}
.plan-card.current { border-color: #c5922e; background: #fffbf0; }
.plan-card-name  { font-family: 'DM Sans', sans-serif; font-weight: 700; font-size: 14px; color: #1a1f36; margin-bottom: 4px; }
.plan-card-price { font-size: 22px; font-weight: 700; color: #1a1f36; margin: 8px 0; }
.plan-card-price span { font-size: 13px; font-weight: 400; color: #6b7280; }
.plan-card-btn {
    display: block; margin-top: 12px;
    background: #c5922e; color: #fff;
    border: none; border-radius: 6px;
    padding: 8px; font-size: 13px; font-weight: 600;
    font-family: inherit; cursor: pointer; width: 100%;
    transition: background .15s;
}
.plan-card-btn:hover { background: #b38326; }
.plan-card-btn:disabled { background: #e4e7ec; color: #6b7280; cursor: default; }

/* ── Leaderboard rank medals ─────────────────────────────── */
.rank-medal { display:inline-block;width:22px;height:22px;border-radius:50%;font-size:11px;font-weight:700;text-align:center;line-height:22px; }
.rank-1 { background:#fef3c7;color:#92400e; }
.rank-2 { background:#f1f5f9;color:#475569; }
.rank-3 { background:#fce7d8;color:#9a3412; }
.rank-n { background:#f8fafc;color:#94a3b8; }

/* ── Sidebar inline login panel ──────────────────────────── */
.nav-login-toggle {
    background: none; border: none; cursor: pointer;
    width: 100%; text-align: left;
    font-family: inherit;
}
.sidebar-login-panel {
    padding: 10px 14px 12px;
    background: rgba(0,0,0,.18);
    border-top: 1px solid rgba(255,255,255,.06);
    border-bottom: 1px solid rgba(255,255,255,.06);
    margin-bottom: 2px;
}
.sidebar-login-form { display:flex; flex-direction:column; gap:7px; }
.sidebar-login-input {
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 5px;
    padding: 7px 10px;
    font-size: 12.5px;
    color: #fff;
    font-family: inherit;
    outline: none;
    transition: border-color .15s;
}
.sidebar-login-input::placeholder { color: rgba(255,255,255,.35); }
.sidebar-login-input:focus { border-color: rgba(197,146,46,.7); }
.sidebar-login-btn {
    background: rgba(197,146,46,.85);
    border: none; border-radius: 5px;
    padding: 7px; color: #fff;
    font-size: 12.5px; font-weight: 600;
    font-family: inherit; cursor: pointer;
    transition: background .15s;
}
.sidebar-login-btn:hover { background: #c5922e; }
.sidebar-login-link {
    font-size: 11.5px;
    color: rgba(255,255,255,.38);
    text-decoration: none;
}
.sidebar-login-link:hover { color: rgba(255,255,255,.65); text-decoration: underline; }

/* Mobile menu */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    background: #1a1f36;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 6px;
    padding: 8px 7px;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
}
.mobile-menu-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform .2s, opacity .2s;
}
.mobile-menu-btn.active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.mobile-menu-btn.active span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 999;
}
.sidebar-overlay.show { display: block; }

@media (max-width: 900px) {
    .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-table { min-width: 540px; }
    .mobile-menu-btn { display: flex; width: 44px; height: 44px; }
}

/* ── Global search ──────────────────────────────────────── */
.sidebar-search { padding: 14px 16px 10px; }
.sidebar-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.sidebar-search-icon {
    position: absolute;
    left: 10px;
    font-size: 13px;
    opacity: .4;
    pointer-events: none;
}
.sidebar-search-wrap input[type="search"] {
    width: 100%;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 6px;
    padding: 9px 12px 9px 32px !important;
    box-sizing: border-box;
    color: #fff;
    font-size: 12px;
    outline: none;
    font-family: inherit;
}
.sidebar-search-wrap input::placeholder { color: rgba(255,255,255,.3); }
.sidebar-search-wrap input:focus { border-color: rgba(255,255,255,.25); background: rgba(255,255,255,.1); }

.global-search-results {
    display: none;
    background: #232840;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 8px;
    margin-top: 6px;
    max-height: 360px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,.3);
    /* Firefox */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.18) transparent;
}
/* WebKit / Blink (Chrome, Edge, Safari) */
.global-search-results::-webkit-scrollbar        { width: 8px; }
.global-search-results::-webkit-scrollbar-track  { background: transparent; }
.global-search-results::-webkit-scrollbar-thumb  { background: rgba(255,255,255,.15); border-radius: 4px; }
.global-search-results::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.28); }
.gsr-section {
    padding: 8px 12px 4px;
    font-size: 10px;
    font-weight: 600;
    color: rgba(255,255,255,.4);
    text-transform: uppercase;
    letter-spacing: .06em;
}
.gsr-item {
    display: flex;
    flex-direction: column;
    padding: 7px 12px;
    text-decoration: none;
    color: #fff;
    font-size: 12px;
    border-bottom: 1px solid rgba(255,255,255,.05);
    transition: background .15s;
}
.gsr-item:hover { background: rgba(255,255,255,.08); }
.gsr-item strong { font-weight: 600; font-size: 13px; }
.gsr-item span { color: rgba(255,255,255,.4); font-size: 11px; margin-top: 1px; }
.gsr-empty { padding: 12px; text-align: center; color: rgba(255,255,255,.3); font-size: 12px; }
