:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #1b2431;
  --muted: #6b7788;
  --line: #e2e7f0;
  --brand: #4f46e5;
  --brand-dark: #3f37c9;
  --brand-soft: #eef0ff;
  --danger: #d9463f;
  --ok: #1f9d63;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.spacer { flex: 1; }

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 17px; margin: 0; }
.logo {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #7c6cf5);
  color: #fff; font-weight: 700; letter-spacing: .5px;
}

/* layout */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  padding: 20px 24px;
  align-items: start;
}

/* sidebar */
.sidebar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 82px;
}
.search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.search:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.filters { display: flex; gap: 6px; margin: 10px 0 6px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--muted);
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.list { display: flex; flex-direction: column; gap: 6px; max-height: 62vh; overflow: auto; }
.list-item {
  text-align: left;
  border: 1px solid transparent;
  background: #fafbff;
  border-radius: 9px;
  padding: 10px 12px;
  cursor: pointer;
}
.list-item:hover { background: var(--brand-soft); }
.list-item.selected { border-color: var(--brand); background: var(--brand-soft); }
.list-item .li-title { font-weight: 600; font-size: 14px; }
.list-item .li-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 0; }

/* badges */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge.draft { background: #fff3d6; color: #9a6b00; }
.badge.published { background: #dff5e9; color: var(--ok); }

/* viewer */
.viewer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--shadow);
  min-height: 60vh;
}
.placeholder { text-align: center; padding: 60px 0; }
.placeholder h2 { font-weight: 600; }

.doc-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.doc-head h2 { margin: 0; font-size: 24px; }
.doc-meta { color: var(--muted); font-size: 13px; margin-top: 6px; display: flex; gap: 14px; flex-wrap: wrap; }
.doc-summary { margin: 18px 0; padding: 14px 16px; background: #f7f8fd; border-left: 3px solid var(--brand); border-radius: 6px; }
.doc-section { margin-top: 22px; }
.doc-section h3 { font-size: 15px; margin: 0 0 8px; color: var(--brand-dark); text-transform: uppercase; letter-spacing: .04em; }
.doc-section ul { margin: 0; padding-left: 20px; }
.doc-section li { margin-bottom: 6px; line-height: 1.5; }
.doc-actions { display: flex; gap: 8px; }

/* buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f2f4fa; }
.btn-danger { background: #fff; border-color: #f0c4c1; color: var(--danger); }
.btn-danger:hover { background: #fdeceb; }
.icon-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 15px; color: var(--muted); padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: #f0f2f8; color: var(--ink); }

/* dialog */
.editor {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(720px, 94vw);
  max-height: 90vh;
  box-shadow: 0 20px 60px rgba(16, 24, 40, .25);
}
.editor::backdrop { background: rgba(16, 24, 40, .45); }
.editor form { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; overflow: auto; max-height: 90vh; }
.editor-head { display: flex; justify-content: space-between; align-items: center; }
.editor-head h2 { margin: 0; font-size: 19px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: #445; }
input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
/* highlighted element */
#editorForm > label:nth-child(4) > select {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 0 0 3px var(--brand-soft);
  font-weight: 600;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sections-head { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.sections-head h3 { margin: 0; font-size: 14px; }
.section-row { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fbfcff; }
.section-row-head { display: flex; gap: 8px; }
.section-heading { flex: 1; font-weight: 600; }
.items { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.item-row { display: flex; gap: 8px; }
.item-row input { flex: 1; }
.add-item { font-size: 12.5px; padding: 5px 10px; }
.editor-actions { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13.5px; box-shadow: var(--shadow); z-index: 50;
}

@media (max-width: 780px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .grid { grid-template-columns: 1fr; }
}

@media print {
  .topbar, .sidebar, .doc-actions { display: none !important; }
  .layout { display: block; padding: 0; }
  .viewer { border: none; box-shadow: none; padding: 0; }
}
