:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #1f2937;
  --muted: #667085;
  --line: #d7dde7;
  --accent: #2276d2;
  --danger: #b42318;
  --ok: #047857;
  --shadow: 0 1px 2px rgb(15 23 42 / 8%);
}

body.dark {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #172033;
  --text: #e5e7eb;
  --muted: #a8b3c7;
  --line: #31415d;
  --accent: #72b7ff;
  --danger: #fca5a5;
  --ok: #34d399;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 0;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button {
  font: inherit;
}

.monitor-app {
  height: 100vh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

header {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mark {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex: 0 0 auto;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.2;
}

h2 {
  font-size: 14px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.ghost {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-2);
  color: var(--text);
  padding: 2px 7px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.ghost:hover {
  border-color: var(--accent);
}

.ghost:disabled {
  cursor: default;
  opacity: 0.6;
}

.header-icon-button {
  width: 28px;
  height: 24px;
  min-height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  flex: 0 0 auto;
}

.header-action-icon {
  width: 17px;
  height: 17px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.resume-icon,
.theme-icon-sun {
  display: none;
}

#pauseBtn.paused .pause-icon,
body.dark .theme-icon-moon {
  display: none;
}

#pauseBtn.paused .resume-icon,
body.dark .theme-icon-sun {
  display: block;
}

.danger-action {
  min-height: 24px;
  border: 1px solid var(--danger);
  border-radius: 5px;
  background: var(--danger);
  color: white;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

body.dark .danger-action {
  color: #111827;
}

.stop-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(15 23 42 / 40%);
  backdrop-filter: blur(2px);
}

.stop-confirm-dialog {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 12px 40px rgb(15 23 42 / 24%);
  color: var(--text);
  overflow: hidden;
}

.stop-confirm-content {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.stop-confirm-icon {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.stop-confirm-content p {
  margin: 0;
  font-size: 15px;
}

.stop-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
}

.shutdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(15 23 42 / 62%);
  backdrop-filter: blur(2px);
}

.shutdown-message {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 40px rgb(15 23 42 / 24%);
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 18px;
  text-align: left;
}

.shutdown-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
  display: block;
}

.shutdown-icon-fallback {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--panel);
}

.shutdown-icon-fallback::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent);
  box-shadow: inset 0 0 0 6px color-mix(in srgb, var(--panel) 82%, transparent);
}

.shutdown-message h1 {
  margin: 0 0 8px;
  font-size: 18px;
}

.shutdown-message p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

main {
  min-width: 0;
  min-height: 0;
  padding: 10px 12px 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.operations-grid {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(260px, 1.15fr) minmax(240px, 0.85fr) minmax(280px, 1fr);
  gap: 10px;
}

.status-panel {
  min-height: 132px;
  display: grid;
  grid-template-rows: repeat(4, auto);
  align-content: start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
  box-shadow: var(--shadow);
}

.server-panel {
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
}

.server-panel .diagnostic-line {
  grid-row: 5;
  align-self: end;
}

.status-panel.active {
  border-color: var(--accent);
}

.status-panel.warning {
  border-color: #d97706;
}

.status-panel.error {
  border-color: var(--danger);
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.state-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 999px;
  padding: 1px 8px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 11px;
  white-space: nowrap;
}

.status-panel.active .state-pill {
  border-color: var(--accent);
  color: var(--accent);
}

.status-panel.warning .state-pill {
  border-color: #d97706;
  color: #b45309;
}

.status-panel.error .state-pill {
  border-color: var(--danger);
  color: var(--danger);
}

.primary-metric {
  display: grid;
  align-content: center;
  gap: 3px;
}

.primary-metric span,
.metric-grid span,
.action-stack span,
.slowest-action-row span {
  color: var(--muted);
  font-size: 12px;
}

.primary-metric strong {
  font-size: 32px;
  line-height: 1;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.metric-grid.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-grid div,
.action-stack div,
.slowest-action-row {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.metric-grid strong,
.action-stack strong,
.slowest-action-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  line-height: 1.1;
}

.metric-grid small,
.action-stack small,
.diagnostic-line,
.heartbeat-line {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-stack {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.performance-content {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(165px, 1fr) minmax(0, max-content);
  gap: 10px;
  align-items: start;
}

.performance-content .action-stack strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slowest-action-row strong {
  overflow: visible;
  text-overflow: clip;
}

.performance-meta-stack {
  min-width: 0;
  display: grid;
  justify-items: end;
  gap: 7px;
  text-align: right;
}

.diagnostic-line span {
  color: var(--text);
  font-weight: 650;
}

.heartbeat-line.error {
  color: var(--danger);
}

.status {
  flex: 0 0 auto;
  min-height: 14px;
  color: var(--muted);
  font-size: 12px;
}

.status:empty {
  display: none;
}

.status.error {
  color: var(--danger);
}

.panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clients-panel {
  flex: 0 0 auto;
}

.lucidum-servers-panel {
  flex: 0 0 auto;
}

.model-operations-panel {
  flex: 0 0 auto;
}

.model-operations-panel .section-header > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.operations-header-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.operations-header-actions .meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operations-content {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 8px;
}

.operations-table-wrap,
.operation-timeline-wrap {
  max-height: min(170px, 22vh);
  border-radius: 7px;
}

.model-operations-panel table {
  font-size: 11px;
}

.model-operations-panel th,
.model-operations-panel td {
  padding: 4px 7px;
  line-height: 1.2;
  white-space: nowrap;
}

.operation-row {
  cursor: pointer;
}

.operation-row:hover td,
.operation-row.selected td {
  background: color-mix(in srgb, var(--accent) 9%, var(--panel));
}

.operation-phase-cell {
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.operation-detail {
  min-width: 0;
  min-height: 72px;
}

.operation-detail-empty {
  height: 100%;
  min-height: 72px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 12px;
}

.operation-detail-empty[hidden],
.operation-detail [hidden] {
  display: none !important;
}

.operation-detail-heading {
  min-width: 0;
  min-height: 23px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 5px;
}

.operation-detail-heading strong,
.operation-detail-heading .meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-metadata {
  min-height: 17px;
  padding: 0 2px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lucidum-servers-table-wrap {
  max-height: min(135px, 20vh);
}

.lucidum-servers-panel table {
  font-size: 11px;
}

.lucidum-servers-panel th,
.lucidum-servers-panel td {
  padding: 3px 8px;
  line-height: 1.2;
  vertical-align: middle;
}

.current-server-row td {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.server-title,
.server-listeners {
  white-space: nowrap;
}

.server-link {
  color: var(--accent);
  text-decoration: none;
}

.server-link:hover {
  text-decoration: underline;
}

.server-stop-button {
  width: 16px;
  height: 16px;
  min-height: 16px;
  display: grid;
  place-items: center;
  border: 1px solid var(--danger);
  border-radius: 4px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 10px;
  font-weight: 750;
  line-height: 1;
  padding: 0;
}

.server-stop-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.recent-activity-panel {
  flex: 1 1 auto;
  min-height: 0;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.table-wrap {
  max-height: min(320px, 40vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.clients-table-wrap {
  max-height: min(170px, 24vh);
}

.recent-activity-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.clients-panel th,
.clients-panel td {
  padding: 4px 9px;
  line-height: 1.2;
}

.recent-activity-panel table {
  font-size: 11px;
}

.recent-activity-panel th,
.recent-activity-panel td {
  padding: 4px 8px;
  line-height: 1.2;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 700;
}

td {
  max-width: 280px;
  overflow-wrap: anywhere;
}

.client-browser {
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 22px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 16px;
  border-radius: 999px;
  padding: 0 6px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 11px;
  line-height: 14px;
  white-space: nowrap;
}

.pill.active,
.pill.ok {
  color: var(--ok);
}

.pill.error {
  color: var(--danger);
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .monitor-app {
    height: auto;
    min-height: 100vh;
  }

  .operations-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .performance-content {
    grid-template-columns: minmax(0, 1fr);
  }

  .performance-meta-stack {
    justify-items: start;
    text-align: left;
  }

  .operations-content {
    grid-template-columns: minmax(0, 1fr);
  }

  .operations-header-actions {
    align-items: flex-end;
    flex-direction: column;
    gap: 4px;
  }

  main {
    min-height: auto;
    overflow: visible;
  }

  .recent-activity-table-wrap {
    max-height: min(320px, 45vh);
  }

  .primary-metric strong {
    font-size: 32px;
  }
}
