:root {
  --accent: #1e5fd6;
  --red-bg: #fdeaea;
  --red: #d32f2f;
  --bg: #f2f4f7;
  --card-bg: #ffffff;
  --text: #1a1f26;
  --muted: #6b7280;
  --border: #e2e5ea;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 76px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #163263;
  color: #fff;
  padding: 16px 16px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-icon {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
}

.topbar-logo-text {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 34px;
  font-weight: 800;
}

.topbar-header {
  min-width: 0;
  font-size: 26px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lang-switch {
  display: flex;
  gap: 4px;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}
.lang-switch a {
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
}
.lang-switch a.active {
  color: var(--accent);
  background: #fff;
}

.logout-link {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  padding: 4px 8px;
}

.content {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.section-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin: 20px 0 10px;
}
.section-label:first-child { margin-top: 0; }

.empty-state { color: var(--muted); text-align: center; padding: 40px 20px; }

/* ---- home: shake-table report ---- */
.source-card {
  background: var(--accent);
  color: #fff;
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
}
.source-updated { font-size: 13px; opacity: 0.8; margin-top: 4px; }

.file-select-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
}
.file-select-row label { font-size: 11px; opacity: 0.8; text-transform: uppercase; font-weight: 700; }
.file-select-row select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

.stats-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 480px) {
  .stats-row { grid-template-columns: repeat(4, 1fr); }
}
.stat-box { background: var(--card-bg); border-radius: 10px; padding: 10px; text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,0.05); }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.stat-value { font-size: 16px; font-weight: 700; margin-top: 2px; }

.test-type { font-size: 13px; color: var(--muted); margin-top: 10px; }

.scope-grid { display: flex; flex-direction: column; gap: 16px; }
.scope-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.scope-title {
  background: #eef0f4;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.unit-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  background: #eef0f4;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  letter-spacing: 0.02em;
}
.scope-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.scope-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text);
}
.badge-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.badge-range { color: var(--muted); }
.scope-panel canvas { display: block; padding: 10px; box-sizing: border-box; }

.chart-scale-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 0 12px 10px;
  flex-wrap: wrap;
}
.chart-scale-row label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
}
.chart-scale-row input {
  width: 84px;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.chart-scale-reset {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  background: #eef0f4;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}

/* ---- events ---- */
.event-list { display: flex; flex-direction: column; gap: 10px; }
.event-item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  border-left: 6px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.event-time { font-size: 12px; color: var(--muted); }
.event-message { font-weight: 600; margin-top: 2px; }

/* ---- settings ---- */
.settings-box {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.settings-label { font-size: 12px; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; font-weight: 700; }
.building-form { display: flex; gap: 8px; }
.building-form input { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--border); font-size: 15px; }
.building-form button { padding: 10px 16px; border-radius: 10px; border: none; background: var(--accent); color: #fff; font-weight: 700; }

/* ---- map page ---- */
.content:has(#map-container) { padding: 12px; max-width: 100%; }
.map-hint {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 8px;
}
#map-container {
  height: calc(100vh - 190px);
  min-height: 320px;
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.marker-pin {
  width: 26px;
  height: 26px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

/* ---- login page ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.login-title {
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 20px;
}
.login-error {
  background: var(--red-bg);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
  text-align: center;
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; display: flex; flex-direction: column; gap: 6px; }
.login-form input { padding: 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 15px; }
.login-form button {
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  margin-top: 4px;
}
.login-lang { justify-content: center; margin-top: 20px; }
.login-lang a { color: var(--muted); }
.login-lang a.active { background: var(--accent); color: #fff; }

/* ---- bottom nav ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: #ffffff;
  font-size: 20px;
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
}
.nav-item {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
}
.nav-item.active { color: var(--accent); font-weight: 700; }
