:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --success: #15803d;
  --danger: #b91c1c;
  --warning: #b45309;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { color: var(--text); background: var(--bg); font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; }
body { min-height: 100vh; margin: 0; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

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

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(390px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 12px 32px rgba(17, 24, 39, .06); }
.login-card h1 { margin: 22px 0 6px; font-size: 26px; }
.login-card > p { margin: 0; font-size: 14px; }
.form-stack { display: grid; gap: 16px; margin-top: 24px; }

label { display: grid; gap: 7px; color: #374151; font-size: 13px; font-weight: 650; }
.input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 9px; outline: none; color: var(--text); background: #fff; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.button { min-height: 40px; padding: 8px 14px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 700; white-space: nowrap; transition: background .15s, border-color .15s; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button.full { width: 100%; }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { color: #374151; border-color: var(--line-strong); background: #fff; }
.button.secondary:hover { background: var(--surface-soft); }
.button.success { color: #fff; background: var(--success); }
.button.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.link-button { padding: 0; border: 0; color: var(--muted); background: none; cursor: pointer; }
.alert, .toast { padding: 11px 13px; border-radius: 9px; font-size: 13px; }
.alert.error, .toast.error { color: #991b1b; background: #fee2e2; }

.app { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; width: 220px; flex-direction: column; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface); }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 22px; }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand strong { font-size: 14px; }
.sidebar-brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.nav { display: grid; gap: 4px; }
.nav-item { display: flex; width: 100%; align-items: center; gap: 10px; padding: 11px 12px; border: 0; border-radius: 9px; color: #4b5563; background: transparent; cursor: pointer; text-align: left; font-weight: 650; }
.nav-item:hover { background: var(--surface-soft); }
.nav-item.active { color: var(--primary-dark); background: #eff6ff; }
.nav-icon { display: grid; width: 20px; height: 20px; place-items: center; color: currentColor; font-size: 14px; }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding: 15px 7px 2px; border-top: 1px solid var(--line); font-size: 13px; }

.main { min-height: 100vh; margin-left: 220px; padding: 26px 28px 52px; }
.topbar { display: flex; max-width: 1320px; align-items: center; justify-content: space-between; gap: 16px; margin: 0 auto 20px; }
.topbar h1 { margin: 0; font-size: 25px; letter-spacing: -.02em; }
.top-actions, .hero-actions, .filter-row, .form-actions { display: flex; align-items: center; gap: 9px; }
.status-chip { display: inline-flex; min-height: 28px; align-items: center; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status-chip.neutral { color: #4b5563; background: #f3f4f6; }
.status-chip.running { color: #166534; background: #dcfce7; }
.status-chip.stopped { color: #991b1b; background: #fee2e2; }
.toast { position: fixed; top: 18px; right: 22px; z-index: 50; max-width: 380px; color: #1e3a8a; background: #dbeafe; box-shadow: 0 8px 24px rgba(17, 24, 39, .12); }
.page { display: none; max-width: 1320px; margin: 0 auto; }
.page.active { display: block; }

.task-panel { display: flex; min-height: 126px; align-items: center; justify-content: space-between; gap: 20px; padding: 24px; border: 1px solid #bfdbfe; border-radius: var(--radius); background: #eff6ff; }
.task-panel h2 { margin: 0 0 7px; font-size: 24px; }
.task-panel p { margin: 0; color: #4b5563; font-size: 14px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 14px 0; }
.metric, .card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric { min-width: 0; padding: 16px; }
.metric span, .metric small { display: block; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.metric strong { display: block; overflow: hidden; margin: 7px 0 4px; font-size: 20px; text-overflow: ellipsis; white-space: nowrap; }
.card { margin-bottom: 14px; padding: 18px; }
.compact-card { align-self: start; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2, .section-intro h2 { margin: 0 0 4px; font-size: 17px; }
.card-head p, .section-intro p { margin: 0; color: var(--muted); font-size: 13px; }
.content-grid { display: grid; gap: 14px; }
.content-grid.two-one { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); }
.empty { padding: 25px 14px; border: 1px dashed var(--line-strong); border-radius: 9px; color: var(--muted); background: var(--surface-soft); text-align: center; }

.list-item, .timeline-item, .result-card, .selected-card { border-top: 1px solid var(--line); background: #fff; }
.list > :first-child, .timeline > :first-child, .course-results > :first-child, .selected-grid > :first-child { border-top: 0; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 2px; }
.list-item h3, .result-card h3, .selected-card h3 { margin: 0 0 4px; font-size: 14px; }
.list-item p, .result-card p, .selected-card p { margin: 0; color: var(--muted); font-size: 12px; }
.guide-list { display: grid; gap: 10px; margin: 0; padding-left: 22px; color: #4b5563; font-size: 13px; line-height: 1.6; }
.timeline-item { position: relative; padding: 13px 4px 13px 23px; }
.timeline-item::before { position: absolute; top: 18px; left: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); content: ""; }
.timeline-item strong { font-size: 13px; }
.timeline-item small { display: block; margin-top: 4px; color: var(--muted); }

.section-intro { margin-bottom: 14px; }
.course-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, .85fr); gap: 14px; }
.stack-gap { display: flex; flex-direction: column; }
.search-grid { display: grid; grid-template-columns: 1fr .65fr auto; gap: 12px; align-items: end; }
.search-button { height: 44px; }
.filter-row { margin-top: 14px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 7px; font-weight: 500; }
.check input { accent-color: var(--primary); }
.push { margin-left: auto; }
.course-results, .selected-grid, .list, .timeline { display: grid; }
.result-card { padding: 15px 2px; }
.result-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.result-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.tag { display: inline-flex; align-items: center; padding: 3px 7px; border-radius: 999px; color: #4b5563; background: #f3f4f6; font-size: 11px; font-weight: 700; }
.tag.stock { color: #166534; background: #dcfce7; }
.tag.full { color: #991b1b; background: #fee2e2; }
.tag.warn { color: #92400e; background: #fef3c7; }
.tag.info { color: #1d4ed8; background: #dbeafe; }
.tag.duplicate { color: #9d174d; background: #fce7f3; }
.result-detail { color: var(--muted); font-size: 12px; line-height: 1.6; }
.sticky-card { position: sticky; top: 16px; }
.selected-card { padding: 12px 2px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.span-2 { grid-column: span 2; }
.detail-list { margin: 0; }
.detail-list div { display: flex; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; font-weight: 700; text-align: right; }
.notice { padding: 16px; border: 1px solid #bae6fd; border-radius: var(--radius); background: #f0f9ff; }
.notice h3 { margin: 0 0 7px; font-size: 15px; }
.notice p { margin: 0; color: #4b5563; font-size: 13px; line-height: 1.65; }

@media (max-width: 1020px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .course-layout, .content-grid.two-one { grid-template-columns: 1fr; }
  .sticky-card { position: static; }
  .search-grid { grid-template-columns: 1fr 1fr; }
  .search-button { grid-column: span 2; }
}

@media (max-width: 720px) {
  body { padding-bottom: 68px; }
  .sidebar { position: fixed; inset: auto 0 0; width: auto; padding: 8px max(10px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); border-top: 1px solid var(--line); border-right: 0; }
  .sidebar-brand, .sidebar-foot { display: none; }
  .nav { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .nav-item { flex-direction: column; justify-content: center; gap: 2px; min-height: 50px; padding: 5px; text-align: center; }
  .nav-icon { height: 17px; font-size: 12px; }
  .nav-item span:last-child { font-size: 11px; }
  .main { margin-left: 0; padding: 18px 14px 32px; }
  .topbar { margin-bottom: 15px; }
  .topbar h1 { font-size: 21px; }
  .top-actions .status-chip { display: none; }
  .task-panel { min-height: 0; align-items: flex-start; flex-direction: column; padding: 18px; }
  .task-panel h2 { font-size: 21px; }
  .hero-actions { width: 100%; }
  .hero-actions .button { flex: 1; }
  .metrics { gap: 9px; margin: 10px 0; }
  .metric { padding: 14px; }
  .metric strong { font-size: 18px; }
  .card { padding: 15px; }
  .search-grid, .form-grid { grid-template-columns: 1fr; }
  .search-button, .span-2 { grid-column: span 1; }
  .filter-row { align-items: flex-start; }
  .push { width: 100%; margin-left: 0; }
  .result-main { flex-direction: column; }
  .result-main .button { width: 100%; }
  .toast { top: 10px; right: 12px; left: 12px; max-width: none; }
  .login-card { padding: 24px; }
}

@media (max-width: 430px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric small { white-space: normal; }
  .hero-actions { flex-direction: column-reverse; }
  .hero-actions .button { width: 100%; }
  .card-head { align-items: flex-start; }
  .card-head .button { padding-inline: 10px; }
}
