/* Statotest brand tokens — brandmanual.statotest.com, 2026-08-19.
   Ratio: ~70% white, ~20% black + indigo, ~10% red (signal only, never a
   decorative fill). Manrope throughout, SemiBold headings, no italics or
   shadows.

   Dark palette approximates the main statotest.com portal's own dark mode
   (screenshot reference, 2026-08-20) — not colour-picked pixel-for-pixel
   (this app themes independently), but close enough to sit inside the same
   iframe without looking like a different product. Theme resolution: an
   explicit `data-theme` (set from `?theme=` for iframe embedding, see
   main.ts) always wins; absent that, `prefers-color-scheme` decides. */

:root {
  color-scheme: light dark;
  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-text: #000000;
  --color-text-muted: #5c5c66;
  --color-text-faint: #8a8a94;
  --color-indigo: #1f04a3;
  --color-indigo-soft: #eeeafa;
  --color-signal: #e21752;
  --color-signal-hover: #c31047;
  --color-border: #d9d9e3;
  --color-shadow: rgba(0, 0, 0, 0.12);
  --color-overlay: rgba(0, 0, 0, 0.45);
  --font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Chart series palette (uPlot, chart.ts/device-chart.ts) — deliberately
     separate from the brand's indigo/signal-red (signal red stays reserved
     for signal/error use, style.css:1-4). Read via getComputedStyle at
     chart-build time (see chart-theme.ts): canvas drawing needs a resolved
     colour, not a live var() reference, unlike --color-* elsewhere which
     CSS resolves itself. Tuned brighter under the dark blocks below so each
     series keeps contrast against the dark background, not just the light
     one. */
  --chart-series-1: #1f6fb2;
  --chart-series-2: #b8720b;
  --chart-series-3: #1a8a63;
  --chart-series-4: #6a4fd1;
  --chart-series-5: #2094c9;
  --chart-series-6: #8a7415;
  --chart-grid: var(--color-border);
  --chart-axis-text: var(--color-text-muted);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #14162a;
    --color-surface: #1c1f3a;
    --color-text: #f2f2f7;
    --color-text-muted: #a0a3bd;
    --color-text-faint: #6d709a;
    --color-indigo: #8a7cf5;
    --color-indigo-soft: #262a4a;
    --color-signal: #ff5478;
    --color-signal-hover: #ff7a94;
    --color-border: #2e3152;
    --color-shadow: rgba(0, 0, 0, 0.5);
    --color-overlay: rgba(0, 0, 0, 0.6);
    --chart-series-1: #6cc0ff;
    --chart-series-2: #ffbf5c;
    --chart-series-3: #4fe0a8;
    --chart-series-4: #b8a6ff;
    --chart-series-5: #7fd4ff;
    --chart-series-6: #e0c268;
  }
}

:root[data-theme="dark"] {
  --color-bg: #14162a;
  --color-surface: #1c1f3a;
  --color-text: #f2f2f7;
  --color-text-muted: #a0a3bd;
  --color-text-faint: #6d709a;
  --color-indigo: #8a7cf5;
  --color-indigo-soft: #262a4a;
  --color-signal: #ff5478;
  --color-signal-hover: #ff7a94;
  --color-border: #2e3152;
  --color-shadow: rgba(0, 0, 0, 0.5);
  --color-overlay: rgba(0, 0, 0, 0.6);
  --chart-series-1: #6cc0ff;
  --chart-series-2: #ffbf5c;
  --chart-series-3: #4fe0a8;
  --chart-series-4: #b8a6ff;
  --chart-series-5: #7fd4ff;
  --chart-series-6: #e0c268;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-family);
  font-weight: 400;
  line-height: 1.5;
}

h1,
h2,
h3 {
  font-weight: 600;
  margin: 0;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--color-indigo);
  background: var(--color-surface);
  color: var(--color-indigo);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

button:hover {
  background: var(--color-indigo-soft);
}

button.primary {
  background: var(--color-signal);
  border-color: var(--color-signal);
  color: #fff;
}

button.primary:hover {
  background: var(--color-signal-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input,
select {
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  background: var(--color-surface);
  color: var(--color-text);
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.error {
  color: var(--color-signal);
  font-size: 0.9rem;
}

.loading {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* Toast notifications — top-right, for genuine failures. Logical empty
   states ("no sessions match") stay inline; this is reserved for things
   that actually went wrong. */

#toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: min(360px, calc(100vw - 2.5rem));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--color-surface);
  border-left: 4px solid var(--color-indigo);
  border-radius: 6px;
  box-shadow: 0 4px 16px var(--color-shadow);
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  color: var(--color-text);
  animation: toast-in 0.15s ease-out;
}

.toast-error {
  border-left-color: var(--color-signal);
}

.toast span {
  flex: 1;
}

.toast-dismiss {
  border: none;
  background: none;
  color: var(--color-text-faint);
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.toast-dismiss:hover {
  background: none;
  color: var(--color-text);
}

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

/* Login modal */

.modal {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  width: min(360px, 90vw);
  padding: 2.5rem 2rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--color-shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-content h1 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Preview modal — a dimmed overlay (unlike the login modal's full opaque
   takeover), sized for a scrollable data table rather than a form. */

.preview-modal {
  background: var(--color-overlay);
}

.preview-modal-content {
  width: min(900px, 92vw);
  max-height: 85vh;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preview-modal-header h2 {
  font-size: 1.1rem;
}

.modal-close {
  border: none;
  background: none;
  color: var(--color-text-faint);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 0.25rem;
  cursor: pointer;
}

.modal-close:hover {
  background: none;
  color: var(--color-text);
}

.preview-body {
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  min-height: 0;
  padding-right: 0.5rem;
}

.preview-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.preview-body thead th {
  position: sticky;
  top: 0;
  background: var(--color-indigo-soft);
  z-index: 1;
}

.preview-body th,
.preview-body td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
  text-align: right;
  white-space: nowrap;
}

.preview-body th:first-child,
.preview-body td:first-child {
  text-align: left;
}

/* Synthesized from TIMESTAMP[US] for display — not a column in the CSV.
   Muted, italic and set off by a dashed divider so that's obvious at a
   glance. */
.preview-body .preview-local-time {
  color: var(--color-text-muted);
  font-style: italic;
  border-right: 1px dashed var(--color-border);
}

.preview-truncated-note {
  margin: 0;
  padding: 0.5rem 0.25rem 0.25rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.preview-chart {
  flex: 0 0 auto;
  min-height: 260px;
}

.preview-chart-error {
  margin: 0;
  padding: 0.5rem 0.25rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Table/Charts view switch — a segmented pill in the section header. Only
   one of #table-view / #charts-view is visible at a time; .charts-hide
   marks the filter fields that are session/file-specific and don't apply
   to the aggregate charts view. */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.view-switch {
  display: inline-flex;
  background: var(--color-indigo-soft);
  border-radius: 999px;
  padding: 0.2rem;
  gap: 0.15rem;
}

.view-switch__option {
  border: none;
  background: none;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.view-switch__option:hover {
  background: none;
  color: var(--color-text);
}

.view-switch__option[aria-pressed="true"] {
  background: var(--color-indigo);
  color: #ffffff;
}

.view-switch__option[aria-pressed="true"]:hover {
  color: #ffffff;
}

.device-chart-card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.device-chart-card h3 {
  font-size: 0.95rem;
  margin-bottom: 0.6rem;
}

.device-chart-card .chart-container {
  min-height: 220px;
}

.charts-empty {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* Chart toolbar — on-chart pan/zoom/reset buttons plus an info popover
   describing the hover-only keyboard shortcuts (chart-keyboard.ts). Inserted
   as a sibling right before each chart's own canvas container. */

.chart-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.chart-toolbar button {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  line-height: 1;
}

.chart-toolbar__info {
  position: relative;
}

.chart-toolbar__info-toggle {
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  font-weight: 700;
}

.chart-toolbar__popover {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 10;
  width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--color-shadow);
  padding: 0.65rem 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text);
}

.chart-toolbar__popover p {
  margin: 0 0 0.4rem;
  color: var(--color-text-muted);
}

.chart-toolbar__popover ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.chart-toolbar__popover kbd {
  font-family: ui-monospace, monospace;
  background: var(--color-indigo-soft);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  font-size: 0.75rem;
  margin-right: 0.15rem;
}

/* Session row state — the row for the one session whose files are currently
   shown below the table is marked "Opened"; opening another row or closing
   this one (clicking "Opened" again) clears the mark. */

#sessions tbody tr.session-opened {
  background: var(--color-indigo-soft);
}

#sessions td.session-actions {
  display: flex;
  gap: 0.4rem;
}

/* Brand mark: "STATO" black + "TEST" red, per the manual's wordmark. */

.brand-mark {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  margin: 0;
  color: var(--color-text);
}

.brand-mark .accent {
  color: var(--color-signal);
}

/* App shell */

#app[hidden] {
  display: none;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--color-border);
  position: relative;
  overflow: hidden;
}

/* Restrained nod to the manual's blueprint-line motif — thin indigo lines
   anchored top-right, bleeding off-edge, never a full pattern fill. */
header::after {
  content: "";
  position: absolute;
  top: -20px;
  right: -20px;
  width: 220px;
  height: 120px;
  pointer-events: none;
  background-image: repeating-linear-gradient(
      100deg,
      transparent,
      transparent 22px,
      var(--color-indigo) 22px,
      var(--color-indigo) 23px
    ),
    repeating-linear-gradient(10deg, transparent, transparent 30px, var(--color-indigo) 30px, var(--color-indigo) 31px);
  opacity: 0.12;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.account {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.selector-bar {
  display: flex;
  gap: 1.5rem;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--color-border);
}

.selector-bar select {
  min-width: 220px;
}

main {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 2rem;
  padding: 1.5rem 2rem;
}

aside h2,
section h2 {
  font-size: 1rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

#devices {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#devices li {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
}

#devices label {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.95rem;
  color: var(--color-text);
  cursor: pointer;
}

#devices small {
  color: var(--color-text-muted);
  margin-left: auto;
}

#filters {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
}

th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#files {
  margin-top: 1.5rem;
}

#files pre {
  background: var(--color-indigo-soft);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  main {
    grid-template-columns: 1fr;
  }

  header,
  .selector-bar,
  main {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
