:root {
  color-scheme: light;
  --bg: #f5f1e9;
  --ink: #17201b;
  --muted: #69736d;
  --line: #ded8ca;
  --panel: #fffefa;
  --panel-2: #f7f3ea;
  --surface-strong: #142721;
  --surface-deep: #0e1b18;
  --accent: #bf4f28;
  --accent-2: #d99f45;
  --accent-3: #276c63;
  --danger: #b64135;
  --ok: #1f7a54;
  --shadow: 0 28px 80px rgba(20, 39, 33, 0.16);
  --shadow-soft: 0 14px 34px rgba(20, 39, 33, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(20, 39, 33, 0.035) 0 1px, transparent 1px 22px),
    var(--bg);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr;
  min-height: 100vh;
}

.login-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-panel {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid rgba(20, 39, 33, 0.12);
  border-top: 5px solid var(--accent);
  border-radius: 10px;
  background: rgba(255, 254, 250, 0.96);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand h1 {
  font-size: 24px;
}

.login-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.app-shell.auth-locked .rail {
  display: none !important;
}

.app-shell.auth-locked .workspace {
  display: none !important;
}

.app-shell.auth-locked .topbar {
  display: none !important;
}

.app-shell.auth-locked .page-section {
  display: none !important;
}

.app-shell.auth-ready .login-gate {
  display: none !important;
}

.rail {
  position: sticky;
  top: 0;
  z-index: 20;
  height: auto;
  padding: 8px 24px;
  border-bottom: 1px solid rgba(20, 39, 33, 0.12);
  background: rgba(255, 254, 250, 0.9);
  backdrop-filter: blur(18px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 210px;
  font-weight: 900;
  line-height: 1.2;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--surface-strong);
  color: #fff8ea;
  box-shadow: 0 12px 24px rgba(20, 39, 33, 0.2);
}

.nav-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  justify-content: end;
  gap: 6px;
  overflow-x: auto;
  padding: 4px;
}

.nav-item {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.nav-item.active,
.nav-item:hover {
  color: var(--ink);
  border-color: rgba(20, 39, 33, 0.12);
  background: #fff;
  box-shadow: inset 0 -3px 0 var(--accent), var(--shadow-soft);
}

.workspace {
  width: 100%;
  max-width: 1720px;
  margin: 0 auto;
  padding: 14px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.page-section {
  display: none;
}

.page-section:not(.active) {
  display: none !important;
}

.page-section.active {
  min-width: 0;
  display: grid !important;
  gap: 10px;
  animation: page-in 140ms ease-out;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.topbar,
.band-head,
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.topbar {
  position: relative;
  top: auto;
  grid-column: 1;
  min-height: 0;
  padding: 10px 14px;
  border: 1px solid rgba(20, 39, 33, 0.1);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  background: rgba(255, 254, 250, 0.9);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.topbar::before {
  content: none;
}

.topbar::after {
  content: none;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-3);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.topbar .eyebrow {
  color: var(--accent);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: none;
  font-size: clamp(22px, 2.4vw, 30px);
  line-height: 1.05;
}

h2 {
  font-size: 20px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.status-pill {
  border: 1px solid var(--line);
  background: #fffefa;
  padding: 6px 9px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.status-pill.muted {
  color: var(--muted);
}

.command-strip {
  display: none;
}

.command-strip span {
  display: inline-flex;
  align-items: center;
  border-left: 3px solid var(--accent-2);
  padding: 7px 10px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.ops-dashboard {
  display: grid;
  grid-template-columns: 1.2fr repeat(2, minmax(150px, 0.8fr));
  gap: 10px;
}

.ops-card {
  min-height: 96px;
  padding: 14px;
  border: 1px solid rgba(20, 39, 33, 0.1);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.94);
  box-shadow: var(--shadow-soft);
  display: grid;
  align-content: space-between;
  gap: 10px;
}

.ops-card-main {
  grid-row: span 2;
  min-height: 206px;
  background:
    linear-gradient(135deg, rgba(191, 79, 40, 0.12), transparent 54%),
    #fffefa;
}

.ops-card span,
.summary-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.ops-card strong {
  font-size: 28px;
  line-height: 1;
}

.ops-card-main strong {
  font-size: 34px;
  line-height: 1.05;
}

.ops-card p,
.workflow-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.ops-card-risk strong {
  color: var(--danger);
}

.workflow-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.workflow-card {
  min-height: 118px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(20, 39, 33, 0.12);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow-soft);
}

.workflow-card span {
  color: var(--accent);
  font-weight: 900;
  font-size: 12px;
}

.workflow-card strong {
  font-size: 24px;
}

.workflow-card:hover {
  transform: translateY(-2px);
  border-color: rgba(191, 79, 40, 0.38);
  box-shadow: var(--shadow);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.summary-band {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.summary-item {
  display: grid;
  gap: 5px;
  padding: 10px 14px;
  border-right: 1px solid var(--line);
}

.summary-item:last-child {
  border-right: 0;
}

.summary-item strong {
  font-size: 25px;
  line-height: 1;
}

.agent-summary-grid {
  grid-column: 1;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: var(--panel);
}

.agent-admin-grid {
  grid-column: 1;
  display: grid;
  grid-template-columns: minmax(420px, 1.35fr) minmax(300px, 0.65fr);
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.agent-money-stack {
  display: grid;
  align-content: start;
  border-left: 1px solid var(--line);
}

.agent-money-stack .catalog-form {
  border-right: 0;
}

.agent-price-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.agent-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.agent-form .panel-head,
.agent-form .form-actions,
.agent-form > label:nth-of-type(5),
.agent-form > label:last-of-type,
.agent-form .inline-options,
.agent-form .field-pair {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions button {
  flex: 1;
}

.inline-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
}

.inline-options legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.inline-options label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.inline-options input {
  width: 16px;
  min-height: 16px;
}

.field-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.positive-number {
  color: var(--ok);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.panel,
.data-band,
.output-band {
  background: transparent;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  display: grid;
  gap: 10px;
}

.panel-head span {
  color: var(--muted);
  font-weight: 900;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: #fffefa;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(191, 79, 40, 0.55);
  outline-offset: 1px;
}

button {
  min-height: 34px;
  border: 1px solid var(--surface-strong);
  border-radius: 6px;
  background: var(--surface-strong);
  color: #fff8ea;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 900;
}

button:hover {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 10px 22px rgba(191, 79, 40, 0.18);
}

button.secondary {
  background: #fffefa;
  color: var(--surface-strong);
}

button[disabled] {
  border-color: var(--line);
  background: #e9e4d8;
  color: var(--muted);
  cursor: not-allowed;
}

code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  color: #242424;
  word-break: break-all;
}

textarea {
  min-height: 96px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.data-band,
.output-band {
  display: grid;
  grid-template-columns: 1fr;
  border: 1px solid rgba(20, 39, 33, 0.11);
  border-radius: 10px;
  background: rgba(255, 254, 250, 0.82);
  box-shadow: var(--shadow-soft);
  overflow: clip;
}

.band-head {
  grid-column: 1;
  grid-row: auto;
  min-height: 0;
  padding: 8px 12px;
  background: rgba(247, 243, 234, 0.92);
  color: var(--ink);
  align-items: center;
  align-content: center;
  flex-direction: row;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.band-head:not(:has(button)) {
  display: none;
}

.band-head .eyebrow {
  display: none;
}

.band-head h2 {
  display: none;
}

.band-head button {
  width: auto;
  margin-top: 0;
  border-color: var(--surface-strong);
  background: var(--surface-strong);
  color: #fff8ea;
}

.sub-band-head {
  grid-column: 1;
  padding: 18px 20px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.filter-bar {
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 243, 234, 0.88);
}

.filter-bar button {
  align-self: end;
}

.grant-form {
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  align-items: end;
  background: var(--panel);
}

.catalog-grid,
.page-grid {
  grid-column: 1;
  display: grid;
  gap: 0;
}

.page-grid-narrow {
  grid-template-columns: minmax(320px, 380px) minmax(720px, 1fr);
  align-items: start;
}

.page-grid-narrow > .catalog-form {
  grid-column: 1;
  align-self: start;
  height: max-content;
  width: 100%;
}

.page-grid-narrow > .table-wrap {
  grid-column: 2;
  border-top: 0;
  border-left: 1px solid var(--line);
  align-self: stretch;
  min-width: 0;
}

.catalog-form {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fffefa;
}

.catalog-form:last-child {
  border-right: 0;
}

.script-product-grid {
  grid-template-columns: minmax(360px, 0.9fr) minmax(0, 1.25fr);
  align-items: stretch;
  background: linear-gradient(90deg, #fffefa, #f7f3ea);
}

.script-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.script-version-form {
  order: -2;
  grid-column: 1;
  grid-row: 1 / span 3;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background:
    linear-gradient(180deg, rgba(39, 108, 99, 0.08), transparent 45%),
    #fffefa;
}

.script-form .panel-head,
.script-form .source-label,
.script-form button,
.script-version-form .panel-head,
.script-version-form button {
  grid-column: 1 / -1;
}

.script-version-form textarea {
  min-height: 54px;
}

.script-version-form .source-label {
  grid-column: auto;
}

.script-version-form .source-label textarea {
  max-height: 72px;
}

.advanced-drawer {
  order: -1;
  grid-column: 2;
  margin: 10px 12px 0;
  padding: 10px 12px;
  border: 1px solid rgba(20, 39, 33, 0.12);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fffefa;
  box-shadow: var(--shadow-soft);
}

.advanced-drawer summary {
  cursor: pointer;
  color: var(--surface-strong);
  font-weight: 900;
}

.advanced-drawer p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#scriptTemplateForm,
#scriptForm {
  grid-column: 2;
  display: none;
  margin: 0 12px 12px;
  border: 1px solid var(--line);
  border-top: 0;
}

.advanced-drawer[open] ~ #scriptTemplateForm,
.advanced-drawer[open] ~ #scriptForm {
  display: grid;
}

.management-grid {
  display: grid;
  gap: 0;
}

.muted-text {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.action-row button {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
}

.table-wrap {
  grid-column: 1;
  overflow-x: auto;
  background: var(--panel);
  border-top: 1px solid rgba(20, 39, 33, 0.04);
}

.pagination-bar {
  grid-column: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

.pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.pagination-actions button {
  min-width: 68px;
  min-height: 32px;
  padding: 5px 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #f4efe4;
}

tbody tr:hover {
  background: #fff2d6;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.tag {
  display: inline-block;
  border: 1px solid var(--line);
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: #fffefa;
}

.tag.ok {
  border-color: rgba(31, 122, 85, 0.35);
  color: var(--ok);
}

.tag.bad {
  border-color: rgba(169, 50, 50, 0.35);
  color: var(--danger);
}

.output {
  grid-column: 1;
  margin: 0;
  min-height: 160px;
  max-height: 520px;
  overflow: auto;
  padding: 12px;
  background: var(--surface-deep);
  color: #f4efe4;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar,
  .page-section.active {
    grid-column: 1;
  }

  .topbar {
    position: relative;
    top: 0;
    min-height: 0;
  }

  h1 {
    max-width: none;
  }

  .data-band,
  .output-band {
    grid-template-columns: 1fr;
  }

  .band-head,
  .filter-bar,
  .grant-form,
  .catalog-grid,
  .page-grid,
  .table-wrap,
  .sub-band-head,
  .output {
    grid-column: 1;
  }

  .band-head {
    grid-row: auto;
  }
}

@media (max-width: 860px) {
  .rail {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .nav-list {
    justify-content: start;
  }

  .workspace {
    padding: 16px;
  }

  .ops-dashboard,
  .workflow-board,
  .control-grid,
  .script-product-grid,
  .page-grid-narrow,
  .summary-grid,
  .grant-form,
  .agent-admin-grid,
  .filter-bar {
    grid-template-columns: 1fr;
  }

  .agent-form {
    grid-template-columns: 1fr;
  }

  .agent-form > * {
    grid-column: 1 !important;
  }

  .agent-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .agent-money-stack {
    border-left: 0;
  }

  .pagination-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .ops-card-main {
    min-height: 170px;
  }

  .script-form,
  .script-version-form {
    grid-template-columns: 1fr;
  }

  .advanced-drawer,
  #scriptTemplateForm,
  #scriptForm {
    grid-column: 1;
    margin-left: 0;
    margin-right: 0;
  }
}

@media (max-width: 520px) {
  .agent-price-fields {
    grid-template-columns: 1fr;
  }
}
