/* ------------------------------------------------------------------ *
 *  Theme tokens: :root provides sentinel-light defaults; each block  *
 *  overrides only color / surface / shadow tokens. Geometry and      *
 *  typography variables are set once in :root and never change.      *
 * ------------------------------------------------------------------ */
:root,
[data-theme="sentinel-light"] {
  color-scheme: light;

  /* Geometry and typography - constant across all themes */
  --radius: 18px;
  --radius-small: 10px;
  --space-1: 0.4rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Page */
  --page-bg:
    radial-gradient(circle at 85% -10%, rgba(39, 95, 158, 0.12), transparent 32rem)
    #f3f6f9;

  /* Surfaces */
  --surface: #ffffff;
  --surface-soft: #f3f6f9;
  --surface-card: #ffffff;
  --line: #dce3ea;
  --shadow: 0 14px 40px rgba(24, 42, 67, 0.09);

  /* Typography */
  --ink: #172235;
  --muted: #647084;

  /* Header */
  --header-bg: #101c2c;
  --header-subtitle: #c8d5e4;
  --header-eyebrow: #83b7ee;

  /* Accent palette */
  --blue: #275f9e;
  --blue-dark: #184774;
  --teal: #168278;
  --green: #267a55;
  --amber: #a45f08;
  --red: #a73f45;
  --navy: #101c2c;

  /* Interactive */
  --focus-ring-color: rgba(39, 95, 158, 0.38);
  --accent-tint: rgba(39, 95, 158, 0.1);

  /* Form controls */
  --input-bg: #ffffff;
  --input-border: #bcc7d3;
  --input-border-file: #9facba;
  --choice-checked-bg: #f1f7fd;

  /* Component surfaces */
  --btn-secondary-bg: #eaf2fa;
  --upload-bg: #edf5f4;
  --tint-note: #f1f8f7;

  /* Validation */
  --error-text: #76292f;
  --error-bg: #fae9eb;

  /* Status badges */
  --badge-idle-text: #4d5b6c;
  --badge-idle-bg: #e8edf2;
  --badge-running-text: #164f82;
  --badge-running-bg: #dfedf9;
  --badge-success-text: #175c40;
  --badge-success-bg: #dcf1e7;
  --badge-danger-text: #7c2930;
  --badge-danger-bg: #f7dfe2;
  --badge-warning-text: #764304;
  --badge-warning-bg: #f8e8cd;

  /* Progress */
  --progress-track-bg: #e4eaf0;

  /* Empty state */
  --empty-border: #bdc8d3;

  /* Select controls */
  --select-bg: #ffffff;
  --select-text: #172235;
  --select-border: #bcc7d3;
  --select-focus: rgba(39, 95, 158, 0.38);
  --select-option-bg: #ffffff;
  --select-option-text: #172235;
  --select-option-selected-bg: #dfedf9;
  --select-option-selected-text: #172235;

  /* Dialog */
  --backdrop: rgba(9, 18, 31, 0.72);
  --dialog-shadow: 0 24px 80px rgba(10, 22, 38, 0.32);
}

[data-theme="command-dark"] {
  color-scheme: dark;

  --page-bg: #0f1923;
  --surface: #152232;
  --surface-soft: #1c2d3e;
  --surface-card: #1a2c3e;
  --line: #263848;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.36);

  --ink: #d4e8f8;
  --muted: #6e8ea8;

  --header-bg: #090f1c;
  --header-subtitle: #8099b2;
  --header-eyebrow: #5a90bc;

  --blue: #4ca8e8;
  --blue-dark: #3a90d8;
  --teal: #22b8a0;
  --green: #2cb880;
  --amber: #c8902a;
  --red: #cc6470;
  --navy: #090f1c;

  --focus-ring-color: rgba(76, 168, 232, 0.55);
  --accent-tint: rgba(76, 168, 232, 0.12);

  --input-bg: #182433;
  --input-border: #2e4255;
  --input-border-file: #2e4255;
  --choice-checked-bg: #142436;

  --btn-secondary-bg: #152030;
  --upload-bg: #112232;
  --tint-note: #0e1e2e;
  --error-text: #e88090;
  --error-bg: #280f14;

  --badge-idle-text: #6e88a0;
  --badge-idle-bg: #1c2a38;
  --badge-running-text: #4ca8e8;
  --badge-running-bg: #0c1e30;
  --badge-success-text: #2cb880;
  --badge-success-bg: #0a201a;
  --badge-danger-text: #e88090;
  --badge-danger-bg: #280f14;
  --badge-warning-text: #c8902a;
  --badge-warning-bg: #201408;

  --progress-track-bg: #1a2c3e;
  --empty-border: #263848;
  --backdrop: rgba(0, 5, 15, 0.86);
  --dialog-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);

  /* Select controls */
  --select-bg: #182433;
  --select-text: #d4e8f8;
  --select-border: #2e4255;
  --select-focus: rgba(76, 168, 232, 0.55);
  --select-option-bg: #152232;
  --select-option-text: #d4e8f8;
  --select-option-selected-bg: #1a3050;
  --select-option-selected-text: #d4e8f8;
}

[data-theme="warm-neutral"] {
  color-scheme: light;

  --page-bg:
    radial-gradient(circle at 75% -5%, rgba(22, 130, 120, 0.07), transparent 26rem)
    #f6f0ea;
  --surface: #fdfaf6;
  --surface-soft: #f5ede4;
  --surface-card: #fdfaf6;
  --line: #ddd0c4;
  --shadow: 0 14px 40px rgba(40, 28, 16, 0.09);

  --ink: #2c221a;
  --muted: #7a6a60;

  --header-bg: #1e1810;
  --header-subtitle: #b8a89e;
  --header-eyebrow: #88bab4;

  --blue: #168278;
  --blue-dark: #0e6860;
  --teal: #168278;
  --green: #267a55;
  --amber: #a45f08;
  --red: #a73f45;
  --navy: #1e1810;

  --focus-ring-color: rgba(22, 130, 120, 0.4);
  --accent-tint: rgba(22, 130, 120, 0.1);

  --input-bg: #fdfaf6;
  --input-border: #c8b8ae;
  --input-border-file: #c8b8ae;
  --choice-checked-bg: #e4f4f2;

  --btn-secondary-bg: #e2f0ee;
  --upload-bg: #e8f0ed;
  --tint-note: #eaf4f2;
  --error-text: #7a2828;
  --error-bg: #f5dedd;

  --badge-idle-text: #5e6060;
  --badge-idle-bg: #e8dfd8;
  --badge-running-text: #1a5068;
  --badge-running-bg: #d8eef5;
  --badge-success-text: #1a5a44;
  --badge-success-bg: #d8f0e8;
  --badge-danger-text: #7a2828;
  --badge-danger-bg: #f5dedd;
  --badge-warning-text: #704020;
  --badge-warning-bg: #f5e8d0;

  --progress-track-bg: #ece4de;
  --empty-border: #c8b8ae;
  --backdrop: rgba(20, 14, 8, 0.72);
  --dialog-shadow: 0 24px 80px rgba(40, 28, 16, 0.28);

  /* Select controls */
  --select-bg: #fdfaf6;
  --select-text: #2c221a;
  --select-border: #c8b8ae;
  --select-focus: rgba(22, 130, 120, 0.4);
  --select-option-bg: #fdfaf6;
  --select-option-text: #2c221a;
  --select-option-selected-bg: #d8eef5;
  --select-option-selected-text: #2c221a;
}

/* ------------------------------------------------------------------ *
 *  Reset and base                                                     *
 * ------------------------------------------------------------------ */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--page-bg);
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="file"],
input[type="radio"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus-ring-color);
  outline-offset: 3px;
}

/* ------------------------------------------------------------------ *
 *  Skip link                                                          *
 * ------------------------------------------------------------------ */
.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 20;
  padding: 0.65rem 1rem;
  color: white;
  background: var(--header-bg);
  border-radius: var(--radius-small);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

/* ------------------------------------------------------------------ *
 *  Site header                                                        *
 * ------------------------------------------------------------------ */
.site-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  padding: 1.4rem clamp(1rem, 4vw, 4rem);
  color: white;
  background: var(--header-bg);
}

.site-header h1,
.section-heading h2,
.status-card h2 {
  margin: 0;
  line-height: 1.15;
}

.site-header h1 {
  font-size: clamp(1.45rem, 3vw, 2rem);
}

.subtitle {
  margin: 0.3rem 0 0;
  color: var(--header-subtitle);
}

.brand-mark {
  width: 3.25rem;
  height: 3.25rem;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  overflow: visible;
}

/* Header right column: local badge + theme control */
.header-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
}

.local-badge {
  padding: 0.55rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: #dceaff;
  font-size: 0.82rem;
  white-space: nowrap;
}

.theme-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-label {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.65);
  white-space: nowrap;
}

.theme-select {
  width: auto;
  min-height: unset;
  padding: 0.3rem 1.6rem 0.3rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.78rem;
  color-scheme: light;
}

[data-theme="command-dark"] .theme-select {
  color-scheme: dark;
}

.theme-select option {
  background: var(--select-option-bg);
  color: var(--select-option-text);
}

.theme-select option:checked {
  background: var(--select-option-selected-bg);
  color: var(--select-option-selected-text);
}

.theme-select:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ *
 *  Eyebrow labels                                                     *
 * ------------------------------------------------------------------ */
.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--blue);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.site-header .eyebrow {
  color: var(--header-eyebrow);
}

/* ------------------------------------------------------------------ *
 *  App shell layout                                                   *
 * ------------------------------------------------------------------ */
.app-shell {
  display: grid;
  grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr) minmax(17rem, 22rem);
  gap: var(--space-4);
  align-items: start;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: var(--space-4);
}

.setup-panel,
.status-card,
.content-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.setup-panel {
  position: sticky;
  top: var(--space-3);
  align-self: start;
  padding: var(--space-4);
}

.results-panel {
  min-width: 0;
}

.preview-panel {
  position: sticky;
  top: var(--space-3);
  align-self: start;
  min-width: 0;
  max-height: calc(100vh - var(--space-3) * 2);
  overflow-y: auto;
}

.status-card,
.content-section {
  padding: clamp(1rem, 2.5vw, 1.75rem);
}

.content-section {
  margin-top: var(--space-4);
  scroll-margin-top: 1rem;
}

.section-heading {
  margin-bottom: var(--space-3);
}

.section-note,
.field-note,
.quiet-text {
  color: var(--muted);
  font-size: 0.88rem;
}

.section-note {
  max-width: 48rem;
  margin: 0.5rem 0 0;
}

.inline-heading,
.status-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

/* ------------------------------------------------------------------ *
 *  Form controls                                                      *
 * ------------------------------------------------------------------ */
fieldset {
  padding: 0;
  border: 0;
}

legend,
.field-group > label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: 0.88rem;
  font-weight: 750;
}

.source-choice {
  display: grid;
  gap: var(--space-2);
  margin: var(--space-4) 0;
}

.choice-card {
  display: flex;
  min-height: 4.6rem;
  align-items: flex-start;
  gap: var(--space-2);
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
}

.choice-card:has(input:checked) {
  border-color: var(--blue);
  background: var(--choice-checked-bg);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.choice-card input {
  margin-top: 0.25rem;
}

.choice-card span {
  display: grid;
}

.choice-card small {
  color: var(--muted);
}

.field-group {
  margin: var(--space-4) 0;
}

select {
  width: 100%;
  min-height: 2.8rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--select-border);
  border-radius: var(--radius-small);
  color: var(--select-text);
  background: var(--select-bg);
}

select:hover:not(:disabled) {
  border-color: var(--select-focus);
}

select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

select option {
  background: var(--select-option-bg);
  color: var(--select-option-text);
}

select option:checked {
  background: var(--select-option-selected-bg);
  color: var(--select-option-selected-text);
}

input[type="text"],
input:not([type]) {
  width: 100%;
  min-height: 2.8rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-small);
  color: var(--ink);
  background: var(--input-bg);
}

input[type="file"] {
  width: 100%;
  padding: 0.7rem;
  border: 1px dashed var(--input-border-file);
  border-radius: var(--radius-small);
  background: var(--surface-soft);
}

.field-note {
  margin: 0.4rem 0 0;
}

.upload-selection {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: 0.7rem;
  border-radius: var(--radius-small);
  background: var(--upload-bg);
}

.upload-selection div {
  display: grid;
  min-width: 0;
}

.upload-selection strong {
  overflow-wrap: anywhere;
}

.upload-selection span {
  color: var(--muted);
  font-size: 0.82rem;
}

/* ------------------------------------------------------------------ *
 *  Buttons                                                            *
 * ------------------------------------------------------------------ */
.primary-button,
.secondary-button,
.text-button,
.icon-button,
.filter-group button,
.evidence-button {
  min-height: 2.75rem;
  border: 0;
  border-radius: var(--radius-small);
  font-weight: 750;
}

.primary-button {
  width: 100%;
  padding: 0.7rem 1rem;
  color: white;
  background: var(--blue);
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.secondary-button,
.evidence-button {
  padding: 0.55rem 0.85rem;
  color: var(--blue-dark);
  background: var(--btn-secondary-bg);
}

.text-button,
.icon-button {
  padding: 0.45rem 0.65rem;
  color: var(--blue-dark);
  background: transparent;
}

/* ------------------------------------------------------------------ *
 *  Privacy note                                                       *
 * ------------------------------------------------------------------ */
.privacy-note {
  margin-top: var(--space-4);
  padding: var(--space-3);
  border-left: 3px solid var(--teal);
  color: var(--muted);
  background: var(--tint-note);
  font-size: 0.85rem;
}

.privacy-note strong {
  color: var(--ink);
}

.privacy-note p {
  margin: 0.25rem 0 0;
}

/* ------------------------------------------------------------------ *
 *  Validation                                                         *
 * ------------------------------------------------------------------ */
.form-error {
  padding: 0.75rem;
  border-radius: var(--radius-small);
  color: var(--error-text);
  background: var(--error-bg);
}

/* ------------------------------------------------------------------ *
 *  Status badges and pills                                            *
 * ------------------------------------------------------------------ */
.status-badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-idle,
.pill {
  color: var(--badge-idle-text);
  background: var(--badge-idle-bg);
}

.status-queued,
.status-running {
  color: var(--badge-running-text);
  background: var(--badge-running-bg);
}

.status-completed {
  color: var(--badge-success-text);
  background: var(--badge-success-bg);
}

.status-failed,
.severity-critical,
.severity-high {
  color: var(--badge-danger-text);
  background: var(--badge-danger-bg);
}

.severity-warning {
  color: var(--badge-warning-text);
  background: var(--badge-warning-bg);
}

/* ------------------------------------------------------------------ *
 *  Status card                                                        *
 * ------------------------------------------------------------------ */
.status-message {
  min-height: 1.5rem;
  color: var(--muted);
}

.progress-track {
  height: 0.72rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--progress-track-bg);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--teal));
  transition: width 300ms ease;
}

.progress-track.indeterminate .progress-bar {
  width: 35%;
  animation: indeterminate 1.2s ease-in-out infinite alternate;
}

@keyframes indeterminate {
  from { transform: translateX(-70%); }
  to { transform: translateX(260%); }
}

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.2rem;
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.job-meta strong,
.job-meta code {
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ *
 *  Summary grid                                                       *
 * ------------------------------------------------------------------ */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(7rem, 1fr));
  gap: var(--space-2);
}

.metric-card {
  display: grid;
  min-height: 6rem;
  align-content: space-between;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.metric-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

.metric-card strong {
  font-size: 1.7rem;
}

.empty-metric {
  opacity: 0.65;
}

/* ------------------------------------------------------------------ *
 *  Result navigation                                                  *
 * ------------------------------------------------------------------ */
.result-nav {
  display: flex;
  gap: var(--space-1);
  margin: var(--space-4) 0 0;
  overflow-x: auto;
}

.result-nav a {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--blue-dark);
  background: var(--surface-card);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ *
 *  Filter group                                                       *
 * ------------------------------------------------------------------ */
.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.filter-group button {
  min-height: 2.75rem;
  padding: 0.35rem 0.65rem;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.78rem;
}

.filter-group button[aria-pressed="true"] {
  color: white;
  background: var(--blue);
}

/* ------------------------------------------------------------------ *
 *  Record cards                                                       *
 * ------------------------------------------------------------------ */
.record-list,
.lifecycle-grid {
  display: grid;
  gap: var(--space-2);
}

.record-card,
.lifecycle-card {
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-card);
}

.record-card {
  display: grid;
  grid-template-columns: 5rem minmax(0, 1fr);
  gap: var(--space-3);
}

.record-time {
  color: var(--blue-dark);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.record-time-seekable {
  cursor: pointer;
  text-decoration: underline dotted;
  border-radius: 4px;
  padding: 0 2px;
}

.record-time-seekable:hover,
.record-time-seekable:focus-visible {
  background: var(--accent-tint);
  outline: 2px solid var(--blue);
}

.record-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.record-card h3,
.lifecycle-card h3 {
  margin: 0;
  font-size: 1rem;
}

.record-message {
  margin: 0.3rem 0 0;
}

.record-meta,
.evidence-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.7rem;
  margin-top: 0.65rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.record-meta span {
  overflow-wrap: anywhere;
}

.record-card.behavior-emphasis,
.record-card.alert-emphasis {
  border-left: 4px solid var(--amber);
}

/* ------------------------------------------------------------------ *
 *  Lifecycle grid                                                     *
 * ------------------------------------------------------------------ */
.lifecycle-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.lifecycle-card dl,
.metadata-list {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.4rem 0.8rem;
  margin: 0.8rem 0 0;
  font-size: 0.85rem;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ *
 *  Empty state                                                        *
 * ------------------------------------------------------------------ */
.empty-state {
  width: 100%;
  margin: 0;
  padding: 1.2rem;
  border: 1px dashed var(--empty-border);
  border-radius: 14px;
  color: var(--muted);
  background: var(--surface-soft);
  text-align: center;
}

/* ------------------------------------------------------------------ *
 *  Evidence dialog                                                    *
 * ------------------------------------------------------------------ */
dialog {
  width: min(62rem, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--dialog-shadow);
}

dialog::backdrop {
  background: var(--backdrop);
}

.dialog-shell {
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: var(--space-4);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.dialog-header h2 {
  margin: 0;
}

#evidence-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 65vh;
  margin: var(--space-3) auto;
  border-radius: var(--radius-small);
  object-fit: contain;
  background: var(--surface-soft);
}

.evidence-loading {
  min-height: 16rem;
  display: grid;
  place-items: center;
  margin-top: var(--space-3);
  border-radius: var(--radius-small);
  color: var(--muted);
  background: var(--surface-soft);
}

/* ------------------------------------------------------------------ *
 *  Noscript message                                                   *
 * ------------------------------------------------------------------ */
.noscript-message {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  padding: 1rem;
  color: white;
  background: var(--red);
  text-align: center;
}

/* ------------------------------------------------------------------ *
 *  Source preview panel                                               *
 * ------------------------------------------------------------------ */
.source-preview {
  width: 100%;
  margin: 0;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.source-preview figcaption {
  margin-bottom: var(--space-2);
}

.preview-video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 50vh;
  border-radius: var(--radius-small);
  background: var(--navy);
  object-fit: contain;
}

.preview-caption {
  margin: var(--space-2) 0 0;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.45;
}

/* ------------------------------------------------------------------ *
 *  Utility                                                            *
 * ------------------------------------------------------------------ */
[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------ *
 *  Responsive: 1050px                                                 *
 * ------------------------------------------------------------------ */
@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .setup-panel,
  .preview-panel {
    position: static;
  }

  .source-choice {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(7rem, 1fr));
  }
}

/* At 768px and below: stack source preview above results in single-column layout. */
@media (max-width: 768px) {
  .preview-panel {
    order: -1;
  }

  .preview-video {
    max-height: 40vh;
  }
}

/* ------------------------------------------------------------------ *
 *  Responsive: 720px (header collapses, app-shell narrows)           *
 * ------------------------------------------------------------------ */
@media (max-width: 720px) {
  .site-header {
    grid-template-columns: auto minmax(0, 1fr);
    padding: 1rem;
  }

  .header-aside {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-self: start;
    flex-wrap: wrap;
  }

  .app-shell {
    padding: 0.75rem;
  }

  .source-choice,
  .lifecycle-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inline-heading,
  .status-topline {
    display: grid;
  }

  .record-card {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .record-title-row {
    display: grid;
  }
}

/* ------------------------------------------------------------------ *
 *  Responsive: 420px                                                  *
 * ------------------------------------------------------------------ */
@media (max-width: 420px) {
  .brand-mark {
    width: 2.75rem;
    height: 2.75rem;
  }

  .subtitle {
    font-size: 0.88rem;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .metric-card {
    min-height: 5.2rem;
  }

  .job-meta {
    display: grid;
  }
}

/* ------------------------------------------------------------------ *
 *  Reduced motion                                                     *
 * ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ------------------------------------------------------------------ *
 *  Settings panel                                                     *
 * ------------------------------------------------------------------ */
.settings-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.settings-status {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: var(--space-1);
  min-height: 0;
}

.settings-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 var(--space-1);
}

.settings-lock {
  font-size: 0.85rem;
  color: var(--badge-danger-text);
  margin: var(--space-2) 0 0;
}

.preset-select-group {
  margin-bottom: var(--space-3);
}

.settings-tabs {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-3);
  border-bottom: 1px solid var(--line);
}

.settings-tab {
  min-height: 2.75rem;
  padding: 0.55rem 0.8rem;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  background: transparent;
  font-weight: 750;
}

.settings-tab[aria-selected="true"] {
  border-bottom-color: var(--blue);
  color: var(--blue-dark);
}

.settings-tab-panel {
  padding-top: var(--space-4);
}

.preset-select {
  display: block;
  width: 100%;
  margin-top: var(--space-1);
  padding: 0.45em 0.75em;
  font-size: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--input-bg, var(--surface));
  color: var(--text);
  cursor: pointer;
}

.preset-select:disabled {
  opacity: 0.55;
  cursor: default;
}

.preset-helper {
  font-size: 0.85rem;
  color: var(--muted);
  margin: var(--space-1) 0 0;
  min-height: 1.2em;
}

.preset-apply-btn {
  margin-bottom: var(--space-2);
}

.settings-note {
  font-size: 0.78rem;
  color: var(--muted);
  opacity: 0.75;
  text-align: center;
  margin: 0 0 var(--space-1);
}

/* ------------------------------------------------------------------ *
 *  Object chip (on event/behavior cards)                             *
 * ------------------------------------------------------------------ */
.object-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.1em 0.55em;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: var(--radius-small, 4px);
  background: var(--badge-idle-bg);
  color: var(--badge-idle-text);
  white-space: nowrap;
  cursor: default;
}

/* ------------------------------------------------------------------ *
 *  Lifecycle card head row                                            *
 * ------------------------------------------------------------------ */
.lifecycle-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: var(--space-2);
}

.lifecycle-head-row h3 {
  margin: 0;
}

.lifecycle-object-id {
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
}

/* ------------------------------------------------------------------ *
 *  Continuity summary                                                 *
 * ------------------------------------------------------------------ */
.continuity-summary {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.continuity-stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 5.5rem;
}

.continuity-label {
  font-size: 0.75rem;
  color: var(--muted);
}

.continuity-value {
  font-size: 1.25rem;
}

/* ------------------------------------------------------------------ *
 *  Object filter group                                                *
 * ------------------------------------------------------------------ */
.event-filter-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.object-filter-group {
  display: grid;
  grid-template-columns: auto minmax(9rem, 13rem);
  align-items: center;
  gap: var(--space-2);
}

.object-filter-group label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  white-space: nowrap;
}

.object-filter-group select {
  min-height: 2.4rem;
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
  font-size: 0.85rem;
}

/* Gear / settings trigger button */
.setup-heading-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.settings-trigger {
  flex-shrink: 0;
  /* Override the global min-height so the icon sits tight to the eyebrow. */
  min-height: unset;
  padding: 0.3rem;
  /* Pull up to visually align with the eyebrow "NEW ANALYSIS" label. */
  margin-top: -0.45rem;
  opacity: 0.65;
  transition: opacity 0.15s;
}

.settings-trigger:hover:not(:disabled) {
  opacity: 1;
}

.settings-trigger:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Settings dialog overrides */
#settings-dialog {
  width: min(48rem, calc(100% - 2rem));
}

/* ------------------------------------------------------------------ *
 *  AI Observations                                                    *
 * ------------------------------------------------------------------ */
.observation-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0;
}

.observation-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(128, 128, 128, 0.12);
}

.observation-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.observation-type-label {
  flex-shrink: 0;
  min-width: 5.25rem;
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue);
  text-align: right;
}

.observation-message {
  margin: 0;
  color: var(--ink);
  line-height: 1.45;
}

.alert-decision-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0;
}

.alert-decision-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(128, 128, 128, 0.12);
}

.alert-decision-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.alert-decision-badge {
  flex-shrink: 0;
  min-width: 7rem;
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-align: right;
}

.alert-decision-message {
  margin: 0;
  color: var(--ink);
  line-height: 1.45;
}

/* ---- Visual Analyzer provider cards ---- */
.va-provider-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.va-provider-card {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  padding: var(--space-2) var(--space-3);
}

.va-provider-unavailable {
  opacity: 0.75;
}

.va-provider-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.va-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 99px;
  white-space: nowrap;
}

.va-badge-available {
  background: rgba(38, 122, 85, 0.14);
  color: var(--green);
}

.va-badge-unavailable {
  background: rgba(167, 63, 69, 0.12);
  color: var(--red);
}

.va-reason {
  margin: var(--space-1) 0;
  font-size: 0.82rem;
  color: var(--red);
}

.va-meta-list {
  list-style: none;
  padding: 0;
  margin: var(--space-1) 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.va-meta-list li + li {
  margin-top: 0.15rem;
}

.va-caps {
  margin: var(--space-1) 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ---- Latency Metrics section ---- */
.latency-metrics-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.latency-summary-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.latency-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  white-space: nowrap;
}

.latency-badge-ok {
  background: rgba(38, 122, 85, 0.14);
  color: var(--green);
}

.latency-badge-over {
  background: rgba(167, 63, 69, 0.12);
  color: var(--red);
}

.latency-phases {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
  word-break: break-word;
}

.latency-phases-excluded {
  font-style: italic;
}

.latency-phase-table {
  border-collapse: collapse;
  font-size: 0.82rem;
  width: 100%;
  max-width: 28rem;
}

.latency-phase-table td {
  padding: 0.15rem 0.5rem 0.15rem 0;
  color: var(--ink);
  vertical-align: top;
}

.latency-phase-time {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
