:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --card: rgba(255, 255, 255, 0.10);
  --card-border: rgba(255, 255, 255, 0.18);
  --text: #f8fafc;
  --muted: #cbd5e1;
  --accent: #2465f3;
  --accent-2: #053eb9;
  --shadow: rgba(2, 6, 23, 0.32);
}

* {
  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;
  background:
    radial-gradient(circle at 20% 10%, rgba(56, 189, 248, 0.24), transparent 32%),
    radial-gradient(circle at 80% 20%, rgba(37, 99, 235, 0.28), transparent 34%),
    linear-gradient(135deg, #020617, var(--bg));
  color: var(--text);
}

.page {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 64px 0;
}

.card {
  width: min(640px, 100%);
  margin: 0 auto;
  padding: 40px;
  border: 1px solid var(--card-border);
  border-radius: 32px;
  background: var(--card);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px var(--shadow);
  text-align: center;
}

.app-icon-wrapper {
  margin: 0 auto 24px;
  display: grid;
  place-items: center;
}

.app-icon {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 16px 36px rgba(37, 99, 235, 0.35);
}

.app-icon img {
  border-radius: 24px;
  width: 96px;
  height: 96px;
}

span[hidden] {
  display: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 4.25rem);
  line-height: 1;
  letter-spacing: -0.06em;
}

.subtitle {
  max-width: 520px;
  margin: 20px auto 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.7;
}

.meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 32px 0;
}

.meta div {
  padding: 16px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.07);
}

.meta span,
.hint {
  color: var(--muted);
}

.meta span {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
}

.meta strong {
  font-size: 1rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 0 28px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 18px 40px rgba(37, 99, 235, 0.35);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 48px rgba(37, 99, 235, 0.44);
}

.button-disabled,
.button-disabled:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.hint {
  margin: 20px auto 0;
  max-width: 520px;
  font-size: 0.92rem;
  line-height: 1.6;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 24px;
}

.info-grid article {
  padding: 24px;
  border: 1px solid var(--card-border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.08);
}

.info-grid h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.info-grid p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.95rem;
}

.list-header {
  text-align: center;
  margin-bottom: 32px;
}

.brand-logo {
  display: block;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 12px 32px rgba(37, 99, 235, 0.3);
}

.access-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 6px 14px;
  border: 1px solid rgba(37, 99, 235, 0.35);
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.15);
  color: #93c5fd;
  font-size: 0.85rem;
  font-weight: 600;
}

.access-chip-master {
  border-color: rgba(250, 204, 21, 0.45);
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.14), rgba(120, 53, 15, 0.2));
  box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.12) inset;
}

.chip-shimmer-text {
  background-image: linear-gradient(100deg, #b45309 20%, #fde68a 40%, #fffbea 50%, #fde68a 60%, #b45309 80%);
  background-size: 220% 100%;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  font-weight: 800;
  animation: chip-shimmer 3s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .chip-shimmer-text {
    animation: none;
  }
}

.forbidden-card {
  width: min(560px, 100%);
}

.forbidden-card h2 {
  margin: 4px 0 0;
  font-size: 1.8rem;
}

.back-nav {
  margin-bottom: 20px;
}

.back-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

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

.app-list,
.admin-list #appList {
  display: grid;
  gap: 14px;
}

.app-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: var(--card);
  backdrop-filter: blur(18px);
  color: var(--text);
  text-decoration: none;
  transition: transform 180ms ease, background 180ms ease;
}

a.app-item:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.16);
}

.app-item img {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  flex-shrink: 0;
}

.app-item-info {
  flex: 1;
  min-width: 0;
}

.app-item-info strong {
  display: block;
  font-size: 1.05rem;
}

.app-item-info span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-item-info p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.app-item-meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  opacity: 0.85;
}

.app-item-chart {
  flex-shrink: 0;
  display: none;
  width: 220px;
}

.app-item-chart .sparkline {
  display: block;
  width: 100%;
  height: 40px;
  opacity: 0.9;
}

.download-chart-card {
  margin-top: 24px;
  padding: 20px;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  text-align: left;
}

.download-chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.download-chart-head span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.download-chart-head strong {
  font-size: 1.3rem;
}

.chart-wrap {
  position: relative;
}

#downloadChart {
  display: block;
  width: 100%;
}

.chart-tip {
  position: absolute;
  transform: translateX(-50%);
  padding: 5px 9px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: #0f172a;
  color: var(--text);
  font-size: 0.72rem;
  white-space: nowrap;
  pointer-events: none;
}

.admin-card {
  width: min(640px, 100%);
  text-align: left;
  margin-bottom: 40px;
}

.admin-card h2,
.admin-list h2 {
  margin: 0 0 12px;
}

.admin-card form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.admin-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.admin-card input,
.admin-card textarea {
  padding: 12px 14px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font: inherit;
}

.admin-card input:focus,
.admin-card textarea:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.admin-card .req {
  color: #f87171;
}

.admin-card .button {
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.admin-card .button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.admin-list {
  width: min(640px, 100%);
  margin: 0 auto;
}

.button-danger {
  min-height: 40px;
  padding: 0 18px;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  box-shadow: 0 12px 28px rgba(239, 68, 68, 0.3);
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
}

.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.button-ghost {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
  border: 1px solid var(--card-border);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.group-fieldset {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 14px;
}

.group-fieldset legend {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0 6px;
}

.group-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.group-checks .check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 0.92rem;
}

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.inline-form input,
.inline-form select {
  flex: 1;
  min-width: 160px;
  padding: 12px 14px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font: inherit;
}

.inline-form select option {
  color: #0f172a;
}

.inline-form .button {
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 46px;
}

.item-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.admin-item.slim {
  padding: 12px 16px;
}

.admin-list {
  margin-bottom: 40px;
}

.admin-list h2 {
  margin: 0 0 12px;
}

code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.85em;
}

/* ---------- Admin layout with side menu ---------- */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  border-right: 1px solid var(--card-border);
  background: rgba(2, 6, 23, 0.5);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px 20px;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 16px;
}

.sidebar-brand img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.sidebar-brand strong {
  display: block;
  font-size: 0.95rem;
  line-height: 1.2;
}

.sidebar-brand span {
  color: var(--muted);
  font-size: 0.75rem;
}

.sidebar-nav {
  display: grid;
  gap: 4px;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 150ms ease, color 150ms ease;
}

.sidebar-nav a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-nav a.active {
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.3);
}

.nav-icon {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--card-border);
}

.sidebar-footer .button {
  width: 100%;
  min-height: 44px;
}

.admin-content {
  flex: 1;
  min-width: 0;
  padding: 40px clamp(20px, 4vw, 48px);
  max-width: 960px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.admin-header h1 {
  font-size: clamp(1.8rem, 3vw, 2.4rem);
}

.admin-header .button {
  min-height: 46px;
}

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

.section-head h2 {
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 36px;
}

.stat-card {
  padding: 22px;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: var(--card);
  backdrop-filter: blur(18px);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.stat-card strong {
  font-size: 2rem;
  letter-spacing: -0.03em;
}

.group-card {
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: var(--card);
  backdrop-filter: blur(18px);
  padding: 20px;
  margin-bottom: 18px;
  display: grid;
  gap: 12px;
}

.group-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.group-card-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  word-break: break-all;
  white-space: normal !important;
}

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 56px 24px;
  border: 1px dashed var(--card-border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.04);
  text-align: center;
}

.empty-state svg {
  width: 176px;
  height: auto;
  margin-bottom: 20px;
}

.empty-state h2 {
  margin: 0;
  font-size: 1.1rem;
}

.empty-state p {
  margin: 8px 0 0;
  max-width: 380px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

@media (max-width: 860px) {
  .admin-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--card-border);
  }

  .sidebar-brand {
    border: none;
    padding: 0;
    margin: 0;
  }

  .sidebar-brand div {
    display: none;
  }

  .sidebar-nav {
    display: flex;
    flex: 1;
    gap: 4px;
    overflow-x: auto;
  }

  .sidebar-nav a {
    padding: 9px 12px;
    white-space: nowrap;
  }

  .sidebar-footer {
    border: none;
    padding: 0;
  }

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

@media (max-width: 720px) {
  .page {
    padding: 32px 0;
  }

  .card {
    padding: 28px 20px;
    border-radius: 24px;
  }

  .meta,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }
}

@media (min-width: 560px) {
  .app-item-chart {
    display: block;
  }
}
