/* ============================================================
   Design tokens — light (default) and dark themes
   ============================================================ */
:root {
  color-scheme: light;
  --canvas: #f6f7f9;
  --surface: #ffffff;
  --surface-subtle: #f6f7f9;
  --surface-strong: #eceef3;
  --sidebar: #f6f7f9;
  --sidebar-hover: #e9ebf1;
  --text: #171923;
  --text-soft: #414654;
  --muted: #6e7484;
  --line: #e5e7ee;
  --line-strong: #d2d5e0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-contrast: #ffffff;
  --primary-soft: #eef0fd;
  --primary-soft-line: #d8dcfa;
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --success: #1a7f4e;
  --success-soft: #e8f6ee;
  --success-line: #bee4cf;
  --warning: #96610f;
  --warning-soft: #fdf3de;
  --warning-line: #eed8a7;
  --danger: #d43030;
  --danger-hover: #b32424;
  --danger-contrast: #ffffff;
  --danger-soft: #fdecec;
  --danger-line: #f4c4c4;
  --info: #3660c9;
  --info-soft: #ecf1fd;
  --info-line: #c9d8f6;
  --focus-ring: rgba(79, 70, 229, 0.2);
  --selection: #dbe0fe;
  --terminal-bg: #12141d;
  --terminal-text: #dce1ef;
  --terminal-line: #272b3a;
  --code-inline-bg: #f2f3f8;
  --code-inline-line: #e2e4ee;
  --code-inline-text: #454b5e;
  --chat-bg: #f1f2f6;
  --wechat-bubble: #d9f4e0;
  --wechat-bubble-line: #b9e5c7;
  --phone-chrome: #22242f;
  --phone-bg: #eef0f4;
  --phone-contact-avatar: #7b8294;
  --backdrop: rgba(15, 17, 26, 0.55);
  --topbar-bg: rgba(255, 255, 255, 0.85);
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(18, 21, 31, 0.05);
  --shadow-md: 0 12px 34px rgba(18, 21, 31, 0.14);
  --sidebar-width: 248px;
  --sidebar-collapsed-width: 72px;
  --topbar-height: 60px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0f1014;
  --surface: #16171d;
  --surface-subtle: #1c1d25;
  --surface-strong: #262834;
  --sidebar: #0f1014;
  --sidebar-hover: #1c1d25;
  --text: #e9eaf1;
  --text-soft: #c4c8d4;
  --muted: #8e92a3;
  --line: #23252f;
  --line-strong: #363948;
  --primary: #8b93f8;
  --primary-hover: #a4abfb;
  --primary-contrast: #12131a;
  --primary-soft: rgba(139, 147, 248, 0.14);
  --primary-soft-line: rgba(139, 147, 248, 0.38);
  --accent-gradient: linear-gradient(135deg, #6f77f2, #9d7bf5);
  --success: #58c78d;
  --success-soft: rgba(88, 199, 141, 0.13);
  --success-line: rgba(88, 199, 141, 0.4);
  --warning: #e0aa48;
  --warning-soft: rgba(224, 170, 72, 0.13);
  --warning-line: rgba(224, 170, 72, 0.42);
  --danger: #f28080;
  --danger-hover: #f59d9d;
  --danger-contrast: #16171d;
  --danger-soft: rgba(242, 128, 128, 0.13);
  --danger-line: rgba(242, 128, 128, 0.4);
  --info: #82a8f8;
  --info-soft: rgba(130, 168, 248, 0.13);
  --info-line: rgba(130, 168, 248, 0.4);
  --focus-ring: rgba(139, 147, 248, 0.28);
  --selection: #3a3f78;
  --terminal-bg: #0c0d13;
  --terminal-text: #d6dbeb;
  --terminal-line: #23263a;
  --code-inline-bg: #21232e;
  --code-inline-line: #343748;
  --code-inline-text: #c6cadb;
  --chat-bg: #121319;
  --wechat-bubble: #1d3a2a;
  --wechat-bubble-line: #2e5c42;
  --phone-chrome: #1a1b25;
  --phone-bg: #14151c;
  --phone-contact-avatar: #4c5165;
  --backdrop: rgba(0, 0, 0, 0.66);
  --topbar-bg: rgba(15, 16, 20, 0.82);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 16px 44px rgba(0, 0, 0, 0.55);
}

/* ============================================================
   Base
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--canvas);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body.nav-open,
body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 150ms ease;
}

a:hover {
  color: var(--primary-hover);
}

img,
svg {
  max-width: 100%;
}

p {
  margin: 0 0 12px;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--text);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

h1 {
  font-size: 24px;
  letter-spacing: -0.015em;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 14px;
}

code,
pre {
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

code {
  max-width: 100%;
  padding: 1px 6px;
  border: 1px solid var(--code-inline-line);
  border-radius: 5px;
  background: var(--code-inline-bg);
  color: var(--code-inline-text);
  font-size: 0.88em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

::selection {
  background: var(--selection);
  color: var(--text);
}

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

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  clip-path: inset(50%) !important;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

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

.main-wrapper {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  flex-direction: column;
}

/* ============================================================
   Navigation — light sidebar
   ============================================================ */
.sidebar {
  position: sticky;
  top: 0;
  z-index: 120;
  display: flex;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  height: 100vh;
  min-height: 560px;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 12px 14px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  color: var(--text-soft);
  transition: width 180ms ease, flex-basis 180ms ease, transform 180ms ease;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
  padding: 2px 38px 16px 6px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 9px;
  background: var(--accent-gradient);
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.brand-text {
  min-width: 0;
  opacity: 1;
  transition: opacity 120ms ease;
}

.brand strong,
.brand span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

.brand span {
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
}

.sidebar-toggle-btn,
.mobile-nav-toggle,
.sidebar-backdrop {
  border: 0;
  cursor: pointer;
}

.sidebar-toggle-btn {
  position: absolute;
  top: 19px;
  right: 13px;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.sidebar-toggle-btn:hover {
  border-color: var(--line);
  background: var(--sidebar-hover);
  color: var(--text);
}

.sidebar-toggle-btn svg {
  transition: transform 160ms ease;
}

.nav {
  display: grid;
  gap: 3px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  grid-auto-rows: min-content;
  align-content: start;
  overflow-x: hidden;
  padding: 14px 2px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.nav-section-label {
  display: block;
  padding: 12px 12px 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.nav a,
.logout button {
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  font-weight: 500;
  line-height: 1.25;
  text-align: left;
  transition: color 150ms ease, background 150ms ease;
}

.nav a svg,
.logout button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  opacity: 0.82;
}

.nav a:hover,
.logout button:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}

.nav a.active {
  background: var(--primary-soft);
  color: var(--primary-hover);
  font-weight: 650;
}

.nav a.active svg {
  opacity: 1;
}

.nav-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  padding-right: 2px;
  padding-left: 2px;
}

.logout button {
  color: var(--text-soft);
}

.sidebar-backdrop,
.mobile-nav-toggle {
  display: none;
}

.sidebar-collapsed .sidebar {
  flex-basis: var(--sidebar-collapsed-width);
  width: var(--sidebar-collapsed-width);
}

.sidebar-collapsed .brand {
  justify-content: center;
  padding-right: 5px;
}

.sidebar-collapsed .brand-text,
.sidebar-collapsed .nav-text,
.sidebar-collapsed .nav-section-label {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-collapsed .nav-section-label {
  height: 0;
  overflow: hidden;
  padding: 0;
}

.sidebar-collapsed .sidebar-toggle-btn {
  top: 61px;
  right: 20px;
}

.sidebar-collapsed .sidebar-toggle-btn svg {
  transform: rotate(180deg);
}

.sidebar-collapsed .nav {
  padding-top: 50px;
}

.sidebar-collapsed .nav a,
.sidebar-collapsed .logout button {
  justify-content: center;
  gap: 0;
  padding-inline: 8px;
}

/* ============================================================
   Topbar and page frame
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  display: flex;
  min-height: var(--topbar-height);
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  backdrop-filter: blur(10px) saturate(1.4);
}

.topbar-left,
.topbar-right,
.user-profile {
  display: flex;
  min-width: 0;
  align-items: center;
}

.topbar-left {
  gap: 8px;
  overflow: hidden;
}

.topbar-right {
  gap: 12px;
  flex-shrink: 0;
}

.topbar-project-tag,
.topbar-sep {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.topbar-page-title {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-toggle {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.theme-toggle:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
  color: var(--text);
}

.theme-toggle svg {
  width: 17px;
  height: 17px;
}

.theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

.user-profile {
  gap: 9px;
}

.avatar-ring {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  border: 1px solid var(--primary-soft-line);
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.user-meta span {
  display: block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-meta .username {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.user-meta .role {
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
}

.main {
  width: 100%;
  max-width: 1520px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}

.main:focus {
  outline: none;
}

.page-header {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin: 0 0 24px;
}

.page-header > div:first-child {
  min-width: 0;
}

.page-header h1 {
  overflow-wrap: anywhere;
}

.page-header p {
  max-width: 800px;
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.compact-page-header {
  margin-bottom: 20px;
}

.compact-page-header h1 {
  font-size: 22px;
}

.header-actions,
.status-actions,
.runtime-actions,
.modal-actions {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.header-actions {
  justify-content: flex-end;
}

.muted {
  color: var(--muted) !important;
}

.is-loading {
  cursor: progress;
  opacity: 0.55;
  transition: opacity 150ms ease;
}

/* ============================================================
   Panels and overview data
   ============================================================ */
.panel {
  min-width: 0;
  margin: 0 0 20px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.panel[tabindex="0"]:focus-visible {
  outline-offset: -3px;
}

.panel > :last-child,
.panel > :last-child > :last-child {
  margin-bottom: 0;
}

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

.panel-title h2 {
  min-width: 0;
}

.narrow {
  width: min(100%, 760px);
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  align-items: start;
}

.wide-split {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.split > .panel,
.split > form.panel {
  margin-bottom: 0;
}

.split + .split,
.split + .panel,
.panel + .split {
  margin-top: 20px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1px;
  margin: 0 0 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
  box-shadow: var(--shadow-sm);
}

.metric {
  display: flex;
  min-width: 0;
  min-height: 88px;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  padding: 15px 17px;
  background: var(--surface);
}

.metric > span,
.metric > a:first-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
}

.metric strong {
  min-width: 0;
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.metric strong .status-badge {
  vertical-align: middle;
}

.metric-date {
  font-size: 14px !important;
  font-weight: 600 !important;
}

.metric-link {
  color: inherit;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 1px;
  margin: 0 0 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
  box-shadow: var(--shadow-sm);
}

.summary-strip > div {
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
}

.summary-strip > div:last-child {
  border-right: 0;
}

.summary-strip span,
.summary-strip strong {
  display: block;
  overflow-wrap: anywhere;
}

.summary-strip span {
  color: var(--muted);
  font-size: 12px;
}

.summary-strip strong {
  margin-top: 5px;
  color: var(--text);
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dashboard-strip strong {
  font-size: 21px;
}

.dashboard-viz-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(220px, 0.7fr);
  gap: 26px;
  align-items: stretch;
}

.dashboard-bars {
  display: grid;
  gap: 13px;
  align-content: center;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 130px) minmax(100px, 1fr) 42px;
  gap: 12px;
  align-items: center;
}

.bar-row > span {
  color: var(--text-soft);
  font-size: 12px;
}

.bar-row > strong {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.bar-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-gradient);
  transition: width 400ms ease;
}

.dashboard-donut {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 18px;
  border-left: 1px solid var(--line);
}

.donut-ring {
  display: grid;
  width: 126px;
  height: 126px;
  flex: 0 0 126px;
  place-items: center;
  border: 12px solid var(--surface-strong);
  border-radius: 50%;
}

.donut-ring.has-pending strong {
  color: var(--warning);
}

.donut-ring div,
.donut-ring span,
.donut-ring strong {
  display: block;
  text-align: center;
}

.donut-ring strong {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.donut-ring span {
  color: var(--muted);
  font-size: 11px;
}

.donut-legend {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.donut-legend span {
  color: var(--text-soft);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.donut-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 3px;
}

.legend-active {
  background: var(--line-strong);
}

.legend-pending {
  background: var(--warning);
}

/* ============================================================
   Buttons and controls
   ============================================================ */
.button {
  display: inline-flex;
  min-width: 0;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.button:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
  color: var(--text);
}

.button.primary {
  border-color: transparent;
  background: var(--primary);
  color: var(--primary-contrast);
}

.button.primary:hover {
  border-color: transparent;
  background: var(--primary-hover);
  color: var(--primary-contrast);
}

.button.danger {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}

.button.danger:hover {
  border-color: transparent;
  background: var(--danger);
  color: var(--danger-contrast);
}

.button.small {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 12px;
}

.button.full {
  width: 100%;
}

.button:disabled,
.button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.48;
  pointer-events: none;
}

.button-loading {
  position: relative;
  cursor: wait;
}

.button-loading::before,
.busy-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  content: "";
}

.busy-spinner {
  display: inline-block;
}

.busy-spinner.large {
  width: 26px;
  height: 26px;
  border-width: 3px;
}

.busy-indicator {
  display: flex;
  min-height: 150px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Forms
   ============================================================ */
.form {
  display: grid;
  gap: 16px;
}

.form label,
.filters label,
.tight-form label {
  display: grid;
  min-width: 0;
  gap: 6px;
}

label > span,
.form-section > h3 {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

input,
select {
  min-height: 38px;
  padding: 8px 12px;
}

textarea {
  min-height: 104px;
  padding: 10px 12px;
  line-height: 1.6;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--muted);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: 0;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-strong);
  color: var(--muted);
  cursor: not-allowed;
}

.checkbox {
  display: grid !important;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 9px !important;
  align-items: start;
  cursor: pointer;
}

.checkbox input {
  width: 17px;
  height: 17px;
  min-height: 0;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

.checkbox span {
  font-size: 13px;
  font-weight: 500;
}

.form-section {
  display: grid;
  gap: 14px;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-of-type {
  padding-bottom: 0;
  border-bottom: 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

.filters .button {
  align-self: end;
  min-height: 38px;
}

.compact-filters {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.compact-filters label {
  min-width: 0;
}

.search-bar,
.inline-form-row {
  display: flex;
  min-width: 0;
  align-items: flex-end;
  gap: 8px;
}

.search-bar input,
.inline-form-row > :first-child {
  flex: 1 1 auto;
}

.tight-form {
  display: grid;
  gap: 10px;
}

.toggle-fields {
  display: none;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.toggle-fields.show {
  display: grid;
}

textarea.code-editor,
.code-editor {
  min-height: 420px;
  border-color: var(--terminal-line);
  background: var(--terminal-bg);
  color: var(--terminal-text);
  font: 12px/1.65 ui-monospace, "SFMono-Regular", Consolas, monospace;
  tab-size: 2;
}

.tall-editor {
  min-height: 620px !important;
}

/* ============================================================
   Tables and definition lists
   ============================================================ */
table {
  width: 100%;
  max-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--text-soft);
  font-size: 13px;
}

th,
td {
  min-width: 90px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  background: transparent;
  border-bottom-color: var(--line-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

thead th:first-child {
  border-top-left-radius: 5px;
}

thead th:last-child {
  border-top-right-radius: 5px;
}

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

tbody tr:hover td {
  background: var(--surface-subtle);
}

td form {
  margin: 0;
}

.panel > table,
.responsive-table {
  display: table;
  width: 100%;
  min-width: 680px;
  table-layout: auto;
}

.table-subtext {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.actions {
  width: 1%;
  min-width: 80px;
  text-align: right;
  white-space: nowrap;
}

.actions .button,
.actions button {
  white-space: nowrap;
}

.kv {
  display: grid;
  grid-template-columns: minmax(110px, 0.38fr) minmax(0, 1fr);
  margin: 0;
  border-top: 1px solid var(--line);
}

.kv dt,
.kv dd {
  min-width: 0;
  margin: 0;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kv dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.kv dd {
  color: var(--text-soft);
}

.kv.compact dt,
.kv.compact dd {
  padding-block: 8px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
}

.pagination-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.progress-bar,
.quality-meter {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.progress-bar span,
.quality-meter span {
  display: block;
  min-width: 2px;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-gradient);
}

/* ============================================================
   Status and feedback
   ============================================================ */
.pill,
.status-badge {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
  text-align: left;
}

.pill {
  padding: 3px 9px;
}

.status-badge {
  padding: 3px 9px;
}

.status-badge::before {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
  content: "";
}

.pill.ok,
.status-badge.active,
.status-badge.approved,
.status-badge.completed,
.status-badge.success,
.status-badge.configured,
.status-badge.running,
.status-badge.scan_success,
.status-badge.health-ok,
.status-badge.analysis-low,
.status-badge.platform-active,
.status-badge.bound {
  border-color: var(--success-line);
  background: var(--success-soft);
  color: var(--success);
}

.pill.bad,
.status-badge.failed,
.status-badge.error,
.status-badge.rejected,
.status-badge.disabled,
.status-badge.canceled,
.status-badge.health-error,
.status-badge.analysis-high,
.status-badge.not_configured {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.pill.warning,
.status-badge.pending,
.status-badge.pending_review,
.status-badge.pending_admin,
.status-badge.queued,
.status-badge.waiting_message,
.status-badge.warning,
.status-badge.health-warning,
.status-badge.analysis-medium {
  border-color: var(--warning-line);
  background: var(--warning-soft);
  color: var(--warning);
}

.status-badge.draft,
.status-badge.paused,
.status-badge.platform-planned,
.status-badge.health-info,
.status-badge.starting,
.status-badge.qr_ready,
.status-badge.waiting_scan,
.status-badge.created {
  border-color: var(--info-line);
  background: var(--info-soft);
  color: var(--info);
}

.ok {
  color: var(--success);
}

.bad {
  color: var(--danger);
}

.flash,
.notice,
.form-error {
  margin: 0 0 16px;
  padding: 11px 14px;
  border: 1px solid;
  border-radius: var(--radius-sm);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.async-error {
  margin-bottom: 14px;
}

.flash,
.notice {
  border-color: var(--warning-line);
  background: var(--warning-soft);
  color: var(--warning);
}

.flash.success,
.flash.ok {
  border-color: var(--success-line);
  background: var(--success-soft);
  color: var(--success);
}

.flash.error,
.form-error {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.notice p,
.form-error p {
  margin: 0 0 6px;
}

.notice p:last-child,
.form-error p:last-child {
  margin-bottom: 0;
}

.health-list {
  display: grid;
  gap: 8px;
}

.compact-health-list {
  gap: 7px;
}

.health-item {
  display: grid;
  min-width: 0;
  gap: 2px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text-soft);
  transition: border-color 150ms ease, background 150ms ease;
}

a.health-item:hover {
  border-color: var(--line-strong);
  background: var(--surface-strong);
  color: var(--text);
}

.health-item strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.health-item span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.health-item.health-ok,
.health-item.analysis-low {
  border-left-color: var(--success);
}

.health-item.health-info {
  border-left-color: var(--info);
}

.health-item.health-warning,
.health-item.analysis-medium {
  border-left-color: var(--warning);
}

.health-item.health-error,
.health-item.analysis-high {
  border-left-color: var(--danger);
}

.empty-state {
  padding-block: 40px;
  text-align: center;
}

.empty-state h2 {
  margin: 14px 0 6px;
}

.empty-state p {
  max-width: 560px;
  margin: 0 auto;
  color: var(--muted);
}

.empty-state.compact {
  padding-block: 24px;
}

/* ============================================================
   Operational pages
   ============================================================ */
.runtime-actions {
  margin-bottom: 17px;
}

.runtime-actions form,
.status-actions form {
  margin: 0;
}

.ops-toolbar {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
}

.ops-toolbar .summary-strip,
.insight-panel .summary-strip {
  margin-bottom: 0;
}

.ops-diagnostics-grid,
.insight-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.ops-diagnostics-grid h3,
.insight-grid h2 {
  margin-bottom: 10px;
}

.compact-link-list {
  display: grid;
  gap: 6px;
}

.compact-link-list a {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  transition: background 150ms ease, border-color 150ms ease;
}

.compact-link-list a:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.compact-link-list span {
  color: var(--muted);
  font-size: 11px;
}

.config-editor-split {
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
}

.config-list-pane,
.config-preview-pane {
  min-width: 0;
}

.config-card {
  gap: 12px;
}

.sticky-preview {
  position: sticky;
  top: calc(var(--topbar-height) + 20px);
}

.config-preview,
.log-preview,
.prompt-preview {
  width: 100%;
  max-width: 100%;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--terminal-line);
  border-radius: var(--radius-sm);
  background: var(--terminal-bg);
  color: var(--terminal-text);
  font: 12px/1.65 ui-monospace, "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  scrollbar-width: thin;
}

.config-preview {
  max-height: calc(100vh - 150px);
  padding: 15px;
}

.log-preview {
  min-height: 150px;
  max-height: 440px;
  padding: 14px;
}

.prompt-preview {
  max-height: 600px;
}

.prompt-panel {
  min-width: 0;
}

.prompt-details,
.diff-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.prompt-details summary,
.diff-box summary {
  padding: 11px 13px;
  color: var(--text-soft);
  cursor: pointer;
  font-weight: 600;
}

.prompt-details[open] summary,
.diff-box[open] summary {
  border-bottom: 1px solid var(--line);
}

.prompt-details .config-preview,
.diff-box pre {
  border: 0;
  border-radius: 0 0 7px 7px;
}

.audit-list,
.version-list,
.log-list {
  display: grid;
  gap: 0;
}

.audit-item,
.version-item {
  min-width: 0;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.audit-item:last-child,
.version-item:last-child {
  border-bottom: 0;
}

.audit-header {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.audit-item p {
  margin: 5px 0 0;
  color: var(--text-soft);
  overflow-wrap: anywhere;
}

.audit-detail {
  min-width: 280px;
  max-width: 700px;
}

.version-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.version-item strong,
.version-item span {
  display: block;
  overflow-wrap: anywhere;
}

.version-item span {
  color: var(--muted);
  font-size: 11px;
}

.tag-list {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: 6px;
}

/* ============================================================
   Workbench
   ============================================================ */
.workbench-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.7fr);
  gap: 20px;
  align-items: start;
}

.workbench-main,
.workbench-side,
.editor-panel,
.side-panel {
  min-width: 0;
}

.workbench-side {
  position: sticky;
  top: calc(var(--topbar-height) + 20px);
}

.workbench-side .panel:last-child {
  margin-bottom: 0;
}

.robot-form {
  gap: 18px;
}

.sim-chat {
  display: grid;
  gap: 9px;
}

.sim-message {
  width: min(88%, 620px);
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.sim-message.bot {
  margin-left: auto;
  border-color: var(--primary-soft-line);
  background: var(--primary-soft);
}

.sim-message strong {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
}

.sim-message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dense-chat {
  max-height: 520px;
  overflow-y: auto;
  padding-right: 4px;
}

.reply-box {
  padding: 13px;
  border: 1px solid var(--primary-soft-line);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
}

.reply-box span {
  color: var(--primary);
  font-size: 11px;
  font-weight: 650;
}

.reply-box p {
  margin: 5px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ============================================================
   Log index and chat detail
   ============================================================ */
.log-list.flat {
  gap: 0;
}

.log-item {
  display: block;
  min-width: 0;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
  color: var(--text-soft);
  transition: background 150ms ease;
}

a.log-item:hover,
.log-item:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.log-item:last-child {
  border-bottom: 0;
}

.log-item strong,
.log-item span,
.log-item p {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.log-item strong {
  color: var(--text);
  font-size: 13px;
}

.log-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.log-item p {
  margin: 6px 0 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.log-title-link {
  display: inline-block;
  max-width: 100%;
}

.dense-log-list .log-item {
  padding-block: 9px;
}

.dense-log-list .log-item p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.markdown-body {
  color: var(--text-soft);
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.markdown-body h1 {
  margin: 0 0 18px;
  font-size: 22px;
}

.markdown-body h2 {
  margin: 22px 0 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol {
  margin: 0 0 12px;
}

.markdown-body blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--line-strong);
  background: var(--surface-subtle);
}

.markdown-body pre {
  max-width: 100%;
  overflow: auto;
  padding: 13px;
  border-radius: var(--radius-sm);
  background: var(--terminal-bg);
  color: var(--terminal-text);
}

.markdown-body table {
  display: block;
  overflow-x: auto;
}

.log-index-body {
  max-width: 100%;
  overflow-x: hidden;
}

.log-index-body h1 {
  font-size: 22px;
}

.log-index-body h2 {
  margin-top: 20px;
}

.im-chat-container {
  display: grid;
  grid-template-columns: minmax(190px, 260px) minmax(0, 1fr);
  min-height: 560px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.im-chat-meta {
  min-width: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--surface-subtle);
}

.meta-title {
  margin-bottom: 15px;
  font-size: 14px;
}

.meta-item {
  display: grid;
  gap: 3px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

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

.meta-val {
  color: var(--text-soft);
  overflow-wrap: anywhere;
}

.im-chat-flow {
  display: flex;
  min-width: 0;
  max-height: 72vh;
  flex-direction: column;
  gap: 13px;
  overflow-y: auto;
  padding: 24px;
  background: var(--chat-bg);
}

.im-chat-date {
  display: flex;
  justify-content: center;
  margin: 5px 0;
}

.im-chat-date span {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
}

.im-chat-msg {
  display: flex;
  width: min(82%, 720px);
  min-width: 0;
  gap: 9px;
  align-items: flex-start;
}

.im-chat-msg.msg-bot {
  margin-left: auto;
  flex-direction: row-reverse;
}

.msg-avatar {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
}

.msg-bot .msg-avatar {
  border-color: var(--primary-soft-line);
  background: var(--primary-soft);
  color: var(--primary);
}

.msg-body-wrapper {
  min-width: 0;
}

.msg-info {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
}

.msg-bot .msg-info {
  justify-content: flex-end;
}

.msg-sender-name,
.msg-time {
  color: var(--muted);
  font-size: 10px;
}

.msg-sender-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-bubble {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
}

.msg-bot .msg-bubble {
  border-color: var(--primary-soft-line);
  background: var(--primary-soft);
}

/* ============================================================
   QR and phone simulator
   ============================================================ */
.qr-panel {
  display: grid;
  max-width: 420px;
  place-items: center;
  gap: 13px;
  margin-inline: auto;
  text-align: center;
}

.qr-wrapper {
  position: relative;
  width: min(100%, 300px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
}

.qr-panel img,
.qr-wrapper img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qr-placeholder {
  display: grid;
  width: min(100%, 300px);
  aspect-ratio: 1;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-subtle);
  color: var(--muted);
}

.laser-line {
  display: none;
}

.phone-mockup {
  width: min(100%, 390px);
  min-height: 620px;
  margin-inline: auto;
  overflow: hidden;
  border: 1px solid var(--phone-chrome);
  border-radius: 14px;
  background: var(--phone-bg);
  box-shadow: var(--shadow-md);
}

.phone-status-bar,
.phone-header {
  background: var(--phone-chrome);
  color: #ffffff;
}

.phone-status-bar {
  display: flex;
  min-height: 26px;
  align-items: center;
  justify-content: space-between;
  padding: 4px 14px;
  font-size: 10px;
}

.phone-header {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.phone-header .title {
  max-width: 100%;
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phone-chat-area {
  display: flex;
  min-height: 490px;
  max-height: 560px;
  flex-direction: column;
  gap: 13px;
  overflow-y: auto;
  padding: 16px 12px;
}

.phone-date {
  align-self: center;
  color: var(--muted);
  font-size: 10px;
}

.phone-bubble-row {
  display: flex;
  max-width: 88%;
  align-items: flex-start;
  gap: 7px;
}

.phone-bubble-row.msg-contact {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.phone-avatar {
  display: grid;
  width: 29px;
  height: 29px;
  flex: 0 0 29px;
  place-items: center;
  border-radius: 7px;
  background: var(--accent-gradient);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
}

.phone-bubble-row.msg-contact .phone-avatar {
  background: var(--phone-contact-avatar);
}

.phone-bubble-wrapper {
  min-width: 0;
}

.phone-sender-name {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 9px;
}

.phone-bubble-row.msg-contact .phone-sender-name {
  text-align: right;
}

.phone-bubble {
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.phone-bubble-row.msg-contact .phone-bubble {
  border-color: var(--wechat-bubble-line);
  background: var(--wechat-bubble);
}

.phone-typing-indicator {
  display: flex;
  gap: 3px;
  padding: 10px;
}

.phone-typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 900ms ease-in-out infinite alternate;
}

.phone-typing-dot:nth-child(2) { animation-delay: 150ms; }
.phone-typing-dot:nth-child(3) { animation-delay: 300ms; }

@keyframes typing {
  to { opacity: 0.35; transform: translateY(-2px); }
}

.phone-input-bar {
  display: flex;
  min-height: 54px;
  align-items: center;
  gap: 7px;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.phone-input-bar input {
  min-height: 36px;
}

.phone-input-bar .send-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  flex: 0 0 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--primary-contrast);
  cursor: pointer;
  padding: 0;
  transition: background 150ms ease;
}

.phone-input-bar .send-btn:hover {
  background: var(--primary-hover);
}

.phone-input-bar .send-btn svg {
  max-width: none;
}

.segmented-control {
  display: inline-flex;
  max-width: 100%;
  gap: 2px;
  margin-bottom: 14px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
}

.segmented-control a {
  min-width: 92px;
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-soft);
  text-align: center;
  transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.segmented-control a.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  font-weight: 650;
}

/* ============================================================
   Modals
   ============================================================ */
.modal-backdrop,
.waiting-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 20px;
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-backdrop[hidden],
.waiting-modal-backdrop[hidden] {
  display: none;
}

.modal-dialog,
.waiting-dialog {
  width: min(100%, 720px);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.optimized-dialog {
  width: min(100%, 820px);
}

.waiting-dialog {
  width: min(100%, 440px);
}

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

.modal-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.modal-close {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

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

.waiting-dialog-body {
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 32px 24px;
  text-align: center;
}

.waiting-dialog-body p {
  color: var(--muted);
}

.optimized-review-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}

.optimized-field {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.optimized-field.wide {
  grid-column: 1 / -1;
}

.optimized-field > span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.optimized-field pre {
  max-width: 100%;
  margin: 0;
  color: var(--text-soft);
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.modal-actions {
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

/* ============================================================
   Authentication
   ============================================================ */
.is-guest {
  background:
    radial-gradient(60% 40% at 50% 0%, var(--primary-soft) 0%, transparent 100%),
    var(--canvas);
}

.is-guest .app-shell {
  min-height: 100vh;
  align-items: stretch;
  justify-content: center;
}

.is-guest .main-wrapper {
  width: 100%;
}

.auth-brand {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(100%, 1080px);
  margin-inline: auto;
  padding: 16px 20px;
}

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

.auth-brand .brand-mark {
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.auth-brand strong,
.auth-brand span {
  display: block;
}

.auth-brand strong {
  font-size: 14px;
}

.auth-brand span {
  color: var(--muted);
  font-size: 11px;
}

.auth-main {
  display: grid;
  flex: 1 1 auto;
  place-items: start center;
  padding-top: clamp(30px, 8vh, 86px);
}

.auth-card {
  width: min(100%, 430px);
  padding: 30px 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.auth-card h1 {
  font-size: 22px;
}

.auth-card > p:first-of-type {
  margin: 7px 0 20px;
  color: var(--muted);
}

.auth-card .form {
  margin-top: 18px;
}

.auth-switch {
  margin: 18px 0 0;
  text-align: center;
}

.auth-hint {
  margin-top: 12px !important;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ============================================================
   Motion and responsive
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1100px) {
  .main {
    padding-inline: 22px;
  }

  .dashboard-viz-grid,
  .config-editor-split,
  .workbench-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .dashboard-donut {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .config-preview {
    max-height: 520px;
  }

  .sticky-preview,
  .workbench-side {
    position: static;
  }
}

@media (max-width: 900px) {
  :root {
    --topbar-height: 56px;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 220;
    width: min(82vw, 292px);
    height: 100dvh;
    min-height: 0;
    flex-basis: auto;
    padding-top: 14px;
    border-right: 1px solid var(--line);
    background: var(--surface);
    transform: translateX(-102%);
    box-shadow: var(--shadow-md);
  }

  .sidebar-collapsed .sidebar {
    width: min(82vw, 292px);
  }

  .sidebar-collapsed .brand {
    justify-content: flex-start;
    padding-right: 38px;
  }

  .sidebar-collapsed .brand-text,
  .sidebar-collapsed .nav-text,
  .sidebar-collapsed .nav-section-label {
    height: auto;
    width: auto;
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-collapsed .nav-section-label {
    padding: 12px 12px 6px;
  }

  .sidebar-collapsed .sidebar-toggle-btn,
  .sidebar-toggle-btn {
    top: 18px;
    right: 13px;
  }

  .sidebar-collapsed .sidebar-toggle-btn svg {
    transform: rotate(0deg);
  }

  .sidebar-collapsed .nav,
  .nav {
    padding-top: 14px;
  }

  .sidebar-collapsed .nav a,
  .sidebar-collapsed .logout button {
    justify-content: flex-start;
    gap: 11px;
    padding-inline: 12px;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 210;
    display: block;
    background: var(--backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  .sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-nav-toggle {
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-soft);
  }

  .mobile-nav-toggle:hover {
    background: var(--surface-subtle);
  }

  .topbar {
    padding-inline: 16px;
  }

  .topbar-project-tag,
  .topbar-sep {
    display: none;
  }

  .main {
    padding: 20px 18px 36px;
  }

  .page-header {
    gap: 15px;
  }

  .split,
  .wide-split,
  .ops-diagnostics-grid,
  .insight-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .split > .panel,
  .split > form.panel {
    margin-bottom: 0;
  }

  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .im-chat-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .meta-title {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  h1 {
    font-size: 21px;
  }

  .main {
    padding: 16px 12px 30px;
  }

  .topbar {
    gap: 10px;
    padding-inline: 12px;
  }

  .user-meta {
    display: none;
  }

  .page-header,
  .compact-page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 18px;
  }

  .page-header > .button,
  .page-header > .pill,
  .page-header > .status-badge {
    align-self: flex-start;
  }

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

  .panel {
    margin-bottom: 14px;
    padding: 16px;
  }

  .panel-title {
    align-items: flex-start;
    gap: 9px;
  }

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

  .metric {
    min-height: 80px;
    padding: 12px;
  }

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

  .summary-strip > div {
    padding: 12px;
  }

  .bar-row {
    grid-template-columns: minmax(78px, 105px) minmax(60px, 1fr) 32px;
    gap: 8px;
  }

  .dashboard-donut {
    flex-direction: column;
  }

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

  .filters .button,
  .form-actions .button {
    width: 100%;
  }

  .search-bar,
  .inline-form-row {
    align-items: stretch;
    flex-direction: column;
  }

  .search-bar .button,
  .inline-form-row .button {
    width: 100%;
  }

  .status-actions,
  .runtime-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .status-actions form,
  .runtime-actions form,
  .status-actions .button,
  .runtime-actions .button {
    width: 100%;
  }

  .kv {
    grid-template-columns: minmax(88px, 0.42fr) minmax(0, 1fr);
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .pagination-actions {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pagination-actions .button {
    width: 100%;
  }

  .im-chat-flow {
    max-height: none;
    padding: 14px 10px;
  }

  .im-chat-msg {
    width: 92%;
  }

  .msg-avatar {
    width: 27px;
    height: 27px;
    flex-basis: 27px;
  }

  .optimized-review-grid {
    grid-template-columns: minmax(0, 1fr);
    padding: 14px;
  }

  .optimized-field.wide {
    grid-column: auto;
  }

  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-actions .button {
    width: 100%;
  }

  .auth-brand {
    justify-content: space-between;
  }

  .auth-main {
    padding-top: 18px;
  }

  .auth-card {
    padding: 22px 18px;
  }
}

@media (max-width: 390px) {
  .metrics,
  .summary-strip {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .bar-row > span {
    grid-column: 1 / -1;
  }

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

  .kv dt {
    padding-bottom: 2px;
    border-bottom: 0;
  }

  .kv dd {
    padding-top: 2px;
  }
}
