/* ============================================================================
   Trend Radar — Control Panel
   Top-right floating cluster: theme / language / font toggles.
   Glassy surface, subtle shadow, Raycast-style segmented controls.
   ============================================================================ */

.tr-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: var(--overlay);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-2);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  color: var(--fg-soft);
  user-select: none;
}

.tr-panel-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-soft);
}

.tr-panel-group .tr-seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 6px 12px;
  height: 28px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.tr-panel-group .tr-seg:hover { color: var(--fg); }

.tr-panel-group .tr-seg[aria-pressed="true"],
.tr-panel-group .tr-seg.is-active {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-1);
}

.tr-panel-group .tr-seg svg {
  width: 14px;
  height: 14px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
}

.tr-panel-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

.tr-panel-kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted-2);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-left: 4px;
  letter-spacing: 0.04em;
}

/* Responsive: panel collapses on small screens */
@media (max-width: 640px) {
  .tr-panel {
    top: 12px;
    right: 12px;
    gap: 4px;
    padding: 4px;
  }
  .tr-panel-group .tr-seg {
    padding: 5px 9px;
    font-size: 12px;
    height: 26px;
  }
  .tr-panel-kbd { display: none; }
}

/* ============================================================================
   Layout primitives shared by all 3 pages
   ============================================================================ */

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  transition: background var(--dur-slow) var(--ease), color var(--dur-slow) var(--ease);
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
a:hover { border-bottom-color: var(--accent); }

button { font-family: inherit; }

/* ---------- App shell ---------- */
.tr-shell {
  max-width: var(--container);
  margin: 0 auto;
  padding: 32px 24px 96px;
}

@media (max-width: 720px) {
  .tr-shell { padding: 24px 16px 80px; }
}

/* ---------- Top nav ---------- */
.tr-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 28px;
  margin-bottom: 40px;
  border-bottom: 1px solid var(--border-soft);
}

.tr-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--fg);
}

.tr-brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), oklch(70% 0.14 280));
  position: relative;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-1);
}
.tr-brand-mark::after {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--accent-fg);
  border-radius: 50%;
  opacity: 0.95;
}

.tr-nav-links {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tr-nav-link {
  font-size: var(--fs-md);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 0;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.tr-nav-link:hover { color: var(--fg); background: var(--surface-2); }
.tr-nav-link.is-active { color: var(--fg); background: var(--surface-2); }

.tr-nav-search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-1);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.tr-nav-search:focus-within { border-color: var(--accent); box-shadow: var(--ring); }

.tr-nav-search svg { width: 14px; height: 14px; stroke: var(--muted); fill: none; stroke-width: 1.6; }
.tr-nav-search input {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  flex: 1;
  min-width: 0;
}
.tr-nav-search input::placeholder { color: var(--placeholder); }

@media (max-width: 820px) {
  .tr-nav { flex-wrap: wrap; row-gap: 14px; }
  .tr-nav-links { order: 3; width: 100%; justify-content: flex-start; }
  .tr-nav-search { order: 2; flex: 1; min-width: 0; }
}
@media (max-width: 560px) {
  .tr-nav-search .tr-nav-search-label { display: none; }
  .tr-nav-search { min-width: 0; }
}

/* ---------- Page header ---------- */
.tr-page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.tr-eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tr-eyebrow::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

.tr-page-title {
  font-family: var(--font-display);
  font-size: var(--fs-4xl);
  line-height: 1.05;
  letter-spacing: var(--tracking-tight);
  margin: 0;
  color: var(--fg);
  font-weight: 600;
}

.tr-page-sub {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: var(--fs-lg);
  line-height: 1.5;
  max-width: 56ch;
}

@media (max-width: 720px) {
  .tr-page-head { flex-direction: column; align-items: flex-start; }
  .tr-page-title { font-size: var(--fs-3xl); }
}

/* ---------- Cards ---------- */
.tr-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 22px;
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.tr-card--soft { background: var(--surface-2); }
.tr-card--padless { padding: 0; }
.tr-card--hover:hover { box-shadow: var(--shadow-3); }

.tr-card-eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tr-card-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  letter-spacing: var(--tracking-tight);
  margin: 0 0 6px;
  color: var(--fg);
  font-weight: 600;
}

.tr-card-meta {
  font-size: var(--fs-sm);
  color: var(--muted);
  margin: 0;
}

/* ---------- Buttons ---------- */
.tr-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg-soft);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.tr-btn:hover { border-color: var(--border-strong); color: var(--fg); }

.tr-btn--primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.tr-btn--primary:hover {
  background: var(--fg-soft);
  border-color: var(--fg-soft);
  color: var(--bg);
}

.tr-btn--ghost { background: transparent; border-color: transparent; }
.tr-btn--ghost:hover { background: var(--surface-2); border-color: transparent; }

.tr-btn--sm { padding: 5px 10px; font-size: var(--fs-xs); }

.tr-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.02em;
  background: var(--surface-2);
  color: var(--fg-soft);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tr-chip:hover { border-color: var(--border-strong); }
.tr-chip.is-active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.tr-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.tr-chip--accent .tr-chip-dot { background: var(--accent); }
.tr-chip--danger .tr-chip-dot { background: var(--danger); }
.tr-chip--positive .tr-chip-dot { background: var(--positive); }

/* ---------- KPI card ---------- */
.tr-kpi {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tr-kpi-label {
  font-size: var(--fs-sm);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tr-kpi-value {
  font-family: var(--font-display);
  font-size: 36px;
  line-height: 1;
  letter-spacing: var(--tracking-tight);
  color: var(--fg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tr-kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.02em;
}
.tr-kpi-delta--up    { color: var(--positive); }
.tr-kpi-delta--down  { color: var(--danger); }
.tr-kpi-delta--flat  { color: var(--muted); }

.tr-kpi-foot {
  font-size: var(--fs-xs);
  color: var(--muted-2);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

/* ---------- Layout grids ---------- */
.tr-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.tr-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

@media (max-width: 900px) {
  .tr-grid-3 { grid-template-columns: 1fr; }
  .tr-grid-2 { grid-template-columns: 1fr; }
}

/* Two-column layout: main + side insight panel */
.tr-2col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 980px) { .tr-2col { grid-template-columns: 1fr; } }

/* ---------- Footer ---------- */
.tr-footer {
  margin-top: 80px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: var(--fs-xs);
  color: var(--muted);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.tr-footer a { color: var(--muted); }
.tr-footer a:hover { color: var(--fg); }

/* ---------- Utility ---------- */
.tr-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tr-muted { color: var(--muted); }
.tr-fg { color: var(--fg); }
.tr-row { display: flex; align-items: center; gap: 10px; }
.tr-row--between { justify-content: space-between; }
.tr-stack { display: flex; flex-direction: column; gap: 8px; }
.tr-stack--lg { gap: 18px; }
.tr-hr { height: 1px; background: var(--border-soft); margin: 20px 0; border: 0; }
.tr-hidden { display: none !important; }

/* Focus ring for accessibility */
:focus-visible {
  outline: 0;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}
