:root {
  --bg: #0b0d12;
  --bg-grad-a: #10131b;
  --bg-grad-b: #0b0d12;
  --surface: #151922;
  --surface-2: #1b2029;
  --surface-3: #222834;
  --border: #262d3a;
  --border-strong: #333c4d;
  --text: #e7eaf0;
  --muted: #9aa4b5;
  --muted-2: #6b7688;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.14);
  --slate: #94a3b8;
  --slate-soft: rgba(148, 163, 184, 0.14);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --sidebar-w: 248px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}

/* Layout shell */

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

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 16px;
  background: linear-gradient(180deg, rgba(21, 25, 34, 0.9), rgba(13, 16, 22, 0.9));
  border-right: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45);
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.2px;
}

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

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.nav-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 10px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  opacity: 0.85;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: #c7c9ff;
}

.nav-item.active svg {
  opacity: 1;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--accent-2);
  font-weight: 700;
  font-size: 13px;
}

.user-email {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}

.cache-note {
  font-size: 11px;
  color: var(--muted-2);
  text-align: center;
}

[data-reload].is-loading svg {
  animation: spin 0.8s linear infinite;
}

/* Main content */

.main {
  min-width: 0;
  padding: 26px 30px 60px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 24px;
  letter-spacing: -0.2px;
}

.page-sub {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.crumbs a:hover {
  color: var(--text);
}

.crumbs .sep {
  color: var(--muted-2);
}

/* Inputs */

.search {
  position: relative;
}

.search input,
.field input,
select.input,
input.input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  outline: none;
  transition: border 0.15s, box-shadow 0.15s;
}

.search input {
  min-width: 230px;
  padding-left: 34px;
}

.search svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted-2);
}

.field input:focus,
select.input:focus,
input.input:focus,
.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select.input {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa4b5' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, border 0.15s, transform 0.05s;
}

.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

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

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c74f6);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #6b6ef4, #8a82f8);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 7px 11px;
  font-size: 12.5px;
}

/* Segmented control */

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.segmented button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.segmented button:hover {
  color: var(--text);
}

.segmented button.active {
  background: var(--accent-soft);
  color: #c7c9ff;
}

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-pad {
  padding: 18px 20px;
}

.section {
  margin-top: 22px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 16px;
}

.section-title .muted {
  color: var(--muted);
  font-weight: 400;
  font-size: 13px;
  margin-left: 8px;
}

/* KPI grid */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.kpi {
  position: relative;
  overflow: hidden;
  padding: 16px 18px;
}

.kpi-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.kpi-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.kpi-dot.green { background: var(--green); }
.kpi-dot.amber { background: var(--amber); }
.kpi-dot.slate { background: var(--slate); }
.kpi-dot.red { background: var(--red); }
.kpi-dot.cyan { background: var(--accent-2); }

.kpi-value {
  margin-top: 10px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.kpi-value.pending {
  color: var(--muted-2);
  font-size: 22px;
}

.kpi-foot {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted-2);
}

/* Stat cards (home detail) */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.stat {
  padding: 16px 18px;
}

.stat-label {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.stat-value {
  margin-top: 8px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.stat-sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted-2);
}

.stat-wide {
  grid-column: span 2;
}

.donut-layout {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.donut-wrap {
  position: relative;
  width: 132px;
  height: 132px;
  flex: 0 0 auto;
}

.donut {
  width: 132px;
  height: 132px;
  display: block;
}

.donut circle {
  transition: stroke-dasharray 0.4s ease, stroke-dashoffset 0.4s ease;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.donut-total {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.4px;
  line-height: 1;
}

.donut-sub {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted-2);
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex: 1;
  min-width: 130px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.legend-name {
  color: var(--text);
}

.legend-val {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
  .stat-wide {
    grid-column: auto;
  }
}

/* Tables */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.data thead th {
  position: sticky;
  top: 0;
  text-align: left;
  padding: 12px 16px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data thead th.sortable {
  cursor: pointer;
  user-select: none;
}

table.data thead th.sortable:hover {
  color: var(--text);
}

table.data thead th .arrow {
  margin-left: 5px;
  opacity: 0.6;
  font-size: 10px;
}

table.data tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data tbody tr:last-child td {
  border-bottom: none;
}

table.data tbody tr {
  transition: background 0.12s;
}

table.data tbody tr.clickable {
  cursor: pointer;
}

table.data tbody tr.clickable:hover {
  background: var(--surface-2);
}

.cell-strong {
  font-weight: 600;
}

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

.cell-mono {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
  font-size: 12.5px;
  color: var(--muted);
}

.cell-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

th.cell-num {
  text-align: right;
}

/* Badges & chips */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.active {
  color: var(--green);
  background: var(--green-soft);
  border-color: rgba(52, 211, 153, 0.25);
}

.badge.trial {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: rgba(251, 191, 36, 0.25);
}

.badge.inactive {
  color: var(--slate);
  background: var(--slate-soft);
  border-color: rgba(148, 163, 184, 0.22);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.tag.warn {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: rgba(251, 191, 36, 0.25);
}

.tag.danger {
  color: var(--red);
  background: var(--red-soft);
  border-color: rgba(248, 113, 113, 0.25);
}

.device-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 7px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.chip b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.chip .chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
}

/* Filter bar */

.filters {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-field .field-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.filter-field input,
.filter-field select {
  min-width: 150px;
}

.filters .spacer {
  flex: 1;
}

/* Pagination */

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

.pagination .range {
  color: var(--muted);
  font-size: 13px;
}

.pagination .pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination .page-now {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
  min-width: 74px;
  text-align: center;
}

/* Meta list (home header) */

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px 24px;
  margin-top: 16px;
}

.meta-item .meta-key {
  font-size: 11.5px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.meta-item .meta-val {
  margin-top: 3px;
  font-weight: 500;
}

.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.home-title {
  font-size: 22px;
  letter-spacing: -0.3px;
}

.home-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.home-org {
  color: var(--muted);
  margin-top: 4px;
}

.notes {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
}

/* States */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 56px 20px;
  color: var(--muted);
}

.state .state-icon {
  width: 40px;
  height: 40px;
  opacity: 0.5;
}

.state-title {
  font-weight: 600;
  color: var(--text);
}

.state.error {
  color: var(--red);
}

.state.error .state-title {
  color: var(--red);
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton-row {
  height: 46px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* Rank badge */

.rank {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--muted);
}

.rank.top {
  background: var(--accent-soft);
  color: #c7c9ff;
}

/* Bar meter */

.meter {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 6px;
}

.meter > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* Auth page */

.auth-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 30px 34px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.auth-title {
  font-size: 22px;
}

.auth-desc {
  margin: 6px 0 22px;
  color: var(--muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--red-soft);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: var(--red);
  font-size: 13px;
}

.link-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.link-back:hover {
  color: var(--text);
}

/* Responsive */

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

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 14px;
  }

  .brand {
    padding: 0;
  }

  .nav {
    flex-direction: row;
    margin: 0;
  }

  .nav-label {
    display: none;
  }

  .sidebar-footer {
    margin: 0 0 0 auto;
    padding: 0;
    border: none;
    flex-direction: row;
    align-items: center;
  }

  .user-chip {
    display: none;
  }

  .main {
    padding: 20px 16px 48px;
  }
}
