:root {
  --primary: #165dff;
  --primary-hover: #4080ff;
  --primary-soft: #e8f3ff;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-muted: #f2f3f5;
  --line: #e5e6eb;
  --line-strong: #c9cdd4;
  --text: #1d2129;
  --text-secondary: #4e5969;
  --text-muted: #86909c;
  --success: #00b42a;
  --success-soft: #e8ffea;
  --warning: #ff7d00;
  --warning-soft: #fff7e8;
  --danger: #f53f3f;
  --danger-soft: #fff2f0;
  --purple: #722ed1;
  --purple-soft: #f5e8ff;
  --shadow: 0 8px 24px rgb(29 33 41 / 12%);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
a { color: inherit; }

.appShell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.appShell.isCollapsed { grid-template-columns: 64px minmax(0, 1fr); }

.sideNav {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  height: 100vh;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  transition: width 160ms ease, transform 160ms ease;
}

.brandBlock {
  display: flex;
  height: 56px;
  flex: 0 0 56px;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  white-space: nowrap;
}

.brandMark {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.brandTitle { font-size: 15px; font-weight: 600; line-height: 20px; }
.brandSub { color: var(--text-muted); font-size: 11px; line-height: 16px; }

.navScroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 12px 8px;
}

.navSection + .navSection { margin-top: 12px; }
.navSectionLabel { padding: 0 10px 6px; color: var(--text-muted); font-size: 11px; line-height: 20px; }

.navLink {
  position: relative;
  display: grid;
  min-height: 38px;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin: 2px 0;
  padding: 0 10px;
  border-radius: 3px;
  color: var(--text-secondary);
  text-decoration: none;
}

.navLink:hover { background: var(--surface-muted); color: var(--text); }
.navLink.isActive { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.navLink.isActive::before {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: -8px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--primary);
  content: "";
}

.navGlyph {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}

.navLink.isActive .navGlyph, .navLink:hover .navGlyph { color: var(--primary); }
.navTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sideFooter { padding: 8px; border-top: 1px solid var(--line); }
.collapseButton {
  display: flex;
  width: 100%;
  height: 32px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text-secondary);
}
.collapseButton:hover { border-color: var(--line); background: var(--surface-muted); color: var(--primary); }

.appShell.isCollapsed .brandCopy,
.appShell.isCollapsed .navSectionLabel,
.appShell.isCollapsed .navTitle,
.appShell.isCollapsed .collapseText { display: none; }
.appShell.isCollapsed .brandBlock { justify-content: center; padding: 0; }
.appShell.isCollapsed .navLink { grid-template-columns: 1fr; justify-items: center; padding: 0; }
.appShell.isCollapsed .navLink.isActive::before { left: -8px; }
.appShell.isCollapsed .navLink:hover::after {
  position: absolute;
  top: 50%;
  left: calc(100% + 10px);
  z-index: 50;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  content: attr(data-tooltip);
  font-size: 12px;
  font-weight: 400;
  transform: translateY(-50%);
  white-space: nowrap;
}

.pageArea { min-width: 0; }

.topBar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(8px);
}

.topBarStart, .topBarEnd, .breadcrumbs, .inline, .buttonGroup, .filters, .tabs, .pagination {
  display: flex;
  align-items: center;
}
.topBarStart, .topBarEnd { gap: 12px; min-width: 0; }
.breadcrumbs { gap: 7px; min-width: 0; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.breadcrumbs strong { max-width: 180px; overflow: hidden; color: var(--text-secondary); font-weight: 500; text-overflow: ellipsis; }
.breadcrumbDivider { color: var(--line-strong); }

.globalSearch {
  width: min(28vw, 320px);
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: none;
  background: var(--bg);
  color: var(--text);
}
.globalSearch:focus, .control:focus, textarea:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 2px rgb(22 93 255 / 10%); }

.iconButton {
  display: inline-grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 17px;
  line-height: 1;
}
.iconButton:hover { background: var(--primary-soft); color: var(--primary); }
.mobileMenuButton { display: none; }
.userAvatar { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: #d6e8ff; color: var(--primary); font-size: 12px; font-weight: 600; }

.pageContent { display: grid; gap: 16px; padding: 20px 24px 36px; }
.pageHeader { display: flex; min-height: 60px; align-items: flex-start; justify-content: space-between; gap: 20px; }
.pageHeaderCopy { min-width: 0; }
.pageHeader h1 { margin: 0; font-size: 20px; font-weight: 600; line-height: 30px; }
.pageHeader p { max-width: 760px; margin: 5px 0 0; color: var(--text-muted); font-size: 13px; line-height: 20px; }
.pageHeaderActions { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }

.primaryButton, .secondaryButton, .textButton, .dangerButton {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: 3px;
  font-weight: 500;
  white-space: nowrap;
}
.primaryButton { border: 1px solid var(--primary); background: var(--primary); color: #fff; }
.primaryButton:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.secondaryButton { border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); }
.secondaryButton:hover { border-color: var(--primary); color: var(--primary); }
.textButton { border: 1px solid transparent; background: transparent; color: var(--primary); }
.textButton:hover { background: var(--primary-soft); }
.dangerButton { border: 1px solid var(--danger); background: var(--danger); color: #fff; }

.card { min-width: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.cardHeader { display: flex; min-height: 48px; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.cardTitle { margin: 0; font-size: 15px; font-weight: 600; line-height: 22px; }
.cardSubtitle { margin-top: 2px; color: var(--text-muted); font-size: 12px; line-height: 18px; }
.cardBody { padding: 16px; }

.grid { display: grid; gap: 16px; }
.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }

.metricCard { display: grid; min-height: 128px; grid-template-rows: auto 1fr auto; gap: 9px; padding: 16px; }
.metricLabel { color: var(--text-secondary); font-size: 12px; }
.metricValue { align-self: center; font-size: 24px; font-weight: 600; line-height: 32px; }
.metricNote { color: var(--text-muted); font-size: 12px; line-height: 18px; }
.metricAccent { width: 28px; height: 3px; border-radius: 2px; background: var(--primary); }
.metricAccent.green { background: var(--success); }
.metricAccent.orange { background: var(--warning); }
.metricAccent.purple { background: var(--purple); }

.notice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 13px 16px;
  border: 1px solid #bedaff;
  border-radius: 4px;
  background: #f2f8ff;
}
.notice.warning { border-color: #ffcf8b; background: var(--warning-soft); }
.notice.danger { border-color: #ffb7b7; background: var(--danger-soft); }
.noticeIcon { display: grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; }
.notice.warning .noticeIcon { background: var(--warning); }
.notice.danger .noticeIcon { background: var(--danger); }
.noticeTitle { font-weight: 600; line-height: 20px; }
.noticeText { margin-top: 2px; color: var(--text-secondary); font-size: 12px; line-height: 20px; }

.tag {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
}
.tag.blue { border-color: #bedaff; background: var(--primary-soft); color: var(--primary); }
.tag.green { border-color: #aff0b5; background: var(--success-soft); color: var(--success); }
.tag.orange { border-color: #ffcf8b; background: var(--warning-soft); color: var(--warning); }
.tag.red { border-color: #ffb7b7; background: var(--danger-soft); color: var(--danger); }
.tag.purple { border-color: #d3adf7; background: var(--purple-soft); color: var(--purple); }

.filters { flex-wrap: wrap; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.field { display: grid; min-width: 150px; gap: 6px; }
.field.grow { min-width: 220px; flex: 1 1 260px; }
.field label { color: var(--text-secondary); font-size: 12px; line-height: 18px; }
.control {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: 0;
  background: var(--surface);
  color: var(--text);
}
textarea.control { height: auto; min-height: 78px; padding: 8px 10px; line-height: 20px; resize: vertical; }

.tableWrap { width: 100%; overflow: auto; }
.dataTable { width: 100%; min-width: 900px; border-collapse: collapse; table-layout: fixed; }
.dataTable th, .dataTable td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.dataTable th { height: 40px; background: var(--bg); color: var(--text-secondary); font-size: 12px; font-weight: 500; }
.dataTable td { min-height: 44px; color: var(--text-secondary); line-height: 20px; }
.dataTable tbody tr:hover { background: #f7faff; }
.dataTable tbody tr:last-child td { border-bottom: 0; }
.dataTable .primaryCell { color: var(--text); font-weight: 500; }
.cellMeta { display: block; margin-top: 2px; color: var(--text-muted); font-size: 11px; line-height: 16px; }
.tableActions { display: flex; align-items: center; gap: 4px; }
.tableEmpty { padding: 36px !important; color: var(--text-muted) !important; text-align: center !important; }
.pagination { justify-content: space-between; min-height: 48px; gap: 12px; padding: 8px 16px; border-top: 1px solid var(--line); color: var(--text-muted); font-size: 12px; }

.tabs { gap: 2px; min-height: 40px; border-bottom: 1px solid var(--line); }
.tabButton { height: 40px; padding: 0 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--text-secondary); }
.tabButton:hover { color: var(--primary); }
.tabButton.isActive { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }

.segmented { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-muted); }
.segmentButton { min-height: 28px; padding: 0 12px; border: 0; border-radius: 2px; background: transparent; color: var(--text-secondary); }
.segmentButton.isActive { background: var(--surface); box-shadow: 0 1px 2px rgb(29 33 41 / 12%); color: var(--primary); font-weight: 500; }

.list { display: grid; gap: 0; }
.listItem { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 60px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.listItem:last-child { border-bottom: 0; }
.listItemTitle { font-weight: 500; line-height: 20px; }
.listItemText { margin-top: 2px; color: var(--text-muted); font-size: 12px; line-height: 18px; }

.stepList { display: grid; gap: 16px; }
.step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; }
.stepIndex { display: grid; width: 24px; height: 24px; place-items: center; border: 1px solid #bedaff; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 11px; font-weight: 600; }
.stepTitle { font-weight: 500; line-height: 22px; }
.stepText { color: var(--text-muted); font-size: 12px; line-height: 18px; }

.modeCards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.modeCard { min-height: 118px; padding: 14px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.modeCard.isEnabled { border-color: #bedaff; background: #f7faff; }
.modeCardTitle { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; }
.modeCard p { margin: 9px 0 0; color: var(--text-muted); font-size: 12px; line-height: 18px; }

.builderLayout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, .7fr); gap: 16px; }
.logicBar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.conditionList { display: grid; gap: 10px; }
.conditionRow { display: grid; grid-template-columns: 24px minmax(150px, 1.2fr) minmax(110px, .7fr) minmax(140px, 1fr) 32px; align-items: center; gap: 8px; }
.conditionIndex { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 50%; background: var(--surface-muted); color: var(--text-muted); font-size: 11px; }
.builderFooter { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.estimateBox { display: grid; min-height: 152px; place-items: center; padding: 20px; border: 1px dashed var(--line-strong); border-radius: 4px; background: var(--bg); text-align: center; }
.estimateValue { margin: 8px 0 4px; font-size: 24px; font-weight: 600; }
.estimateHint { max-width: 240px; color: var(--text-muted); font-size: 12px; line-height: 18px; }

.boundaryGrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.boundaryItem { padding: 14px; border-left: 3px solid var(--danger); background: var(--danger-soft); }
.boundaryItem strong { display: block; margin-bottom: 5px; }
.boundaryItem span { color: var(--text-secondary); font-size: 12px; line-height: 18px; }

.permissionLayers { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.permissionLayer { padding: 14px; border: 1px solid var(--line); border-radius: 4px; }
.permissionNumber { color: var(--primary); font-size: 12px; font-weight: 600; }
.permissionLayer h3 { margin: 8px 0 5px; font-size: 14px; }
.permissionLayer p { margin: 0; color: var(--text-muted); font-size: 12px; line-height: 18px; }

.definitionGrid { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 0; border: 1px solid var(--line); border-bottom: 0; }
.definitionGrid dt, .definitionGrid dd { min-height: 42px; margin: 0; padding: 10px 12px; border-bottom: 1px solid var(--line); line-height: 20px; }
.definitionGrid dt { background: var(--bg); color: var(--text-secondary); font-size: 12px; }
.definitionGrid dd { color: var(--text); }

.formGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.formGrid .full { grid-column: 1 / -1; }
.formHint { color: var(--text-muted); font-size: 11px; line-height: 17px; }
.required { color: var(--danger); }

.drawerMask {
  position: fixed;
  inset: 0;
  z-index: 80;
  visibility: hidden;
  background: rgb(29 33 41 / 38%);
  opacity: 0;
  transition: opacity 180ms ease, visibility 180ms ease;
}
.drawerMask.isOpen { visibility: visible; opacity: 1; }
.drawer {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  width: min(560px, calc(100vw - 48px));
  height: 100%;
  grid-template-rows: 56px minmax(0, 1fr) 60px;
  background: var(--surface);
  box-shadow: -8px 0 24px rgb(29 33 41 / 14%);
  transform: translateX(100%);
  transition: transform 180ms ease;
}
.drawerMask.isOpen .drawer { transform: translateX(0); }
.drawerHeader, .drawerFooter { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.drawerHeader h2 { margin: 0; font-size: 16px; font-weight: 600; }
.drawerBody { overflow: auto; padding: 20px; }
.drawerFooter { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.drawerSection + .drawerSection { margin-top: 20px; }
.drawerSection h3 { margin: 0 0 10px; font-size: 14px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  display: flex;
  max-width: min(380px, calc(100vw - 32px));
  min-height: 40px;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid #aff0b5;
  border-radius: 4px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.isVisible { opacity: 1; transform: translateY(0); }
.toastDot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--success); }
.drawerMask.isOpen + .toast { bottom: 76px; }

@media (min-width: 1040px) {
  .drawerMask.isOpen + .toast { right: 584px; bottom: 24px; }
}

.mobileNavMask { display: none; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

@media (max-width: 1180px) {
  .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modeCards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .permissionLayers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .globalSearch { width: 220px; }
}

@media (max-width: 900px) {
  .appShell, .appShell.isCollapsed { display: block; }
  .sideNav { position: fixed; left: 0; width: min(280px, calc(100vw - 48px)); transform: translateX(-100%); }
  .appShell.isMobileNavOpen .sideNav { transform: translateX(0); }
  .appShell.isCollapsed .brandCopy, .appShell.isCollapsed .navSectionLabel, .appShell.isCollapsed .navTitle, .appShell.isCollapsed .collapseText { display: block; }
  .appShell.isCollapsed .brandBlock { justify-content: flex-start; padding: 0 16px; }
  .appShell.isCollapsed .navLink { grid-template-columns: 20px minmax(0, 1fr); justify-items: stretch; padding: 0 10px; }
  .collapseButton { display: none; }
  .mobileNavMask { position: fixed; inset: 0; z-index: 25; display: block; visibility: hidden; border: 0; background: rgb(29 33 41 / 38%); opacity: 0; transition: opacity 160ms ease, visibility 160ms ease; }
  .appShell.isMobileNavOpen .mobileNavMask { visibility: visible; opacity: 1; }
  .mobileMenuButton { display: inline-grid; }
  .topBar { padding: 0 16px; }
  .breadcrumbs span:first-child, .breadcrumbs .breadcrumbDivider:first-of-type { display: none; }
  .globalSearch { width: 180px; }
  .pageContent { padding: 16px; }
  .pageHeader { align-items: stretch; }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .builderLayout { grid-template-columns: 1fr; }
  .boundaryGrid { grid-template-columns: 1fr; }
  .conditionRow { grid-template-columns: 24px minmax(0, 1fr) minmax(100px, .6fr) 32px; }
  .conditionRow .conditionValue { grid-column: 2 / 4; }
}

@media (max-width: 640px) {
  .topBarEnd .globalSearch, .topBarEnd .notificationButton { display: none; }
  .breadcrumbs strong { max-width: 140px; }
  .pageHeader { flex-direction: column; }
  .pageHeaderActions { align-self: flex-start; flex-wrap: wrap; }
  .grid2, .grid3, .grid4, .permissionLayers, .modeCards { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .notice { grid-template-columns: auto minmax(0, 1fr); }
  .notice > :last-child { grid-column: 2; justify-self: start; }
  .filters { align-items: stretch; }
  .field, .field.grow { width: 100%; min-width: 0; flex-basis: 100%; }
  .filterActions { width: 100%; }
  .filterActions .primaryButton, .filterActions .secondaryButton { flex: 1; }
  .builderFooter { align-items: stretch; flex-direction: column; }
  .builderFooter .buttonGroup { width: 100%; }
  .builderFooter .buttonGroup button { flex: 1; }
  .conditionRow { grid-template-columns: 24px minmax(0, 1fr) 32px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .conditionRow .conditionTag, .conditionRow .conditionOperator, .conditionRow .conditionValue { grid-column: 2; }
  .conditionRow .removeCondition { grid-column: 3; grid-row: 1; }
  .formGrid { grid-template-columns: 1fr; }
  .formGrid .full { grid-column: auto; }
  .drawer { width: 100vw; }
  .drawerBody { padding: 16px; }
  .definitionGrid { grid-template-columns: 96px minmax(0, 1fr); }
  .toast { right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
