:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #687385;
  --line: #d8dee8;
  --paper: #fbfbfa;
  --panel: #ffffff;
  --accent: #226f68;
  --accent-2: #8a4f2a;
  --accent-3: #345995;
  --danger: #a33a3a;
  --soft: #eef4f2;
  --draft: #fff7e8;
  --source: #eef3fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

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

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button.secondary {
  background: white;
  color: var(--accent);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

.icon-btn {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

.nav {
  min-height: 100vh;
  background: #24313d;
  color: white;
  padding: 18px 12px;
  position: sticky;
  top: 0;
}

.brand {
  font-size: 24px;
  font-weight: 800;
  margin: 0 8px 18px;
}

.nav-btn {
  width: 100%;
  display: block;
  border: 0;
  background: transparent;
  text-align: left;
  color: #dbe5ef;
  margin-bottom: 4px;
}

.nav-btn.active,
.nav-btn:hover {
  background: #384858;
  color: white;
}

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

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

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

h3 {
  font-size: 16px;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.panel,
.item,
.chapter {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.compact {
  margin-bottom: 16px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

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

.toolbar {
  margin-bottom: 14px;
}

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

.list,
.chapters,
.topic-grid {
  display: grid;
  gap: 12px;
}

.list.tight {
  gap: 8px;
}

.analysis-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
  gap: 12px;
  margin-bottom: 12px;
}

.mini-item,
.evidence {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: white;
}

.mini-item strong,
.evidence strong {
  display: block;
  font-size: 14px;
  line-height: 1.35;
}

.analysis-titles,
.evidence-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.analysis-titles {
  display: flex;
  flex-wrap: wrap;
}

.title-candidate {
  width: 100%;
  text-align: left;
}

.topic-grid {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.item-actions,
.chapter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.meta,
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--soft);
  color: #31544f;
  font-size: 12px;
}

.chip.kind {
  background: #f2ece7;
  color: var(--accent-2);
}

.chip.removable {
  gap: 6px;
  padding-right: 4px;
}

.chip-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  width: 20px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 15px;
  line-height: 1;
}

.linked-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.raw,
.draft {
  border-radius: 6px;
  padding: 12px;
  white-space: pre-wrap;
  line-height: 1.55;
  margin-top: 12px;
}

.raw {
  background: var(--source);
  border-left: 4px solid var(--accent-3);
}

.draft {
  background: var(--draft);
  border-left: 4px solid var(--accent-2);
}

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

.notice {
  margin-top: 14px;
  color: var(--accent);
  min-height: 24px;
}

.chapter {
  display: grid;
  gap: 10px;
}

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

.export-box {
  margin-top: 14px;
  max-height: 360px;
  overflow: auto;
  background: #17212b;
  color: #eef6f6;
  border-radius: 8px;
  padding: 14px;
  white-space: pre-wrap;
}

.principles {
  line-height: 1.8;
}

.stats {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 14px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: min(720px, calc(100vw - 32px));
  width: 720px;
}

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

.dialog-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 860px) {
  body {
    grid-template-columns: 1fr;
  }

  .nav {
    min-height: auto;
    position: static;
    display: flex;
    overflow-x: auto;
    gap: 4px;
  }

  .brand {
    flex: 0 0 auto;
    margin: 6px 12px 0 4px;
  }

  .nav-btn {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .input-grid,
  .split,
  .analysis-layout {
    grid-template-columns: 1fr;
  }

  .app {
    padding: 16px;
  }

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