:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f3f6fb;
  --text: #172033;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-2: #0f172a;
  --sidebar: #0b1220;
  --sidebar-2: #111c31;
  --sidebar-text: #f8fafc;
  --sidebar-muted: #94a3b8;
  --good: #138a55;
  --bad: #c2410c;
  --running: #2563eb;
  --shadow: 0 10px 30px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 9px 13px;
  cursor: pointer;
}

button:hover {
  border-color: color-mix(in srgb, var(--accent), var(--line) 45%);
}

button.primary {
  background: var(--accent-2);
  color: white;
  border-color: var(--accent-2);
}

button.secondary {
  background: var(--panel-2);
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 11px;
  background: rgba(255,255,255,.62);
  color: var(--text);
}

.inline-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

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

.app.sidebar-collapsed {
  grid-template-columns: 72px minmax(0, 1fr);
}

.sidebar {
  padding: 24px 18px;
  border-right: 0;
  background:
    radial-gradient(circle at 24px 20px, rgba(37, 99, 235, .32), transparent 9rem),
    linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: relative;
  transition: padding .2s ease;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand > div:last-child,
.nav-item,
.side-note {
  transition: opacity .16s ease, transform .16s ease;
}

.sidebar-toggle {
  position: absolute;
  top: 72px;
  right: -13px;
  z-index: 20;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18);
  background: #ffffff;
  color: var(--sidebar);
  box-shadow: 0 8px 22px rgba(2, 6, 23, .18);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  padding: 0;
}

.sidebar-toggle:hover {
  transform: scale(1.05);
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: #2563eb;
  color: white;
  font-size: 21px;
}

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

h1 {
  font-size: 18px;
}

.brand p, .topbar p, .panel-head p, .script-card p, .side-note span, small {
  color: var(--muted);
}

.sidebar .brand p,
.sidebar .side-note span {
  color: var(--sidebar-muted);
}

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

.nav-item {
  width: 100%;
  text-align: left;
  background: rgba(255,255,255,.06);
  color: var(--sidebar-text);
  border-color: rgba(255,255,255,.1);
}

.nav-item.active {
  background: #ffffff;
  color: var(--sidebar);
  border-color: #ffffff;
}

.nav-item:hover {
  border-color: rgba(255,255,255,.32);
  background: rgba(255,255,255,.12);
}

.nav-item.active:hover {
  background: #ffffff;
  color: white;
  color: var(--sidebar);
  border-color: #ffffff;
}

.side-note {
  margin-top: auto;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  display: grid;
  gap: 6px;
}

.side-button {
  margin-top: 8px;
  border-color: rgba(255,255,255,.18);
  background: rgba(255,255,255,.1);
  color: var(--sidebar-text);
}

.side-button:hover {
  border-color: rgba(255,255,255,.42);
  background: rgba(255,255,255,.16);
}

.main {
  padding: 24px;
  min-width: 0;
  max-width: calc(100vw - 230px);
  overflow-x: hidden;
  background: #ffffff;
  transition: max-width .2s ease;
}

.app.sidebar-collapsed .sidebar {
  padding: 24px 12px;
  align-items: center;
}

.app.sidebar-collapsed .brand {
  justify-content: center;
}

.app.sidebar-collapsed .brand > div:last-child,
.app.sidebar-collapsed .side-note {
  opacity: 0;
  transform: translateX(-6px);
  pointer-events: none;
  width: 0;
  height: 0;
  overflow: hidden;
}

.app.sidebar-collapsed .nav {
  width: 100%;
}

.app.sidebar-collapsed .nav-item {
  width: 48px;
  height: 48px;
  padding: 0;
  overflow: hidden;
  text-align: center;
  justify-self: center;
  border-radius: 16px;
  font-size: 0;
}

.app.sidebar-collapsed .nav-item::first-letter {
  font-size: 18px;
  font-weight: 800;
}

.app.sidebar-collapsed .sidebar-toggle {
  transform: rotate(180deg);
}

.app.sidebar-collapsed .sidebar-toggle:hover {
  transform: rotate(180deg) scale(1.05);
}

.app.sidebar-collapsed .main {
  max-width: calc(100vw - 72px);
}

.page {
  display: none;
}

.page.active {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.topbar {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: start;
  flex-wrap: wrap;
}

.topbar h2 {
  font-size: 28px;
  letter-spacing: -0.03em;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.actions label {
  min-width: 118px;
}

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

.stats article, .panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.stats article {
  padding: 16px;
  display: grid;
  gap: 4px;
}

.notice {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--muted);
  background: #ffffff;
}

.notice.ok {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good), var(--line) 60%);
}

.notice.error {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad), var(--line) 60%);
}

.notice span {
  color: var(--muted);
}

.stats span {
  color: var(--muted);
  font-size: 13px;
}

.stats strong {
  font-size: 28px;
}

.work-stack {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  align-items: start;
  min-width: 0;
}

.table-panel {
  min-width: 0;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  max-width: 100%;
  scrollbar-gutter: stable;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

th, td {
  padding: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
  background: #ffffff;
  overflow: hidden;
}

th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--panel);
  padding: 9px 10px;
  user-select: none;
}

.thumb {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2a2826, #d9a15b);
  color: white;
}

.prompt {
  max-width: 340px;
  line-height: 1.45;
}

.editable-table tr {
  height: var(--row-height, 88px);
}

.editable-table tr:hover td,
.editable-table tr.is-selected td {
  background: #f8fafc;
}

.editable-table td {
  min-width: 0;
  max-width: none;
}

.editable-table td:nth-child(6),
.editable-table td:nth-child(7),
.editable-table td:nth-child(8),
.editable-table td:nth-child(9),
.editable-table td:nth-child(10),
.editable-table td:nth-child(14) {
  min-width: 0;
}

.action-col {
  width: 104px;
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--panel) !important;
}

.select-col {
  width: 42px;
  text-align: center;
  position: sticky;
  left: 104px;
  z-index: 2;
  background: var(--panel) !important;
}

.row-generate {
  width: calc(100% - 12px);
  min-height: 32px;
  margin: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

.row-generate:hover:not(:disabled) {
  border-color: var(--accent);
}

.row-generate-running {
  color: var(--running);
  cursor: progress;
}

.row-generate-succeeded {
  color: var(--good);
}

.row-generate-failed {
  color: var(--bad);
}

.text-cell,
.tag-cell,
.image-cell,
.status-pill {
  border: 0;
  border-radius: 0;
  background: transparent;
  width: 100%;
  min-height: var(--row-height, 88px);
  height: var(--row-height, 88px);
  padding: 8px 10px;
  text-align: left;
  color: var(--text);
  overflow: hidden;
}

.text-cell {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  line-height: 1.42;
  word-break: break-word;
}

.result-cell {
  color: var(--good);
}

.tag-cell {
  min-height: var(--row-height, 88px);
  padding-top: 12px;
  color: var(--accent-2);
}

.tag-cell::first-line {
  background: var(--panel-2);
}

.status-pill {
  min-height: auto;
  height: auto;
  padding: 8px;
  display: inline-flex;
  width: auto;
  margin: 8px;
}

.image-cell {
  display: grid;
  place-items: center;
  padding: 6px;
}

.image-stack {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.image-thumb {
  display: grid;
  place-items: center;
  min-width: 56px;
  max-width: 120px;
  flex: 0 0 auto;
}

.image-cell img,
.image-cell .image-fallback,
.image-cell .image-empty {
  width: min(120px, calc(100% - 8px));
  height: min(96px, calc(var(--row-height, 88px) - 12px));
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  word-break: break-word;
}

.image-cell .image-fallback {
  display: none;
}

.log-detail {
  display: block;
  margin-top: 6px;
  white-space: pre-wrap;
  line-height: 1.5;
}

.log-json {
  margin-top: 8px;
}

.log-json summary {
  cursor: pointer;
  color: var(--accent-2);
  font-size: 12px;
}

.log-json pre {
  margin: 8px 0 0;
  padding: 10px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.version-card {
  display: grid;
  gap: 10px;
  border-left: 4px solid var(--line);
}

.version-card.current {
  border-left-color: var(--accent);
}

.version-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.version-head strong {
  font-size: 18px;
  color: var(--accent-2);
}

.version-head span {
  color: var(--muted);
  font-size: 13px;
}

.version-card h3 {
  margin: 0;
  font-size: 16px;
}

.version-card ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.7;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
}

.col-resizer:hover {
  background: color-mix(in srgb, var(--accent), transparent 60%);
}

.row-resizer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 7px;
  cursor: row-resize;
  z-index: 4;
}

.row-resizer:hover {
  background: color-mix(in srgb, var(--accent), transparent 60%);
}

.editable-table td.action-col,
.editable-table td.select-col {
  position: sticky;
}

body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
}

.pill.ok .dot { background: var(--good); }
.pill.bad .dot { background: var(--bad); }
.pill.running .dot { background: var(--running); }

.run-panel {
  display: grid;
  gap: 14px;
  grid-template-columns: 180px minmax(220px, 1fr) 180px minmax(260px, 1.1fr);
  align-items: center;
}

.run-panel h3,
.run-panel p {
  margin: 0;
}

.mapping-bottom-panel {
  box-shadow: none;
}

.table-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.mapping-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-height: none;
  overflow: auto;
  padding-right: 4px;
}

.mapping-panel {
  display: grid;
  gap: 10px;
}

.mapping-panel summary {
  cursor: pointer;
  display: grid;
  gap: 2px;
  color: var(--text);
  font-weight: 600;
}

.mapping-panel summary small {
  font-weight: 400;
}

.mapping-panel[open] {
  gap: 12px;
}

.mapping-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  color: var(--muted);
}

.mapping-row span {
  color: var(--text);
  font-size: 13px;
}

hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #f59e0b);
  transition: width .2s ease;
}

.flow {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 9px;
  color: var(--muted);
}

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

.script-card {
  min-height: 190px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.script-card.dashed {
  border-style: dashed;
  background: transparent;
}

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

.config-grid .wide {
  grid-column: 1 / -1;
}

.log-panel {
  display: grid;
  gap: 0;
}

.log-row {
  display: grid;
  grid-template-columns: 150px 80px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  line-height: 1.45;
}

.muted {
  color: var(--muted);
}

.run-message {
  min-height: 20px;
  color: var(--muted);
}

.run-message.ok {
  color: var(--good);
}

.run-message.error {
  color: var(--bad);
}

.cell-dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  width: min(720px, calc(100vw - 36px));
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.cell-dialog::backdrop {
  background: rgba(0,0,0,.18);
}

.cell-dialog form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#editorValue {
  min-height: 260px;
  resize: vertical;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255,255,255,.72);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
}

.login-page {
  min-height: 100vh;
  background:
    linear-gradient(135deg, #f8fafc 0%, #ffffff 44%, #f1f5f9 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 22px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand p {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form button {
  width: 100%;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .app.sidebar-collapsed {
    grid-template-columns: 1fr;
  }
  .main {
    max-width: 100vw;
    padding: 16px;
  }
  .app.sidebar-collapsed .main {
    max-width: 100vw;
  }
  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-toggle {
    display: none;
  }
  .app.sidebar-collapsed .sidebar {
    align-items: stretch;
    padding: 24px 18px;
  }
  .app.sidebar-collapsed .brand > div:last-child,
  .app.sidebar-collapsed .side-note {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    width: auto;
    height: auto;
    overflow: visible;
  }
  .app.sidebar-collapsed .nav-item {
    width: 100%;
    height: auto;
    padding: 10px 14px;
    text-align: left;
    font-size: 14px;
  }
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .side-note {
    display: none;
  }
  .content-grid,
  .work-stack,
  .stats,
  .script-grid,
  .config-grid {
    grid-template-columns: 1fr;
  }
  .run-panel,
  .mapping-list {
    grid-template-columns: 1fr;
  }
}
