:root {
  color-scheme: light;
  --bg: #d9dee7;
  --panel: #eef1f5;
  --panel-dark: #d7dce5;
  --panel-head: #c8d0dc;
  --text: #1f2933;
  --muted: #596472;
  --border: #9da8b6;
  --border-dark: #748092;
  --primary: #1f5f9f;
  --primary-dark: #174a7c;
  --danger: #a61b1b;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Microsoft YaHei", sans-serif;
  font-size: 12px;
  line-height: 1.35;
  background: var(--bg);
  color: var(--text);
}

body.admin-body {
  min-height: 100vh;
  overflow: hidden;
  background: #d9dee7;
}

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

button {
  min-height: 24px;
  border: 1px solid #7d8794;
  border-radius: 2px;
  padding: 3px 9px;
  background: linear-gradient(#f8fafc, #d8dee8);
  color: #17212b;
  cursor: pointer;
  font-weight: 600;
  transition: none;
}

button:hover {
  border-color: #315f94;
  background: linear-gradient(#ffffff, #cbd8e8);
  transform: none;
}

button:active {
  background: linear-gradient(#c6cfdb, #edf1f6);
}

button:disabled {
  cursor: progress;
  opacity: 0.6;
  transform: none;
}

button.secondary,
button.ghost {
  border-color: #8792a0;
  background: linear-gradient(#f7f9fb, #d8dde5);
  color: #1f2933;
}

button.ghost:hover {
  border-color: #9a3412;
  background: linear-gradient(#fff7ed, #ead0bc);
  color: #7c2d12;
}

input,
select,
textarea {
  width: 100%;
  min-height: 24px;
  border: 1px solid #8792a0;
  border-radius: 2px;
  padding: 3px 6px;
  background: #ffffff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 1px solid #2f6fad;
  outline-offset: -1px;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 2px;
  color: #303946;
  font-size: 12px;
}

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

h1,
h2,
h3,
h4 {
  font-weight: 700;
}

h1 {
  margin-bottom: 2px;
  font-size: 15px;
}

h2 {
  margin: 0 0 2px;
  font-size: 17px;
}

h3 {
  margin: 0;
  font-size: 14px;
}

h4 {
  margin: 0 0 4px;
  font-size: 12px;
}

p {
  margin-bottom: 4px;
}

.subtitle,
.hint {
  color: var(--muted);
  font-size: 11px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #315f94;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-right: 1px solid var(--border-dark);
  background: #cbd2dc;
}

.brand {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border-dark);
  background: linear-gradient(#e8ecf2, #c3cad5);
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid #315f94;
  border-radius: 2px;
  background: #2f6fad;
  color: white;
  font-size: 15px;
  font-weight: 800;
}

.brand-kicker {
  margin: 0;
  color: #4a5564;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 0;
  font-size: 13px;
  white-space: nowrap;
}

.nav-menu {
  display: grid;
  gap: 4px;
}

.nav-item {
  position: relative;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid #8b96a5;
  background: linear-gradient(#eef2f7, #cdd4df);
  color: #1f2933;
  text-align: left;
}

.nav-item::before,
.nav-item.active::after {
  content: none;
}

.nav-item:hover,
.nav-item.active {
  border-color: #315f94;
  background: linear-gradient(#e8f1fb, #b9cbe0);
  color: #113a63;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 6px;
  border: 1px solid var(--border-dark);
  background: #e4e8ee;
  color: var(--muted);
  font-size: 11px;
}

.main-shell {
  min-width: 0;
  height: 100vh;
  overflow: auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-dark);
  background: linear-gradient(#eef2f7, #c8d0dc);
}

.topbar h2 {
  font-size: 16px;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
  padding: 3px;
  border: 1px solid #a5afbd;
  background: #e6eaf0;
}

.user-bar span {
  color: #344152;
  font-weight: 600;
}

.content {
  display: grid;
  gap: 6px;
  padding: 6px;
}

.admin-page {
  display: none;
}

.admin-page.active {
  display: block;
}

.panel {
  border: 1px solid var(--border-dark);
  border-radius: 0;
  padding: 6px;
  background: var(--panel);
  box-shadow: none;
  backdrop-filter: none;
}

.panel-title,
.control-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: -6px -6px 6px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-head);
}

.panel-title.compact {
  margin-bottom: 6px;
}

.panel-title h3,
.panel h4 {
  margin: 0;
}

.workflow-hero {
  display: grid;
  gap: 5px;
}

.control-panel {
  padding-bottom: 6px;
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) 96px minmax(360px, 2fr);
  gap: 6px;
  align-items: end;
}

.project-select-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(260px, 0.55fr);
  gap: 6px;
  align-items: stretch;
}

.project-create-form {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.project-create-form .wide {
  grid-column: span 4;
}

.project-create-form button[type="submit"] {
  grid-column: span 2;
  align-self: end;
}

.project-list-box {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.status-control-strip {
  margin-bottom: 5px;
}

.operation-layout {
  grid-template-columns: minmax(440px, 0.95fr) minmax(0, 1.05fr);
}

.guide-panel {
  display: grid;
  gap: 5px;
}

.guide-summary {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(0, 1.2fr);
  gap: 5px;
}

.guide-flow,
.guide-current {
  min-width: 0;
  border: 1px solid var(--border);
  background: #ffffff;
  padding: 5px 6px;
}

.guide-flow {
  display: grid;
  gap: 3px;
}

.guide-flow strong,
.guide-current strong {
  color: #174a7c;
}

.guide-flow span,
.guide-current span {
  display: block;
  color: #303946;
}

.guide-current {
  display: grid;
  grid-template-columns: 120px repeat(3, minmax(0, 1fr));
  gap: 5px;
  align-items: start;
}

.guide-current strong {
  font-size: 12px;
}

.guide-current span {
  border-left: 1px solid #c2cad5;
  padding-left: 5px;
}

.guide-details {
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--border);
  background: #ffffff;
}

.guide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.guide-table th,
.guide-table td {
  border: 1px solid #c2cad5;
  padding: 3px 5px;
  text-align: left;
  vertical-align: top;
}

.guide-table th {
  position: sticky;
  top: 0;
  background: #dfe5ed;
  color: #17324d;
  z-index: 1;
}

.guide-table tr:nth-child(even) td {
  background: #f5f7fa;
}

.operation-stack {
  display: grid;
  gap: 6px;
}

.current-context {
  min-height: 24px;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 3px 6px;
  border: 1px solid #9da8b6;
  background: #ffffff;
  color: #344152;
  overflow: hidden;
}

.current-context strong {
  flex: 0 0 auto;
  color: #174a7c;
}

.current-context span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
}

.project-panel,
.resource-panel {
  min-width: 0;
}

.project-entry-grid,
.project-entry-grid.unified {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  align-items: start;
}

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

.compact-form {
  padding: 5px;
  border: 1px solid var(--border);
  background: #e8ecf2;
}

.compact-form textarea {
  min-height: 48px;
}

.wide,
.output-card,
.actions-card,
.browser-card {
  grid-column: 1 / -1;
}

.list-panel {
  min-height: 96px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px;
  background: #ffffff;
}

.compact-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

.list-button {
  display: block;
  width: 100%;
  min-height: 22px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 3px 5px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
  font-weight: 500;
}

.list-button:hover,
.list-button.active {
  border-color: #6f8eb4;
  background: #dbe8f6;
  color: #143a63;
}

.resource-panel {
  display: grid;
  gap: 5px;
}

.resource-tabs {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.resource-tab {
  min-height: 22px;
  border: 1px solid #8792a0;
  border-radius: 0;
  padding: 2px 7px;
  background: linear-gradient(#f8fafc, #d8dee8);
  color: #1f2933;
}

.resource-tab:hover,
.resource-tab.active {
  border-color: #315f94;
  background: #dbe8f6;
  color: #143a63;
}

.file-list-inline {
  min-height: 34px;
  max-height: 74px;
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  align-content: flex-start;
}

.compact-file-button {
  width: auto;
  margin: 0;
  background: #f8fafc;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 2px 4px;
  border: 1px solid var(--border);
  background: #dfe5ed;
}

.preview-toolbar span:first-child {
  color: #17324d;
  font-weight: 700;
}

.markdown-body {
  min-height: 360px;
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 7px 9px;
  background: #ffffff;
  color: var(--text);
  line-height: 1.5;
  font-size: 12px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 8px 0 4px;
  color: #174a7c;
}

.markdown-body h1 { font-size: 16px; }
.markdown-body h2 { font-size: 14px; }
.markdown-body h3 { font-size: 13px; }

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol {
  margin: 4px 0;
}

.markdown-body blockquote {
  margin: 5px 0;
  padding: 2px 7px;
  border-left: 3px solid #6f8eb4;
  color: #3d4856;
  background: #eef4fb;
}

.markdown-body pre {
  min-height: auto;
  max-height: none;
  margin: 5px 0;
  border-radius: 0;
  padding: 6px;
  background: #17212b;
  color: #e8edf4;
}

.markdown-body code,
pre {
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
}

.markdown-body :not(pre) > code {
  border: 1px solid #bac4d0;
  border-radius: 0;
  padding: 0 3px;
  background: #eef1f5;
  color: #17324d;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 5px 0;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 3px 5px;
  text-align: left;
}

.plain-text-preview {
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.65;
  color: #17212b;
}

.flow-step,
.writing-groups {
  display: grid;
  gap: 6px;
}

.step-heading {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
}

.step-number {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid #315f94;
  border-radius: 0;
  background: #2f6fad;
  color: white;
  font-weight: 700;
}

.stage-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.75fr) minmax(0, 1.25fr);
  gap: 6px;
  align-items: center;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: #e8ecf2;
}

.stage-card h4 {
  margin: 0 0 2px;
}

.stage-card p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.outline-card {
  grid-template-columns: minmax(0, 1fr) auto;
}

.compact-actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.action-strip button,
.action-grid button,
.compact-actions button {
  min-height: 24px;
}

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

.summary-item {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 5px;
  background: #ffffff;
  min-width: 0;
}

.summary-item strong {
  display: block;
  margin-bottom: 1px;
  color: #174a7c;
  font-size: 11px;
}

.summary-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.output-dock {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding: 0;
}

.output-dock .panel-title {
  margin: 0;
}

.output-dock pre {
  min-height: 92px;
  max-height: 150px;
  margin: 0;
  border: 0;
  border-top: 1px solid var(--border-dark);
  border-radius: 0;
  padding: 6px;
  background: #111820;
  color: #d9e4f2;
}

pre {
  min-height: 160px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 6px;
  background: #17212b;
  color: #e8edf4;
  white-space: pre-wrap;
}

.error {
  color: var(--danger);
}

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

.login-shell {
  width: min(100%, 360px);
}

.login-card h1 {
  font-size: 20px;
}

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

.login-error {
  min-height: 18px;
  margin: 8px 0 0;
}

@media (max-width: 1100px) {
  body.admin-body {
    overflow: auto;
  }

  .admin-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-dark);
  }

  .nav-menu {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    overflow-x: auto;
  }

  .workspace-layout,
  .operation-layout,
  .project-select-layout,
  .project-create-form,
  .control-strip,
  .guide-summary,
  .guide-current,
  .stage-card,
  .outline-card {
    grid-template-columns: 1fr;
  }

  .project-create-form .wide,
  .project-create-form button[type="submit"] {
    grid-column: 1 / -1;
  }

  .compact-actions,
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main-shell {
    height: auto;
    overflow: visible;
  }

  .topbar,
  .output-dock {
    position: static;
  }
}

@media (max-width: 860px) {
  .grid-form,
  .action-grid,
  .compact-actions,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .user-bar,
  .panel-title,
  .control-title {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-menu {
    grid-template-columns: 1fr;
  }

  .user-bar button {
    width: 100%;
  }
}
