:root {
  color-scheme: dark;
  --bg: #070a0e;
  --surface: #0d1218;
  --surface-raised: #111923;
  --line: #202a35;
  --line-strong: #2c3947;
  --text: #f2f6f9;
  --muted: #8d9aa7;
  --accent: #42f5b0;
  --accent-soft: rgba(66, 245, 176, 0.12);
  --blue: #55a9ff;
  --danger: #ff6b78;
  --radius: 14px;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.3);
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% -20%, rgba(85, 169, 255, 0.13), transparent 34rem),
    radial-gradient(circle at 88% 0%, rgba(66, 245, 176, 0.08), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-size: 16px;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar,
.toolbar,
.panel-heading,
.status-cluster,
.toolbar-actions,
.brand-block {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.brand-block { gap: 14px; }
.brand-mark {
  width: 11px;
  height: 42px;
  border-radius: 99px;
  background: linear-gradient(180deg, var(--accent), var(--blue));
  box-shadow: 0 0 24px rgba(66, 245, 176, 0.35);
}

.eyebrow,
.panel-kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 2vw, 1.8rem); letter-spacing: -0.03em; }
h2 { margin-bottom: 0; font-size: 1.08rem; }

.status-cluster { gap: 12px; }
.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.875rem;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(141, 154, 167, 0.1);
}
.connection-status.online { color: var(--accent); }
.connection-status.online .status-dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.connection-status.error { color: var(--danger); }
.connection-status.error .status-dot { background: var(--danger); }

.toolbar {
  justify-content: space-between;
  gap: 20px;
  margin: 24px 0 18px;
}

.period-switch {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(13, 18, 24, 0.82);
}
.period-switch button {
  min-height: 36px;
  padding: 0 15px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
}
.period-switch button:hover { color: var(--text); }
.period-switch button.active { background: var(--surface-raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }

.toolbar-actions { gap: 10px; }
.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.875rem;
}
.search-field span { white-space: nowrap; }
.search-field input {
  width: 180px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.search-field:focus-within { border-color: var(--blue); }

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 9px;
  font-weight: 650;
  font-size: 0.875rem;
}
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #04120d; }
.primary-button:hover { background: #70fac4; }
.primary-button:disabled { cursor: wait; opacity: 0.6; }
.secondary-button { border: 1px solid var(--line); background: transparent; color: var(--muted); }
.secondary-button:hover { border-color: var(--line-strong); color: var(--text); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}
.insight-panel {
  display: grid;
  grid-template-columns: minmax(210px, 0.42fr) minmax(320px, 1fr);
  gap: 14px 28px;
  align-items: center;
  margin-bottom: 14px;
  padding: 20px;
  border: 1px solid rgba(85, 169, 255, 0.3);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(17, 25, 35, 0.96), rgba(11, 22, 27, 0.9));
  box-shadow: var(--shadow);
}
.insight-summary {
  margin: 0;
  color: #dce5eb;
  font-size: 1rem;
  line-height: 1.8;
}
.insight-facts {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  gap: 8px;
}
.insight-fact {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  color: #aebbc6;
  background: rgba(7, 10, 14, 0.45);
  font-size: 0.78rem;
}
.insight-fact.positive { border-color: rgba(66, 245, 176, 0.35); color: var(--accent); }
.insight-fact.negative { border-color: rgba(255, 107, 120, 0.35); color: #ff9aa4; }
.metric-card {
  position: relative;
  min-height: 142px;
  padding: 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(17, 25, 35, 0.92), rgba(10, 15, 21, 0.92));
  box-shadow: var(--shadow);
}
.metric-card::after {
  content: "";
  position: absolute;
  right: -20px;
  bottom: -42px;
  width: 110px;
  height: 110px;
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 50%;
}
.metric-card-accent { border-color: rgba(66, 245, 176, 0.32); }
.metric-card p { margin-bottom: 18px; color: var(--muted); font-size: 0.875rem; }
.metric-card strong { display: block; margin-bottom: 7px; font-size: clamp(2rem, 4vw, 2.65rem); line-height: 1; letter-spacing: -0.05em; }
.metric-card span { color: #65727f; font-size: 0.78rem; }

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.75fr);
  gap: 14px;
  margin-top: 14px;
}
.chart-panel { min-height: 350px; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 14px 20px 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.legend-events { background: var(--accent); }
.legend-installations { background: #ffb45c; }
.legend-searches { background: var(--blue); }
.legend-jumps { background: #ff7183; }
.legend-git { background: #b78cff; }
.trend-chart-wrap { padding: 4px 14px 12px; }
.trend-chart { display: block; width: 100%; min-height: 230px; overflow: visible; }
.chart-grid-line { stroke: rgba(141, 154, 167, 0.16); stroke-width: 1; }
.chart-axis-label { fill: #71808e; font-size: 11px; }
.chart-empty-text { fill: var(--muted); font-size: 13px; }
.chart-area { fill: rgba(66, 245, 176, 0.08); }
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-line.events, .chart-dot.events { stroke: var(--accent); fill: var(--accent); }
.chart-line.installations, .chart-dot.installations { stroke: #ffb45c; fill: #ffb45c; }
.chart-line.searches, .chart-dot.searches { stroke: var(--blue); fill: var(--blue); }
.chart-line.jumps, .chart-dot.jumps { stroke: #ff7183; fill: #ff7183; }
.chart-line.git, .chart-dot.git { stroke: #b78cff; fill: #b78cff; }
.version-chart-layout {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(180px, 1.1fr);
  align-items: center;
  gap: 4px;
  min-height: 270px;
  padding: 8px 18px 18px;
}
.version-chart { display: block; width: min(100%, 230px); margin: 0 auto; }
.donut-track, .donut-segment { fill: none; stroke-width: 24; }
.donut-track { stroke: #1a232d; }
.donut-segment { transition: opacity 160ms ease; }
.donut-segment:hover { opacity: 0.78; }
.donut-value { fill: var(--text); font-size: 32px; font-weight: 700; }
.donut-label { fill: var(--muted); font-size: 12px; }
.version-legend { display: grid; gap: 10px; align-content: center; }
.version-legend-item { display: grid; grid-template-columns: 14px 1fr; gap: 9px; align-items: start; }
.version-swatch { width: 12px; height: 12px; margin-top: 3px; }
.version-legend-item strong { display: block; color: var(--text); font-size: 0.86rem; }
.version-legend-item small { display: block; margin-top: 3px; color: var(--muted); font-size: 0.72rem; line-height: 1.4; }
.empty-state.compact { padding: 28px 10px; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(0, 1.78fr);
  gap: 14px;
  margin-top: 14px;
}
.panel {
  min-height: 430px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(13, 18, 24, 0.86);
  box-shadow: var(--shadow);
}
.panel-heading {
  justify-content: space-between;
  min-height: 75px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-heading > span { color: var(--muted); font-size: 0.78rem; }
.event-bars { padding: 12px 18px 20px; }
.event-bar-button {
  width: 100%;
  padding: 11px 0;
  border: 0;
  border-bottom: 1px solid rgba(32, 42, 53, 0.65);
  background: transparent;
  color: var(--text);
  text-align: left;
}
.event-bar-button:last-child { border-bottom: 0; }
.event-bar-label { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 0.875rem; }
.event-bar-label span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.event-bar-track { height: 4px; overflow: hidden; border-radius: 99px; background: #1a232d; }
.event-bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--blue)); transform-origin: left; }
.event-bar-button:hover .event-bar-label span:first-child { color: var(--accent); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 14px 16px; border-bottom: 1px solid rgba(32, 42, 53, 0.7); text-align: left; vertical-align: top; }
th { color: #71808e; font-size: 0.72rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; }
td { color: #bdc7d0; }
tbody tr:hover { background: rgba(85, 169, 255, 0.035); }
.event-name { color: var(--text); font-weight: 650; }
.event-code { display: block; margin-top: 4px; color: #65727f; font: 0.72rem/1.4 "Cascadia Code", Consolas, monospace; }
.event-description { display: block; margin-top: 5px; color: #82909c; font-size: 0.75rem; line-height: 1.45; }
.property-list { display: grid; gap: 5px; margin-top: 7px; }
.property-item { color: #a9b5c0; font-size: 0.76rem; line-height: 1.5; }
.property-item strong { color: #d1dae1; font-weight: 600; }
.cell-main { display: block; color: #cbd3da; }
.cell-sub { display: block; margin-top: 4px; color: #65727f; font-size: 0.75rem; }
.source-tag {
  display: inline-flex;
  padding: 4px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  color: #aab8c4;
  font-size: 0.75rem;
}
details { max-width: 300px; }
summary { color: var(--blue); cursor: pointer; }
pre { max-width: 320px; margin: 8px 0 0; overflow: auto; color: #a9b5c0; font: 0.75rem/1.55 "Cascadia Code", Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.empty-state, .empty-cell { color: var(--muted); text-align: center; }
.empty-state { padding: 90px 20px; }
.empty-cell { padding: 80px 20px; }

dialog {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: 0 32px 100px rgba(0,0,0,0.7);
}
dialog::backdrop { background: rgba(2, 5, 8, 0.8); backdrop-filter: blur(8px); }
dialog form { padding: 30px; }
.dialog-mark { margin-bottom: 16px; color: var(--accent); text-shadow: 0 0 18px var(--accent); }
.dialog-copy { margin: 14px 0 22px; color: var(--muted); line-height: 1.65; font-size: 0.9rem; }
.key-field { display: grid; gap: 8px; color: #aab6c0; font-size: 0.875rem; }
.key-field input {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: 0;
  background: #080d12;
  color: var(--text);
}
.key-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { min-height: 21px; margin: 9px 0 4px; color: var(--danger); font-size: 0.82rem; }
.dialog-submit { width: 100%; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 5;
  max-width: min(360px, calc(100% - 44px));
  padding: 11px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #121a23;
  color: var(--text);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 180ms ease;
  font-size: 0.875rem;
}
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .insight-panel { grid-template-columns: 1fr; }
  .insight-facts { grid-column: 1; }
  .chart-grid { grid-template-columns: 1fr; }
  .content-grid { grid-template-columns: 1fr; }
  .distribution-panel { min-height: 320px; }
}

@media (max-width: 700px) {
  .app-shell { width: min(100% - 24px, 1480px); padding-top: 18px; }
  .topbar { align-items: flex-start; }
  .status-cluster { flex-direction: column; align-items: flex-end; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-actions { align-items: stretch; }
  .search-field { flex: 1; }
  .search-field input { width: 100%; min-width: 0; }
  .period-switch { display: grid; grid-template-columns: repeat(4, 1fr); }
  .period-switch button { padding: 0 8px; }
  .version-chart-layout { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 125px; }
  .toolbar-actions { flex-direction: column; }
  .topbar { gap: 12px; }
  .connection-status { display: none; }
  .secondary-button { padding: 0 10px; }
  th, td { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
