:root {
  color-scheme: dark;
  --bg: #101113;
  --panel: #1a1c20;
  --panel-2: #22252b;
  --line: #2d323a;
  --text: #ffffff;
  --muted: #aab0b8;
  --soft: #c9cdd2;
  --orange: #ff7f2a;
  --green: #3ddc97;
  --blue: #56ccf2;
  --yellow: #ffd166;
  --red: #ff6b6b;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Poppins, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.hidden {
  display: none !important;
}

.auth-card {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 380px);
  gap: 32px;
  align-items: center;
  min-height: calc(100vh - 72px);
}

.auth-brand {
  max-width: 560px;
}

.brand-logo {
  display: block;
  width: clamp(86px, 10vw, 132px);
  height: auto;
  margin: 0 0 24px;
}

.auth-card h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1.05;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--orange);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted {
  margin: 10px 0 0;
  color: var(--muted);
}

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

.login-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 600;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111316;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

input:focus {
  border-color: var(--orange);
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111316;
  color: var(--soft);
  padding: 0 30px 0 10px;
  outline: none;
}

select:focus {
  border-color: var(--orange);
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--orange);
  color: white;
  padding: 0 18px;
  font-weight: 700;
  cursor: pointer;
}

button.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--soft);
}

button.text-button {
  min-height: 30px;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 13px;
  font-weight: 700;
}

button.text-button:hover {
  color: white;
}

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

.info {
  margin: 0;
  color: var(--green);
  font-size: 13px;
}

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

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

.range-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.range-switch button {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--soft);
  padding: 0 12px;
}

.range-switch button.active {
  background: var(--orange);
  color: white;
}

.metrics-grid,
.charts-grid,
.bottom-grid {
  display: grid;
  gap: 16px;
}

.metrics-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 16px;
}

.charts-grid,
.bottom-grid,
.insights-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bottom-grid {
  margin-top: 16px;
}

.insights-grid {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.metric {
  padding: 18px;
}

.metric span,
.panel-title span {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--soft);
}

.panel {
  min-height: 350px;
  padding: 18px;
  min-width: 0;
}

.panel.compact {
  min-height: 280px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.panel-title h2 {
  margin: 0 0 4px;
  font-size: 17px;
}

.plan-filter {
  display: inline-flex;
  flex-shrink: 0;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111316;
}

.user-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.user-filters select {
  max-width: 160px;
}

.plan-filter-button {
  min-height: 30px;
  border-radius: 6px;
  background: transparent;
  color: var(--soft);
  padding: 0 10px;
  font-size: 12px;
}

.plan-filter-button.active {
  background: var(--orange);
  color: white;
}

canvas {
  width: 100% !important;
  height: 260px !important;
  max-height: 260px;
}

.health-list,
.activity-list,
.role-breakdown,
.insight-list {
  display: grid;
  gap: 12px;
}

.health-row,
.activity-row,
.role-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--soft);
}

.health-row strong,
.activity-row time,
.role-row strong {
  color: white;
  font-weight: 700;
}

.health-row strong {
  min-width: 0;
  max-width: 58%;
  overflow-wrap: anywhere;
  text-align: right;
  white-space: normal;
}

.health-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.activity-row time,
.role-row strong {
  white-space: nowrap;
}

.role-row div {
  display: grid;
  gap: 2px;
}

.role-row small {
  color: var(--muted);
}

.insight-row {
  display: grid;
  gap: 4px;
  min-height: 0;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--soft);
  padding: 0 0 12px;
  text-align: left;
  cursor: pointer;
}

.insight-row:hover {
  color: white;
}

.insight-row span {
  min-width: 0;
  color: white;
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.insight-row small {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.users-panel {
  min-height: 0;
  margin-top: 16px;
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

td {
  color: var(--soft);
  font-size: 13px;
}

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

.user-cell strong {
  color: white;
  font-size: 13px;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: rgba(255, 127, 42, 0.08);
}

.badge {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--panel-2);
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
}

.badge.good {
  background: rgba(61, 220, 151, 0.16);
  color: var(--green);
}

.badge.warn {
  background: rgba(255, 209, 102, 0.14);
  color: var(--yellow);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(520px, 920px);
}

.drawer-backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.drawer-panel {
  height: 100vh;
  min-width: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--bg);
  padding: 24px;
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.34);
}

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

.drawer-user-heading {
  display: flex;
  min-width: 0;
  gap: 16px;
  align-items: center;
}

.drawer-user-heading > div:last-child {
  min-width: 0;
}

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

.drawer-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.user-avatar {
  display: grid;
  flex: 0 0 72px;
  width: 72px;
  height: 72px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(255, 127, 42, 0.28), rgba(86, 204, 242, 0.16));
  color: white;
  font-size: 24px;
  font-weight: 800;
}

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

.drawer-header h2 {
  margin: 0;
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.08;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
}

.drawer-loading {
  display: grid;
  min-height: 260px;
  place-items: center;
  color: var(--muted);
}

.user-detail {
  display: grid;
  gap: 16px;
}

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

.detail-summary > div,
.mini-metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.detail-summary strong {
  display: block;
  min-width: 0;
  color: white;
  font-size: 14px;
  overflow-wrap: anywhere;
}

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

.mini-metric {
  min-height: 92px;
}

.mini-metric strong {
  font-size: 24px;
}

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

.detail-panel {
  min-height: 330px;
}

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

@media (max-width: 980px) {
  .charts-grid,
  .bottom-grid,
  .insights-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .panel.compact {
    min-height: 300px;
  }

  .drawer {
    grid-template-columns: minmax(0, 1fr) minmax(480px, 82vw);
  }
}

@media (max-width: 840px) {
  .auth-card,
  .topbar,
  .metrics-grid,
  .detail-summary,
  .detail-metrics,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

  .drawer-backdrop {
    display: none;
  }

  .drawer-panel {
    border-left: 0;
    padding: 20px;
  }

  .topbar {
    display: grid;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1;
  }

  .panel-title {
    display: grid;
  }

  .panel-title span {
    max-width: 100%;
  }

  .plan-filter {
    width: fit-content;
  }

  .user-filters {
    justify-content: flex-start;
  }

  .user-filters select {
    max-width: none;
    flex: 1 1 160px;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding: 18px 0 32px;
  }

  .auth-card {
    min-height: calc(100vh - 36px);
    gap: 22px;
  }

  .auth-card h1,
  .topbar h1 {
    font-size: 34px;
  }

  .actions,
  .range-switch,
  .user-filters {
    width: 100%;
  }

  .range-switch {
    justify-content: space-between;
  }

  .range-switch button {
    flex: 1;
    padding: 0 8px;
  }

  .actions > button {
    min-width: calc(50% - 5px);
  }

  .metric {
    padding: 16px;
  }

  .metric strong {
    font-size: 30px;
  }

  .panel,
  .panel.compact {
    min-height: 260px;
    padding: 14px;
  }

  .panel-title {
    gap: 4px;
    margin-bottom: 12px;
  }

  .panel-title h2 {
    font-size: 16px;
  }

  canvas {
    height: 220px !important;
    max-height: 220px;
  }

  .health-row,
  .activity-row,
  .role-row {
    align-items: flex-start;
  }

  .activity-row {
    display: grid;
  }

  .activity-row time,
  .role-row strong {
    white-space: normal;
  }

  .health-row strong {
    max-width: 52%;
  }

  .users-panel {
    padding-left: 0;
    padding-right: 0;
  }

  .users-panel > .panel-title {
    padding: 0 14px;
  }

  .table-wrap {
    padding: 0 0 4px 14px;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 11px 8px;
  }

  .drawer-panel {
    padding: 16px 10px 28px;
  }

  .drawer-header {
    display: grid;
    gap: 12px;
  }

  .drawer-user-heading {
    align-items: flex-start;
    gap: 12px;
  }

  .user-avatar {
    flex-basis: 56px;
    width: 56px;
    height: 56px;
    font-size: 20px;
  }

  .drawer-header h2 {
    font-size: 28px;
  }

  .icon-button {
    position: absolute;
    top: 12px;
    right: 10px;
  }

  .drawer-actions {
    gap: 6px;
  }

  .detail-summary,
  .detail-metrics,
  .detail-grid {
    gap: 10px;
  }

  .detail-summary > div,
  .mini-metric {
    padding: 12px;
  }

  .mini-metric {
    min-height: 82px;
  }

  .mini-metric strong {
    font-size: 22px;
  }
}

@media (max-width: 420px) {
  .auth-card h1,
  .topbar h1 {
    font-size: 30px;
  }

  .actions > button {
    min-width: 100%;
  }

  .user-filters select,
  .plan-filter {
    width: 100%;
  }

  .plan-filter {
    justify-content: space-between;
  }

  .plan-filter-button {
    flex: 1;
  }

  .drawer-user-heading {
    padding-right: 48px;
  }

  .drawer-actions button {
    flex: 1 1 auto;
  }
}
