:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --text: #1f2340;
  --muted: #7a7f9b;
  --accent: #7b43ff;
  --accent-2: #4bb6ff;
  --accent-3: #35d07f;
  --accent-4: #9e84ff;
  --border: rgba(34, 42, 89, 0.08);
  --shadow: 0 18px 50px rgba(31, 35, 64, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(123, 67, 255, 0.12), transparent 30%),
    radial-gradient(circle at top right, rgba(75, 182, 255, 0.12), transparent 25%),
    linear-gradient(180deg, #f7f9fd 0%, var(--bg) 100%);
}

a { color: inherit; }

.dashboard-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 100vh;
  padding: 22px 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f9ff 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-brand,
.sidebar-foot {
  padding: 18px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 74px;
  height: auto;
  display: block;
}

.sidebar-brand strong,
.sidebar-foot strong {
  display: block;
  font-size: 16px;
  font-weight: 800;
}

.sidebar-brand span,
.sidebar-foot p,
.lede,
.eyebrow,
.panel-subtle,
.filter-summary,
.chart-legend,
.activity-copy span,
.table-panel td span,
.data-table th {
  color: var(--muted);
}

.sidebar-nav {
  display: grid;
  gap: 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  text-decoration: none;
  font-weight: 700;
  border: 1px solid transparent;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(123, 67, 255, 0.09);
  border-color: rgba(123, 67, 255, 0.12);
  color: var(--accent);
}

.sidebar-foot {
  margin-top: auto;
}

.sidebar-foot p {
  margin: 0 0 6px;
}

.content {
  padding: 24px;
  display: grid;
  gap: 18px;
}

.appbar,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.appbar {
  padding: 22px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12px;
  font-weight: 800;
}

h1, h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

h1 { font-size: clamp(26px, 4vw, 42px); }
h2 { font-size: 20px; }

.lede {
  margin: 8px 0 0;
  max-width: 72ch;
  line-height: 1.5;
}

.appbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(123, 67, 255, 0.08);
  border: 1px solid rgba(123, 67, 255, 0.12);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent-3);
  box-shadow: 0 0 0 4px rgba(53, 208, 127, 0.12);
}

.refresh-btn,
.filter-chip,
.filter-reset,
.carousel-btn,
.delete-btn {
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
}

.refresh-btn {
  padding: 13px 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #5f2cff);
  box-shadow: 0 14px 24px rgba(123, 67, 255, 0.2);
}

.logout-form {
  margin: 0;
}

.logout-btn {
  padding: 13px 16px;
  border: 1px solid rgba(140, 41, 82, 0.16);
  border-radius: 14px;
  background: rgba(255, 240, 245, 0.9);
  color: #8c2952;
  font-weight: 800;
  cursor: pointer;
}

.filter-panel {
  padding: 18px 22px;
  position: relative;
  z-index: 2;
}

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

.filter-summary {
  margin: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(123, 67, 255, 0.08);
  border: 1px solid rgba(123, 67, 255, 0.12);
  line-height: 1.3;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.8fr auto auto;
  gap: 12px;
  align-items: end;
  position: relative;
  z-index: 3;
}

.range-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-chip,
.filter-reset,
.carousel-btn,
.delete-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  pointer-events: auto;
}

.filter-chip {
  padding: 12px 14px;
  position: relative;
  z-index: 4;
}

.filter-chip.is-active {
  background: linear-gradient(135deg, var(--accent), #5f2cff);
  color: #fff;
  border-color: transparent;
}

.filter-field {
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.filter-field input,
.filter-field select {
  min-width: 0;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 13px 14px;
  border-radius: 14px;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 700;
}

.filter-reset {
  padding: 13px 16px;
}

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

.kpi-card {
  padding: 18px;
  display: grid;
  gap: 6px;
}

.kpi-card span {
  font-size: 13px;
  color: #fff;
  opacity: 0.88;
}

.kpi-card strong {
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1;
  color: #fff;
}

.kpi-card small {
  color: rgba(255, 255, 255, 0.78);
}

.kpi-purple { background: linear-gradient(180deg, #7b43ff 0%, #5e2cff 100%); }
.kpi-blue { background: linear-gradient(180deg, #4bb6ff 0%, #2d7dff 100%); }
.kpi-green { background: linear-gradient(180deg, #35d07f 0%, #1aa65d 100%); }
.kpi-ghost { background: linear-gradient(180deg, #ffffff 0%, #f1f4fb 100%); }
.kpi-ghost span,
.kpi-ghost small,
.kpi-ghost strong { color: var(--text); }

.main-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
}

.panel {
  padding: 22px;
}

body.is-loading .panel {
  opacity: 0.94;
  transition: opacity 180ms ease;
}

body.is-loading .filter-panel::after {
  content: '';
  position: absolute;
  left: 18px;
  right: 18px;
  top: 10px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(123, 67, 255, 0.7), transparent);
  animation: loading-scan 1s ease-in-out infinite;
  pointer-events: none;
}

@keyframes loading-scan {
  0% { transform: translateX(-18px); opacity: 0.25; }
  50% { opacity: 1; }
  100% { transform: translateX(18px); opacity: 0.25; }
}

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

.panel-subtle {
  font-size: 13px;
  font-weight: 700;
}

.chart-wrap {
  height: 320px;
}

.chart-svg {
  width: 100%;
  height: 100%;
}

.chart-grid {
  stroke: rgba(34, 42, 89, 0.08);
  stroke-width: 1;
}

.chart-label,
.chart-tick {
  fill: var(--muted);
  font-size: 12px;
}

.chart-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line-primary { stroke: var(--accent); }
.chart-line-secondary { stroke: var(--accent-2); }
.chart-line-tertiary { stroke: var(--accent-3); }

.chart-bar {
  fill: rgba(123, 67, 255, 0.15);
}

.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 13px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.chart-legend span:nth-child(1) i { background: var(--accent); }
.chart-legend span:nth-child(2) i { background: var(--accent-2); }
.chart-legend span:nth-child(3) i { background: var(--accent-3); }

.stack {
  display: grid;
  gap: 12px;
}

.activity-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: 16px;
  background: rgba(123, 67, 255, 0.05);
  border: 1px solid rgba(123, 67, 255, 0.08);
}

.activity-badge {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #5f2cff);
  color: #fff;
  font-weight: 800;
}

.activity-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.activity-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-row time {
  font-size: 12px;
  color: var(--muted);
}

.table-panel {
  overflow: hidden;
}

.code-panel {
  display: grid;
  gap: 14px;
}

.code-help {
  margin: 0;
  color: var(--muted);
}

.code-box {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  color: var(--text);
  padding: 18px;
  font: 600 15px/1.6 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.table-scroll {
  overflow-x: auto;
}

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

.data-table th,
.data-table td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid rgba(34, 42, 89, 0.08);
}

.data-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.data-table td strong {
  display: block;
  margin-bottom: 4px;
}

.data-table td span {
  display: block;
  font-size: 12px;
}

.empty-state,
.empty-cell {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.users-grid {
  grid-template-columns: 1fr 1.2fr;
}

.user-form {
  display: grid;
  gap: 14px;
}

.user-form label {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.user-form input {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 14px 16px;
  border-radius: 14px;
}

.form-message {
  margin-top: 14px;
  min-height: 24px;
  font-size: 14px;
}

.form-message[data-kind="success"] { color: #1f8a59; }
.form-message[data-kind="error"] { color: #b33b58; }

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
  border-radius: 16px;
  background: rgba(123, 67, 255, 0.05);
  border: 1px solid rgba(123, 67, 255, 0.08);
}

.delete-btn {
  padding: 11px 16px;
  background: #fff0f5;
  color: #8c2952;
}

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

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

.login-card {
  width: min(460px, 100%);
  padding: 28px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.login-logo {
  display: block;
  width: min(100%, 320px);
  height: auto;
  margin-bottom: 14px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.login-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.login-form input {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.login-form button {
  margin-top: 8px;
  padding: 14px 16px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #5f2cff);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.error {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 127, 159, 0.14);
  border: 1px solid rgba(255, 127, 159, 0.25);
  color: #8f2042;
}

@media (max-width: 1180px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: relative;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .kpi-grid,
  .main-grid,
  .users-grid,
  .filter-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .content {
    padding: 16px;
  }

  .appbar,
  .filter-top,
  .activity-row,
  .user-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .appbar-actions {
    justify-content: flex-start;
  }

  .kpi-grid,
  .main-grid,
  .users-grid,
  .filter-grid {
    grid-template-columns: 1fr;
  }

  .range-group {
    flex-direction: column;
  }
}
