/* App Tracker — navy & orange.
 *
 * Brand: deep navy for chrome and text, orange for accents and actions.
 * Chart marks use their own validated steps (series-1 / series-2): the brand
 * navy is too dark to read as a colour in a chart, and the brand orange is
 * under 3:1 on white. Checked with the dataviz palette validator (CVD ΔE 27.6).
 */

:root {
  color-scheme: light;

  --navy-950: #0d1730;
  --navy-900: #14234a;
  --navy-700: #22396e;
  --navy-100: #e6ebf5;
  --navy-50:  #f1f4fa;
  --orange-600: #d65a0a;
  --orange-500: #f07c1b;
  --orange-100: #fdeadb;

  --bg: #f3f5f9;
  --surface: #ffffff;
  --border: #e7eaf1;
  --gridline: #edf0f5;

  --text-primary: #14234a;
  --text-secondary: #4f5b76;
  --text-muted: #8590a8;

  --series-1: #2a4f9e;       /* navy, chart marks */
  --series-1-tint: #dfe6f4;
  --series-2: #e8690f;       /* orange, chart marks */
  --series-2-tint: #fbe3d1;
  --star: #f2a33a;
  --star-empty: #dfe3ec;

  --good: #1f7a4d;
  --bad: #c2410c;
  --critical: #c42b2b;

  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 35, 74, 0.04), 0 8px 24px rgba(20, 35, 74, 0.06);
  --font: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
pre { background: var(--navy-50); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--orange-500); outline-offset: 2px; }

.muted { color: var(--text-muted); }

/* ---------- Shell ---------- */

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  padding: 28px 0;
  background: var(--navy-900);
}

.sidebar-logo { display: block; }
.logo-tile { fill: var(--orange-500); }
.logo-bar { fill: var(--navy-900); }
.sidebar .logo-tile { fill: var(--surface); }
.sidebar .logo-bar:last-child { fill: var(--orange-500); }

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-link {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  color: #9aa8c9;
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover { color: var(--surface); background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.sidebar-link.is-active { color: var(--orange-500); background: rgba(240, 124, 27, 0.14); }
.sidebar-signout-form { margin-top: auto; }

.main {
  padding: 28px 36px 48px;
  min-width: 0;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.card-foot { margin-top: auto; font-size: 13px; text-align: center; }

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 14px 10px 28px;
  min-height: 76px;
}

.topbar-tabs { display: flex; gap: 34px; overflow-x: auto; scrollbar-width: none; }

.topbar-tab {
  position: relative;
  padding: 24px 0;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.topbar-tab:hover { color: var(--text-primary); text-decoration: none; }
.topbar-tab.is-active { color: var(--text-primary); font-weight: 700; }
.topbar-tab.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  height: 3px;
  border-radius: 3px;
  background: var(--orange-500);
}

.topbar-actions { display: flex; align-items: center; gap: 16px; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 18px;
  border-left: 1px solid var(--border);
  font-weight: 500;
  color: var(--text-secondary);
}

.button-round {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  background: var(--orange-500);
  color: var(--navy-950);
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(240, 124, 27, 0.35);
  transition: transform 0.15s, background 0.15s;
}

.button-round:hover { background: #f58a2f; transform: rotate(-30deg); }

.button-primary {
  width: 100%;
  padding: 13px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--navy-900);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.button-primary:hover { background: var(--navy-700); }

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.avatar-navy { background: var(--navy-100); color: var(--navy-900); }
.avatar-orange { background: var(--orange-100); color: #9a3d05; }

/* Sync status popover */

.sync-status { position: relative; }

.sync-status summary {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.sync-status summary::-webkit-details-marker { display: none; }
.sync-status summary:hover { background: var(--navy-50); }

.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.sync-status.is-failing .sync-dot { background: var(--critical); }
.sync-status.is-failing summary { color: var(--critical); font-weight: 700; }

.sync-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: 320px;
  padding: 16px;
  display: grid;
  gap: 14px;
  font-size: 13px;
}

.sync-row { display: grid; grid-template-columns: 24px 1fr; gap: 10px; }
.sync-state { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; }
.sync-state-succeeded { background: #e3f3ea; color: var(--good); }
.sync-state-failed { background: #fbe4e4; color: var(--critical); }
.sync-state-running, .sync-state-never { background: var(--navy-50); color: var(--text-muted); }
.sync-error { margin-top: 4px; color: var(--critical); word-break: break-word; }

/* Flash */

.flash {
  margin-top: 16px;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 500;
}

.flash-notice { background: var(--navy-100); color: var(--navy-900); }
.flash-alert { background: #fbe4e4; color: var(--critical); }

/* ---------- Filters ---------- */

.filters {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin: 24px 0 20px;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.segmented-option {
  padding: 7px 16px;
  border-radius: 9px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
}

.segmented-option:hover { color: var(--text-primary); text-decoration: none; background: var(--navy-50); }
.segmented-option.is-selected { background: var(--navy-900); color: #fff; }

.filters-note { color: var(--text-muted); font-size: 13px; }
.filters-note strong { color: var(--text-secondary); }

/* ---------- Grid ---------- */

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

.grid > .card { padding: 28px 30px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card-rating     { grid-column: span 3; }
.card-downloads  { grid-column: span 6; }
.card-gauge      { grid-column: span 3; }
.card-reviews    { grid-column: span 6; grid-row: span 2; }
.card-ring       { grid-column: span 3; }
.card-stability  { grid-column: span 3; }
.card-issues     { grid-column: span 3; }

@media (max-width: 1280px) {
  .card-rating, .card-gauge, .card-ring, .card-stability, .card-issues { grid-column: span 6; }
  .card-downloads, .card-reviews { grid-column: span 12; grid-row: auto; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    z-index: 30;
    height: auto;
    flex-direction: row;
    justify-content: space-between;
    padding: 10px 16px;
    gap: 12px;
  }
  .sidebar-nav { flex-direction: row; gap: 4px; }
  .sidebar-link { width: 42px; height: 42px; }
  .sidebar-signout-form { margin-top: 0; }
  .main { padding: 16px 16px 40px; }
  .topbar { padding: 8px 12px; min-height: 0; }
  .topbar-tabs, .topbar-user-email { display: none; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .topbar-user { border-left: 0; padding-left: 0; }
  .grid { gap: 16px; }
  .grid > .card { grid-column: span 12; padding: 22px 20px; }
  .sync-popover { right: auto; left: 0; width: min(320px, calc(100vw - 32px)); }
}

/* ---------- Figures ---------- */

.figure-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.figure-xl { font-size: 56px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.figure-hero { font-size: 48px; font-weight: 700; line-height: 1.05; letter-spacing: -0.02em; }
.figure-lg { font-size: 40px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.figure-md { font-size: 22px; font-weight: 700; line-height: 1.2; margin-bottom: 10px; }
.figure-accent { color: var(--orange-600); }

.figure-label { color: var(--text-secondary); font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.figure-label-accent { color: var(--orange-600); }

.figure-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, auto)) 1fr;
  gap: 18px 44px;
  align-items: start;
}

.figure-aside { justify-self: end; text-align: right; }

@media (max-width: 760px) {
  .figure-group { grid-template-columns: 1fr 1fr; }
  .figure-aside { grid-column: span 2; justify-self: start; text-align: left; display: grid; grid-template-columns: auto auto; gap: 0 18px; }
  .figure-hero { font-size: 40px; }
}

.delta { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.delta strong { font-weight: 700; }
.delta-good { color: var(--good); }
.delta-bad { color: var(--bad); }
.delta-flat { color: var(--text-secondary); }

/* Stars: one glyph, filled to --fill so half stars work. */
.stars { display: inline-flex; gap: 3px; }
.star {
  width: 18px;
  height: 18px;
  background: linear-gradient(90deg, var(--star) var(--fill), var(--star-empty) var(--fill));
  clip-path: polygon(50% 0%, 61.8% 35.4%, 100% 38.2%, 69.1% 61.8%, 80.9% 100%, 50% 76.4%, 19.1% 100%, 30.9% 61.8%, 0% 38.2%, 38.2% 35.4%);
}
.stars-sm .star { width: 15px; height: 15px; }

/* ---------- Charts ---------- */

.chart { position: relative; margin-top: auto; }
.chart-narrow { display: none; }
@media (max-width: 600px) {
  .chart-wide { display: none; }
  .chart-narrow { display: block; }
}
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.gridline { stroke: var(--gridline); stroke-width: 1; }
.axis-label { fill: var(--text-muted); font-size: 12px; font-family: var(--font); }
.axis-label.tick { font-variant-numeric: tabular-nums; }

.mark.series-1, .end-dot.series-1 { fill: var(--series-1); }
.mark.series-2, .end-dot.series-2 { fill: var(--series-2); }
.line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.line.series-1 { stroke: var(--series-1); }
.area.series-1 { fill: var(--series-1); opacity: 0.1; }
.end-dot { stroke: var(--surface); stroke-width: 2; }

.hit { fill: transparent; cursor: crosshair; outline: none; }
.hit.is-active, .hit:focus-visible { fill: var(--navy-900); fill-opacity: 0.04; }

.chart-tooltip {
  position: absolute;
  z-index: 10;
  transform: translate(-50%, calc(-100% - 12px));
  min-width: 140px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--navy-950);
  color: #fff;
  font-size: 13px;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(13, 23, 48, 0.25);
}

.chart-tooltip-title { color: #aeb9d4; font-size: 12px; margin-bottom: 4px; }
.chart-tooltip-row { display: flex; align-items: center; gap: 8px; }
.chart-tooltip-row strong { font-size: 15px; }
.chart-tooltip-row span:last-child { color: #c9d1e4; }
.chart-tooltip-key { width: 12px; height: 3px; border-radius: 2px; }
.chart-tooltip-key.series-1 { background: #7f9ee0; }
.chart-tooltip-key.series-2 { background: var(--orange-500); }

.chart-empty {
  margin-top: auto;
  padding: 26px 18px;
  border-radius: 12px;
  background: var(--navy-50);
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 18px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.legend li { display: flex; align-items: center; gap: 7px; }
.legend-key { width: 10px; height: 10px; border-radius: 3px; }
.legend-key.series-1 { background: var(--series-1); }
.legend-key.series-2 { background: var(--series-2); }

.legend-split { justify-content: space-between; margin-top: auto; }
.legend-split strong { color: var(--text-primary); margin-left: 4px; }

.table-view { font-size: 13px; color: var(--text-secondary); }
.table-view summary { cursor: pointer; color: var(--text-muted); width: max-content; }
.table-view table { width: 100%; margin-top: 8px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 6px 4px; border-bottom: 1px solid var(--border); text-align: right; }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-view tbody { display: block; max-height: 220px; overflow-y: auto; }
.table-view thead, .table-view tbody tr { display: table; width: 100%; table-layout: fixed; }

/* Gauge & rings */

.gauge-wrap, .ring-wrap { position: relative; width: min(100%, 220px); margin: 4px auto 0; }
.gauge, .ring { display: block; width: 100%; height: auto; }
.meter-track { fill: none; stroke-width: 12; stroke-linecap: round; }
.meter-track.series-1 { stroke: var(--series-1-tint); }
.meter-fill { fill: none; stroke-width: 12; stroke-linecap: round; }
.meter-fill.series-1 { stroke: var(--series-1); }

.gauge-center, .ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.gauge-center { padding-bottom: 8%; }
.gauge-verdict { font-size: 22px; font-weight: 800; color: var(--text-primary); }
.gauge-caption { display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--text-secondary); font-size: 14px; line-height: 1.35; }
.gauge-caption p { max-width: 190px; }

.ring-track { fill: none; stroke: var(--navy-50); }
.ring-fill { fill: none; }
.ring-fill.series-1 { stroke: var(--series-1); }
.ring-fill.series-2 { stroke: var(--series-2); }

/* Sparkline */

.sparkline { display: block; width: 100%; height: auto; margin: 4px 0; overflow: visible; }
.sparkline-line { stroke: #b5c0d8; }

/* ---------- Lists ---------- */

.review-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 26px; }
.review { display: grid; grid-template-columns: 52px 1fr; gap: 18px; }
.review .avatar { width: 52px; height: 52px; font-size: 16px; }
.review-author { font-weight: 700; font-size: 16px; }
.review-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--text-muted); font-size: 13px; margin: 4px 0 8px; }
.review-title { font-weight: 600; margin-bottom: 2px; }
.review-text { color: var(--text-secondary); font-size: 14px; line-height: 1.65; }

.stat-rows { margin: 4px 0 0; display: grid; }
.stat-rows > div { display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.stat-rows > div:last-child { border-bottom: 0; }
.stat-rows dt { color: var(--text-secondary); font-weight: 500; }
.stat-rows dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-rows .stat-delta .delta { margin: 0; }
.stat-rows-compact > div { grid-template-columns: 1fr auto; padding: 8px 0; font-size: 14px; }

.issue-list { list-style: none; margin: 0; padding: 0; }
.issue-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto 30px; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.issue-list li:last-child { border-bottom: 0; }
.issue-text { display: grid; min-width: 0; font-size: 13px; }
.issue-title {
  color: var(--series-1);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.issue-count { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }

.icon-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--navy-50);
  color: var(--series-1);
}

.icon-button:hover { background: var(--navy-100); }

.not-connected {
  margin-top: auto;
  padding: 20px;
  border: 1px dashed #cdd4e3;
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 14px;
  display: grid;
  gap: 8px;
}

.not-connected code { color: var(--text-muted); word-break: break-all; }

.empty-state { margin-top: 24px; padding: 32px; display: grid; gap: 12px; }

/* ---------- Sign in ---------- */

.auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 16px;
}
.auth .flash { width: min(400px, 100%); margin: 0; }
.auth-card { width: min(400px, 100%); padding: 36px 32px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.auth-brand h1 { font-size: 24px; font-weight: 800; }
.auth-form { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.auth-form input[type="email"], .auth-form input[type="password"] {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  color: var(--text-primary);
  background: var(--navy-50);
}
.auth-form input:focus { outline: 2px solid var(--orange-500); outline-offset: 0; background: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
