:root {
  color-scheme: light;
  --primary: #0f5c7f;
  --primary-strong: #0b4661;
  --accent: #93c041;
  --ink: #182230;
  --muted: #667085;
  --faint: #98a2b3;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --success: #079455;
  --success-bg: #ecfdf3;
  --warning: #dc6803;
  --warning-bg: #fffaeb;
  --danger: #d92d20;
  --danger-bg: #fef3f2;
  --info-bg: #eff8ff;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(16 24 40 / .06);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
h1, h2, h3, p, dl, dd { margin: 0; }

.app-shell { min-height: 100vh; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, auto) minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 68px;
  padding: 10px 24px;
  background: rgb(255 255 255 / .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 14px;
  line-height: 1.2;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.top-nav {
  display: inline-flex;
  justify-self: center;
  gap: 4px;
  padding: 4px;
  background: #f2f4f7;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.top-nav button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.top-nav button:hover,
.top-nav button[aria-current="page"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(16 24 40 / .08);
}

.header-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.header-meta span,
.header-meta b,
.panel-count,
.subtle-label {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 800;
}

.header-meta b {
  color: var(--success);
  background: var(--success-bg);
  border-color: rgb(0 143 122 / .22);
}

.page {
  width: min(1480px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.page-title {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(520px, .95fr);
  gap: 20px;
  align-items: end;
  margin-bottom: 18px;
}

.view-intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -4px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.view-intro strong {
  display: block;
  font-size: 14px;
}

.view-intro span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.view-panel[hidden] {
  display: none !important;
}

.eyebrow {
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.page-title h1 {
  margin-top: 4px;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.page-title p:not(.eyebrow) {
  margin-top: 8px;
  max-width: 720px;
  color: var(--muted);
  font-size: 15px;
}

.quick-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  min-height: 82px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat span {
  display: block;
  color: var(--faint);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 9px;
  font-size: 28px;
  line-height: 1;
}

.stat.attention strong { color: var(--danger); }
.stat.success strong { color: var(--success); }
.stat.waiting strong { color: var(--primary); }
.stat.missing strong { color: var(--warning); }

.operations-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  margin-bottom: 16px;
}

body[data-view="attention"] .operations-grid {
  grid-template-columns: minmax(0, 1fr) 340px;
}

body[data-view="attention"] .group-board,
body[data-view="engine"] .group-board,
body[data-view="runs"] .group-board {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, .75fr);
  gap: 16px;
  margin-top: 16px;
}

body[data-view="engine"] .two-column {
  grid-template-columns: minmax(0, 1fr);
}

body[data-view="engine"] .two-column .panel:last-child {
  display: none;
}

body[data-view="groups"] .two-column {
  grid-template-columns: minmax(0, 1fr);
}

body[data-view="groups"] .two-column .panel:first-child {
  display: none;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin-top: 2px;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel-count,
.subtle-label {
  color: var(--muted);
  background: var(--surface-soft);
}

.attention-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.attention-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: #fff;
}

.attention-row.severity-failed { border-left-color: var(--danger); }
.attention-row.severity-missing { border-left-color: var(--warning); }

.row-main h3 {
  font-size: 14px;
  line-height: 1.25;
}

.row-main p {
  margin-top: 3px;
  color: var(--muted);
}

.row-main small,
.today-row small,
.timeline-row small {
  display: block;
  color: var(--faint);
  font-size: 12px;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.row-actions a,
.row-actions button {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.row-actions a {
  color: var(--primary-strong);
  border-color: rgb(15 92 127 / .28);
}

.row-actions button:disabled {
  color: var(--faint);
  cursor: not-allowed;
}

.status-chip {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--info-bg);
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-chip.failed,
.status-chip.failure { background: var(--danger-bg); color: #b42318; }
.status-chip.missing { background: var(--warning-bg); color: #b54708; }
.status-chip.success { background: var(--success-bg); color: #067647; }
.status-chip.started { background: var(--info-bg); color: var(--primary-strong); }

.today-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.today-row,
.timeline-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.today-row:last-child,
.timeline-row:last-child { border-bottom: 0; }

.today-row strong,
.timeline-row strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}

.dot.success { background: var(--success); }
.dot.waiting,
.dot.started { background: var(--primary); }
.dot.missing { background: var(--warning); }
.dot.failed { background: var(--danger); }

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

.group-card {
  min-height: 174px;
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-top-width: 4px;
  border-radius: var(--radius);
}

.group-card.health-healthy { border-top-color: var(--success); }
.group-card.health-attention { border-top-color: var(--warning); }
.group-card.health-failed { border-top-color: var(--danger); }

.group-card header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.group-card header strong { font-size: 24px; }
.group-card header span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.group-card dl {
  display: grid;
  gap: 9px;
}

.group-card dt {
  color: var(--faint);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.group-card dd {
  margin-top: 2px;
  font-weight: 750;
  line-height: 1.25;
}

.group-card footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.group-card footer span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 7px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.table-wrap,
.runs-table-wrap {
  overflow-x: auto;
}

.matrix,
.runs-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

.matrix th,
.matrix td,
.runs-table th,
.runs-table td {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

.matrix thead th,
.runs-table thead th {
  background: var(--surface-soft);
  color: var(--faint);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.matrix th:not(:first-child),
.matrix td:not(:first-child) {
  width: 64px;
  text-align: center;
}

.matrix tbody tr:hover,
.runs-table tbody tr:hover {
  background: rgb(15 92 127 / .045);
}

.matrix-status {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--line-strong);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.matrix-status.success { background: var(--success); }
.matrix-status.waiting { background: var(--primary); }
.matrix-status.waiting_event,
.matrix-status.waiting_person,
.matrix-status.waiting_time,
.matrix-status.scheduled,
.matrix-status.running { background: var(--primary); }
.matrix-status.no_action,
.matrix-status.inactive,
.matrix-status.blocked { background: #71717a; }
.matrix-status.missing { background: var(--warning); }
.matrix-status.failed { background: var(--danger); }
.matrix-status.not_applicable { background: #a1a1aa; }

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

.journey-card,
.stream-card,
.engine-group {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.journey-card > header {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.journey-card > header > span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 900;
}

.journey-card h3,
.engine-group h3 {
  font-size: 15px;
  line-height: 1.2;
}

.journey-card p,
.stream-card p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.journey-rows,
.engine-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.journey-row,
.engine-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.engine-row {
  grid-template-columns: 124px minmax(0, 1fr);
}

.journey-row strong,
.engine-row strong,
.stream-card strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
}

.journey-row small,
.engine-row small {
  display: block;
  margin-top: 2px;
  color: var(--faint);
  font-size: 12px;
}

.journey-row b {
  min-width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--info-bg);
  color: var(--primary-strong);
  font-size: 12px;
}

.mode-pill {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--info-bg);
  color: var(--primary-strong);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.mode-pill.scheduled_once { background: var(--warning-bg); color: #b54708; }
.mode-pill.scheduled_check { background: #f2f4f8; color: #334155; }
.mode-pill.event_driven { background: var(--success-bg); color: #067647; }
.mode-pill.state_driven { background: #eef4ff; color: #3538cd; }
.mode-pill.manual { background: #f9f5ff; color: #6941c6; }

.stream-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.family-list {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.family-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.family-section > header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.family-section h3 {
  font-size: 14px;
  line-height: 1.25;
}

.family-section > header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.family-table {
  display: grid;
}

.family-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 132px minmax(220px, 1.2fr) minmax(130px, .6fr);
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.family-row:first-child {
  border-top: 0;
}

.family-row:hover {
  background: rgb(15 92 127 / .035);
}

.family-row strong {
  font-size: 13px;
  line-height: 1.25;
}

.family-row small {
  color: var(--muted);
  font-size: 12px;
}

.stream-card header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.stream-card header span {
  color: var(--faint);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.stream-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stream-card dt {
  color: var(--faint);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.stream-card dd {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 800;
}

.timeline-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  padding: 12px 16px 16px;
}

.timeline-group {
  min-width: 0;
}

.timeline-group h3 {
  margin-bottom: 4px;
  font-size: 14px;
}

.runs-table {
  min-width: 960px;
  font-size: 13px;
}

.runs-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.error-text { color: #b42318; }
.empty-cell {
  color: var(--muted);
  text-align: center !important;
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
}

.empty-state strong { color: var(--ink); }
.muted {
  color: var(--muted);
  padding: 12px;
}

@media (max-width: 1120px) {
  .app-header {
    grid-template-columns: 1fr auto;
  }

  .top-nav {
    grid-column: 1 / -1;
    justify-self: stretch;
    overflow-x: auto;
  }

  .page-title,
  .operations-grid,
  .two-column {
    grid-template-columns: 1fr;
  }

  .quick-status,
  .group-board,
  .journey-grid,
  .stream-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-header {
    padding: 10px 14px;
  }

  .header-meta {
    justify-content: flex-start;
  }

  .page {
    width: calc(100% - 24px);
    padding-top: 18px;
  }

  .page-title h1 {
    font-size: 25px;
  }

  .quick-status,
  .group-board,
  .timeline-list,
  .journey-grid,
  .stream-grid {
    grid-template-columns: 1fr;
  }

  .journey-row,
  .engine-row,
  .family-row {
    grid-template-columns: 1fr;
  }

  .attention-row {
    grid-template-columns: 1fr;
  }

  .row-actions {
    justify-content: flex-start;
  }
}
