/* === reset === */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
a {
  color: inherit;
  text-decoration: none;
}
button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
ul,
ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
img,
svg {
  display: block;
}
table {
  border-collapse: collapse;
  width: 100%;
}
input,
select {
  font: inherit;
  color: inherit;
}

/* === layout === */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* sidebar */
.sidebar {
  background: var(--c-sidebar-bg);
  color: var(--c-sidebar-fg);
  padding: var(--s-5) var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-3);
  color: var(--c-sidebar-fg-active);
  font-weight: var(--fw-bold);
  font-size: var(--fs-lg);
}
.sidebar__brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  background: var(--c-primary);
  display: grid;
  place-items: center;
  color: #fff;
}
.sidebar__section-label {
  padding: 0 var(--s-3);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-soft);
  margin-top: var(--s-2);
}
.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  border-radius: var(--r-md);
  color: var(--c-sidebar-fg);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.sidebar__link:hover {
  background: var(--c-sidebar-item-active);
  color: var(--c-sidebar-fg-active);
}
.sidebar__link.is-active {
  background: var(--c-sidebar-item-active);
  color: var(--c-sidebar-fg-active);
}
.sidebar__link .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.sidebar__badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.08);
  color: var(--c-sidebar-fg-active);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  padding: 2px 8px;
  border-radius: var(--r-pill);
}
.sidebar__upgrade {
  margin-top: auto;
  background: var(--c-primary);
  color: #fff;
  border-radius: var(--r-lg);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.sidebar__upgrade-title {
  font-weight: var(--fw-semibold);
}
.sidebar__upgrade-text {
  font-size: var(--fs-sm);
  opacity: 0.85;
}

/* main */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: 0 var(--s-6);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__search {
  flex: 1;
  max-width: 560px;
  position: relative;
}
.topbar__search input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 0 var(--s-4) 0 var(--s-10);
  background: var(--c-surface-2);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease);
}
.topbar__search input:focus {
  border-color: var(--c-primary);
  background: var(--c-surface);
}
.topbar__search .icon {
  position: absolute;
  left: var(--s-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-soft);
  width: 18px;
  height: 18px;
}
.topbar__search .kbd {
  position: absolute;
  right: var(--s-3);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-xs);
  color: var(--c-text-soft);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 2px 6px;
}
.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.topbar__icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  color: var(--c-text-muted);
  transition: background var(--dur-fast) var(--ease);
}
.topbar__icon-btn:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}
.topbar__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  background: linear-gradient(135deg, #fbbf24, #f97316);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-sm);
}

/* content area */
.content {
  padding: var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
}

/* page header */
.page-head {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  flex-wrap: wrap;
}
.page-head__title {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  margin: 0;
}
.page-head__subtitle {
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}
.page-head__actions {
  margin-left: auto;
  display: flex;
  gap: var(--s-3);
  align-items: center;
}

/* === components === */

/* button */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 40px;
  padding: 0 var(--s-4);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn .icon {
  width: 16px;
  height: 16px;
}
.btn--primary {
  background: var(--c-primary);
  color: #fff;
}
.btn--primary:hover {
  background: var(--c-primary-hover);
}
.btn--ghost {
  background: transparent;
  color: var(--c-text);
  border: 1px solid var(--c-border);
}
.btn--ghost:hover {
  background: var(--c-surface-2);
}
.btn--sm {
  height: 32px;
  padding: 0 var(--s-3);
  font-size: var(--fs-sm);
}

/* card */
.card {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--sh-sm);
  border: 1px solid var(--c-border-soft);
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-4);
}
.card__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--c-text);
  margin: 0;
}
.card__menu {
  color: var(--c-text-soft);
}

/* kpi */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s-4);
}
.kpi {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  border: 1px solid var(--c-border-soft);
  box-shadow: var(--sh-sm);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.kpi__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.kpi__icon {
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  color: var(--c-primary);
  background: var(--c-primary-soft);
}
.kpi__icon .icon {
  width: 16px;
  height: 16px;
}
.kpi__value {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.02em;
}
.kpi__foot {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}
.kpi__foot small {
  font-size: var(--fs-sm);
}

/* delta */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  padding: 2px 8px;
  border-radius: var(--r-pill);
}
.delta .icon {
  width: 12px;
  height: 12px;
}
.delta--up {
  color: var(--c-success);
  background: var(--c-success-soft);
}
.delta--down {
  color: var(--c-danger);
  background: var(--c-danger-soft);
}

/* badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  padding: 3px 8px;
  border-radius: var(--r-pill);
}
.badge .icon {
  width: 12px;
  height: 12px;
}
.badge--success {
  color: var(--c-success);
  background: var(--c-success-soft);
}
.badge--warning {
  color: var(--c-warning);
  background: var(--c-warning-soft);
}
.badge--danger {
  color: var(--c-danger);
  background: var(--c-danger-soft);
}
.badge--info {
  color: var(--c-info);
  background: var(--c-info-soft);
}
.badge--neutral {
  color: var(--c-text-muted);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
}

/* score letter */
.score {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
}
.score--a {
  background: var(--c-success-soft);
  color: var(--c-success);
}
.score--b {
  background: #fef3c7;
  color: #b45309;
}
.score--c {
  background: var(--c-warning-soft);
  color: var(--c-warning);
}
.score--d {
  background: var(--c-danger-soft);
  color: var(--c-danger);
}

/* progress bar */
.progress {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.progress__bar {
  flex: 1;
  height: 6px;
  background: var(--c-border-soft);
  border-radius: var(--r-pill);
  overflow: hidden;
  min-width: 60px;
}
.progress__fill {
  height: 100%;
  background: var(--c-success);
  border-radius: var(--r-pill);
}
.progress__fill--primary {
  background: var(--c-primary);
}
.progress__fill--warning {
  background: var(--c-warning);
}
.progress__value {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  min-width: 48px;
  text-align: right;
}

/* avatar */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-sm);
  flex-shrink: 0;
}
.avatar--blue {
  background: linear-gradient(135deg, #60a5fa, #2563eb);
}
.avatar--green {
  background: linear-gradient(135deg, #4ade80, #16a34a);
}
.avatar--orange {
  background: linear-gradient(135deg, #fb923c, #ea580c);
}
.avatar--purple {
  background: linear-gradient(135deg, #c084fc, #a855f7);
}
.avatar--pink {
  background: linear-gradient(135deg, #f472b6, #db2777);
}

/* table */
.table-wrap {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--c-border-soft);
  box-shadow: var(--sh-sm);
  overflow: hidden;
}
.table-toolbar {
  padding: var(--s-4) var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  border-bottom: 1px solid var(--c-border-soft);
  flex-wrap: wrap;
}
.table-toolbar__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}
.table-toolbar__count {
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
  margin-left: var(--s-1);
}
.table-toolbar__filters {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.table-toolbar__spacer {
  flex: 1;
}
.filter-chip {
  height: 32px;
  padding: 0 var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--fs-sm);
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}
.filter-chip .icon {
  width: 14px;
  height: 14px;
  color: var(--c-text-soft);
}
.filter-chip:hover {
  background: var(--c-surface-2);
}

.table {
  width: 100%;
  font-size: var(--fs-sm);
}
.table thead th {
  text-align: left;
  font-weight: var(--fw-medium);
  color: var(--c-text-muted);
  padding: var(--s-3) var(--s-5);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border-soft);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.table tbody td {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--c-border-soft);
  vertical-align: middle;
}
.table tbody tr:last-child td {
  border-bottom: none;
}
.table tbody tr {
  transition: background var(--dur-fast) var(--ease);
}
.table tbody tr:hover {
  background: var(--c-surface-2);
}
.table tbody tr.is-expanded {
  background: #fffbeb;
}
.table__cell-stack {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.table__rank {
  font-weight: var(--fw-bold);
  color: var(--c-text);
  width: 24px;
}
.table__caret {
  width: 16px;
  height: 16px;
  color: var(--c-text-soft);
  transition: transform var(--dur-fast) var(--ease);
}
.table tr.is-expanded .table__caret {
  transform: rotate(90deg);
}
.table__primary {
  font-weight: var(--fw-semibold);
  color: var(--c-text);
}
.table__sub {
  color: var(--c-text-muted);
  font-size: var(--fs-xs);
}
.table__num {
  font-variant-numeric: tabular-nums;
  font-weight: var(--fw-semibold);
}

/* expanded row content */
.expand-row td {
  padding: var(--s-5);
  background: var(--c-surface-2);
}
.expand-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-4);
}
.expand-card {
  background: var(--c-surface);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border-soft);
  padding: var(--s-4);
}
.expand-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--s-3);
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}
.expand-card__row {
  display: flex;
  justify-content: space-between;
  padding: var(--s-2) 0;
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--c-border-soft);
}
.expand-card__row:last-child {
  border-bottom: none;
}
.expand-card__row span:last-child {
  font-weight: var(--fw-semibold);
}

/* layout grid for dashboard */
.grid {
  display: grid;
  gap: var(--s-4);
}
.grid--2 {
  grid-template-columns: 2fr 1fr;
}
.grid--3 {
  grid-template-columns: repeat(3, 1fr);
}

/* chart placeholder */
.chart {
  height: 240px;
  position: relative;
}
.chart svg {
  width: 100%;
  height: 100%;
}

/* top-list */
.top-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.top-list__item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) 0;
}
.top-list__rank {
  width: 24px;
  height: 24px;
  border-radius: var(--r-pill);
  display: grid;
  place-items: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  background: var(--c-surface-2);
  color: var(--c-text-muted);
}
.top-list__rank--1 {
  background: #fef3c7;
  color: #b45309;
}
.top-list__rank--2 {
  background: #e5e7eb;
  color: #4b5563;
}
.top-list__rank--3 {
  background: #ffedd5;
  color: #c2410c;
}
.top-list__name {
  flex: 1;
  font-weight: var(--fw-medium);
}
.top-list__score {
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
}

/* gauge */
.gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
}
.gauge__value {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
}
.gauge__label {
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}

/* mobile bottom nav (hidden on desktop) */
.bottom-nav {
  display: none;
}

/* === responsive === */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .topbar {
    padding: 0 var(--s-4);
  }
  .topbar__search {
    max-width: none;
  }
  .content {
    padding: var(--s-4);
    padding-bottom: calc(var(--bottomnav-h) + var(--s-4));
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid--2,
  .grid--3 {
    grid-template-columns: 1fr;
  }
  .expand-grid {
    grid-template-columns: 1fr;
  }
  .table-wrap {
    overflow-x: auto;
  }
  .page-head__title {
    font-size: var(--fs-xl);
  }
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bottomnav-h);
    background: var(--c-surface);
    border-top: 1px solid var(--c-border);
    z-index: 20;
    padding: 0 var(--s-2);
  }
  .bottom-nav__link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--c-text-soft);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    padding: var(--s-2);
  }
  .bottom-nav__link .icon {
    width: 22px;
    height: 22px;
  }
  .bottom-nav__link.is-active {
    color: var(--c-primary);
  }
}

@media (max-width: 560px) {
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
  .kpi {
    padding: var(--s-4);
  }
  .kpi__value {
    font-size: var(--fs-xl);
  }
}

/* utilities */
.row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.row--between {
  justify-content: space-between;
}
.col {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.muted {
  color: var(--c-text-muted);
}
.spacer {
  flex: 1;
}
.hide-mobile {
  /* visible on desktop only */
}
@media (max-width: 900px) {
  .hide-mobile {
    display: none !important;
  }
}
.show-mobile {
  display: none !important;
}
@media (max-width: 900px) {
  .show-mobile {
    display: initial !important;
  }
}
