/* =========================================================================
   vista-tools — internal telemetry console
   Visual layer on top of Pico CSS v2. No JS behavior touched: this file only
   adds chrome, panels and a small "signal console" identity — indigo accent,
   monospace tabular data, uppercase micro-labels, section code-chips.
   Works in Pico's light & dark themes (auto via prefers-color-scheme, plus
   explicit [data-theme] overrides).
   ========================================================================= */

/* ---- design tokens ---------------------------------------------------- */
/* Matches Pico's own light-scheme selector specificity (0,2,0) so our
   accent overrides win by source order; a plain :root would lose to Pico. */
:root:not([data-theme="dark"]) {
  --vista-canvas: #f4f5f7;          /* app background behind panels */
  --vista-border: #e4e7ec;          /* hairline panel border */
  --vista-border-strong: #d3d8df;
  --vista-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --vista-shadow-lift: 0 8px 20px rgba(16, 24, 40, .10), 0 2px 6px rgba(16, 24, 40, .06);
  --vista-radius: 12px;
  --vista-radius-sm: 8px;
  --vista-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --vista-row-hover: rgba(91, 87, 227, .06);
  --vista-ok: #2f9e6b;
  --vista-wip: #c9820f;
  --vista-error-bg: #fdecec;
  --vista-error-border: #e5484d;
  --vista-error-fg: #ad1f26;

  /* accent: indigo — deliberately off Pico's default azure */
  --pico-primary-background: #5b57e3;
  --pico-primary-hover-background: #4a46cf;
  --pico-primary-border: #5b57e3;
  --pico-primary-hover-border: #4a46cf;
  --pico-primary: #4a46cf;
  --pico-primary-hover: #3b38b5;
  --pico-primary-focus: rgba(91, 87, 227, .3);
  --pico-primary-inverse: #fff;
  --pico-primary-underline: rgba(74, 70, 207, .4);
}

/* dark — OS preference (unless a light theme is explicitly forced) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --vista-canvas: #0e1014;
    --vista-border: #23262e;
    --vista-border-strong: #2e323c;
    --vista-shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --vista-shadow-lift: 0 10px 28px rgba(0, 0, 0, .5);
    --vista-row-hover: rgba(125, 120, 240, .12);
    --vista-ok: #45c07f;
    --vista-wip: #e0a13a;
    --vista-error-bg: rgba(229, 72, 77, .12);
    --vista-error-border: #e5484d;
    --vista-error-fg: #ff9ea1;

    --pico-primary-background: #6d68f0;
    --pico-primary-hover-background: #827dff;
    --pico-primary-border: #6d68f0;
    --pico-primary-hover-border: #827dff;
    --pico-primary: #a7a3ff;
    --pico-primary-hover: #c3c0ff;
    --pico-primary-focus: rgba(125, 120, 240, .4);
    --pico-primary-inverse: #fff;
    --pico-primary-underline: rgba(167, 163, 255, .4);
  }
}

/* dark — explicitly forced */
[data-theme="dark"] {
  --vista-canvas: #0e1014;
  --vista-border: #23262e;
  --vista-border-strong: #2e323c;
  --vista-shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --vista-shadow-lift: 0 10px 28px rgba(0, 0, 0, .5);
  --vista-row-hover: rgba(125, 120, 240, .12);
  --vista-ok: #45c07f;
  --vista-wip: #e0a13a;
  --vista-error-bg: rgba(229, 72, 77, .12);
  --vista-error-border: #e5484d;
  --vista-error-fg: #ff9ea1;

  --pico-primary-background: #6d68f0;
  --pico-primary-hover-background: #827dff;
  --pico-primary-border: #6d68f0;
  --pico-primary-hover-border: #827dff;
  --pico-primary: #a7a3ff;
  --pico-primary-hover: #c3c0ff;
  --pico-primary-focus: rgba(125, 120, 240, .4);
  --pico-primary-inverse: #fff;
  --pico-primary-underline: rgba(167, 163, 255, .4);
}

/* ---- app shell -------------------------------------------------------- */
body { background: var(--vista-canvas); }
main.container { padding-top: clamp(1.5rem, 3vw, 2.75rem); padding-bottom: 4rem; }
main.dashboard { max-width: 1200px; }

/* ---- site header ------------------------------------------------------ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--vista-border);
}
.site-header h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.2vw, 1.55rem);
  font-weight: 680;
  letter-spacing: -.01em;
  line-height: 1.15;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.site-header h1 a { color: inherit; text-decoration: none; }
.site-header h1 a:hover { color: var(--pico-primary); }
/* signature logo mark — the one persistent accent block */
.site-header h1::before {
  content: "";
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 7px;
  flex: none;
  background: linear-gradient(135deg, #7c78ff, #4a46cf);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}

/* identity pill (top-right authenticated email) */
#identity {
  font-family: var(--vista-mono);
  font-size: .75rem;
  color: var(--pico-muted-color);
  background: var(--pico-card-background-color);
  border: 1px solid var(--vista-border);
  padding: .3rem .7rem;
  border-radius: 999px;
  white-space: nowrap;
}
#identity strong { color: var(--pico-color); font-weight: 600; margin-left: .4em; }
.logout-link {
  margin-left: .75rem;
  padding-left: .75rem;
  border-left: 1px solid var(--vista-border-strong);
  color: var(--pico-primary);
  text-decoration: none;
}
.logout-link:hover { text-decoration: underline; }

/* muted small text (meta lines, notes) */
.identity { font-size: .8rem; color: var(--pico-muted-color); }

.page-intro {
  color: var(--pico-muted-color);
  max-width: 66ch;
  margin-bottom: 1.75rem;
}
.page-intro a { font-weight: 500; }

/* ---- panels ----------------------------------------------------------- */
.panel {
  background: var(--pico-card-background-color);
  border: 1px solid var(--vista-border);
  border-radius: var(--vista-radius);
  box-shadow: var(--vista-shadow);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .85rem 1.15rem;
  border-bottom: 1px solid var(--vista-border);
}
.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 640;
  letter-spacing: -.005em;
  display: flex;
  align-items: baseline;
  gap: .55rem;
}
/* In a panel header, the eyebrow tag reads as part of the title line — match the
   title's size (keep accent color + mono to still mark it as a category tag). */
.panel-head .eyebrow {
  font-size: 1rem;
  letter-spacing: 0;
  text-transform: none;
}
.panel-body { padding: 1.15rem; }

/* uppercase mono micro-label — the console "eyebrow" */
.eyebrow {
  font-family: var(--vista-mono);
  font-size: .66rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--pico-primary);
}

/* ---- charts ----------------------------------------------------------- */
.chart-body {
  padding: 1.1rem 1.15rem 1.35rem;
  min-height: 120px;
}
.chart-body canvas { display: block; }

/* ---- toolbar (filter forms) ------------------------------------------ */
.toolbar {
  background: var(--pico-card-background-color);
  border: 1px solid var(--vista-border);
  border-radius: var(--vista-radius);
  box-shadow: var(--vista-shadow);
  padding: 1rem 1.15rem;
  margin-bottom: 1.25rem;
}
.toolbar fieldset { margin-bottom: 0; }
/* compact, consistent toolbar type — Pico's fluid base is oversized for a
   dense control row on wide screens. */
.toolbar label { font-size: .8rem; font-weight: 500; color: var(--pico-muted-color); }
.toolbar select, .toolbar input, .toolbar button { font-size: .9rem; }
.toolbar select, .toolbar input { --pico-form-element-spacing-vertical: .55rem; }
.toolbar button { --pico-form-element-spacing-vertical: .55rem; }
/* The action button is a bare grid item (no wrapping label); bottom-aligning the
   grid puts it on the same baseline as the labeled selects/inputs (whose labels
   make their columns taller). */
.toolbar fieldset.grid { align-items: end; }
.toolbar label { margin-bottom: 0; }
/* Pico gives form controls a bottom margin; inside a bottom-aligned toolbar row
   that pushes selects/inputs ~1 row-gap above the bare action button. Zero it so
   control bottoms and the button bottom share one baseline. */
.toolbar select, .toolbar input { margin-bottom: 0; }
.toolbar button { width: auto; margin: 0; }
/* the raw-data toolbar lives inside a panel body — drop its own card chrome */
.panel-body .toolbar {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  margin-bottom: 1rem;
}

/* status strip (meta lines under toolbars) */
#meta,
#rawMeta {
  font-family: var(--vista-mono);
  font-size: .75rem;
  color: var(--pico-muted-color);
  margin: 0 0 1rem;
  padding-left: .75rem;
  border-left: 2px solid var(--vista-border-strong);
  line-height: 1.5;
}
.panel-body #rawMeta { margin-bottom: 1rem; }

/* ---- error banner ----------------------------------------------------- */
.error-banner {
  background: var(--vista-error-bg);
  color: var(--vista-error-fg);
  border: 1px solid var(--vista-error-border);
  border-left-width: 3px;
  padding: .7rem 1rem;
  border-radius: var(--vista-radius-sm);
  margin-bottom: 1rem;
  font-size: .85rem;
}
[hidden] { display: none !important; }

/* ---- raw-data table --------------------------------------------------- */
.table-scroll {
  overflow: auto;
  max-height: 62vh;
  border-top: 1px solid var(--vista-border);
}
#rawTable {
  width: 100%;
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .8rem;
}
#rawTable thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--pico-card-sectioning-background-color, var(--pico-card-background-color));
  font-family: var(--vista-mono);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--pico-muted-color);
  padding: .55rem .7rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--vista-border-strong);
}
#rawTable td {
  padding: .5rem .7rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--vista-border);
  font-variant-numeric: tabular-nums;
  vertical-align: top;
}
#rawTable tbody tr:nth-child(even) td {
  background: var(--pico-table-row-stripped-background-color);
}
#rawTable tbody tr:hover td { background: var(--vista-row-hover); }
/* data column: plain mono text (no code-box chrome) + a trailing eye affordance
   that opens the full-JSON modal. Zero all box props so nothing frames it. */
.data-wrap {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  max-width: 420px;
  vertical-align: middle;
}
.data-wrap.is-clickable { cursor: pointer; }
.data-cell {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--vista-mono);
  font-size: .92em;
  color: var(--pico-muted-color);
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
}
.data-wrap.is-clickable:focus-visible { outline: 2px solid var(--pico-primary-focus); outline-offset: 2px; border-radius: 4px; }
.data-wrap.is-clickable:focus { outline: none; } /* only show ring for keyboard */
.data-eye {
  flex: none;
  width: 15px;
  height: 15px;
  fill: var(--pico-muted-color);
  opacity: .65;
  transition: opacity .12s, fill .12s;
  /* optical centering: monospace digits sit slightly below their line-box
     center (ascender space above), so nudge the eye down to match. */
  position: relative;
  top: .06em;
}
.data-wrap.is-clickable:hover .data-eye { opacity: 1; fill: var(--pico-primary); }
.data-wrap.is-clickable:hover .data-cell { color: var(--pico-color); }

/* ---- pager ------------------------------------------------------------ */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0;
}
.pager button {
  margin: 0;
  width: auto;
  font-size: .82rem;
  --pico-form-element-spacing-vertical: .45rem;
  --pico-form-element-spacing-horizontal: .9rem;
}
.pager-wrap { border-top: 1px solid var(--vista-border); }
#pageInfo {
  font-family: var(--vista-mono);
  font-size: .78rem;
  color: var(--pico-muted-color);
}

/* ---- home: section cards --------------------------------------------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.15rem;
  margin-top: 1.5rem;
}
.sec-card {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  position: relative;
  overflow: hidden;
  background: var(--pico-card-background-color);
  border: 1px solid var(--vista-border);
  border-radius: var(--vista-radius);
  box-shadow: var(--vista-shadow);
  padding: 1.2rem 1.25rem 1.3rem;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.sec-card::before {   /* top accent bar */
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, #7c78ff, #4a46cf);
  opacity: 0;
  transition: opacity .16s ease;
}
.sec-card.is-active::before { opacity: 1; }
.sec-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--vista-shadow-lift);
  border-color: var(--vista-border-strong);
}
.sec-card:hover::before { opacity: 1; }

.sec-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sec-code {
  font-family: var(--vista-mono);
  font-weight: 700;
  font-size: .72rem;
  letter-spacing: .08em;
  color: #fff;
  background: linear-gradient(135deg, #7c78ff, #4a46cf);
  padding: .3rem .5rem;
  border-radius: 7px;
  line-height: 1;
}
.sec-card.is-wip .sec-code {
  background: none;
  color: var(--pico-muted-color);
  border: 1px solid var(--vista-border-strong);
}
.sec-status {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-family: var(--vista-mono);
  font-size: .68rem;
  letter-spacing: .03em;
  color: var(--pico-muted-color);
}
.sec-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.sec-status.ok { color: var(--vista-ok); }
.sec-status.wip { color: var(--vista-wip); }

.sec-card h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 640;
  letter-spacing: -.01em;
}
.sec-card h3 a { text-decoration: none; color: inherit; }
.sec-card h3 a:hover { color: var(--pico-primary); }
.sec-card p {
  margin: 0;
  font-size: .875rem;
  line-height: 1.5;
  color: var(--pico-muted-color);
}
.sec-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: auto;
  padding-top: .4rem;
}
.sec-actions [role="button"] {
  margin: 0;
  width: auto;
  font-size: .85rem;
  padding: .45rem .9rem;
}

/* refined "building" badge (kept for reuse) */
.badge {
  display: inline-block;
  font-family: var(--vista-mono);
  font-size: .66rem;
  letter-spacing: .04em;
  padding: .15rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--vista-border-strong);
  background: transparent;
  color: var(--pico-muted-color);
  vertical-align: middle;
}

/* ---- track test page -------------------------------------------------- */
.sdk-bar .panel-body {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.sdk-bar button { margin: 0; width: auto; }
.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem;
  margin: 0;
}
.btn-row button { margin: 0; width: auto; }

/* inline status chips (#stat / #sst) */
.status-chip {
  font-family: var(--vista-mono);
  font-size: .78rem;
  color: var(--pico-muted-color);
  background: var(--pico-card-sectioning-background-color, transparent);
  border: 1px solid var(--vista-border);
  padding: .25rem .6rem;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---- console (log box) ------------------------------------------------ */
.console-panel { margin-bottom: 1.5rem; }
.console-head {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--vista-border);
  font-family: var(--vista-mono);
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--pico-muted-color);
}
.console-head::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3fb950;
  box-shadow: 0 0 0 3px rgba(63, 185, 80, .18);
}
.log-box {
  background: #0d1117;
  color: #4ec472;
  margin: 0;
  padding: 12px 14px;
  height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  font: 12px/1.5 var(--vista-mono);
  border: 0;
  border-radius: 0 0 var(--vista-radius) var(--vista-radius);
}

/* ---- motion / responsive --------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .sec-card { transition: none; }
  .sec-card:hover { transform: none; }
}
@media (max-width: 640px) {
  .site-header { align-items: flex-start; }
  .table-scroll { max-height: 70vh; }
  /* stack toolbar controls (Pico's auto-fit grid would otherwise cram them in
     one row on narrow screens); button goes full-width at the bottom. */
  .toolbar fieldset.grid { grid-template-columns: 1fr; align-items: stretch; gap: .75rem; }
  .toolbar button { width: 100%; }
  main.container { padding-top: 1.5rem; }
  .panel-head, .panel-body, .chart-body, .toolbar { padding-left: .9rem; padding-right: .9rem; }
  .site-header h1 { font-size: 1.15rem; }
  #identity { white-space: normal; }
  /* data cell shouldn't force the row wider than the phone viewport */
  .data-wrap { max-width: 60vw; }
}

/* ---- JSON modal (dialog sizing/scroll; affordance styles live above) ---- */

#dataModal {
  max-width: min(680px, 92vw);
  width: 100%;
  border: 1px solid var(--vista-border);
  border-radius: var(--vista-radius);
  padding: 0;
  background: var(--pico-card-background-color);
  box-shadow: var(--vista-shadow-lift);
}
#dataModal::backdrop { background: rgba(16, 24, 40, .5); }
#dataModal article { margin: 0; }
.data-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--vista-border);
  background: var(--pico-card-sectioning-background-color, var(--vista-canvas));
  border-radius: var(--vista-radius) var(--vista-radius) 0 0;
  margin: 0;
}
.data-modal-head button { width: auto; margin: 0; padding: .2rem .6rem; }
.data-modal-body {
  margin: 0;
  padding: 1rem;
  max-height: 60vh;
  overflow: auto;
  font-family: var(--vista-mono);
  font-size: .8rem;
  white-space: pre;
  background: transparent;
}
