:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --panel: #ffffff;
  --panel-strong: #f8fafc;
  --ink: #18212f;
  --muted: #647184;
  --line: #d9e0e7;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --green: #15803d;
  --green-soft: #dcfce7;
  --amber: #b45309;
  --amber-soft: #ffedd5;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(34, 197, 94, 0.16), transparent 34%),
    linear-gradient(145deg, #050816 0%, #0b1120 46%, #111827 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 420px);
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.32);
  padding: 28px;
}

.login-mark {
  width: 48px;
  height: 48px;
  display: block;
  margin-bottom: 22px;
}

.login-panel h1 {
  margin: 0 0 24px;
  color: #f8fafc;
  font-size: 32px;
  line-height: 1;
}

.login-panel .eyebrow {
  color: #86efac;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.login-form,
.stack-form {
  display: grid;
  gap: 16px;
}

.form-field {
  display: grid;
  gap: 7px;
}

.form-field label {
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.login-panel .form-field label {
  color: #cbd5e1;
}

.form-field input,
.toolbar input,
.toolbar select,
.tracking-filters select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

.login-panel .form-field input {
  border-color: rgba(148, 163, 184, 0.3);
  background: rgba(2, 6, 23, 0.72);
  color: #f8fafc;
}

.form-field input:focus,
.toolbar input:focus,
.toolbar select:focus,
.tracking-filters select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(21, 128, 61, 0.12);
}

.form-error {
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: #f8fafc;
  padding: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 22px;
}

.brand img {
  width: 42px;
  height: 42px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #cbd5e1;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item,
.ghost-action,
.primary-action,
.secondary-action,
.icon-action {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  color: #cbd5e1;
  padding: 9px 10px;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--sidebar-soft);
  color: #fff;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #a7f3d0;
  font-size: 12px;
}

.logout-form {
  margin-top: auto;
}

.ghost-action {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
}

.main-panel {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
}

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

.admin-pill {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.primary-action {
  background: var(--green);
  color: #fff;
  padding: 9px 14px;
}

.secondary-action {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 8px 13px;
}

.icon-action {
  width: 36px;
  background: var(--panel-strong);
  color: var(--ink);
}

.view {
  display: none;
}

.view.is-active {
  display: grid;
  gap: 18px;
}

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

.kpi {
  min-height: 116px;
  display: grid;
  align-content: space-between;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
  padding: 16px;
}

.kpi span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi strong {
  font-size: 28px;
  line-height: 1;
}

.kpi small {
  color: var(--muted);
  font-size: 12px;
}

.kpi.green {
  background: var(--green-soft);
  border-color: #bbf7d0;
}

.kpi.amber {
  background: var(--amber-soft);
  border-color: #fed7aa;
}

.kpi.blue {
  background: var(--blue-soft);
  border-color: #bfdbfe;
}

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

.triple-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.section-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 8px 13px;
  font-weight: 800;
}

.section-tab:hover,
.section-tab.is-active {
  border-color: #bbf7d0;
  background: var(--green-soft);
  color: #166534;
}

.tracking-tab-panel {
  display: none;
}

.tracking-tab-panel.is-active {
  display: grid;
  gap: 18px;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.panel-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

.raw-table {
  width: max-content;
  min-width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding-block: 12px;
  padding-inline: 1ch;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  color: #263244;
}

.raw-table th,
.raw-table td {
  vertical-align: top;
  white-space: nowrap;
}

.raw-table td {
  max-width: 420px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.raw-table td:last-child {
  min-width: 280px;
  max-width: 560px;
}

tr:last-child td {
  border-bottom: 0;
}

.user-cell {
  display: grid;
  gap: 2px;
}

.user-cell strong {
  overflow-wrap: anywhere;
}

.user-cell span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--panel-strong);
  color: #475569;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.good {
  background: var(--green-soft);
  color: #166534;
}

.status-pill.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-pill.bad {
  background: var(--red-soft);
  color: var(--red);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px);
  gap: 12px;
}

.tracking-filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr)) auto;
  gap: 10px;
}

.tracking-kpis {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.rank-list {
  display: grid;
}

.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 12px 1ch;
}

.rank-row:last-child {
  border-bottom: 0;
}

.rank-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.rank-text strong,
.rank-text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-text span {
  color: var(--muted);
  font-size: 13px;
}

.rank-value {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.rank-meter {
  grid-column: 1 / -1;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2f7;
}

.rank-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.mini-list {
  display: grid;
}

.mini-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 12px 1ch;
}

.mini-row:last-child {
  border-bottom: 0;
}

.mini-row strong,
.mini-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-row span {
  color: var(--muted);
  font-size: 13px;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(14, minmax(22px, 1fr));
  align-items: end;
  gap: 8px;
  min-height: 220px;
  padding: 18px 16px;
}

.bar {
  display: grid;
  align-content: end;
  gap: 8px;
  min-width: 0;
}

.bar-track {
  height: 150px;
  display: flex;
  align-items: end;
  border-radius: 8px;
  background: #eef2f7;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  min-height: 4px;
  background: var(--blue);
}

.bar span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.reset-dialog {
  width: min(100%, 480px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.reset-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.reset-card {
  display: grid;
  gap: 16px;
  background: #fff;
  padding-bottom: 16px;
}

.reset-card .form-field,
.dialog-actions,
.reset-card .form-error {
  margin-inline: 16px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-weight: 800;
}

.empty {
  color: var(--muted);
  padding: 18px 1ch;
}

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

  .split-layout {
    grid-template-columns: 1fr;
  }

  .triple-layout {
    grid-template-columns: 1fr;
  }

  .tracking-filters {
    grid-template-columns: 1fr 1fr;
  }

  .tracking-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .brand {
    padding-bottom: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
    padding: 8px 6px;
  }

  .nav-item span:last-child {
    display: none;
  }

  .logout-form {
    margin-top: 12px;
  }

  .main-panel {
    padding: 18px 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .admin-pill {
    max-width: none;
    min-width: 0;
    flex: 1;
  }

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

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

  .tracking-filters {
    grid-template-columns: 1fr;
  }

  .bar-chart {
    overflow-x: auto;
  }
}

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

  .login-panel {
    padding: 22px;
  }

  .tracking-kpis {
    grid-template-columns: 1fr;
  }
}
