/* ============================================================
   map-stats.css — Map Stats page (study-map-stats.html).
   Uses the global design tokens from style.css; the map paths and
   markers themselves are styled by the Map Drills rules in
   study-extras.css (.md-country, .md-marker__dot, …) — this file
   only adds the page layout, the hover outline and .is-selected.
   ============================================================ */

.ms-page {
    --ms-red: #ef4444;
    --ms-amber: #f59e0b;
    --ms-green: #10b981;
    --ms-unseen: rgba(148, 163, 184, 0.28);
    --ms-radius: 20px;
}
.ms-page [hidden] { display: none !important; }

/* ── Toolbar under the header ─────────────────────────────── */
.ms-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 22px;
}
.ms-toolbar__spacer { flex: 1; }
.ms-toolbar .btn { padding: 0.6rem 1.1rem; font-size: 0.92rem; }
.ms-guest-note {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: 999px;
    font-size: 0.83rem;
    font-weight: 600;
    color: #d97706;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.28);
}
.ms-guest-note i { font-size: 1.05rem; }

/* ── Empty state ──────────────────────────────────────────── */
.ms-empty {
    text-align: center;
    padding: 54px 24px 48px;
    max-width: 640px;
    margin: 20px auto 0;
}
.ms-empty:hover { transform: none; }
.ms-empty__map {
    width: 92px;
    height: 92px;
    margin: 0 auto 18px;
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.8rem;
    color: #059669;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(52, 211, 153, 0.06));
    box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.18);
}
.ms-empty h3 { color: var(--text-primary); font-size: 1.4rem; margin: 0 0 8px; }
.ms-empty p { color: var(--text-secondary); margin: 0 auto 22px; max-width: 440px; line-height: 1.55; }

/* ── KPI tiles ────────────────────────────────────────────── */
.ms-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.ms-kpi {
    --ms-kpi-accent: #10b981;
    --ms-kpi-soft: rgba(16, 185, 129, 0.14);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-radius: 18px;
    border: 1px solid var(--border-glass);
    background: var(--bg-glass);
    box-shadow: var(--shadow-glass);
    min-width: 0;
}
.ms-kpi--seen       { --ms-kpi-accent: #3b82f6; --ms-kpi-soft: rgba(59, 130, 246, 0.14); }
.ms-kpi--mastered   { --ms-kpi-accent: #10b981; --ms-kpi-soft: rgba(16, 185, 129, 0.15); }
.ms-kpi--struggling { --ms-kpi-accent: #ef4444; --ms-kpi-soft: rgba(239, 68, 68, 0.13); }
.ms-kpi--accuracy   { --ms-kpi-accent: #8b5cf6; --ms-kpi-soft: rgba(139, 92, 246, 0.14); }
.ms-kpi--drills     { --ms-kpi-accent: #0891b2; --ms-kpi-soft: rgba(6, 182, 212, 0.14); }
.ms-kpi--coins      { --ms-kpi-accent: #d97706; --ms-kpi-soft: rgba(245, 158, 11, 0.16); }
.ms-kpi__icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.45rem;
    color: var(--ms-kpi-accent);
    background: var(--ms-kpi-soft);
}
.ms-kpi__body { min-width: 0; }
.ms-kpi__value {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.15;
    white-space: nowrap;
}
.ms-kpi__label { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; line-height: 1.3; }

/* ── Cards ────────────────────────────────────────────────── */
.ms-card {
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    border-radius: var(--ms-radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-glass);
    min-width: 0;
}
.ms-section { margin-bottom: 18px; }
.ms-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.ms-card__title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}
.ms-card__title i { color: #059669; font-size: 1.15rem; }
.ms-card__hint { font-size: 0.78rem; color: var(--text-muted); }
.ms-muted { color: var(--text-muted); font-size: 0.86rem; margin: 0; line-height: 1.5; }
.ms-btn-sm { padding: 0.5rem 0.95rem; font-size: 0.85rem; border-radius: 10px; }

/* ── Map + detail grid ────────────────────────────────────── */
.ms-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    margin-bottom: 18px;
}
@media (min-width: 1024px) {
    .ms-grid { grid-template-columns: 2fr 1fr; align-items: start; }
}

/* Metric chips */
.ms-metrics { display: flex; gap: 6px; flex-wrap: wrap; }
.ms-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.ms-chip {
    border: 1px solid var(--border-glass);
    background: var(--bg-glass);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 6px 13px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.ms-chip:hover { color: var(--text-primary); border-color: rgba(16, 185, 129, 0.4); }
.ms-chip.is-active {
    background: rgba(16, 185, 129, 0.14);
    color: #059669;
    border-color: rgba(16, 185, 129, 0.35);
}
.ms-chip.is-static { cursor: default; }
.ms-chip.is-static:hover { color: var(--text-secondary); border-color: var(--border-glass); }
.ms-chip__count { color: var(--text-muted); font-weight: 600; margin-left: 2px; }

/* Map wrap */
/* No min-height next to aspect-ratio: browsers transfer it into a min-width
   (240px × 960/500 ≈ 461px) and the map would overflow narrow cards. */
.ms-map-wrap {
    position: relative;
    border-radius: 16px;
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    overflow: hidden;
    aspect-ratio: 960 / 500;
}
@supports not (aspect-ratio: 960 / 500) {
    .ms-map-wrap { min-height: 240px; }
}
.ms-map { width: 100%; height: 100%; }
.ms-map svg.md-map { display: block; width: 100%; height: 100%; }
.ms-map__error {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 20px;
    text-align: center;
}

/* Hover outline + selected state (only additions to the shared map styles) */
.ms-map .md-country:hover { stroke: var(--text-primary); stroke-width: 1; }
.ms-map .md-country.is-selected { stroke: #0f172a; stroke-width: 1.2; }
.ms-map .md-marker:hover .md-marker__dot { stroke: var(--text-primary); stroke-width: 1; }
.ms-map .md-marker.is-selected .md-marker__dot { stroke: #0f172a; stroke-width: 1.5; }
[data-theme="dark"] .ms-map .md-country.is-selected { stroke: #ffffff; }
[data-theme="dark"] .ms-map .md-marker.is-selected .md-marker__dot { stroke: #ffffff; }

/* Zoom buttons */
.ms-map-tools {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ms-map-tools button {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.10);
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.ms-map-tools button:hover { color: #059669; border-color: rgba(16, 185, 129, 0.45); }
.ms-map-tools button:active { transform: translateY(1px); }

/* Tooltip */
.ms-tooltip {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 4;
    pointer-events: none;
    min-width: 160px;
    max-width: 230px;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.45;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}
.ms-tooltip__name {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.ms-tooltip__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12);
}
.ms-tooltip__row { display: flex; justify-content: space-between; gap: 14px; }
.ms-tooltip__row strong { color: var(--text-primary); font-weight: 700; }
.ms-tooltip__muted { color: var(--text-muted); font-style: italic; }

/* Legend */
.ms-legend {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.ms-legend__item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.ms-legend__swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid var(--border-glass);
}
.ms-legend__swatch--unseen { background: var(--ms-unseen); }
.ms-legend__scale { flex: 1; min-width: 200px; }
.ms-legend__bar {
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--ms-red), var(--ms-amber), var(--ms-green));
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}
.ms-legend__labels {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
}
.ms-legend__labels span { white-space: nowrap; }
.ms-legend__labels span:nth-child(2) { text-align: center; }
.ms-legend__labels span:last-child { text-align: right; }

/* Detail card */
.ms-card--detail { display: flex; flex-direction: column; }
.ms-detail { flex: 1; }
.ms-detail__empty {
    text-align: center;
    padding: 46px 12px;
    color: var(--text-muted);
}
.ms-detail__empty i { font-size: 2.4rem; color: #059669; opacity: 0.8; }
.ms-detail__empty p { margin: 10px 0 0; font-size: 0.9rem; }
.ms-detail__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.ms-detail__heading { min-width: 0; }
.ms-detail__name {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    overflow-wrap: anywhere;
}
.ms-detail__region {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.ms-detail__badge {
    --ms-badge: #94a3b8;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    white-space: nowrap;
}
.ms-detail__badge::before {
    content: '';
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--ms-badge);
}
.ms-detail__note { color: var(--text-secondary); font-size: 0.88rem; line-height: 1.55; margin: 0 0 16px; }
.ms-detail__stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}
.ms-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    min-width: 0;
}
.ms-stat__label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.ms-stat__value { font-size: 1.1rem; color: var(--text-primary); font-weight: 700; line-height: 1.2; }
.ms-stat__sub { font-size: 0.74rem; color: var(--text-secondary); }
.ms-flame { font-size: 0.95rem; }
.ms-detail__section { margin-bottom: 16px; }
.ms-detail__label {
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
.ms-detail__actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: auto; }
.ms-detail__actions .btn { padding: 0.6rem 1rem; font-size: 0.9rem; }

/* ── Region breakdown ─────────────────────────────────────── */
.ms-regions { display: flex; flex-direction: column; gap: 6px; }
.ms-region {
    display: grid;
    grid-template-columns: minmax(130px, 1.1fr) 76px minmax(120px, 2fr) 52px;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.ms-region:hover { background: var(--bg-glass); border-color: var(--border-glass); }
.ms-region.is-active { background: rgba(16, 185, 129, 0.08); border-color: rgba(16, 185, 129, 0.35); }
.ms-region__name { font-weight: 600; color: var(--text-primary); font-size: 0.92rem; }
.ms-region.is-active .ms-region__name { color: #059669; }
.ms-region__seen { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.ms-region__bar {
    display: block;
    height: 8px;
    border-radius: 999px;
    background: var(--border-glass);
    overflow: hidden;
}
.ms-region__bar span { display: block; height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.ms-region__pct { font-weight: 700; font-size: 0.86rem; color: var(--text-secondary); text-align: right; white-space: nowrap; }

/* ── Hardest + not practised ──────────────────────────────── */
.ms-two {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    margin-bottom: 18px;
}
@media (min-width: 900px) {
    .ms-two { grid-template-columns: 1fr 1fr; align-items: start; }
}
.ms-hard-list { display: flex; flex-direction: column; gap: 4px; }
.ms-hard {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.ms-hard:hover { background: var(--bg-glass); }
.ms-hard.is-active { background: rgba(16, 185, 129, 0.08); border-color: rgba(16, 185, 129, 0.35); }
.ms-hard__swatch {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12);
}
.ms-hard__name { flex: 1; min-width: 0; font-weight: 600; color: var(--text-primary); font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-hard__acc { font-weight: 700; font-size: 0.86rem; color: var(--text-secondary); width: 46px; text-align: right; }
.ms-hard__tries { font-size: 0.76rem; color: var(--text-muted); width: 64px; text-align: right; white-space: nowrap; }
.ms-unseen-count { color: var(--text-secondary); font-size: 0.88rem; margin: 0 0 12px; }
.ms-unseen-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ms-unseen-chip {
    border: 1px solid var(--border-glass);
    background: var(--bg-glass);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.ms-unseen-chip:hover { color: var(--text-primary); border-color: rgba(16, 185, 129, 0.4); }
.ms-unseen-chip.is-active { background: rgba(16, 185, 129, 0.14); color: #059669; border-color: rgba(16, 185, 129, 0.35); }
.ms-unseen-more { font-size: 0.8rem; color: var(--text-muted); }

/* ── Recent drills ────────────────────────────────────────── */
.ms-spark {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
}
.ms-spark__chart { flex: 1 1 260px; min-width: 200px; max-width: 460px; }
.ms-spark__chart svg { display: block; width: 100%; height: 64px; overflow: visible; }
.ms-spark__caption { font-size: 0.8rem; color: var(--text-secondary); flex: 1 1 160px; }
.ms-spark__base { stroke: var(--border-glass); stroke-width: 1; }
.ms-spark__area { fill: rgba(16, 185, 129, 0.14); stroke: none; }
.ms-spark__line { fill: none; stroke: #10b981; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ms-spark__pt { fill: var(--bg-surface); stroke: #10b981; stroke-width: 1.5; }
.ms-spark__last { fill: #10b981; stroke: var(--bg-surface); stroke-width: 2; }
.ms-spark__label { fill: var(--text-primary); font-size: 11px; font-weight: 700; font-family: var(--font-body); }

.ms-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ms-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.ms-table th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-glass);
    white-space: nowrap;
}
.ms-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border-glass);
    color: var(--text-secondary);
    vertical-align: middle;
}
.ms-table tr:last-child td { border-bottom: none; }
.ms-table .ms-td--num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ms-table .ms-td--date { white-space: nowrap; }
.ms-table .ms-td--mode { color: var(--text-primary); font-weight: 600; }
.ms-table .ms-td--coins { color: #d97706; font-weight: 700; }
.ms-acc { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--text-primary); }
.ms-acc__dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12); }

/* ── Dark theme tweaks ────────────────────────────────────── */
[data-theme="dark"] .ms-map-wrap { background: rgba(15, 23, 42, 0.85); }
[data-theme="dark"] .ms-map-tools button { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45); }
[data-theme="dark"] .ms-tooltip { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55); background: #111c33; }
[data-theme="dark"] .ms-tooltip__dot,
[data-theme="dark"] .ms-hard__swatch,
[data-theme="dark"] .ms-acc__dot { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18); }
[data-theme="dark"] .ms-legend__bar { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10); }
[data-theme="dark"] .ms-guest-note { color: #fbbf24; background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.32); }
[data-theme="dark"] .ms-table .ms-td--coins { color: #fbbf24; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
    .ms-toolbar .btn { flex: 1 1 auto; }
    .ms-guest-note { width: 100%; }
    .ms-card { padding: 14px 14px; border-radius: 16px; }
    .ms-kpis { gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .ms-kpi { padding: 12px 14px; gap: 10px; }
    .ms-kpi__icon { width: 38px; height: 38px; font-size: 1.25rem; }
    .ms-kpi__value { font-size: 1.15rem; }
    .ms-map-wrap { border-radius: 12px; }
    .ms-map-tools { top: 8px; right: 8px; }
    .ms-legend { gap: 10px; }
    .ms-legend__scale { flex-basis: 100%; }
    /* Two-line row: name · seen · pct on line 1, the bar full-width on line 2.
       Cells are pinned explicitly because the DOM order is name, seen, bar,
       pct — with auto-placement the bar would wrap to row 2 and the pct
       would then land on row 3 (column 1), leaving column 3 empty. */
    .ms-region {
        grid-template-columns: 1fr 64px 44px;
        grid-template-rows: auto auto;
        gap: 8px 12px;
        padding: 10px;
    }
    .ms-region__name { grid-column: 1; grid-row: 1; }
    .ms-region__seen { grid-column: 2; grid-row: 1; }
    .ms-region__pct { grid-column: 3; grid-row: 1; }
    .ms-region__bar { grid-column: 1 / -1; grid-row: 2; }
    .ms-hard__tries { display: none; }
    .ms-detail__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .ms-detail__actions .btn { flex: 1 1 auto; }
    .ms-empty { padding: 40px 18px 34px; }
}
