:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #687586;
  --border: #d9e0ea;
  --primary: #1565c0;
  --primary-dark: #0d47a1;
  --danger: #c62828;
  --warn-bg: #fff8e1;
  --warn-text: #795548;
  --ok-bg: #e8f5e9;
  --ok-text: #1b5e20;
  --shadow: 0 2px 8px rgba(31, 41, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, Arial, sans-serif;
  font-size: 14px;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
p {
  margin-top: 0;
}

.app-bar {
  height: 64px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: var(--shadow);
}

.brand,
.top-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-size: 18px;
  font-weight: 500;
}

.brand-name,
.brand-byline {
  display: block;
}

.brand-byline {
  font-size: 11px;
  font-weight: 400;
  line-height: 1.2;
  opacity: 0.78;
}

.top-nav a {
  padding: 8px 10px;
  border-radius: 4px;
}

.top-nav a:hover {
  background: rgba(255, 255, 255, 0.14);
}

.app-main {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 28px;
  line-height: 1.2;
  margin-bottom: 6px;
}

.muted {
  color: var(--muted);
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.md-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.auth-panel {
  display: grid;
  min-height: calc(100vh - 160px);
  place-items: center;
}

.auth-card {
  width: min(420px, 100%);
  text-align: center;
}

.app-credit {
  color: var(--primary);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 14px;
}

.auth-icon,
.empty-state .material-symbols-outlined {
  color: var(--primary);
  font-size: 48px;
}

.md-btn,
.icon-btn {
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
}

.md-btn {
  border-radius: 4px;
  min-height: 40px;
  padding: 0 16px;
  font-weight: 500;
}

.md-btn-primary {
  background: var(--primary);
  color: #fff;
}

.md-btn-primary:hover {
  background: var(--primary-dark);
}

.md-btn-text {
  background: transparent;
  color: var(--primary);
}

.md-btn-large {
  min-height: 48px;
  padding: 0 22px;
}

.form-card {
  display: grid;
  gap: 18px;
  max-width: 520px;
}

.md-label {
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

.md-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  min-height: 42px;
  padding: 8px 10px;
  text-transform: none;
}

.md-input:focus {
  border-color: var(--primary);
  outline: 2px solid rgba(21, 101, 192, 0.14);
}

.button-row {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.list-grid,
.dashboard-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.split-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
}

.action-panel {
  min-width: 0;
}

.action-card,
.stack-form {
  display: grid;
  gap: 14px;
}

.city-stat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.city-stat-table th,
.city-stat-table td {
  text-align: left;
  vertical-align: top;
  padding: 3px 0;
}
.city-stat-table th {
  color: var(--muted);
  font-weight: 500;
  padding-right: 16px;
  white-space: nowrap;
  width: 1%;
}
.city-stat-table td {
  font-weight: 500;
}

.code-sample {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  margin: 12px 0;
  overflow-x: auto;
  padding: 12px;
}

.link-card:hover {
  border-color: var(--primary);
}

.section-title {
  font-size: 18px;
  margin: 28px 0 12px;
}

.empty-state {
  margin: 44px auto;
  max-width: 520px;
  text-align: center;
}

.card-icon {
  color: var(--primary);
  font-size: 32px;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.notice {
  border-radius: 6px;
  padding: 12px 14px;
}

.notice-error {
  background: #ffebee;
  color: var(--danger);
}

.notice-success {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.notice-info {
  background: #e3f2fd;
  color: var(--primary-dark);
}

.notice-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.table-card {
  overflow-x: auto;
  padding: 0;
}

.data-table {
  border-collapse: collapse;
  width: 100%;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.sort-link {
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sort-link:hover {
  color: var(--primary);
}

.actions-col {
  text-align: right;
}

.inline-form {
  display: inline-flex;
}

.inline-form.with-input {
  align-items: center;
  gap: 6px;
}

.mini-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  min-height: 32px;
  padding: 4px 8px;
  width: 140px;
}

.icon-btn {
  background: transparent;
  border-radius: 50%;
  color: var(--primary);
  height: 36px;
  width: 36px;
}

.icon-btn:hover {
  background: rgba(21, 101, 192, 0.1);
}

.icon-btn-danger {
  color: var(--danger);
}

.role-chip {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
}

.role-owner {
  background: #fff3e0;
  color: #e65100;
}

.role-editor {
  background: #e3f2fd;
  color: var(--primary-dark);
}

.role-reader {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.role-pending {
  background: var(--warn-bg);
  color: var(--warn-text);
}

/* ── Participation grid ──────────────────────────────────────────────────── */

.four-column-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-top: 16px;
}

.player-column {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  padding: 8px;
}

.letter-divider {
  border-bottom: 2px solid var(--primary);
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  padding: 4px 0 2px;
}

.player-mini-row {
  align-items: center;
  display: flex;
  font-size: 13px;
  justify-content: space-between;
  padding: 2px 0;
}

.player-mini-name {
  color: #444;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-badge {
  color: #888;
  font-size: 0.75em;
  margin-left: 4px;
}

.p-radios {
  background: #f0f0f0;
  border-radius: 16px;
  display: flex;
  flex-shrink: 0;
  overflow: hidden;
}

.p-radios input[type="radio"] {
  display: none;
}

.p-radios label {
  color: #666;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  transition: background 0.15s, color 0.15s;
}

.p-radios input[type="radio"]:checked + label {
  background: var(--primary);
  color: white;
}

.participation-summary {
  display: flex;
  gap: 20px;
}

.p-chip {
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
}

.p-chip-absent  { background: #fce4ec; color: #c62828; }
.p-chip-joined  { background: #e3f2fd; color: var(--primary-dark); }
.p-chip-played  { background: var(--ok-bg); color: var(--ok-text); }

/* ── Toggle switch ───────────────────────────────────────────────────────── */

.toggle-row {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  user-select: none;
}

.toggle-row span {
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
  text-transform: none;
}

.toggle-input {
  height: 0;
  opacity: 0;
  position: absolute;
  width: 0;
}

.toggle-switch {
  background: var(--border);
  border-radius: 12px;
  flex-shrink: 0;
  height: 24px;
  position: relative;
  transition: background 0.18s;
  width: 44px;
}

.toggle-switch::after {
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  content: '';
  height: 18px;
  left: 3px;
  position: absolute;
  top: 3px;
  transition: transform 0.18s;
  width: 18px;
}

.toggle-input:checked ~ .toggle-switch {
  background: var(--primary);
}

.toggle-input:checked ~ .toggle-switch::after {
  transform: translateX(20px);
}

.toggle-input:focus-visible ~ .toggle-switch {
  outline: 2px solid rgba(21, 101, 192, 0.4);
  outline-offset: 2px;
}

/* ── Player Report Card ──────────────────────────────────────────────────── */

.mt-24 { margin-top: 24px; }
.va-bottom { vertical-align: bottom; }

.pc-name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 22px;
  font-weight: 500;
  color: var(--primary);
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: 10px;
  margin-bottom: 4px;
}
.pc-status-badge {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  background: #f5f5f5;
}
.pc-status-active   { color: #2e7d32; font-weight: 500; }
.pc-status-inactive { color: #d32f2f; font-weight: 500; }
.pc-update-note {
  font-size: 12px;
  color: #999;
  font-weight: 400;
  margin-left: auto;
}

.pc-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px 24px;
  margin-top: 16px;
}
.pc-kpi-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.pc-kpi-sep {
  border-right: 2px solid #e8e8e8;
  padding-right: 20px;
  margin-right: 4px;
}
.pc-field { display: flex; flex-direction: column; gap: 2px; }
.pc-field-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: #888; font-weight: 500; }
.pc-field-value { font-size: 15px; color: #222; }

.pc-kpi-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #888; font-weight: 500; }
.pc-kpi-val   { font-size: 30px; font-weight: 700; line-height: 1.1; }
.pc-kpi-sub   { font-size: 11px; color: #aaa; margin-top: 1px; }
.pc-kpi-blue   { color: var(--primary); }
.pc-kpi-green  { color: #2e7d32; }
.pc-kpi-amber  { color: #f57f17; }
.pc-kpi-orange { color: #e65100; }
.pc-kpi-gold   { color: #b8860b; }
.pc-elite-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #b8860b;
  border: 1px solid #b8860b;
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 5px;
  vertical-align: middle;
  letter-spacing: 0.04em;
}

/* Activity Summary table */
.pc-grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 4px;
}
.pc-grid-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  font-weight: 500;
  padding: 0 14px 6px 0;
  white-space: nowrap;
  vertical-align: bottom;
}
.pc-grid-table th.num, .pc-grid-table td.num { text-align: right; }
.pc-grid-table th:last-child, .pc-grid-table td:last-child { padding-right: 0; }
.pc-bdr { border-bottom: 2px solid #e8e8e8; }
.pc-group-th { text-align: center; color: #555; font-size: 11px; padding-bottom: 3px; border-bottom: 1px solid #e0e0e0; vertical-align: top; }
.pc-sub-th   { font-size: 10px; font-weight: 400; color: #aaa; text-transform: none; letter-spacing: 0; padding-top: 3px; }
.pc-grid-table td {
  padding: 5px 14px 5px 0;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
  color: #555;
}
.pc-grid-table tr:last-child td { border-bottom: none; }
.pc-summary-row td { font-weight: 600; color: #222; background: #f7f9f7; }
.pc-type-sep td { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #aaa; font-weight: 500; padding-top: 12px; padding-bottom: 4px; border-bottom: 1px solid #eee; }

.pc-bar-wrap    { display: flex; align-items: center; gap: 6px; }
.pc-hbar-track  { position: relative; height: 16px; width: 120px; flex-shrink: 0; background: #eee; border-radius: 4px; overflow: hidden; }
.pc-hbar-played { position: absolute; left: 0; top: 0; bottom: 0; background: #388e3c; }
.pc-hbar-joined { position: absolute; top: 0; bottom: 0; background: #1976d2; }
.pc-bar-pct     { font-size: 11px; color: #888; min-width: 32px; text-align: right; }

.pc-priority-tag {
  display: inline-block;
  font-size: 9px;
  background: #fff3e0;
  color: #e65100;
  border-radius: 3px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 5px;
  font-weight: 500;
}
.bar-legend { margin-top: 10px; font-size: 11px; color: #bbb; display: flex; gap: 16px; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 3px; }
.swatch-played { background: #388e3c; }
.swatch-joined { background: #1976d2; }
.swatch-absent { background: #eee; border: 1px solid #ddd; }

.pc-guide { margin-top: 14px; border-top: 1px solid #f0f0f0; padding-top: 8px; }
.pc-guide summary { font-size: 11px; color: #aaa; cursor: pointer; user-select: none; list-style: none; display: flex; align-items: center; gap: 4px; }
.pc-guide summary::-webkit-details-marker { display: none; }
.pc-guide summary::before { content: '▸'; font-size: 10px; transition: transform 0.15s; }
.pc-guide[open] summary::before { transform: rotate(90deg); }
.pc-guide-body { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 20px; margin-top: 10px; }
.pc-guide-item { display: flex; flex-direction: column; gap: 2px; }
.pc-guide-term { font-size: 11px; font-weight: 600; color: #555; }
.pc-guide-def  { font-size: 11px; color: #888; line-height: 1.5; }

/* Heatmap */
.pc-heatmap-wrap  { overflow-x: auto; margin-top: 12px; }
.pc-heatmap-table { border-collapse: separate; border-spacing: 2px; }
.pc-hm-corner     { text-align: left; color: #aaa; font-size: 10px; font-weight: 400; min-width: 44px; padding-right: 6px; vertical-align: bottom; padding-bottom: 4px; }
.pc-hm-hour-th    { width: 22px; text-align: center; font-size: 10px; font-weight: 400; color: #aaa; padding-bottom: 4px; white-space: nowrap; }
.pc-hm-day-label  { text-align: right; padding-right: 8px; color: #555; font-size: 11px; font-weight: 500; white-space: nowrap; vertical-align: middle; }
.pc-hm-cell       { width: 22px; height: 22px; border-radius: 3px; cursor: pointer; }
.pc-hm-no-data    { background: #e0e0e0; }
.pc-hm-dead       { background: #e64a19; }
.pc-hm-at-risk    { background: #ffb74d; }
.pc-hm-occasional { background: #4fc3f7; }
.pc-hm-reliable   { background: #01579b; }
.pc-hm-tz-label   { text-align: right; padding-right: 8px; color: #aaa; font-size: 10px; padding-top: 4px; vertical-align: top; white-space: nowrap; }
.pc-hm-local-hour { text-align: center; font-size: 10px; color: #aaa; padding-top: 4px; vertical-align: top; }
.pc-hm-legend     { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 11px; color: #888; align-items: center; }
.pc-hm-legend-item { display: flex; align-items: center; gap: 5px; }
.pc-hm-swatch     { width: 12px; height: 12px; border-radius: 2px; display: inline-block; flex-shrink: 0; }
.pc-hm-subtitle   { font-size: 12px; color: #888; margin: 0 0 10px; }
.pc-hm-tooltip    { position: fixed; background: rgba(33,33,33,0.92); color: #fff; font-size: 12px; padding: 6px 10px; border-radius: 4px; pointer-events: none; display: none; z-index: 200; white-space: nowrap; }

/* Trend strip */
.pc-trend-section { margin-bottom: 20px; }
.pc-trend-boxes  { display: flex; gap: 3px; }
.pc-trend-box    { width: 32px; height: 26px; border-radius: 4px; cursor: pointer; flex-shrink: 0; }
.pc-trend-labels { display: flex; gap: 3px; margin-top: 3px; }
.pc-trend-label  { width: 32px; text-align: center; font-size: 10px; color: #aaa; flex-shrink: 0; }

/* Event history table */
.event-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 4px; }
.event-table th { background: var(--primary); color: white; padding: 8px 12px; text-align: left; font-weight: 500; white-space: nowrap; }
.event-table th.num, .event-table td.num { text-align: center; }
.event-table td { padding: 7px 12px; border-bottom: 1px solid #eee; }
.event-table tr:last-child td { border-bottom: none; }
.event-table tr:hover td { background: #f9f9f9; }
.status-chip { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; text-transform: capitalize; }
.chip-played { background: #e8f5e9; color: #2e7d32; }
.chip-joined { background: #e3f2fd; color: var(--primary-dark); }
.chip-absent { background: #fce4ec; color: #c62828; }
.priority-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #f57c00; margin-right: 5px; vertical-align: middle; }

.pc-cache-note { font-size: 11px; color: #bbb; text-align: right; margin-top: 8px; }

/* ── Dashboard card links ────────────────────────────────────────────────── */
a.md-card.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, transform 0.15s;
  cursor: pointer;
}
a.md-card.card-link:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.13);
  transform: translateY(-2px);
}
.card-icon-report { color: #7b5ea7; font-size: 32px; }
.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 24px 0 10px;
}

/* ── Ranking report ──────────────────────────────────────────────────────── */
.ranking-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ranking-table th { padding: 8px 10px; text-align: left; border-bottom: 2px solid #e0e0e0; white-space: nowrap; }
.ranking-table th.num, .ranking-table td.num { text-align: right; }
.ranking-table th.sortable { cursor: pointer; user-select: none; }
.ranking-table th.sortable:hover { color: var(--primary); }
.ranking-table td { padding: 7px 10px; border-bottom: 1px solid #f0f0f0; }
.ranking-table tbody tr:hover { background: #fafafa; }
.ranking-table td.att-ok    { color: #2e7d32; font-weight: 600; }
.ranking-table td.att-warn  { color: #e65100; font-weight: 600; }
.ranking-table td.att-low   { color: #c62828; font-weight: 700; background: #fff3e0; }
.ranking-table td.att-grace { color: var(--muted); }
.rl-filter-btn-active { background: var(--primary) !important; color: #fff !important; }
.rl-info { font-size: 13px; color: var(--muted); margin: 8px 0 16px; }
.rl-at-risk-row td { background: #fff8f6 !important; }
.rl-grace-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: #e8f4fd;
  color: #1565c0;
  border: 1px solid #90caf9;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
  cursor: default;
}

@media (max-width: 720px) {
  .app-bar,
  .page-header,
  .button-row,
  .split-grid {
    align-items: stretch;
    flex-direction: column;
  }

  .split-grid {
    display: flex;
  }

  .app-bar {
    height: auto;
    padding: 14px 16px;
  }
}

/* ── Player report: split top card ──────────────────────────────────────────── */
.pc-top-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  align-items: start;
}
.pc-player-half {
  padding-right: 24px;
  border-right: 2px solid #e8e8e8;
}
.pc-city-half {
  padding-left: 24px;
}
.pc-city-heading {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  font-weight: 500;
  margin-bottom: 6px;
}
.pc-city-name {
  font-size: 16px;
  font-weight: 600;
  color: #222;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e8e8e8;
}
.pc-city-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
}
.pc-city-empty {
  display: flex;
  align-items: center;
  height: 100%;
}
@media (max-width: 720px) {
  .pc-top-card {
    grid-template-columns: 1fr;
  }
  .pc-player-half {
    padding-right: 0;
    border-right: none;
    border-bottom: 2px solid #e8e8e8;
    padding-bottom: 20px;
  }
  .pc-city-half {
    padding-left: 0;
    padding-top: 20px;
  }
}
