:root {
  color-scheme: light;
  --paper: #f8f5ed;
  --surface: #ffffff;
  --surface-soft: #f1eee6;
  --ink: #231f1a;
  --muted: #766d63;
  --line: #ddd6c9;
  --brass: #b8873b;
  --moss: #4f6c55;
  --oxblood: #8f382f;
  --blue: #355f7c;
  --shadow: 0 18px 48px rgba(37, 31, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  background: #24211d;
  color: #fbf7ef;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
}

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

.brand span {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.nav-item {
  width: 100%;
  min-height: 68px;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.76);
  background: transparent;
  text-align: left;
}

.nav-item strong,
.nav-item span {
  display: block;
}

.nav-item strong {
  color: inherit;
  font-size: 15px;
}

.nav-item span {
  margin-top: 5px;
  color: rgba(255, 255, 255, 0.52);
  font-size: 12px;
  line-height: 1.35;
}

.nav-item:hover,
.nav-item.active {
  color: #fff;
  background: rgba(184, 135, 59, 0.22);
}

.nav-item:hover span,
.nav-item.active span {
  color: rgba(255, 255, 255, 0.72);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--brass);
  box-shadow: 0 0 0 4px rgba(184, 135, 59, 0.18);
}

.status-dot.online {
  background: #66b882;
  box-shadow: 0 0 0 4px rgba(102, 184, 130, 0.18);
}

.status-dot.offline {
  background: #d96658;
  box-shadow: 0 0 0 4px rgba(217, 102, 88, 0.18);
}

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

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--brass);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 17px;
}

.topbar-actions,
.toolbar,
.form-actions,
.prompt-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-action,
.secondary-action,
.danger-action,
.text-btn,
.icon-btn {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
}

.primary-action {
  color: #fff;
  background: var(--ink);
}

.secondary-action {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.danger-action {
  color: #fff;
  background: var(--oxblood);
}

.text-btn,
.icon-btn {
  color: var(--ink);
  background: transparent;
}

.icon-btn {
  width: 38px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.editor-frame {
  min-height: calc(100vh - 140px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow);
}

.frame-head {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.frame-head h2 {
  margin-bottom: 5px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(37, 31, 24, 0.08);
}

.metric-card {
  min-height: 138px;
  padding: 20px;
}

.metric-card span,
.subtle,
small {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 14px 0 8px;
  font-size: 34px;
}

.metric-card.accent {
  background: #243328;
  color: #fff;
}

.metric-card.accent span,
.metric-card.accent small {
  color: rgba(255, 255, 255, 0.72);
}

.split-layout,
.settings-grid,
.prompt-layout {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(360px, 0.7fr);
  gap: 16px;
}

.editor-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
}

.side-panel {
  align-self: start;
  max-height: calc(100vh - 186px);
  overflow: auto;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.compact-list,
.bar-list,
.knowledge-list,
.field-list,
.note-list {
  display: grid;
  gap: 10px;
}

.list-row,
.knowledge-item,
.field-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.list-row strong,
.knowledge-item strong {
  display: block;
  margin-bottom: 5px;
}

.bar-item {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 10px;
}

.bar-track {
  height: 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--moss);
}

.toolbar {
  margin-bottom: 14px;
  padding: 14px 0 0;
}

.search,
select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: 0;
}

.search,
select,
input {
  height: 40px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.7;
}

.toolbar .search {
  max-width: 420px;
}

.toolbar select {
  max-width: 180px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-soft);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--blue);
  background: rgba(53, 95, 124, 0.12);
  font-size: 12px;
  font-weight: 700;
}

.badge.pending {
  color: var(--brass);
  background: rgba(184, 135, 59, 0.14);
}

.badge.hidden {
  color: var(--oxblood);
  background: rgba(143, 56, 47, 0.12);
}

.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.post-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.post-card p {
  margin: 10px 0 14px;
  color: var(--muted);
  line-height: 1.7;
}

.post-actions {
  display: flex;
  gap: 8px;
}

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

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

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

.knowledge-item {
  cursor: pointer;
}

.knowledge-item.active {
  border-color: var(--brass);
  background: rgba(184, 135, 59, 0.12);
}

.prompt-editor {
  min-height: 480px;
}

.prompt-actions {
  margin-top: 12px;
}

.field-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.note-list p {
  padding: 12px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  line-height: 1.7;
}

dialog {
  width: min(620px, calc(100vw - 40px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(20, 17, 14, 0.46);
}

.dialog-form {
  padding: 20px;
  display: grid;
  gap: 14px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  min-width: 220px;
  padding: 13px 16px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  transition: 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .editor-layout,
  .split-layout,
  .settings-grid,
  .prompt-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    max-height: none;
  }
}

@media (max-width: 700px) {
  .app-shell {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    height: 100vh;
    padding: 16px 10px;
  }

  .brand {
    gap: 8px;
    padding: 6px 6px 16px;
  }

  .brand img {
    width: 34px;
    height: 34px;
  }

  .brand strong {
    font-size: 13px;
  }

  .brand span,
  .nav-item span {
    font-size: 11px;
  }

  .nav-item {
    min-height: 60px;
    padding: 10px;
  }

  .nav-item strong {
    font-size: 13px;
  }

  .main {
    padding: 16px;
  }

  h1 {
    font-size: 26px;
  }

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

  .toolbar .search,
  .toolbar select {
    max-width: none;
  }
}
