:root {
  color-scheme: light;
  --ink: #102c2b;
  --muted: #647673;
  --paper: #f3f7f6;
  --surface: #ffffff;
  --surface-soft: #f8fbfa;
  --line: #d4dfdc;
  --green: #1f6a50;
  --green-deep: #123f3b;
  --green-soft: #e6f1ec;
  --blue: #236aa0;
  --blue-soft: #e6f0f7;
  --orange: #ba6b16;
  --orange-soft: #fff0df;
  --danger: #a53a32;
  --shadow: 0 16px 40px rgba(18, 63, 59, 0.09);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(31, 106, 80, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 106, 80, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
}

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; }

.topbar {
  min-height: 78px;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #fff;
  background: var(--green-deep);
  border-bottom: 3px solid #2d7d63;
}

.brand-block, .topbar-actions, .editor-actions, .summary-primary,
.summary-message, .panel-heading, .modal-heading, .modal-actions {
  display: flex;
  align-items: center;
}

.brand-block { gap: 14px; }
.brand-mark {
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: var(--green-deep);
  background: #dcece5;
  font-size: 18px;
  font-weight: 850;
  letter-spacing: -0.04em;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.topbar .eyebrow { color: #8fc7b5; }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: 0.01em; }
.topbar-actions { gap: 10px; }

.token-field {
  height: 38px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  color: #bcd5cd;
  font-size: 12px;
}

.token-field input {
  width: 105px;
  border: 0;
  outline: 0;
  color: #fff;
  background: transparent;
}

.token-field input::placeholder { color: #92afa6; }

.primary-button, .secondary-button, .icon-button, .ai-button, .danger-button {
  border-radius: 8px;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, opacity .15s ease;
}

.primary-button, .secondary-button, .ai-button, .danger-button {
  min-height: 38px;
  padding: 8px 15px;
  border: 1px solid transparent;
  font-weight: 700;
  text-decoration: none;
}

.primary-button { color: #fff; background: var(--green); }
.secondary-button { color: var(--ink); background: #fff; border-color: var(--line); }
.ai-button { color: #fff; background: var(--blue); border-color: var(--blue); }
.danger-button { color: var(--danger); background: #fff; border-color: #e8b9b5; }
.topbar .secondary-button { color: #e7f3ef; background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.2); }
.primary-button:hover, .secondary-button:hover, .icon-button:hover { transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .45; transform: none !important; }

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  color: var(--green-deep);
  background: var(--surface-soft);
  font-size: 20px;
  line-height: 1;
}

.summary-strip {
  min-height: 72px;
  margin: 0;
  padding: 0 28px;
  display: grid;
  grid-template-columns: minmax(280px, 1.3fr) 150px 150px minmax(280px, 1fr);
  align-items: stretch;
  background: rgba(255,255,255,.88);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 18px rgba(18, 63, 59, 0.04);
}

.summary-strip > div { padding: 14px 20px; border-right: 1px solid var(--line); }
.summary-strip > div:first-child { padding-left: 0; }
.summary-strip > div:last-child { border-right: 0; }
.summary-primary { justify-content: space-between; gap: 14px; font-weight: 800; }
.summary-primary strong {
  padding: 5px 9px;
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 12px;
}
.summary-metric { display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.summary-metric span { color: var(--muted); font-size: 11px; }
.summary-metric strong { font-size: 21px; }
.summary-message { gap: 9px; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #4a9b70; box-shadow: 0 0 0 4px var(--green-soft); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 4px #f7e4e2; }

.module-nav {
  height: 48px;
  padding: 0 28px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--green-deep);
}
.module-tab {
  height: 42px;
  padding: 0 20px;
  border: 0;
  border-radius: 8px 8px 0 0;
  color: #a9c7be;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
}
.module-tab:hover { color: #fff; background: rgba(255,255,255,.06); }
.module-tab.active { color: var(--green-deep); background: var(--paper); }
[hidden] { display: none !important; }

.workspace {
  height: calc(100vh - 201px);
  min-height: 600px;
  padding: 18px 28px 28px;
  display: grid;
  grid-template-columns: 285px minmax(480px, 1fr) 290px;
  gap: 14px;
}

.file-panel, .editor-panel, .history-panel {
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow);
}

.file-panel, .history-panel { display: flex; flex-direction: column; }
.panel-heading { min-height: 72px; padding: 14px 16px; justify-content: space-between; border-bottom: 1px solid var(--line); }
.panel-heading h2, .modal-heading h2 { margin: 0; font-size: 16px; }
.search-box { padding: 11px 13px; border-bottom: 1px solid var(--line); }
.search-box input {
  width: 100%;
  height: 37px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  background: var(--surface-soft);
}
.search-box input:focus, .modal input:focus, .modal select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.file-tree { padding: 8px 8px 18px; overflow: auto; }
.file-group { margin-bottom: 8px; }
.file-group-title {
  padding: 9px 9px 5px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.file-group-count { color: #8ca09b; }
.file-item {
  width: 100%;
  padding: 9px 10px;
  display: block;
  border: 1px solid transparent;
  border-radius: 7px;
  text-align: left;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}
.file-item:hover { background: var(--surface-soft); }
.file-item.active { background: var(--green-soft); border-color: #bcd9cc; }
.file-name { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 750; white-space: nowrap; }
.file-submeta { margin-top: 4px; display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }

.editor-panel { display: flex; flex-direction: column; }
.editor-heading {
  min-height: 90px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 3px solid var(--blue);
  border-bottom: 1px solid var(--line);
}
.file-identity { min-width: 0; }
.file-identity h2 { margin: 6px 0 4px; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; white-space: nowrap; }
.file-identity p { margin: 0; color: var(--muted); font-size: 11px; }
.category-badge { padding: 3px 7px; border-radius: 5px; color: var(--blue); background: var(--blue-soft); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.editor-actions { gap: 8px; flex: none; }
.editor-wrap { min-height: 0; flex: 1; display: grid; grid-template-columns: 48px 1fr; background: #fbfdfc; }
.line-rail { padding-top: 18px; color: #9cafaa; background: #f0f5f3; border-right: 1px solid var(--line); text-align: center; font-family: ui-monospace, monospace; font-size: 9px; line-height: 1.7; }
#contentEditor {
  width: 100%;
  height: 100%;
  min-height: 410px;
  padding: 18px 20px 42px;
  resize: none;
  border: 0;
  outline: 0;
  color: #163b39;
  background: transparent;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
}
#contentEditor:disabled { color: #91a09d; }
.editor-statusbar { min-height: 33px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); background: #f3f7f5; border-top: 1px solid var(--line); font-size: 10px; }
.editor-statusbar .dirty { color: var(--orange); font-weight: 800; }
.editor-statusbar .valid { color: var(--green); font-weight: 800; }
.editor-statusbar .invalid { color: var(--danger); font-weight: 800; }

.history-heading { border-top: 3px solid var(--orange); }
.history-guide { margin: 12px; padding: 11px; border-radius: 7px; color: #73501e; background: var(--orange-soft); font-size: 11px; line-height: 1.55; }
.revision-list { min-height: 0; padding: 0 12px 18px; overflow: auto; }
.revision-card { position: relative; padding: 12px 10px 12px 17px; border-bottom: 1px solid var(--line); }
.revision-card::before { content: ""; position: absolute; top: 17px; left: 2px; width: 7px; height: 7px; border: 2px solid var(--orange); border-radius: 50%; background: #fff; }
.revision-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 800; }
.revision-note { margin: 5px 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.revision-meta { color: #8c9b98; font-size: 9px; }
.restore-button { margin-top: 8px; padding: 4px 8px; border: 1px solid #e1b986; border-radius: 5px; color: #82511d; background: var(--orange-soft); cursor: pointer; font-size: 10px; font-weight: 700; }
.empty-state { padding: 36px 18px; color: #8a9b97; text-align: center; font-size: 12px; line-height: 1.6; }

.settings-view {
  min-height: calc(100vh - 201px);
  padding: 20px 28px 36px;
}
.section-intro {
  min-height: 82px;
  margin-bottom: 15px;
  padding: 16px 19px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 10px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 10px 28px rgba(18,63,59,.06);
}
.section-intro h2 { margin: 2px 0 5px; font-size: 20px; }
.section-intro p:last-child { margin: 0; color: var(--muted); font-size: 12px; }
.settings-grid { display: grid; gap: 14px; }
.model-grid { grid-template-columns: 330px minmax(520px, 1fr); }
.settings-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card-heading {
  min-height: 68px;
  padding: 13px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}
.card-heading h3 { margin: 0; font-size: 16px; }
.count-badge, .state-badge {
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 10px;
  font-weight: 800;
}
.config-list { max-height: calc(100vh - 330px); min-height: 420px; padding: 9px; overflow: auto; }
.config-item {
  width: 100%;
  margin-bottom: 7px;
  padding: 12px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface-soft);
  text-align: left;
  cursor: pointer;
}
.config-item:hover, .config-item.selected { border-color: #9fc8b7; background: var(--green-soft); }
.config-item.active { border-left: 4px solid var(--green); }
.config-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 800; }
.config-subtitle { margin-top: 6px; color: var(--muted); font-size: 10px; line-height: 1.45; white-space: pre-line; }
.mini-state { padding: 2px 5px; border-radius: 4px; color: var(--green); background: #d5e9df; font-size: 9px; }
.config-form { padding: 17px; }
.config-form label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.config-form > label, .config-form > .form-row { margin-bottom: 14px; }
.config-form input, .config-form select, .config-form textarea,
.tool-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: 0;
  color: var(--ink);
  background: var(--surface-soft);
}
.config-form input, .config-form select, .tool-form input { height: 39px; padding: 0 10px; }
.config-form textarea { padding: 9px 10px; resize: vertical; font-family: ui-monospace, monospace; font-size: 11px; line-height: 1.5; }
.config-form input:focus, .config-form select:focus, .config-form textarea:focus,
.tool-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.form-row { display: grid; gap: 12px; }
.two-cols { grid-template-columns: repeat(2, minmax(0,1fr)); }
.three-cols { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-note { margin-top: 3px; padding: 10px; border-radius: 7px; color: #315e57; background: var(--green-soft); font-size: 10px; line-height: 1.5; }
.config-form .inline-checkbox { display: flex; align-items: center; gap: 8px; width: fit-content; font-weight: 600; }
.config-form .inline-checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--green); }
.form-actions { margin-top: 17px; display: flex; align-items: center; gap: 8px; }
.form-spacer { flex: 1; }

.tool-card-grid { display: grid; grid-template-columns: repeat(2, minmax(360px,1fr)); gap: 14px; }
.tool-card { border-top: 3px solid var(--orange); }
.tool-card.enabled { border-top-color: var(--green); }
.tool-card .card-heading { min-height: 73px; }
.tool-state { padding: 4px 8px; border-radius: 5px; color: var(--muted); background: #eef2f1; font-size: 10px; font-weight: 800; }
.tool-state.enabled { color: var(--green); background: var(--green-soft); }
.tool-form { padding: 15px 17px 17px; }
.tool-form label { margin-bottom: 12px; display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.tool-form .inline-checkbox { display: flex; align-items: center; gap: 8px; width: fit-content; font-weight: 600; }
.tool-form .inline-checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--green); }
.tool-form .toggle-row { display: flex; align-items: center; justify-content: space-between; }
.tool-form .toggle-row input { width: 42px; height: 22px; accent-color: var(--green); }
.tool-actions { display: flex; justify-content: flex-end; gap: 8px; }

.operation-grid { display: grid; grid-template-columns: 330px minmax(600px,1fr); gap: 14px; }
.evaluation-result { padding: 24px 18px; }
.evaluation-score { padding: 22px; text-align: center; }
.score-value { display: block; color: var(--green); font-size: 46px; font-weight: 850; letter-spacing: -.04em; }
.score-label { color: var(--muted); font-size: 11px; }
.case-list { margin-top: 16px; display: grid; gap: 7px; }
.case-row { padding: 8px 10px; display: flex; justify-content: space-between; border-radius: 6px; background: var(--surface-soft); font-size: 10px; }
.case-pass { color: var(--green); font-weight: 800; }
.case-fail { color: var(--danger); font-weight: 800; }
.table-wrap { max-height: calc(100vh - 330px); overflow: auto; }
.event-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.event-table th, .event-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.event-table th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: #f2f6f5; font-weight: 800; }
.event-detail { max-width: 360px; color: var(--muted); word-break: break-word; }
.event-status { font-weight: 800; }
.event-status.success { color: var(--green); }
.event-status.failed { color: var(--danger); }

.ai-modal { width: min(580px, calc(100vw - 32px)); }
.modal textarea { width: 100%; padding: 10px; resize: vertical; border: 1px solid var(--line); border-radius: 7px; outline: 0; }

.modal { width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); box-shadow: 0 24px 70px rgba(14, 45, 42, .28); }
.modal::backdrop { background: rgba(10, 35, 33, .5); backdrop-filter: blur(2px); }
.modal form { padding: 20px; }
.modal-heading { justify-content: space-between; margin-bottom: 20px; }
.modal label { margin-top: 14px; display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.modal input, .modal select { width: 100%; height: 41px; padding: 0 11px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: #fff; outline: 0; }
.field-help { color: var(--muted); font-size: 11px; line-height: 1.5; }
.modal-actions { margin-top: 22px; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; right: 26px; bottom: 26px; z-index: 30; max-width: 420px; padding: 12px 16px; border-radius: 8px; color: #fff; background: var(--green-deep); box-shadow: 0 12px 30px rgba(18,63,59,.25); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #812f2a; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 250px minmax(460px, 1fr); }
  .history-panel { position: fixed; right: 16px; bottom: 16px; width: 300px; height: 58vh; z-index: 10; display: none; }
  .history-panel.open { display: flex; }
  .summary-strip { grid-template-columns: 1fr 130px 130px; }
  .summary-message { display: none; }
  .model-grid, .operation-grid { grid-template-columns: 280px minmax(500px,1fr); }
}

@media (max-width: 780px) {
  .topbar { padding: 12px 16px; align-items: flex-start; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .token-field { display: none; }
  .summary-strip { padding: 0 16px; grid-template-columns: 1fr 95px; }
  .summary-strip > div { padding: 12px; }
  .summary-strip .summary-metric:nth-child(3) { display: none; }
  .module-nav { padding: 0 12px; overflow-x: auto; }
  .module-tab { padding: 0 13px; white-space: nowrap; }
  .workspace { height: auto; min-height: calc(100vh - 188px); padding: 12px; grid-template-columns: 1fr; }
  .settings-view { min-height: calc(100vh - 188px); padding: 12px; }
  .section-intro { align-items: flex-start; flex-direction: column; }
  .model-grid, .operation-grid, .tool-card-grid { grid-template-columns: 1fr; }
  .config-list { min-height: 220px; max-height: 320px; }
  .two-cols, .three-cols { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .file-panel { max-height: 320px; }
  .editor-panel { min-height: 650px; }
  .editor-heading { align-items: flex-start; flex-direction: column; }
  .editor-actions { width: 100%; }
  .editor-actions button { flex: 1; }
}
