:root {
  --bg: #f5f5f7;
  --card: rgba(255, 255, 255, 0.86);
  --solid: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --green: #1a7f37;
  --green-soft: rgba(26, 127, 55, 0.1);
  --orange: #b25000;
  --orange-soft: rgba(255, 149, 0, 0.14);
  --red: #c62828;
  --red-soft: rgba(198, 40, 40, 0.1);
  --radius: 18px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.08), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns 180ms ease;
}

.sidebar {
  position: relative;
  height: 100%;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2b2b2f, #5b5b62);
  color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .3px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14px; }
.brand-text small { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); text-align: left; font-size: 13.5px;
}
.nav-item:hover { background: rgba(0, 0, 0, 0.04); color: var(--text); }
.nav-item.active { background: rgba(0, 0, 0, 0.06); color: var(--text); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; font-size: 15px; opacity: .8; }
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 18px; }
.sidebar-foot small { color: var(--muted); font-size: 11px; padding: 0 10px; }

.main {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 32px 40px;
}

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 0 18px;
  background: linear-gradient(to bottom, var(--bg) 70%, rgba(245, 245, 247, 0));
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: -0.4px; }
.subtitle { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.icon-btn {
  width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255, 255, 255, .8); color: var(--muted);
  display: grid; place-items: center; font-size: 17px; line-height: 1;
}
.icon-btn:hover { background: #fff; color: var(--text); }

.btn {
  border: 1px solid var(--line); border-radius: 999px;
  background: #fff; padding: 8px 16px; font-size: 13px; font-weight: 500;
  white-space: nowrap;
}
.btn:hover { background: #fafafa; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--red); }
.btn.wide { width: 100%; padding: 10px 16px; }
.btn:disabled { opacity: .55; cursor: default; }

.view { display: none; }
.view.active { display: block; }

/* ---------- 任务列表 ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar-meta { margin-left: auto; color: var(--muted); font-size: 12px; }

.job-list { display: flex; flex-direction: column; gap: 10px; }
.job-card {
  display: grid; grid-template-columns: minmax(0, 1.6fr) 110px minmax(160px, .9fr) 150px auto;
  align-items: center; gap: 16px;
  background: var(--solid); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.job-card:hover { box-shadow: var(--shadow); }
.job-name { min-width: 0; }
.job-name strong { display: block; font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-name small { color: var(--muted); font-size: 11.5px; }
.job-progress { display: flex; flex-direction: column; gap: 6px; }
.job-progress span { font-size: 11.5px; color: var(--muted); }
.job-time { color: var(--muted); font-size: 12px; }
.job-actions { display: flex; justify-content: flex-end; gap: 6px; }

.progress-track { height: 6px; border-radius: 999px; background: rgba(0,0,0,.07); overflow: hidden; }
.progress-bar { height: 100%; border-radius: 999px; background: var(--accent); transition: width 300ms ease; }
.progress-bar.green { background: var(--green); }
.progress-bar.orange { background: #ff9500; }
.progress-bar.red { background: var(--red); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: rgba(0,0,0,.05); color: var(--muted); white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.queued { background: rgba(0,0,0,.05); color: #6e6e73; }
.chip.running { background: var(--accent-soft); color: var(--accent); }
.chip.done { background: var(--green-soft); color: var(--green); }
.chip.partial { background: var(--orange-soft); color: var(--orange); }
.chip.failed { background: var(--red-soft); color: var(--red); }
.chip.cancelled { background: rgba(0,0,0,.06); color: #86868b; }
.chip.healthy { background: var(--green-soft); color: var(--green); }
.chip.unhealthy { background: var(--red-soft); color: var(--red); }
.chip.offline { background: rgba(0,0,0,.06); color: #86868b; }
.chip.isolated { background: var(--red-soft); color: var(--red); }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 80px 20px; color: var(--muted);
}
.empty-icon { font-size: 34px; margin-bottom: 12px; opacity: .5; }
.empty h2 { margin: 0 0 6px; color: var(--text); font-size: 17px; }
.empty p { margin: 0 0 18px; max-width: 380px; font-size: 13px; line-height: 1.5; }

/* ---------- 下拉 ---------- */
.dropdown { position: relative; }
.dropdown-btn {
  display: flex; align-items: center; gap: 8px; min-width: 120px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  padding: 8px 12px; font-size: 12.5px; color: var(--text);
}
.dropdown-btn:hover { background: #fafafa; }
.dropdown-label { flex: 1; text-align: left; }
.chevron { color: var(--muted); font-size: 12px; transition: transform 160ms ease; }
.dropdown.open .chevron { transform: rotate(180deg); }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 100%;
  background: #fff; border-radius: 12px; padding: 5px;
  box-shadow: 0 10px 40px rgba(0,0,0,.14), 0 0 0 .5px rgba(0,0,0,.05);
  opacity: 0; transform: translateY(-4px) scale(.98); pointer-events: none; z-index: 80;
  transition: opacity 140ms ease, transform 140ms ease;
}
.dropdown.open .dropdown-menu { opacity: 1; transform: none; pointer-events: auto; }
.dropdown-item {
  display: block; width: 100%; border: 0; background: transparent; text-align: left;
  padding: 8px 10px; border-radius: 8px; font-size: 12.5px; white-space: nowrap;
}
.dropdown-item:hover { background: rgba(0,0,0,.05); }
.dropdown-item.selected { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > span { color: var(--muted); font-size: 12px; }
.field input[type="text"], .field input[type="password"] {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; padding: 9px 12px; outline: none; font-size: 13px;
}
.field input:focus { border-color: rgba(0, 113, 227, .5); box-shadow: 0 0 0 3px rgba(0,113,227,.1); }
.hint { margin: 0; color: var(--muted); font-size: 11.5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid { display: grid; gap: 16px; }
.form-error { margin: 0; color: var(--red); font-size: 12.5px; }
.checkbox-field { justify-content: flex-start; }
.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { display: none; }
.switch-track { width: 38px; height: 22px; border-radius: 999px; background: rgba(0,0,0,.14); position: relative; transition: background 160ms ease; flex: 0 0 auto; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform 160ms ease; }
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch-text { font-size: 12.5px; color: var(--text); }

.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: rgba(0,0,0,.05); gap: 2px; }
.segmented button { border: 0; background: transparent; border-radius: 8px; padding: 6px 12px; font-size: 12.5px; color: var(--muted); }
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 600; }
.file-picker {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px dashed rgba(0,0,0,.18); border-radius: 12px; background: rgba(255,255,255,.6);
  padding: 14px; font-size: 12.5px; color: var(--muted); text-align: left;
}
.file-picker:hover { border-color: var(--accent); color: var(--accent); }
.file-picker-icon { font-size: 18px; }
.upload-progress { display: flex; flex-direction: column; gap: 7px; }
.upload-progress span { font-size: 12px; color: var(--muted); }

/* ---------- 弹窗 ---------- */
.modal, .drawer { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop, .drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.28); backdrop-filter: blur(3px); }
.modal-card {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 60px); overflow-y: auto;
  background: #fff; border-radius: 22px; padding: 24px; box-shadow: 0 24px 80px rgba(0,0,0,.22);
}
.modal-head, .drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.modal-head h2, .drawer-head h2 { margin: 0; font-size: 20px; letter-spacing: -.3px; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

.drawer-card {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(720px, 100vw); background: var(--bg); box-shadow: -20px 0 80px rgba(0,0,0,.16);
  display: flex; flex-direction: column;
}
.drawer-head { padding: 22px 24px 14px; margin: 0; background: rgba(255,255,255,.7); backdrop-filter: blur(20px); border-bottom: 1px solid var(--line); }
.drawer-body { padding: 20px 24px 40px; overflow-y: auto; }

/* ---------- Worker ---------- */
.worker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.worker-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.worker-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.worker-head strong { font-size: 16px; }
.worker-rows { display: grid; gap: 8px; }
.worker-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.worker-row span:first-child { color: var(--muted); }
.worker-row span:last-child { text-align: right; }
.worker-error { margin-top: 12px; padding: 9px 10px; border-radius: 10px; background: var(--red-soft); color: var(--red); font-size: 11.5px; line-height: 1.45; }

/* ---------- 机器（只读） ---------- */
.panel-banner { background: var(--orange-soft); color: var(--orange); border-radius: 12px; padding: 12px 14px; font-size: 12.5px; line-height: 1.5; margin-bottom: 14px; }
.panel-banner.error { background: var(--red-soft); color: var(--red); }
.panel-banner.info { background: var(--accent-soft); color: var(--accent); }
.machine-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 16px; }
.machine-stat { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.machine-stat strong { display: block; font-size: 22px; letter-spacing: -.4px; }
.machine-stat span { color: var(--muted); font-size: 12px; }
.machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.machine-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; cursor: pointer; transition: border-color 160ms ease, box-shadow 160ms ease; }
.machine-card:hover { box-shadow: 0 10px 30px rgba(0,0,0,.06); }
.machine-card.selected { border-color: rgba(0,113,227,.45); }
.machine-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.machine-title { min-width: 0; }
.machine-title strong { display: block; font-size: 16px; }
.machine-title small { display: block; color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
.machine-badges { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.badge.worker { background: var(--accent-soft); color: var(--accent); padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.machine-rows { display: grid; gap: 8px; }
.machine-progress { margin-top: 14px; }
.machine-chart-btn { display: inline-block; margin-top: 12px; color: var(--accent); font-size: 12px; }
.machine-chart { display: grid; gap: 4px; margin-top: 12px; }
.chart-label { color: var(--muted); font-size: 11px; margin-top: 6px; }
.chart-loading { color: var(--muted); font-size: 12px; }
.spark { display: block; width: 100%; height: 44px; }
.value-on { color: var(--green); font-weight: 600; }
.value-off { color: var(--muted); }

/* ---------- 设置 ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.settings-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.settings-card h3 { margin: 0 0 14px; font-size: 15px; }
.metric-big { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.metric-label { color: var(--muted); font-size: 12px; margin-top: 2px; }
.metric-row { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.metric-row span:first-child { color: var(--muted); }

/* ---------- 详情 ---------- */
.detail-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; }
.detail-stat { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.detail-stat strong { display: block; font-size: 18px; }
.detail-stat span { color: var(--muted); font-size: 11.5px; }
.shard-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
.shard-table th, .shard-table td { text-align: left; padding: 10px 12px; font-size: 12px; border-bottom: 1px solid var(--line); }
.shard-table th { background: rgba(0,0,0,.03); color: var(--muted); font-weight: 500; }
.shard-table tr:last-child td { border-bottom: 0; }
.detail-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.event-list { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.event-item { display: flex; gap: 8px; font-size: 11.5px; color: var(--muted); }
.event-item time { flex: 0 0 auto; opacity: .8; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: rgba(29,29,31,.92); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 12.5px; box-shadow: 0 10px 40px rgba(0,0,0,.2); z-index: 200;
  max-width: calc(100vw - 40px);
}
.toast.error { background: rgba(198,40,40,.95); }

/* ---------- 登录 ---------- */
.login-body { display: grid; place-items: center; background: radial-gradient(circle at 50% 0%, #fff, var(--bg) 60%); }
.login-card { width: min(380px, calc(100vw - 32px)); background: rgba(255,255,255,.9); border-radius: 24px; padding: 36px 30px; box-shadow: var(--shadow); text-align: center; }
.login-logo { width: 52px; height: 52px; border-radius: 15px; margin: 0 auto 16px; display: grid; place-items: center; background: linear-gradient(145deg,#2b2b2f,#5b5b62); color: #fff; font-weight: 700; }
.login-card h1 { margin: 0 0 6px; font-size: 23px; letter-spacing: -.5px; }
.login-sub { margin: 0 0 26px; color: var(--muted); font-size: 12.5px; }
.login-card .field { text-align: left; margin-bottom: 14px; }
.login-hint { margin: 18px 0 0; color: var(--muted); font-size: 11px; }

/* ---------- 折叠 ---------- */
@media (min-width: 961px) {
  .layout.collapsed { grid-template-columns: 72px minmax(0, 1fr); }
  .layout.collapsed .brand-text,
  .layout.collapsed .nav-text,
  .layout.collapsed .nav-badge,
  .layout.collapsed .sidebar-foot small { display: none; }
  .layout.collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .layout.collapsed .nav-item { justify-content: center; padding: 10px 0; }
}

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 232px; transform: translateX(-100%); transition: transform 180ms ease; z-index: 90; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 60px rgba(0,0,0,.2); }
  .only-desktop { display: grid; }
  .main { padding: 0 16px 32px; }
  .topbar h1 { font-size: 21px; }
  .job-card { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .job-progress, .job-time { grid-column: 1 / -1; }
  .job-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .form-row { grid-template-columns: 1fr; }
  .drawer-card { width: 100vw; }
}

@media (min-width: 961px) {
  #collapseBtn { display: grid; }
}

@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .modal-card { padding: 20px 18px; }
  .shard-table th:nth-child(3), .shard-table td:nth-child(3) { display: none; }
}
