/* Discord-inspired dark admin UI */
:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-mod: #232428;
  --bg-hover: #35373c;
  --bg-input: #1e1f22;
  --text: #f2f3f5;
  --text-muted: #b5bac1;
  --text-faint: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --success: #23a559;
  --danger: #f23f43;
  --warning: #f0b232;
  --border: #3f4147;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
  /* Cap content width on ultrawide / full-screen monitors (~half of 2560) */
  --dashboard-max-width: 1000px;
  --dashboard-pad-x: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg-tertiary);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

a {
  color: #00a8fc;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.boot {
  display: grid;
  place-items: center;
  height: 100vh;
  color: var(--text-muted);
}

/* Layout */
.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-tertiary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  box-sizing: border-box;
}

.shell.shell-embed-style {
  grid-template-columns: 280px 1fr;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

/* Line under bot name / brand at top of sidebar */
.sidebar-divider {
  height: 1px;
  margin: 0 10px 10px;
  background: var(--border);
  flex-shrink: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #eb459e);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
  overflow: hidden;
}

.brand-mark-img {
  background: transparent;
  padding: 0;
}

.brand-mark-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand-mark-lg {
  width: 56px;
  height: 56px;
  font-size: 20px;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.login-brand {
  display: flex;
  justify-content: center;
  margin: 0 0 16px;
}

/* Submissions expandable rows */
.sub-table .sub-row.clickable {
  cursor: pointer;
}

.sub-table .sub-row.clickable:hover td {
  background: var(--bg-hover);
}

.sub-table .sub-row.open td {
  background: var(--bg-mod);
}

.sub-table .sub-chevron {
  color: var(--text-faint);
  font-size: 12px;
  width: 28px;
}

.sub-table .sub-detail-cell {
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px !important;
}

.sub-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.sub-answers {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.sub-answer-row {
  padding: 8px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.sub-answer-row strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

/* Bot profile (per-server) */
.bot-profile-layout {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 700px) {
  .bot-profile-layout {
    grid-template-columns: 1fr;
  }
}

.bot-profile-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bot-profile-preview-img,
.bot-profile-preview-fallback {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
}

.bot-profile-preview-fallback {
  background: linear-gradient(135deg, var(--accent), #eb459e);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 28px;
}

.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  flex-shrink: 0;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-btn.active {
  background: var(--bg-mod);
  color: var(--text);
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Embed-style palette pinned under nav */
.sidebar-palette {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-palette-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
  margin: 0 0 4px;
  padding: 0 4px;
  flex-shrink: 0;
}

.sidebar-palette-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.3;
  margin: 0 0 8px;
  padding: 0 4px;
  flex-shrink: 0;
}

.sidebar-palette-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 2px 8px;
  scrollbar-width: thin;
}

.sidebar-palette-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

.sidebar-palette-item .sp-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 2px;
  word-break: break-all;
}

.sidebar-palette-item .sp-hint {
  font-size: 10px;
  color: var(--text-faint);
  margin: 0 0 4px;
  line-height: 1.25;
}

.sidebar-palette-item .sp-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-palette-item input[type='color'] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-palette-item .input-sm {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
}

.sidebar-palette-item .btn-sm {
  padding: 4px 6px;
  font-size: 11px;
  flex-shrink: 0;
}

.sidebar-palette-add {
  flex-shrink: 0;
  padding: 8px 4px 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-palette-add .label {
  margin-bottom: 2px;
  font-size: 10px;
}

.sidebar-palette-add .sp-add-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-palette-add input[type='color'] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.main {
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  /* Full-bleed bar background; inner content aligns with max-width column */
  padding: 16px
    max(
      var(--dashboard-pad-x),
      calc((100% - var(--dashboard-max-width)) / 2 + var(--dashboard-pad-x))
    );
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  box-sizing: border-box;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

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

.content {
  /* Stop stretching on large monitors; center the column */
  max-width: var(--dashboard-max-width);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
  padding: 20px var(--dashboard-pad-x) 40px;
  overflow: auto;
  flex: 1;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at top, #3c45a5 0%, transparent 50%),
    var(--bg-tertiary);
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.login-card p {
  color: var(--text-muted);
  margin: 0 0 24px;
  line-height: 1.5;
  /* Honor \n in textContent (login copy, etc.) */
  white-space: pre-line;
}

/* No-premium dashboard landing */
.login-card.premium-card {
  width: min(480px, 100%);
  text-align: left;
}

.login-card.premium-card .login-brand {
  text-align: center;
}

.login-card.premium-card h1 {
  text-align: center;
}

.premium-subhead {
  margin: 8px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.premium-server-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-tertiary);
}

.premium-server-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.premium-server-list li:last-child {
  border-bottom: none;
}

.premium-server-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.premium-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.premium-actions .btn {
  flex: 1;
  min-width: 120px;
}

/* Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-mod);
  color: var(--text);
  transition: background 0.12s ease;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
}

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

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover {
  filter: brightness(0.92);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
}

.input,
.select,
.textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
}

/* Shorter selects (topbar Server + filters + all selects) */
.select {
  padding-top: 4px;
  padding-bottom: 4px;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
}

.textarea {
  min-height: 90px;
  resize: vertical;
}

.label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.field {
  margin-bottom: 14px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 12px;
}

/* Dense embed-style sections (roles, status, labels) */
.card.card-compact {
  padding: 12px 14px;
}

.card.card-compact + .card.card-compact {
  margin-top: 10px;
}

.card.card-compact > .card-title {
  margin: 0 0 6px;
  font-size: 14px;
}

.card.card-compact > .faint {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.35;
}

.embed-subhead {
  margin: 0 0 8px;
  padding: 0 0 5px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-left: 3px solid var(--accent);
  border-bottom: 1px solid var(--border);
  line-height: 1.3;
}

/* Space between the previous group’s fields and the next category title */
.embed-role-group + .embed-role-group {
  margin-top: 16px;
}

.field-sm {
  margin-bottom: 0;
}

.field-sm .label {
  margin-bottom: 3px;
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: none;
  font-weight: 600;
  color: var(--text-muted);
}

.input-sm,
.select-sm {
  padding: 5px 8px;
  font-size: 13px;
  border-radius: 6px;
}

.textarea-sm {
  min-height: 56px;
  padding: 6px 8px;
  font-size: 13px;
}

@media (max-width: 1100px) {
  .grid-3 {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 900px) {
  .shell,
  .shell.shell-embed-style {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    max-height: none;
    overflow: visible;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-foot {
    width: 100%;
    margin-top: 0;
  }

  .sidebar-palette {
    width: 100%;
    max-height: 320px;
    order: 10;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Cards & tables */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.card + .card {
  margin-top: 14px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}

/* e.g. "(UTC)" beside a panel title — half title size + 4px */
.card-title-muted {
  font-size: calc(0.5em + 4px);
  font-weight: 500;
  color: var(--text-faint);
  vertical-align: baseline;
}

/* Inset title underline (matches Statistics panels) */
.card-title-rule {
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 12px;
  margin-left: 8px;
  margin-right: 8px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.app-card {
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.app-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.app-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.app-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.badge.ok {
  background: rgba(35, 165, 89, 0.15);
  color: #3ba55d;
}

.badge.warn {
  background: rgba(240, 178, 50, 0.15);
  color: var(--warning);
}

.badge.danger {
  background: rgba(242, 63, 67, 0.15);
  color: #f23f43;
}

a.discord-user-link {
  color: #00a8fc;
  font-weight: 500;
  text-decoration: none;
}

a.discord-user-link:hover {
  text-decoration: underline;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-tertiary);
  position: sticky;
  top: 0;
}

tr:hover td {
  background: var(--bg-hover);
}

/* Drag list */
.q-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.q-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: start;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: grab;
}

.q-item.dragging {
  opacity: 0.5;
  border-color: var(--accent);
}

.q-handle {
  color: var(--text-faint);
  user-select: none;
  padding-top: 2px;
}

.q-item strong {
  display: block;
  margin-bottom: 4px;
}

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

.faint {
  color: var(--text-faint);
  font-size: 12px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  width: min(520px, 100%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal p {
  color: var(--text-muted);
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  z-index: 1100;
  max-width: 360px;
}

.toast.error {
  border-color: var(--danger);
}

.toast.success {
  border-color: var(--success);
}

.hidden {
  display: none !important;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.tab.active {
  background: var(--bg-mod);
  color: var(--text);
  border-color: var(--border);
}

.split {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
}

@media (max-width: 1100px) {
  .split {
    grid-template-columns: 1fr;
  }
}

.preview-box {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.preview-box h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-q {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.preview-q:last-child {
  border-bottom: none;
}

/* Discord-style deploy embed mock (Preview tab) */
.discord-embed {
  display: flex;
  max-width: 520px;
  background: #2b2d31;
  border-radius: 4px;
  overflow: hidden;
}

.discord-embed-bar {
  width: 4px;
  flex-shrink: 0;
  background: var(--accent);
}

.discord-embed-body {
  padding: 8px 12px 10px 12px;
  min-width: 0;
  flex: 1;
}

.discord-embed-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  margin: 0 0 6px;
  line-height: 1.25;
}

.discord-embed-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.discord-embed-footer {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-faint);
}

.preview-apply-row {
  margin-top: 10px;
}

.discord-btn-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  user-select: none;
  pointer-events: none;
}

/* Statistics filters */
.stat-filters-row {
  width: 100%;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.stat-filters-row > .select {
  width: auto;
  min-width: 140px;
}

.stat-filters-clear {
  margin-left: auto;
}

/* Statistics page */
.stat-kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 14px;
  align-items: stretch;
}

/* Prevent global .card + .card { margin-top } from breaking the row */
.stat-kpi-grid > .card + .card {
  margin-top: 0;
}

@media (max-width: 1200px) {
  .stat-kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 700px) {
  .stat-kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.stat-kpi {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  height: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  margin-top: 0;
}

.stat-kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin: 0 0 8px;
  width: 100%;
  text-align: center;
}

.stat-kpi-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 4px;
  text-align: center;
  width: 100%;
}

/* Same footprint under every card (whether "—" or a % delta) */
.stat-kpi-delta {
  display: block;
  margin: 0;
  padding: 0;
  min-height: 1.25em;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  width: 100%;
}

.stat-up {
  color: #3ba55d;
  font-size: 12px;
  font-weight: 600;
}

.stat-down {
  color: #f23f43;
  font-size: 12px;
  font-weight: 600;
}

/* Row 2 — peak (square map) | timeline (same height, remaining width) */
.stat-grid-peak-timeline {
  --stat-peak-size: 260px;
  display: grid;
  grid-template-columns: var(--stat-peak-size) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
  align-items: stretch;
  /* Shared row height (= peak column width → outer peak card is square) */
  min-height: var(--stat-peak-size);
  height: var(--stat-peak-size);
}

.stat-grid-peak-timeline > .card {
  margin-top: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.stat-panel-peak {
  width: 100%;
  max-width: 100%;
}

.stat-panel-timeline {
  min-height: 0;
  height: 100%;
}

/* Peak body: square heat area fills leftover after title/caption, no scroll */
.stat-panel-body-peak {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 2px;
}

.stat-heat-frame {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  /* Square: width follows available height inside the card */
  aspect-ratio: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.stat-heat-caption {
  flex-shrink: 0;
  font-size: 10px;
  line-height: 1.15;
  text-align: center;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Row 3 — status · by app */
.stat-grid-mid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
  align-items: stretch;
}

.stat-grid-mid > .card + .card {
  margin-top: 0;
}

/* Row 4 — reviewers · performance (50% / 50%) */
.stat-grid-tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
  align-items: stretch;
}

.stat-grid-tables > .card + .card {
  margin-top: 0;
}

@media (max-width: 1100px) {
  .stat-grid-peak-timeline {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .stat-panel-peak {
    max-width: none;
    width: 100%;
    height: auto;
  }

  .stat-heat-frame {
    width: min(100%, 260px);
    height: auto;
    max-height: 260px;
  }

  .stat-grid-mid {
    grid-template-columns: 1fr;
  }

  .stat-grid-tables {
    grid-template-columns: 1fr;
  }

  .stat-grid-mid > .card + .card,
  .stat-grid-tables > .card + .card {
    margin-top: 14px;
  }
}

.stat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin-top: 0;
  box-sizing: border-box;
}

.stat-panel .card-title {
  margin-bottom: 10px;
  flex-shrink: 0;
}

/* Inset rule under titles — all stats rows; does not touch card edges */
.stat-grid-peak-timeline .card-title,
.stat-grid-mid .card-title,
.stat-grid-tables .card-title {
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 12px;
  margin-left: 8px;
  margin-right: 8px;
}

/* Fill remaining card height so all panels in a row match */
.stat-panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stat-svg {
  width: 100%;
  height: auto;
  max-height: 200px;
  min-height: 160px;
  display: block;
  flex: 1;
}

/* Timeline next to peak: use full panel height for the chart */
.stat-panel-timeline .stat-svg {
  max-height: none;
  min-height: 0;
  height: 100%;
  flex: 1 1 auto;
}

.stat-panel-timeline .stat-chart-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stat-panel-timeline .stat-chart-wrap .stat-svg {
  flex: 1;
}

/* Full-width timeline chart */
.stat-svg-wide {
  width: 100%;
  height: 210px;
  max-height: none;
  min-height: 190px;
  flex: 1;
}

.stat-chart-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: visible; /* allow tip near edges; JS clamps inside */
}

.stat-chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow);
  /* Positioned via left/top in JS — no centering transform (avoids edge clip) */
  max-width: calc(100% - 16px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-chart-hit {
  cursor: pointer;
}

.stat-chart-dot {
  pointer-events: none;
}

.stat-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  margin-bottom: 6px;
}

.stat-leg-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stat-leg-swatch {
  display: inline-block;
  width: 16px;
  height: 0;
  border-top: 2px solid var(--text-faint);
}

.stat-leg-swatch.daily {
  border-top-color: var(--accent);
  border-top-width: 2.5px;
}

.stat-leg-swatch.avg7 {
  border-top-style: dashed;
  border-top-color: var(--text-faint);
}

.stat-leg-swatch.avg30 {
  border-top-style: dotted;
  border-top-color: #3ba55d;
  border-top-width: 2.5px;
}

.stat-panel .table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.stat-panel .stat-bars {
  flex: 1;
}

.stat-panel .stat-donut-wrap {
  flex: 1;
  align-content: center;
}

.stat-panel-body-center {
  justify-content: center;
  align-items: center;
}

.stat-panel-body-center .stat-donut-wrap {
  justify-content: center;
  align-items: center;
  width: 100%;
}

.stat-panel .stat-heat {
  flex: 1;
  min-height: 0;
}

.stat-donut-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.stat-donut {
  width: 160px;
  height: 160px;
  flex-shrink: 0;
}

.stat-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.stat-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stat-bars {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Name + count on top row; full-width bar underneath */
.stat-bar-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  min-width: 0;
}

.stat-bar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.stat-bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.25;
}

.stat-bar-track {
  height: 8px;
  width: 100%;
  background: var(--bg-tertiary);
  border-radius: 999px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 2px;
}

.stat-bar-meta {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.25;
  white-space: nowrap;
}

.stat-mini-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-mini-bar {
  height: 6px;
  background: var(--success);
  border-radius: 999px;
  min-width: 2px;
  max-width: 80px;
}

.stat-heat {
  display: grid;
  grid-template-columns: minmax(22px, 1.15fr) repeat(6, minmax(0, 1fr));
  grid-template-rows: auto repeat(7, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  align-items: stretch;
  justify-items: stretch;
  overflow: hidden;
}

.stat-heat-corner {
  min-width: 0;
}

.stat-heat-hlabel,
.stat-heat-dlabel {
  font-size: 9px;
  color: var(--text-faint);
  text-align: center;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  align-self: center;
}

.stat-heat-dlabel {
  text-align: left;
  padding-right: 2px;
}

.stat-heat-cell {
  /* Fill grid cell; overall map is square via .stat-heat-frame */
  aspect-ratio: auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  border-radius: 3px;
  background: var(--bg-tertiary);
}

.stat-heat-cell.lv1 {
  background: rgba(88, 101, 242, 0.25);
}
.stat-heat-cell.lv2 {
  background: rgba(88, 101, 242, 0.45);
}
.stat-heat-cell.lv3 {
  background: rgba(88, 101, 242, 0.7);
}
.stat-heat-cell.lv4 {
  background: var(--accent);
}

.search {
  min-width: 200px;
}
