:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #1f2937;
  --muted: #667085;
  --line: #e4e7ec;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --green: #0f8a5f;
  --green-soft: #ecfdf3;
  --amber: #a15c00;
  --amber-soft: #fff7e6;
  --red: #c53a45;
  --sidebar: #1f2937;
  --sidebar-muted: #98a2b3;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.login-view {
  align-items: center;
  background: #eef1f5;
  display: flex;
  min-height: 100vh;
  padding: 24px;
  justify-content: center;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
  max-width: 460px;
  padding: 30px;
  width: 100%;
}
.login-brand { align-items: center; display: flex; gap: 14px; margin-bottom: 4px; }
.login-brand h1 { font-size: 21px; margin: 0; }
.login-brand p { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.login-card label, .form-grid label {
  color: #475467;
  display: grid;
  font-size: 12px;
  font-weight: 600;
  gap: 7px;
}
.login-card input, .form-grid input, .form-grid textarea, .search {
  background: #fff;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  color: var(--ink);
  min-height: 40px;
  padding: 9px 11px;
  width: 100%;
}
.login-card input:focus, .form-grid input:focus, .form-grid textarea:focus, .search:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  outline: 0;
}
.login-note { color: var(--muted); font-size: 11px; margin: -4px 0 0; }
.form-error { color: var(--red); font-size: 12px; margin: 0; min-height: 18px; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex: 0 0 226px;
  flex-direction: column;
  min-height: 100vh;
  padding: 22px 14px 16px;
  position: sticky;
  top: 0;
}
.brand { align-items: center; display: flex; gap: 11px; padding: 2px 8px 28px; }
.brand-mark {
  align-items: center;
  background: var(--blue);
  border-radius: 7px;
  display: flex;
  font-size: 20px;
  font-weight: 800;
  height: 40px;
  justify-content: center;
  width: 40px;
}
.brand b { display: block; font-size: 15px; }
.brand small { color: var(--sidebar-muted); display: block; font-size: 11px; margin-top: 1px; }
.nav { display: grid; gap: 4px; }
.nav-item {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: #d0d5dd;
  padding: 11px 12px;
  text-align: left;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav-item.active { background: #fff; color: var(--ink); font-weight: 700; }
.sidebar-foot { color: var(--sidebar-muted); font-size: 11px; margin-top: auto; padding: 20px 8px 0; }
.connection-line { align-items: center; display: flex; gap: 7px; }
.status-dot { background: #98a2b3; border-radius: 50%; height: 7px; width: 7px; }
.status-dot.ok { background: #32d583; box-shadow: 0 0 0 3px rgba(50, 213, 131, 0.15); }
.status-dot.bad { background: #f97066; }
.nav-quiet {
  background: transparent;
  border: 0;
  color: #d0d5dd;
  margin-top: 10px;
  padding: 0;
  text-align: left;
}
.nav-quiet:hover { color: #fff; }

.main { flex: 1; min-width: 0; padding: 26px 30px 48px; }
.topbar { align-items: center; display: flex; justify-content: space-between; margin-bottom: 22px; }
.eyebrow { color: var(--blue); font-size: 10px; font-weight: 800; letter-spacing: 1.5px; margin: 0; }
.topbar h1 { font-size: 25px; margin: 3px 0 0; }
.top-actions { align-items: center; color: var(--muted); display: flex; font-size: 12px; gap: 12px; }
.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 650;
  min-height: 38px;
  padding: 8px 13px;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.secondary { background: #fff; border-color: #d0d5dd; color: #344054; }
.btn.secondary:hover { background: #f9fafb; }
.btn.tiny { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn:disabled { cursor: default; opacity: 0.45; }

.page-section { display: none; }
.page-section.active { display: block; }
.metric-grid { display: grid; gap: 12px; grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 16px; }
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 112px;
  padding: 16px;
}
.metric-card span { color: var(--muted); display: block; font-size: 12px; }
.metric-card strong { display: block; font-size: 26px; letter-spacing: -0.4px; margin-top: 7px; }
.metric-card small { color: var(--muted); display: block; font-size: 11px; margin-top: 6px; }
.compact-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.dashboard-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr); margin-bottom: 16px; }
.dashboard-grid.even { grid-template-columns: 1fr 1fr; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.panel-head { align-items: flex-start; display: flex; justify-content: space-between; margin-bottom: 16px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-head p { color: var(--muted); font-size: 11px; margin: 3px 0 0; }
.badge { border-radius: 999px; display: inline-flex; font-size: 10px; font-weight: 700; padding: 4px 8px; white-space: nowrap; }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.neutral { background: #f2f4f7; color: var(--muted); }
.text-btn { background: transparent; border: 0; color: var(--blue); font-size: 12px; padding: 0; }
.text-btn:hover { text-decoration: underline; }

.bar-chart { align-items: flex-end; display: flex; gap: 8px; height: 170px; padding: 8px 2px 0; }
.bar-group { align-items: center; display: flex; flex: 1; flex-direction: column; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-group > span { color: var(--muted); font-size: 10px; margin-top: 7px; white-space: nowrap; }
.bar-values { color: #475467; font-size: 10px; margin-bottom: 4px; white-space: nowrap; }
.bar { background: #b2ccff; border-radius: 3px 3px 0 0; display: block; min-height: 3px; width: 70%; }
.bar.solid { background: var(--blue); }
.bar-pair { align-items: flex-end; display: flex; gap: 2px; height: 108px; justify-content: center; width: 100%; }
.bar-pair .bar { width: 36%; }
.bar.blue { background: var(--blue); }
.bar.green { background: #32a979; }
.chart-legend { color: var(--muted); display: flex; font-size: 11px; gap: 16px; justify-content: flex-end; margin-top: 4px; }
.legend { border-radius: 2px; display: inline-block; height: 8px; margin-right: 5px; width: 8px; }
.legend.blue { background: var(--blue); }
.legend.green { background: #32a979; }

.status-list { display: grid; gap: 2px; }
.status-row { align-items: center; border-bottom: 1px solid #f2f4f7; display: flex; font-size: 12px; justify-content: space-between; padding: 9px 0; }
.status-row:last-child { border-bottom: 0; }
.status-row b { font-size: 11px; }
.status-row b.ok { color: var(--green); }
.status-row b.warn { color: var(--amber); }
.compact-list { display: grid; }
.compact-row { align-items: center; border-bottom: 1px solid #f2f4f7; display: flex; gap: 10px; min-height: 56px; padding: 7px 0; }
.compact-row:last-child { border-bottom: 0; }
.compact-row > div { flex: 1; min-width: 0; }
.compact-row b { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-row small { color: var(--muted); display: block; font-size: 10px; margin-top: 2px; }
.user-avatar, .order-mark {
  align-items: center;
  background: var(--blue-soft);
  border-radius: 6px;
  color: var(--blue);
  display: flex;
  flex: 0 0 32px;
  font-size: 12px;
  font-weight: 800;
  height: 32px;
  justify-content: center;
}
.order-mark { background: #fef3f2; color: #b42318; }

.section-toolbar { align-items: flex-end; display: flex; justify-content: space-between; margin-bottom: 16px; }
.section-toolbar h2 { font-size: 19px; margin: 0; }
.section-toolbar p { color: var(--muted); font-size: 11px; margin: 3px 0 0; }
.toolbar-actions { display: flex; gap: 8px; }
.search { min-height: 38px; width: 230px; }
.table-panel { padding: 0; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; min-width: 900px; width: 100%; }
th, td { border-bottom: 1px solid #f2f4f7; padding: 12px 14px; text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: #f9fafb; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
td { font-size: 12px; }
tbody tr:hover { background: #fbfcfe; }
.user-cell { align-items: center; display: flex; gap: 9px; }
.user-cell small { color: var(--muted); display: block; font-size: 10px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
.empty { color: var(--muted); padding: 36px; text-align: center; }
.pager { align-items: center; display: flex; gap: 10px; justify-content: flex-end; min-height: 48px; padding: 8px 14px; }
.pager span { color: var(--muted); font-size: 11px; }
.inline-summary { color: var(--muted); font-size: 12px; margin: -4px 0 12px; }

.funnel { display: grid; gap: 14px; }
.funnel-row > div { align-items: center; display: flex; font-size: 12px; justify-content: space-between; }
.funnel-row > div b { font-size: 13px; }
.funnel-row i { background: #eef2f6; border-radius: 3px; display: block; height: 7px; margin-top: 7px; overflow: hidden; }
.funnel-row i em { background: var(--blue); display: block; height: 100%; }
.funnel-row small { color: var(--muted); display: block; font-size: 10px; margin-top: 4px; text-align: right; }
.compact-table { min-width: 520px; }

.segmented { background: #e9edf2; border-radius: 7px; display: inline-flex; gap: 3px; margin-bottom: 10px; padding: 3px; }
.segment { background: transparent; border: 0; border-radius: 5px; color: #475467; padding: 8px 14px; }
.segment.active { background: #fff; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12); color: var(--ink); font-weight: 700; }
.asset-grid { display: grid; gap: 12px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.asset-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; position: relative; }
.asset-card a { background: #edf1f6; display: block; padding: 12px; }
.asset-card img { aspect-ratio: 346 / 489; background: #fff; display: block; object-fit: cover; width: 100%; }
.asset-card > div { display: grid; gap: 2px; padding: 10px 11px 12px; }
.asset-card b { font-size: 12px; }
.asset-card small { color: var(--muted); font-size: 10px; }
.asset-card > .badge { position: absolute; right: 8px; top: 8px; }

.template-grid { display: grid; gap: 12px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.template-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.template-image { background: #e9eef5; display: block; padding: 10px; }
.template-image img { aspect-ratio: 355 / 500; background: #fff; display: block; object-fit: cover; width: 100%; }
.template-body { padding: 10px; }
.template-title { align-items: flex-start; display: flex; gap: 6px; justify-content: space-between; }
.template-title b { font-size: 12px; line-height: 1.35; }
.template-body small { color: var(--muted); display: block; font-size: 10px; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-actions { align-items: center; display: flex; font-size: 10px; justify-content: space-between; margin-top: 8px; color: var(--muted); }

dialog { border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22); color: var(--ink); max-width: calc(100vw - 36px); padding: 0; }
dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.detail-dialog { width: 620px; }
.template-dialog { width: 680px; }
.dialog-head { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; padding: 16px 18px; }
.dialog-head h2 { font-size: 16px; margin: 0; }
.icon-btn { background: transparent; border: 0; color: #667085; font-size: 24px; height: 32px; line-height: 1; width: 32px; }
.dialog-content { max-height: 72vh; overflow-y: auto; padding: 18px; }
.detail-metrics { display: grid; gap: 10px; grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; }
.detail-metrics > div { background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
.detail-metrics span { color: var(--muted); display: block; font-size: 10px; }
.detail-metrics b { display: block; font-size: 20px; margin-top: 4px; }
.detail-list { display: grid; gap: 1px; margin: 0 0 20px; }
.detail-list > div { background: var(--surface-soft); display: grid; grid-template-columns: 120px 1fr; padding: 9px 11px; }
.detail-list dt { color: var(--muted); font-size: 11px; }
.detail-list dd { font-size: 12px; margin: 0; word-break: break-all; }
.dialog-orders { display: grid; gap: 6px; }
.dialog-orders > div { align-items: center; border: 1px solid var(--line); border-radius: 6px; display: grid; font-size: 11px; gap: 8px; grid-template-columns: 1fr auto auto; padding: 9px; }
.loading-block { color: var(--muted); padding: 40px; text-align: center; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; max-height: 70vh; overflow-y: auto; padding: 18px; }
.span-2 { grid-column: span 2; }
.form-grid textarea { resize: vertical; }
.check-label { align-items: center; display: flex !important; grid-template-columns: auto 1fr; }
.check-label input { box-shadow: none; min-height: auto; width: auto; }
.dialog-actions { border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; }

.toast {
  background: #1f2937;
  border-radius: 6px;
  bottom: 22px;
  color: #fff;
  left: 50%;
  opacity: 0;
  padding: 9px 14px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 8px);
  transition: 0.2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1280px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .asset-grid, .template-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar { flex-basis: 190px; }
  .main { padding: 22px 18px 36px; }
  .dashboard-grid, .dashboard-grid.even { grid-template-columns: 1fr; }
  .asset-grid, .template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .app-shell { display: block; }
  .sidebar { min-height: auto; position: static; width: auto; }
  .brand { padding-bottom: 14px; }
  .nav { display: flex; overflow-x: auto; padding-bottom: 4px; }
  .nav-item { flex: 0 0 auto; }
  .sidebar-foot { display: none; }
  .topbar { align-items: flex-start; display: block; }
  .top-actions { margin-top: 12px; }
  .metric-grid, .compact-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-toolbar { align-items: stretch; display: block; }
  .toolbar-actions { margin-top: 12px; }
  .search { flex: 1; width: auto; }
  .asset-grid, .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .detail-metrics { grid-template-columns: repeat(2, 1fr); }
}
