:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e232d;
  --surface-3: #242b36;
  --border: #313947;
  --text: #f4f7fb;
  --muted: #98a4b5;
  --accent: #2f8cff;
  --accent-2: #22c55e;
  --danger: #f87171;
  --warning: #fbbf24;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

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

button,
select {
  font: inherit;
}

.page-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.app-header,
.detail-panel,
.platform-card,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px;
}

.profile-block {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 16px;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(1.55rem, 2vw, 2.15rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.error-text {
  color: var(--danger);
}

.last-good {
  margin-top: 10px;
  font-size: 0.84rem;
}

.toolbar,
.link-row,
.platform-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toolbar {
  justify-content: flex-end;
}

.field-label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.profile-select {
  min-height: 40px;
  min-width: 180px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.profile-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 140, 255, 0.22);
}

.btn,
.mini-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
}

.btn-secondary,
.mini-link {
  background: var(--surface-2);
  color: var(--text);
}

.btn:hover,
.mini-link:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.link-row {
  margin: 14px 0 0;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 26px 0 14px;
}

.card-grid,
.metric-grid,
.chart-grid,
.insights-grid {
  display: grid;
  gap: 14px;
}

.card-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.metric-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  margin: 18px 0;
}

.chart-grid,
.insights-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.platform-card {
  display: flex;
  flex-direction: column;
  min-height: 232px;
  padding: 16px;
}

.platform-card.has-error {
  border-color: rgba(248, 113, 113, 0.5);
}

.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.source-pill {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 0.74rem;
}

.card-metrics {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.card-metric-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.card-metric-row:last-child {
  border-bottom: none;
}

.card-metric-label,
.metric-label {
  color: var(--muted);
}

.card-metric-stack {
  display: grid;
  justify-items: end;
  gap: 3px;
  text-align: right;
}

.card-metric-value {
  font-weight: 800;
  text-align: right;
}

.metric-trend {
  color: var(--muted);
  font-size: 0.76rem;
}

.trend-up {
  color: var(--accent-2);
}

.trend-down {
  color: var(--danger);
}

.trend-flat {
  color: var(--muted);
}

.platform-links {
  margin-top: auto;
  padding-top: 16px;
}

.metric {
  min-height: 96px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.metric-label {
  margin-bottom: 8px;
  font-size: 0.88rem;
}

.metric-value {
  font-size: 1.7rem;
  font-weight: 850;
}

.detail-panel {
  margin-top: 14px;
  padding: 16px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item,
.provider-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.history-item:last-child,
.provider-item:last-child {
  border-bottom: 0;
}

.provider-list {
  display: grid;
  gap: 8px;
}

.provider-item div {
  display: grid;
  gap: 3px;
}

.provider-item span {
  color: var(--muted);
  font-size: 0.86rem;
}

.provider-status {
  align-self: center;
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.provider-status.is-ready {
  color: var(--accent-2);
  border-color: rgba(34, 197, 94, 0.5);
}

.provider-status.is-fallback {
  color: var(--warning);
  border-color: rgba(251, 191, 36, 0.5);
}

.chart-card,
.insight-card,
.admin-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.chart-card-head,
.chart-card-foot,
.admin-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chart-card-head {
  min-height: 42px;
}

.chart-card-foot {
  color: var(--muted);
  font-size: 0.82rem;
}

.sparkline {
  width: 100%;
  height: 72px;
  margin: 10px 0;
  color: var(--accent);
}

.insight-card {
  display: grid;
  gap: 10px;
}

.insight-metrics {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.admin-form,
.admin-grid {
  display: grid;
  gap: 12px;
}

.admin-form {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}

.admin-list {
  display: grid;
  gap: 14px;
}

.admin-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-top: 14px;
}

.admin-form label,
.admin-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.admin-form input,
.admin-grid input {
  min-height: 38px;
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.admin-form input:focus,
.admin-grid input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 140, 255, 0.18);
}

.admin-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.raw-box {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #d9e3f5;
  font-size: 0.9rem;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 18px;
}

.skeleton span,
.skeleton strong,
.skeleton div {
  display: block;
  height: 16px;
  margin-bottom: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

.skeleton strong {
  width: 70%;
  height: 24px;
}

.skeleton div {
  width: 100%;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 20px, 1240px);
    padding-top: 10px;
  }

  .app-header,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-block {
    align-items: flex-start;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar > * {
    flex: 1 1 100%;
  }

  .profile-select {
    width: 100%;
  }
}
