:root {
  --page: #f4f6f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --sidebar: #172235;
  --sidebar-active: #2b3a53;
  --text: #1f2937;
  --muted: #667085;
  --line: #dfe4ec;
  --accent: #345fa8;
  --accent-soft: #e8effb;
  --ok: #237a52;
  --warn: #9a6700;
  --bad: #b42318;
  --shadow: 0 10px 30px rgba(23, 34, 53, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--page);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

button,
input,
select,
textarea { font: inherit; }

button { cursor: pointer; }

.hidden { display: none !important; }

.shell { min-height: 100vh; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, #eef2f7, #f8fafc);
}

.auth-panel { width: min(430px, 100%); }

#dashboard {
  width: min(1600px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  background: var(--page);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px;
  color: #f8fafc;
  background: var(--sidebar);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 7px;
}

.brand-block strong,
.brand-block small { display: block; }

.brand-block small { margin-top: 3px; color: #aeb9cb; }

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 10px;
  color: #172235;
  background: #dce8fb;
  font-weight: 800;
  font-size: 0.82rem;
}

.primary-action,
.nav-item,
.ghost,
.filter-button,
.task-type-option,
.inline-help,
.task-action {
  border: 0;
  border-radius: 9px;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}

.primary-action {
  width: 100%;
  padding: 11px 14px;
  color: #172235;
  background: #dce8fb;
  font-weight: 700;
}

.primary-action:hover,
button[type="submit"]:hover { transform: translateY(-1px); }

.main-nav,
.sidebar-tools { display: grid; gap: 5px; }

.sidebar-tools { margin-top: 4px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, 0.12); }

.nav-item {
  width: 100%;
  padding: 10px 12px;
  color: #c9d2df;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active { color: #ffffff; background: var(--sidebar-active); }

.sidebar-meta {
  min-width: 0;
  margin-top: auto;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: #9facbf;
}

.sidebar-meta span,
.sidebar-meta strong,
.sidebar-meta small { display: block; }

.sidebar-meta strong {
  margin: 5px 0 9px;
  color: #e9eef6;
  font-size: 0.78rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.workspace { min-width: 0; padding: 30px clamp(20px, 3vw, 44px) 48px; }

.workspace-header,
.section-title,
.section-toolbar,
.task-card-head,
.task-card-footer,
.result-row,
.route-strip > div,
.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.workspace-header { margin-bottom: 24px; align-items: flex-end; }

h1,
h2,
h3,
p { margin: 0; }

h1 { font-size: clamp(1.65rem, 3vw, 2.35rem); line-height: 1.15; }
h2 { font-size: 1.08rem; }
h3 { font-size: 1rem; }

.eyebrow,
.section-kicker {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.eyebrow { margin-bottom: 7px; }
.subtitle { margin-top: 8px; color: var(--muted); line-height: 1.55; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.update-state { color: var(--muted); font-size: 0.86rem; white-space: nowrap; }

.panel,
.content-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.panel { padding: 20px; }
.content-section { margin-top: 16px; padding: 20px; }
.section-title { align-items: flex-start; margin-bottom: 14px; }
.section-hint { margin-top: 5px; color: var(--muted); font-size: 0.88rem; line-height: 1.5; }

.priority-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 16px;
}

.memory-panel { min-height: 198px; }
.memory-panel h2 { margin-top: 7px; font-size: 1.5rem; }
.metric-value { font-size: 1.8rem; font-variant-numeric: tabular-nums; }

.memory-meter {
  height: 10px;
  margin: 21px 0 15px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf3;
}

.memory-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease, background 180ms ease;
}

.memory-meter span.warning { background: var(--warn); }
.memory-meter span.danger { background: var(--bad); }

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

.metric-split span { color: var(--muted); }
.metric-split strong { display: block; margin-top: 4px; color: var(--text); font-variant-numeric: tabular-nums; }

.summary-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.summary-stats div { padding: 13px; border-radius: 10px; background: var(--surface-soft); }
.summary-stats span { color: var(--muted); font-size: 0.84rem; }
.summary-stats strong { display: block; margin-top: 4px; font-size: 1.45rem; }

.ghost,
.inline-help,
.task-action,
.filter-button {
  padding: 8px 11px;
  color: #31445f;
  background: #edf1f6;
}

.ghost:hover,
.inline-help:hover,
.task-action:hover,
.filter-button:hover { background: #e1e7ef; }

.compact-button { padding: 7px 10px; font-size: 0.86rem; white-space: nowrap; }

.route-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.88rem;
}

.route-strip strong { color: var(--text); }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #98a2b3; }
.status-dot.unknown { background: #98a2b3; }
.status-dot.ok { background: var(--ok); }
.status-dot.bad { background: var(--bad); }
.route-details { position: relative; }
.route-details summary { cursor: pointer; color: var(--accent); white-space: nowrap; }
.server-details { display: grid; gap: 8px; margin-top: 10px; min-width: 260px; }
.server-detail-row { display: grid; gap: 3px; padding: 9px; border-radius: 8px; background: var(--surface); }

.task-list { display: grid; gap: 10px; }

.task-card {
  min-width: 0;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.task-card-head { align-items: flex-start; }
.task-identity { min-width: 0; }
.task-title-line { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.task-id { max-width: 100%; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.task-type { padding: 3px 7px; border-radius: 6px; color: #345681; background: var(--accent-soft); font-size: 0.78rem; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: #edf1f6;
  font-size: 0.8rem;
  white-space: nowrap;
}

.badge.running { color: #175c3d; background: #e7f5ee; }
.badge.pending { color: #7a5200; background: #fff5d9; }
.badge.paused { color: #7a5200; background: #fff5d9; }
.badge.failed,
.badge.cancelled { color: #8f1d15; background: #fdecea; }
.badge.completed { color: #35506e; background: #eaf0f6; }

.task-progress-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  margin: 14px 0 10px;
  align-items: center;
}

.progress-track { height: 7px; overflow: hidden; border-radius: 999px; background: #e9edf2; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.progress-label { color: var(--muted); font-size: 0.83rem; white-space: nowrap; }
.task-key-parameters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.task-key-parameters span { padding: 5px 8px; border: 1px solid #d9e2ee; border-radius: 999px; color: #31445f; background: #f5f8fc; font-size: 0.8rem; }
.task-card-footer { align-items: flex-end; }
.task-summary-line { min-width: 0; color: var(--muted); font-size: 0.86rem; line-height: 1.5; }
.error-text { color: var(--bad); }
.task-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.task-action { font-size: 0.83rem; }
.task-action.danger { color: var(--bad); background: #fdecea; }
.task-action:disabled { opacity: 0.45; cursor: not-allowed; }
.task-parameters { margin-top: 12px; color: var(--muted); font-size: 0.84rem; }
.task-parameters summary { cursor: pointer; }
.meta-list { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.meta-list span { padding: 5px 8px; border-radius: 7px; background: var(--surface-soft); overflow-wrap: anywhere; }

.empty-state { padding: 28px 16px; color: var(--muted); text-align: center; border: 1px dashed #ccd3dd; border-radius: 11px; background: var(--surface-soft); }

.section-toolbar,
.results-toolbar {
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}

.filter-group { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-button.active { color: #ffffff; background: var(--accent); }

.task-type-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.task-type-option {
  display: grid;
  gap: 6px;
  padding: 15px;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
}

.task-type-option span { color: var(--muted); font-size: 0.84rem; line-height: 1.4; }
.task-type-option.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.create-panel { max-width: 900px; }

.form { display: grid; gap: 11px; margin-top: 16px; }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form label:not(.checkbox-row) { display: block; margin-bottom: 6px; color: #475467; font-size: 0.88rem; }
.field-span-2 { grid-column: 1 / -1; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.label-row label { margin-bottom: 6px !important; }
.inline-help { padding: 5px 8px; font-size: 0.8rem; }
.battle-plan-control { display: grid; grid-template-columns: 145px minmax(0, 1fr); gap: 8px; }

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  color: var(--text);
  border: 1px solid #cfd6e1;
  border-radius: 9px;
  background: #ffffff;
}

textarea { resize: vertical; line-height: 1.5; }
input:focus,
select:focus,
textarea:focus { outline: 2px solid #a9c0e6; outline-offset: 1px; border-color: var(--accent); }

button:focus-visible,
summary:focus-visible,
[role="tab"]:focus-visible {
  outline: 2px solid #6f91c8;
  outline-offset: 2px;
}
.checkbox-row { display: flex; align-items: center; gap: 9px; color: #475467; }
.checkbox-row input { width: auto; }
.field-hint { margin-top: -5px; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 4px; }

button[type="submit"] {
  padding: 10px 16px;
  color: #ffffff;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  font-weight: 700;
}

.results-toolbar label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 0.85rem; }
.results-toolbar select { width: auto; min-width: 132px; }
.results-search { margin-left: auto; }
.results-search input { width: min(260px, 40vw); }
.result-heading { margin: 18px 0 10px; }
.result-list { display: grid; }
.result-row {
  min-width: 0;
  padding: 13px 4px;
  border-bottom: 1px solid var(--line);
  align-items: flex-start;
}
.result-row:last-child { border-bottom: 0; }
.result-main { min-width: 0; }
.result-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.result-file { margin-top: 4px; color: var(--muted); font-size: 0.84rem; overflow-wrap: anywhere; }
.result-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 5px; color: var(--muted); font-size: 0.8rem; }
.result-download { flex: 0 0 auto; }
.compact-results .result-row:nth-child(n + 11) { display: none; }

.table-wrap { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th,
td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.empty { padding: 24px; color: var(--muted); text-align: center; }
.lookup-row { cursor: pointer; }
.lookup-row:hover { background: var(--surface-soft); }

.drawer,
.modal-shell { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop,
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.46); backdrop-filter: blur(2px); }
.drawer-panel {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  width: min(720px, 92vw);
  height: 100%;
  padding: 20px;
  background: var(--surface);
  box-shadow: -16px 0 40px rgba(15, 23, 42, 0.18);
}

.log-view {
  width: 100%;
  height: calc(100vh - 92px);
  margin: 0;
  padding: 15px;
  overflow: auto;
  border-radius: 10px;
  color: #e7edf5;
  background: #151b24;
  font: 0.86rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.modal-shell { display: grid; place-items: center; padding: 22px; }
.modal-panel { position: relative; z-index: 1; width: min(720px, calc(100vw - 32px)); max-height: min(82vh, 780px); overflow: auto; }
.modal-panel-wide { width: min(1100px, calc(100vw - 32px)); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lookup-toolbar { margin-bottom: 13px; }
.help-doc { display: grid; gap: 13px; }
.help-block { padding: 14px; border-radius: 10px; background: var(--surface-soft); }
.help-block h3 { margin-bottom: 8px; }
.help-block p,
.help-block li { line-height: 1.6; }
.help-block ul,
.help-block ol { display: grid; gap: 6px; margin: 7px 0 0; padding-left: 22px; }
.help-block pre,
.help-view { padding: 14px; overflow: auto; border-radius: 10px; background: var(--surface-soft); line-height: 1.55; white-space: pre-wrap; }
.prose-help p { margin-bottom: 10px; }
.action-rules-table { min-width: 900px; table-layout: fixed; }
.action-rules-table th:nth-child(1) { width: 18%; }
.action-rules-table th:nth-child(2),
.action-rules-table th:nth-child(3) { width: 30%; }
.action-rules-table th:nth-child(4) { width: 12%; }
.action-rules-table th:nth-child(5) { width: 10%; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 14px;
  color: #ffffff;
  border-radius: 9px;
  background: var(--ok);
  box-shadow: var(--shadow);
}
.toast.error { background: var(--bad); }

@media (max-width: 960px) {
  #dashboard { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 14px 16px; }
  .brand-block { padding: 0; }
  .primary-action { width: auto; grid-column: 2; grid-row: 1; }
  .main-nav { grid-column: 1 / -1; display: flex; overflow-x: auto; }
  .nav-item { width: auto; white-space: nowrap; }
  .sidebar-tools { grid-column: 1 / -1; display: flex; margin: 0; padding: 0; border: 0; }
  .sidebar-meta { display: none; }
  .priority-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .workspace { padding: 20px 12px 36px; }
  .workspace-header { align-items: flex-start; }
  .header-actions { align-items: flex-end; flex-direction: column; }
  .priority-grid { gap: 10px; }
  .panel,
  .content-section { padding: 15px; border-radius: 11px; }
  .metric-split { grid-template-columns: 1fr; }
  .summary-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .summary-stats div { padding: 9px 7px; text-align: center; }
  .summary-stats strong { font-size: 1.2rem; }
  .route-strip { align-items: flex-start; flex-direction: column; }
  .route-strip > div { align-items: flex-start; flex-wrap: wrap; justify-content: flex-start; }
  .task-card-footer,
  .result-row { align-items: flex-start; flex-direction: column; }
  .task-actions { justify-content: flex-start; }
  .task-type-picker { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .field-span-2 { grid-column: auto; }
  .battle-plan-control { grid-template-columns: 1fr; }
  .results-toolbar { align-items: stretch; flex-direction: column; }
  .results-toolbar label { align-items: stretch; flex-direction: column; }
  .results-toolbar select,
  .results-search input { width: 100%; }
  .results-search { margin-left: 0; }
  .drawer-panel { width: 100%; }
}

@media (max-width: 430px) {
  .sidebar { grid-template-columns: 1fr; }
  .primary-action { grid-column: 1; grid-row: auto; }
  .workspace-header { flex-direction: column; }
  .header-actions { width: 100%; flex-direction: row; justify-content: space-between; align-items: center; }
  .summary-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
