:root {
  color-scheme: light;
  font-family: Inter, "Noto Sans SC", "Segoe UI", "Microsoft YaHei", ui-sans-serif, system-ui, sans-serif;
  font-synthesis: none;
  --background: #f7f7f8;
  --foreground: #18181b;
  --card: #ffffff;
  --secondary: #f0f0f1;
  --muted: #f1f1f2;
  --muted-foreground: #6b6b72;
  --border: #dedee2;
  --border-strong: #c9c9cf;
  --primary: #18181b;
  --primary-foreground: #ffffff;
  --success: #15803d;
  --warning: #b26a00;
  --danger: #dc2626;
  --info: #2563eb;
  --ring: #18181b;
  --header-background: rgb(255 255 255 / 0.92);
  --status-neutral: #a1a1aa;
  --control-foreground: #3f3f46;
  --primary-hover: #303034;
  --toggle-track-background: #d4d4d8;
  --toggle-knob-background: #ffffff;
  --shadow-color: rgb(24 24 27 / 0.22);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #101012;
  --foreground: #f4f4f5;
  --card: #18181b;
  --secondary: #242427;
  --muted: #202024;
  --muted-foreground: #a1a1aa;
  --border: #303034;
  --border-strong: #45454b;
  --primary: #ffffff;
  --primary-foreground: #111113;
  --success: #4ade80;
  --warning: #facc15;
  --danger: #f87171;
  --info: #60a5fa;
  --ring: #e4e4e7;
  --header-background: rgb(24 24 27 / 0.92);
  --status-neutral: #71717a;
  --control-foreground: #d4d4d8;
  --primary-hover: #e4e4e7;
  --toggle-track-background: #45454b;
  --toggle-knob-background: #f4f4f5;
  --shadow-color: rgb(0 0 0 / 0.48);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--background);
  scrollbar-gutter: stable;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  text-rendering: optimizeLegibility;
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--foreground);
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--secondary);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

h1,
h2,
p {
  margin: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: var(--header-background);
  backdrop-filter: blur(12px);
}

.app-header-inner {
  display: flex;
  width: min(1120px, 100%);
  min-height: 64px;
  margin: 0 auto;
  padding: 12px 24px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-lockup {
  min-width: 0;
}

.brand-copy {
  min-width: 0;
}

.brand-copy strong {
  display: block;
  overflow: hidden;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-name-line {
  display: inline;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
}

.connection-status {
  display: inline-flex;
  min-height: 34px;
  padding: 0 10px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--secondary);
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-indicator {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--status-neutral);
}

.connection-status[data-state="connecting"] {
  border-color: color-mix(in srgb, var(--warning) 22%, transparent);
  background: color-mix(in srgb, var(--warning) 8%, transparent);
  color: var(--warning);
}

.connection-status[data-state="connecting"] .status-indicator {
  background: var(--warning);
}

.connection-status[data-state="online"] {
  border-color: color-mix(in srgb, var(--success) 20%, transparent);
  background: color-mix(in srgb, var(--success) 8%, transparent);
  color: var(--success);
}

.connection-status[data-state="online"] .status-indicator {
  background: var(--success);
}

.connection-status[data-state="error"] {
  border-color: color-mix(in srgb, var(--danger) 20%, transparent);
  background: color-mix(in srgb, var(--danger) 7%, transparent);
  color: var(--danger);
}

.connection-status[data-state="error"] .status-indicator {
  background: var(--danger);
}

.app-main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px 24px 40px;
}

.theme-segmented {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 3px;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--secondary);
}

.theme-segmented button {
  display: inline-grid;
  width: 32px;
  min-height: 28px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 600;
}

.theme-segmented svg {
  width: 15px;
  height: 15px;
}

.theme-segmented button:hover:not(:disabled) {
  border-color: transparent;
  background: color-mix(in srgb, var(--card) 65%, transparent);
}

.theme-segmented button[aria-pressed="true"] {
  background: var(--card);
  box-shadow: 0 1px 2px var(--shadow-color);
  color: var(--foreground);
}

.panel,
.metric-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.connection-panel {
  padding: 20px;
}

.panel-header {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-header h2 {
  font-size: 15px;
  font-weight: 650;
}

#connection-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.key-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 7px;
  color: var(--control-foreground);
  font-size: 13px;
  font-weight: 600;
}

.key-input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.key-input-wrap input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-right: 0;
  border-radius: 6px 0 0 6px;
  background: var(--card);
  color: var(--foreground);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.key-input-wrap:focus-within input,
.key-input-wrap:focus-within .input-action {
  border-color: var(--ring);
}

.key-input-wrap:focus-within {
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--ring);
}

.key-input-wrap input:focus-visible,
.input-action:focus-visible {
  outline: none;
}

.input-action {
  height: 40px;
  border-color: var(--border-strong);
  border-radius: 0 6px 6px 0;
  background: var(--secondary);
  font-size: 12px;
  font-weight: 600;
}

.connection-actions {
  display: flex;
  gap: 8px;
}

.connection-actions button {
  min-width: 82px;
  height: 40px;
}

.primary-button {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 600;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.outline-button {
  background: var(--card);
  font-weight: 600;
}

.connection-options {
  display: flex;
  grid-column: 1 / -1;
  min-height: 30px;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 22px;
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--control-foreground);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  user-select: none;
}

.keepalive-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--control-foreground);
  font-size: 12px;
  font-weight: 500;
}

.keepalive-control select {
  min-width: 104px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--card);
  color: var(--foreground);
  font: inherit;
  outline: none;
}

.keepalive-control select:focus-visible {
  border-color: var(--ring);
  box-shadow: 0 0 0 1px var(--ring);
}

.keepalive-control select:disabled {
  cursor: wait;
  opacity: 0.58;
}

.toggle-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.toggle-track {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  flex: 0 0 auto;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--toggle-track-background);
  transition: background-color 150ms ease, border-color 150ms ease;
}

.toggle-track::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--toggle-knob-background);
  box-shadow: 0 1px 2px var(--shadow-color);
  content: "";
  transition: transform 150ms ease;
}

.toggle-control input:checked + .toggle-track {
  border-color: var(--primary);
  background: var(--primary);
}

.toggle-control input:checked + .toggle-track::after {
  transform: translateX(14px);
}

.toggle-control input:focus-visible + .toggle-track {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.toggle-control input:disabled + .toggle-track,
.toggle-control input:disabled ~ span:last-child {
  cursor: not-allowed;
  opacity: 0.48;
}

.connection-message {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--muted);
  color: var(--muted-foreground);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.connection-message:empty {
  display: none;
}

.connection-message[data-state="error"] {
  border-color: color-mix(in srgb, var(--danger) 18%, transparent);
  background: color-mix(in srgb, var(--danger) 6%, transparent);
  color: var(--danger);
}

.connection-message[data-state="success"] {
  border-color: color-mix(in srgb, var(--success) 18%, transparent);
  background: color-mix(in srgb, var(--success) 6%, transparent);
  color: var(--success);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 16px;
  gap: 14px;
}

.metric-card {
  display: flex;
  min-width: 0;
  min-height: 100px;
  padding: 17px 18px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.metric-label {
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 500;
}

.metric-value {
  overflow: hidden;
  color: var(--foreground);
  font-size: 25px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-overflow: ellipsis;
}

.metric-success .metric-value {
  color: var(--success);
}

.metric-failure .metric-value {
  color: var(--danger);
}

.metric-time {
  font-size: 21px;
}

.activity-panel {
  margin-top: 16px;
  overflow: hidden;
}

.activity-heading {
  min-height: 74px;
  padding: 16px 18px;
}

.compact-button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 12px;
}

.activity-table-wrap {
  width: 100%;
  overflow-x: auto;
  border-top: 1px solid var(--border);
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

th,
td {
  min-height: 44px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

th {
  height: 40px;
  background: color-mix(in srgb, var(--muted) 70%, transparent);
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 600;
}

tbody tr {
  transition: background-color 120ms ease;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--muted) 48%, transparent);
}

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

th:first-child {
  width: 112px;
}

th:nth-child(3) {
  width: 92px;
}

th:nth-child(4) {
  width: 156px;
}

th:last-child {
  width: 108px;
}

.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.result-badge,
.mode-badge {
  display: inline-flex;
  min-height: 23px;
  padding: 0 7px;
  align-items: center;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.mode-badge {
  background: var(--secondary);
  color: var(--control-foreground);
}

.result-success {
  background: color-mix(in srgb, var(--success) 9%, transparent);
  color: var(--success);
}

.result-error {
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  color: var(--danger);
}

.activity-result {
  display: flex;
  align-items: center;
  gap: 8px;
}

.error-details-button {
  min-height: 26px;
  padding: 0 7px;
  border-color: transparent;
  background: transparent;
  color: var(--danger);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.error-details-button:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--danger) 18%, transparent);
  background: color-mix(in srgb, var(--danger) 7%, transparent);
}

.activity-error-row[hidden] {
  display: none;
}

.activity-error-row td {
  padding: 0;
  background: color-mix(in srgb, var(--danger) 4%, var(--card));
}

.activity-error-detail {
  padding: 14px 18px 18px;
  border-bottom: 1px solid var(--border);
}

.activity-error-metadata {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  margin: 0;
  gap: 7px 12px;
  font-size: 12px;
  line-height: 1.5;
}

.activity-error-metadata dt {
  color: var(--muted-foreground);
  font-weight: 600;
}

.activity-error-metadata dd {
  min-width: 0;
  margin: 0;
  color: var(--foreground);
  overflow-wrap: anywhere;
}

.activity-error-body-label {
  margin-top: 14px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 600;
}

.activity-error-body {
  max-height: 320px;
  margin: 7px 0 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--background);
  color: var(--foreground);
  font: 12px/1.55 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  overflow-wrap: normal;
  white-space: pre-wrap;
}

.empty-row td {
  height: 170px;
  color: var(--muted-foreground);
  text-align: center;
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  padding: 14px;
  align-items: start;
  gap: 11px;
  border: 1px solid color-mix(in srgb, var(--warning) 35%, var(--border));
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 12px 32px var(--shadow-color);
  pointer-events: auto;
}

.toast[hidden] {
  display: none;
}

.toast-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  color: var(--warning);
}

.toast-icon svg {
  width: 19px;
  height: 19px;
}

.toast-content {
  min-width: 0;
  font-size: 13px;
  line-height: 1.55;
}

.toast-content strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.toast-content p + p {
  margin-top: 5px;
}

.toast-content a {
  color: var(--info);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.toast-close {
  display: grid;
  width: 28px;
  min-height: 28px;
  padding: 0;
  place-items: center;
  border-color: transparent;
  background: transparent;
  color: var(--muted-foreground);
}

.toast-close svg {
  width: 16px;
  height: 16px;
}

.keepalive-audio,
.keepalive-video {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 1;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 760px) {
  .app-header-inner {
    padding-right: 16px;
    padding-left: 16px;
  }

  .app-main {
    padding: 22px 16px 32px;
  }

  #connection-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .connection-actions {
    grid-row: 3;
    width: 100%;
  }

  .connection-actions button {
    flex: 1;
  }

  .connection-options {
    grid-row: 2;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
}

@media (max-width: 460px) {
  .toast-region {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }

  .app-header-inner {
    min-height: 66px;
    padding-right: 12px;
    padding-left: 12px;
    gap: 10px;
  }

  .brand-copy strong {
    font-size: 14px;
    line-height: 1.15;
  }

  .header-actions {
    gap: 6px;
  }

  .theme-segmented {
    padding: 2px;
  }

  .theme-segmented button {
    width: 28px;
    min-height: 26px;
  }

  .connection-status {
    width: 30px;
    min-height: 30px;
    padding: 0;
    justify-content: center;
  }

  #connection-status-text {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .app-main {
    padding-right: 12px;
    padding-left: 12px;
  }

  .connection-panel {
    padding: 16px;
  }

  .connection-options {
    gap: 12px 18px;
  }

  .metric-card {
    min-height: 91px;
    padding: 15px;
  }

  .metric-value {
    font-size: 23px;
  }

  .metric-time {
    font-size: 18px;
  }

  .activity-heading {
    padding-right: 14px;
    padding-left: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
