:root {
  color-scheme: dark;
  --bg: #101217;
  --sidebar: #151922;
  --panel: #181d26;
  --panel-2: #202633;
  --panel-3: #252d3b;
  --line: #313948;
  --text: #eff2f6;
  --muted: #9aa6b2;
  --green: #49d17d;
  --amber: #e6b84d;
  --red: #ef6b6b;
  --cyan: #58c7e6;
  --violet: #a58cff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

button, select, input {
  font: inherit;
}

.sidebar {
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  display: grid;
  gap: 2px;
  padding: 4px 6px 8px;
}

.brand strong {
  font-size: 17px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

nav {
  display: grid;
  gap: 3px;
}

nav button,
.session button,
form button,
.toolbar button,
th button {
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 34px;
  padding: 7px 10px;
  cursor: pointer;
}

nav button {
  text-align: left;
}

nav button:hover,
nav button.active {
  background: var(--panel-2);
  border-color: var(--line);
}

.session {
  margin-top: auto;
  color: var(--muted);
  display: grid;
  gap: 8px;
}

.session button,
form button,
.toolbar button {
  background: var(--panel-2);
  border-color: var(--line);
  text-align: center;
}

main {
  min-width: 0;
}

header {
  min-height: 72px;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 18, 23, 0.88);
  padding: 12px 22px;
  position: sticky;
  top: 0;
  z-index: 5;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: 0;
}

#view-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#view-filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

select,
input {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 34px;
  padding: 7px 10px;
}

input {
  width: 180px;
}

#content {
  padding: 18px 22px 34px;
  display: grid;
  gap: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.card,
.chart,
.table-panel,
.notice,
.login-panel form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.card {
  min-height: 86px;
  padding: 13px;
  display: grid;
  align-content: space-between;
}

.card span {
  color: var(--muted);
  font-size: 12px;
}

.card strong {
  font-size: 23px;
  line-height: 1.1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.chart {
  padding: 12px;
  min-height: 306px;
}

.chart h2,
.table-panel h2 {
  font-size: 14px;
  font-weight: 700;
}

.chart canvas {
  display: block;
  width: 100%;
  height: 260px;
  margin-top: 8px;
}

.table-panel {
  overflow: hidden;
}

.table-panel h2 {
  padding: 12px 12px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #171b23;
  color: var(--muted);
  font-weight: 650;
}

th button {
  width: 100%;
  min-height: 0;
  padding: 0;
  color: inherit;
  text-align: left;
}

td {
  color: #dce3ea;
}

tbody tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

code {
  color: #c8d3df;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.print-report {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.report-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.report-player {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.report-player img,
.report-avatar-fallback {
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
  border-radius: 8px;
  background: var(--panel-3);
  border: 1px solid var(--line);
}

.report-avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: 26px;
  font-weight: 800;
}

.report-player span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.report-player h2 {
  font-size: 24px;
  margin: 2px 0 4px;
}

.print-report-button {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 36px;
  padding: 8px 12px;
  cursor: pointer;
}

.report-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.report-stat {
  min-height: 78px;
  background: var(--panel);
  padding: 12px;
  display: grid;
  align-content: space-between;
}

.report-stat span {
  color: var(--muted);
  font-size: 12px;
}

.report-stat strong {
  font-size: 20px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.report-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}

.report-columns h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.report-columns dl {
  margin: 0;
  display: grid;
  gap: 8px;
}

.report-columns dl div {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(0, 1fr);
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.report-columns dt {
  color: var(--muted);
}

.report-columns dd {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

a {
  color: var(--cyan);
}

.ok { color: var(--green); }
.warn { color: var(--amber); }
.bad { color: var(--red); }
.info { color: var(--cyan); }

.notice,
.loading {
  padding: 14px;
  color: var(--muted);
}

.notice.bad {
  color: var(--red);
  border-color: rgba(239, 107, 107, 0.55);
}

.notice.warn {
  color: var(--amber);
  border-color: rgba(230, 184, 77, 0.55);
}

.login-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

form {
  width: min(380px, calc(100vw - 32px));
  padding: 22px;
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

#login-error {
  min-height: 20px;
  color: var(--red);
  margin: 0;
}

.hidden { display: none !important; }

@media (max-width: 1120px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .charts {
    grid-template-columns: 1fr;
  }
  .report-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .report-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  body {
    grid-template-columns: 1fr;
  }
  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  header {
    align-items: stretch;
    flex-direction: column;
    position: static;
  }
  .toolbar,
  #view-filters {
    justify-content: stretch;
  }
  select,
  input,
  .toolbar button {
    width: 100%;
  }
  #content {
    padding: 14px;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .table-panel {
    overflow-x: auto;
  }
  .report-top,
  .report-player {
    align-items: flex-start;
  }
  .report-top {
    flex-direction: column;
  }
  .print-report-button {
    width: 100%;
  }
  .report-stats {
    grid-template-columns: 1fr;
  }
  .report-columns dl div {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

body.printing-report {
  display: block;
  background: #fff;
  color: #101217;
}

body.printing-report .sidebar,
body.printing-report header,
body.printing-report #content > :not(.print-report) {
  display: none !important;
}

body.printing-report #content {
  display: block;
  padding: 0;
}

body.printing-report .print-report {
  color: #101217;
  background: #fff;
  border: 0;
  border-radius: 0;
}

body.printing-report .print-report-button {
  display: none;
}

body.printing-report .report-top,
body.printing-report .report-columns dl div {
  border-color: #d7dde5;
}

body.printing-report .report-stats {
  background: #d7dde5;
}

body.printing-report .report-stat {
  background: #fff;
}

body.printing-report .report-player span,
body.printing-report .report-stat span,
body.printing-report .report-columns dt {
  color: #5d6875;
}

body.printing-report .report-player code,
body.printing-report .report-columns dd {
  color: #101217;
}

@media print {
  @page {
    margin: 12mm;
  }

  body {
    display: block;
    background: #fff;
    color: #101217;
  }

  .sidebar,
  header,
  #content > :not(.print-report),
  .print-report-button {
    display: none !important;
  }

  #content {
    display: block;
    padding: 0;
  }

  .print-report {
    color: #101217;
    background: #fff;
    border: 0;
    border-radius: 0;
  }

  .report-top,
  .report-columns dl div {
    border-color: #d7dde5;
  }

  .report-stats {
    background: #d7dde5;
  }

  .report-stat {
    background: #fff;
    break-inside: avoid;
  }

  .report-columns {
    break-inside: avoid;
  }

  .report-player span,
  .report-stat span,
  .report-columns dt {
    color: #5d6875;
  }

  .report-player code,
  .report-columns dd {
    color: #101217;
  }
}
