:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #fff;
  --ink: #111827;
  --muted: #667085;
  --line: #e4e9f1;
  --blue: #2563eb;
  --green: #0f9f6e;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--bg); font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Tahoma, "PingFang SC", "Microsoft YaHei", sans-serif; -webkit-font-smoothing: antialiased; }
button, select { font: inherit; }

.mobile-header { height: 58px; padding: env(safe-area-inset-top) 18px 0; display: flex; align-items: center; justify-content: space-between; color: #fff; background: #172033; }
.brand { display: flex; align-items: center; font-size: 17px; font-weight: 750; letter-spacing: -.03em; }
.brand-name { display: block; }
.mobile-header-actions { display: flex; align-items: center; gap: 11px; }
.mobile-header .locale-switcher select { min-height: 30px; max-width: 72px; padding: 0 19px 0 7px; border: 1px solid rgba(255, 255, 255, .22); border-radius: 8px; color: #eef3f9; background: rgba(255, 255, 255, .08); font-size: 10px; }
.connection { display: inline-flex; align-items: center; gap: 7px; color: #c8d0dd; font-size: 11px; }
.connection i { width: 7px; height: 7px; border-radius: 50%; background: #f79009; }
.connection.ready i { background: #35c895; }
.connection.error i { background: #f97066; }
.mobile-logout { display: inline-flex; align-items: center; min-height: 24px; padding: 0 1px; border-bottom: 1px solid transparent; color: #c8d0dd; background: transparent; font-size: 10px; font-weight: 650; line-height: 1.2; text-decoration: none; cursor: pointer; transition: color .16s ease, border-color .16s ease, opacity .16s ease, transform .16s ease; }
.mobile-logout:hover { color: #fff; border-bottom-color: rgba(255, 255, 255, .48); }
.mobile-logout:active { transform: translateY(1px); }
.mobile-logout[aria-disabled="true"] { cursor: wait; opacity: .5; pointer-events: none; }

main { width: min(100% - 24px, 620px); margin: 0 auto; padding: 23px 0 calc(34px + env(safe-area-inset-bottom)); }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 0 4px 19px; }
.hero p, .card-title p { margin: 0; color: var(--blue); font-size: 9px; font-weight: 800; letter-spacing: .15em; }
.hero h1 { margin: 2px 0 3px; font-size: 29px; line-height: 1.08; letter-spacing: -.055em; }
.hero small { color: var(--muted); font-size: 10px; }
.hero label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 9px; font-weight: 700; }
.hero select { min-height: 38px; max-width: 122px; padding: 0 29px 0 10px; border: 1px solid #d1d9e6; border-radius: 9px; color: var(--ink); background: #fff; outline: none; }
.bi-hero { justify-content: flex-end; margin-bottom: 12px; }
.bi-hero label { gap: 2px; font-size: 8px; }
.bi-hero select { width: 92px; min-height: 26px; max-width: 92px; padding: 0 20px 0 7px; border-radius: 7px; font-size: 9px; }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi-grid article { min-height: 105px; padding: 16px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 8px 24px rgba(16, 24, 40, .045); }
.kpi-grid span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; }
.kpi-grid strong { display: block; margin-top: 8px; font-size: 24px; line-height: 1.05; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.kpi-grid small { display: block; margin-top: 8px; color: #98a2b3; font-size: 8px; letter-spacing: .05em; }
.kpi-grid .primary { color: #fff; border-color: var(--blue); background: linear-gradient(140deg, #2d6df2, #1749b0); }
.kpi-grid .primary span, .kpi-grid .primary small { color: rgba(255, 255, 255, .76); }

.mobile-card { margin-top: 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: 0 9px 26px rgba(16, 24, 40, .05); }
.card-title { padding: 18px 18px 0; }
.card-title h2 { margin: 3px 0 0; font-size: 16px; letter-spacing: -.025em; }
.card-title .data-range { margin: 6px 0 0; color: var(--muted); font-size: 9px; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.mobile-donut-row { padding: 22px 18px 17px; display: grid; grid-template-columns: 138px 1fr; align-items: center; gap: 18px; border-bottom: 1px solid var(--line); }
.mobile-donut { width: 138px; height: 138px; display: grid; place-items: center; border-radius: 50%; background: #d8e0ec; }
.mobile-donut > div { width: 86px; height: 86px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 50%; background: #fff; }
.mobile-donut strong { font-size: 16px; letter-spacing: -.04em; }
.mobile-donut span { margin-top: 2px; color: var(--muted); font-size: 8px; }
.mobile-legend { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.mobile-legend-item { min-width: 0; display: grid; grid-template-columns: 7px 1fr auto; align-items: center; gap: 6px; color: var(--muted); font-size: 9px; }
.mobile-legend-item i { width: 7px; height: 7px; border-radius: 2px; }
.mobile-legend-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-legend-item b { color: var(--ink); font-weight: 650; }

.mobile-ranking { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.mobile-rank { display: grid; grid-template-columns: 92px minmax(60px, 1fr) 72px; align-items: center; gap: 8px; }
.mobile-rank > span:first-child { overflow: hidden; font-size: 10px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.mobile-rank .track { height: 7px; overflow: hidden; border-radius: 99px; background: #edf1f6; }
.mobile-rank .track i { height: 100%; display: block; border-radius: inherit; background: linear-gradient(90deg, #82aaff, var(--blue)); transform-origin: left; animation: grow .45s ease both; }
.mobile-rank b { text-align: right; color: var(--muted); font-size: 9px; font-weight: 600; }
@keyframes grow { from { transform: scaleX(0); } }

.matrix-card { padding-bottom: 2px; }
.mobile-table { margin-top: 17px; overflow: auto; border-top: 1px solid var(--line); }
.mobile-table table { min-width: 600px; width: 100%; border-collapse: collapse; font-size: 10px; font-variant-numeric: tabular-nums; }
.mobile-table th, .mobile-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.mobile-table th { color: var(--muted); background: #fafbfd; font-size: 8px; letter-spacing: .04em; }
.mobile-table th:first-child, .mobile-table td:first-child { position: sticky; left: 0; z-index: 2; text-align: left; background: #fff; box-shadow: 1px 0 var(--line); }
.mobile-table th:first-child { z-index: 3; background: #fafbfd; }
.mobile-table .total { font-weight: 800; background: #f7faff; }
.empty { padding: 28px 10px; color: var(--muted); font-size: 11px; text-align: center; }
.mobile-footer { width: min(100% - 24px, 620px); margin: -16px auto 28px; color: var(--muted); font-size: 9px; text-align: center; }

.mobile-message { position: fixed; z-index: 20; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 32px); padding: 10px 13px; border-radius: 9px; color: #fff; background: #8f241c; font-size: 11px; opacity: 0; transform: translate(-50%, 10px); transition: .18s ease; pointer-events: none; }
.mobile-message.visible { opacity: 1; transform: translate(-50%, 0); }

:focus-visible { outline: 3px solid rgba(37, 99, 235, .35); outline-offset: 2px; }

@media (max-width: 380px) {
  .mobile-header { padding-left: 12px; padding-right: 12px; }
  .mobile-header-actions { gap: 6px; }
  .mobile-header .locale-switcher select { max-width: 58px; padding-left: 5px; padding-right: 15px; font-size: 9px; }
  .connection { max-width: 76px; overflow: hidden; white-space: nowrap; font-size: 10px; }
}

@media (max-width: 370px) {
  .mobile-donut-row { grid-template-columns: 118px 1fr; gap: 12px; }
  .mobile-donut { width: 118px; height: 118px; }
  .mobile-donut > div { width: 76px; height: 76px; }
  .mobile-rank { grid-template-columns: 82px minmax(50px, 1fr) 65px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
