:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f1f2ef;
  --surface-3: #e7e8e3;
  --text: #181917;
  --muted: #70736c;
  --soft: #9a9d94;
  --line: #dedfd8;
  --line-strong: #c5c7be;
  --accent: #5f7563;
  --accent-2: #a27850;
  --accent-soft: #edf2ec;
  --danger: #a04747;
  --warning: #9c6b31;
  --success: #4f7459;
  --shadow: 0 24px 80px rgba(23, 24, 21, 0.1);
  --radius: 8px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #141414;
  --surface: #1d1d1d;
  --surface-2: #262626;
  --surface-3: #303030;
  --text: #f0f0ec;
  --muted: #a7a7a0;
  --soft: #777771;
  --line: #363636;
  --line-strong: #4b4b4b;
  --accent: #9aa78f;
  --accent-2: #c09a72;
  --accent-soft: #242924;
  --danger: #d07a7a;
  --warning: #d2a15c;
  --success: #99be9f;
  --shadow: 0 28px 100px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(95, 117, 99, 0.06), transparent 34%),
    repeating-linear-gradient(0deg, transparent 0, transparent 35px, rgba(127, 127, 118, 0.05) 36px),
    var(--bg);
  font-family: var(--font-sans);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

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

button {
  border: 0;
}

button:not(:disabled) {
  cursor: pointer;
}

input,
select,
textarea {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input,
select {
  min-height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 112px;
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

a {
  color: inherit;
  text-decoration: none;
}

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

h1,
h2,
h3 {
  letter-spacing: 0;
}

.app-shell {
  display: grid;
  max-width: 100vw;
  min-height: 100vh;
  grid-template-columns: 272px minmax(0, 1fr);
  overflow-x: hidden;
}

.rail {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px);
}

.brand {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: var(--surface);
  border-radius: var(--radius);
  background: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
}

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

.brand strong {
  font-size: 0.96rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.74rem;
}

.nav-list {
  display: grid;
  max-width: 100%;
  gap: 8px;
}

.nav-item {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.nav-item svg {
  width: 18px;
  height: 18px;
}

.nav-item:hover,
.nav-item.is-active {
  color: var(--text);
  border-color: var(--line);
  background: var(--surface-2);
}

.rail-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
}

.main-area {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.2vw, 2.35rem);
  font-weight: 680;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  width: 100%;
  max-width: 560px;
  min-width: 0;
  justify-content: flex-end;
  gap: 10px;
}

.search-field {
  display: flex;
  min-width: 260px;
  flex: 1;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.search-field svg {
  width: 17px;
  color: var(--muted);
}

.search-field input {
  min-height: 42px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.view-host {
  min-height: calc(100vh - 134px);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.primary-button svg,
.secondary-button svg,
.ghost-button svg,
.danger-button svg,
.icon-button svg {
  width: 17px;
  height: 17px;
}

.primary-button {
  padding: 0 14px;
  color: var(--surface);
  background: var(--text);
}

.secondary-button {
  padding: 0 14px;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
}

.ghost-button {
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
}

.danger-button {
  padding: 0 12px;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 36%, var(--line));
  background: transparent;
}

.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
}

.compact {
  min-height: 36px;
  padding-inline: 10px;
  font-size: 0.86rem;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.workbench-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(360px, 1fr) minmax(320px, 420px);
  gap: 16px;
  align-items: start;
}

.panel,
.asset-card,
.result-box,
.stat-card,
.modal-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--surface) 70%, transparent);
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 1rem;
}

.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.panel-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.field-grid {
  display: grid;
  gap: 12px;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field label,
.field .label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.hint {
  margin: 6px 0 0;
  color: var(--soft);
  font-size: 0.76rem;
}

.stepper {
  display: grid;
  gap: 8px;
}

.step-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.86rem;
}

.step-number {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.72rem;
  font-weight: 700;
}

.step-item.is-done {
  color: var(--text);
}

.step-item.is-done .step-number {
  color: var(--surface);
  border-color: var(--accent);
  background: var(--accent);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.8rem;
}

button.chip.is-selected,
.chip.is-selected {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.module-picker {
  display: grid;
  gap: 10px;
}

.module-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.module-row span {
  color: var(--muted);
  font-size: 0.8rem;
}

.selected-modules {
  display: grid;
  gap: 12px;
}

.module-editor {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.module-editor summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  cursor: pointer;
  list-style: none;
}

.module-editor summary::-webkit-details-marker {
  display: none;
}

.module-editor summary strong {
  font-size: 0.9rem;
}

.module-editor summary span {
  color: var(--muted);
  font-size: 0.78rem;
}

.module-editor textarea {
  min-height: 88px;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--surface);
}

.role-snapshot {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.snapshot-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.snapshot-row strong {
  color: var(--text);
}

.result-tabs {
  display: flex;
  padding: 6px;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.result-tab {
  flex: 1;
  min-height: 34px;
  color: var(--muted);
  border-radius: 6px;
  background: transparent;
  font-size: 0.82rem;
}

.result-tab.is-active {
  color: var(--text);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.result-text {
  min-height: 520px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 0.9rem;
  line-height: 1.65;
}

.result-actions {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.dashboard-grid {
  display: grid;
  gap: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 16px;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.78rem;
}

.stat-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.6rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar-filters select,
.toolbar-filters input {
  width: auto;
  min-width: 150px;
}

.module-filter-bar {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(0, 1fr) 40px;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.module-search-field {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.module-search-field svg {
  width: 17px;
  color: var(--muted);
}

.module-search-field input {
  min-height: 42px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.quick-type-strip {
  display: flex;
  min-width: 0;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.quick-type {
  display: inline-flex;
  min-height: 40px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  white-space: nowrap;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.quick-type:hover {
  transform: translateY(-1px);
}

.quick-type.is-selected {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.module-quick-settings {
  align-self: stretch;
}

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

.asset-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.asset-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.asset-head h3 {
  margin: 0;
  font-size: 1rem;
}

.asset-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.asset-meta {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.asset-meta b {
  color: var(--text);
  font-weight: 650;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.74rem;
}

.tag.strong {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 44%, var(--line));
  background: var(--accent-soft);
}

.asset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 4px;
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  padding: 32px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.empty-state h3 {
  margin-bottom: 6px;
  color: var(--text);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: var(--surface-2);
  font-size: 0.78rem;
  font-weight: 700;
}

td {
  font-size: 0.86rem;
}

tr:last-child td {
  border-bottom: 0;
}

.preset-preview {
  max-height: 108px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
}

.modal {
  width: min(920px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(6px);
}

.modal-card {
  display: grid;
  max-height: min(88vh, 860px);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.modal-head,
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
}

.modal-body {
  display: grid;
  gap: 16px;
  overflow: auto;
  padding: 16px;
}

.modal-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.form-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.form-section h3 {
  margin: 0;
  font-size: 0.95rem;
}

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

.checkbox-row {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.checkbox-row input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  color: var(--surface);
  border-radius: var(--radius);
  background: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.model-status {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.model-status.is-on {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 16%, transparent);
}

.model-status.is-off {
  color: var(--muted);
  background: var(--surface-2);
}

.tag-manager {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag-pill {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.tag-pill button {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: var(--muted);
  border-radius: 999px;
  background: var(--surface-2);
}

.version-list {
  display: grid;
  gap: 8px;
}

.version-row {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.version-row strong {
  font-size: 0.86rem;
}

.version-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-width: 1380px) {
  .workbench-layout {
    grid-template-columns: 290px minmax(360px, 1fr);
  }

  .result-column {
    grid-column: 1 / -1;
  }

  .result-text {
    min-height: 320px;
  }
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    display: flex;
    overflow: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    white-space: nowrap;
  }

  .rail-footer {
    position: absolute;
    top: 18px;
    right: 16px;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .workbench-layout,
  .tag-manager {
    grid-template-columns: 1fr;
  }

  .module-filter-bar {
    grid-template-columns: minmax(0, 1fr) 40px;
  }

  .module-search-field {
    grid-column: 1 / -1;
  }

  .asset-grid,
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .main-area {
    padding: 16px;
  }

  .topbar-actions,
  .toolbar,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions .primary-button {
    width: 100%;
  }

  .search-field,
  .module-search-field,
  .toolbar-filters select,
  .toolbar-filters input {
    width: 100%;
    min-width: 0;
  }

  .module-filter-bar {
    grid-template-columns: minmax(0, 1fr) 40px;
  }

  .checkbox-grid {
    grid-template-columns: 1fr;
  }

  .asset-grid,
  .stat-grid,
  .two-col,
  .three-col {
    grid-template-columns: 1fr;
  }

  .module-row {
    grid-template-columns: 1fr;
  }

  .rail-footer {
    position: static;
  }
}
