:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-card: #1c2029;
  --bg-card-hover: #222733;
  --border: #2a2f3a;
  --text: #e7eaf0;
  --text-muted: #9aa3b2;
  --text-dim: #6b7484;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.15);
  --green: #3ecf8e;
  --green-soft: rgba(62, 207, 142, 0.15);
  --red: #ff5d6c;
  --amber: #ffb454;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.client-picker {
  display: flex;
  align-items: center;
  gap: 10px;
}

.client-select {
  flex: 1;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 40px 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  transition: border-color 0.15s, background 0.15s;
}

.client-select:hover:not(:disabled) {
  border-color: var(--accent);
}

.client-select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

/* Stream status */
.stream-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.stream-status.live .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
  animation: pulse 2s infinite;
}

.stream-status.error .status-dot {
  background: var(--red);
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--green-soft); }
  70% { box-shadow: 0 0 0 6px rgba(62, 207, 142, 0); }
  100% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0); }
}

/* Main */
.app-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}

.empty-illustration {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty-state h2 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 1.15rem;
}

.empty-state p {
  margin: 0;
  font-size: 0.95rem;
  max-width: 320px;
  margin-inline: auto;
}

/* Reports */
.reports-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.refresh-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.refresh-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.refresh-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.refresh-icon {
  width: 14px;
  height: 14px;
  background: no-repeat center / contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23e7eaf0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='23 4 23 10 17 10'%3E%3C/polyline%3E%3Cpolyline points='1 20 1 14 7 14'%3E%3C/polyline%3E%3Cpath d='M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15'%3E%3C/path%3E%3C/svg%3E");
}

.refresh-btn.is-refreshing .refresh-icon {
  animation: spin 0.7s linear infinite;
}

@media (max-width: 380px) {
  .refresh-label {
    display: none;
  }
}

.reports-heading {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.reports-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}

.reports-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Report card */
.report-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  animation: slide-in 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.report-card.is-new {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft), var(--shadow);
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.report-times {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.report-time-main {
  font-weight: 600;
  font-size: 0.95rem;
}

.report-time-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.report-signal {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.signal-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  min-width: 56px;
}

.signal-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.signal-value {
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Measurements */
.measurements {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.measurement {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.measurement-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.metric-icon {
  font-size: 1.1rem;
}

.metric-value {
  font-weight: 700;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.metric-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.measurement-time {
  display: block;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-muted);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Error */
.error-banner {
  margin-top: 16px;
  padding: 12px 14px;
  background: rgba(255, 93, 108, 0.12);
  border: 1px solid rgba(255, 93, 108, 0.35);
  color: #ffb3ba;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

/* Desktop tweaks */
@media (min-width: 600px) {
  .header-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .app-title {
    flex-shrink: 0;
  }
  .client-picker {
    flex: 1;
    max-width: 420px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .report-card,
  .stream-status.live .status-dot,
  .spinner {
    animation: none !important;
  }
}