[hidden] { display: none !important; }
body.modal-open { overflow: hidden; }

.report-settings,
.add-chapter-panel { margin-bottom: 18px; }
.report-header-form {
  grid-template-columns: minmax(210px, 30fr) minmax(180px, 40fr) minmax(180px, 30fr) auto;
  align-items: end;
}
.report-header-form > .form-group { min-width: 0; }
.report-header-form > .report-header-actions {
  grid-column: 4;
  grid-row: 1;
  align-self: end;
  margin: 0;
  padding: 0;
  border-top: 0;
}
.report-header-form > .report-header-actions .btn { min-height: 44px; white-space: nowrap; }
.report-header-form > .report-structure-field { grid-column: 1 / -1; }
.report-settings summary,
.add-chapter-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 20px;
  cursor: pointer;
  list-style: none;
}
.report-settings summary::-webkit-details-marker,
.add-chapter-panel summary::-webkit-details-marker { display: none; }
.report-settings summary span:first-child,
.add-chapter-panel summary span:first-child { display: flex; flex-direction: column; gap: 3px; }
.report-settings summary strong,
.add-chapter-panel summary strong { font-size: 15px; }
.report-settings summary small,
.add-chapter-panel summary small { color: var(--muted); font-size: 12px; }
.summary-action { color: #68a9fa; font-size: 12px; font-weight: 800; }
.report-settings[open] summary,
.add-chapter-panel[open] summary { border-bottom: 1px solid #1b2a3e; }

.chapters-panel { margin-bottom: 18px; overflow: hidden; scroll-margin-top: 84px; }
.chapters-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px;
  border-bottom: 1px solid #1b2a3e;
}
.chapters-heading h2 { margin: 0; font-size: 17px; }
.chapters-heading p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.chapters-empty { min-height: 180px; display: grid; place-items: center; }
.chapter-list { display: flex; flex-direction: column; }

.chapter-row {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 24px;
  padding: 18px 20px 20px;
  border-bottom: 1px solid #1b2a3e;
  scroll-margin-top: 84px;
}
.chapter-row:last-child { border-bottom: 0; }
.chapter-row.is-child { background: #0b152210; }
.chapter-rail {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 14px;
  padding-right: 20px;
  border-right: 1px solid #1b2a3e;
}
.chapter-controls {
  display: grid;
  grid-template-columns: repeat(4, 40px);
  justify-content: space-between;
  align-content: start;
  gap: 10px;
}
.chapter-controls form { display: contents; }
.chapter-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid #31506e;
  border-radius: 7px;
  background: #102131;
  color: #9ed4ff;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.chapter-icon:hover { border-color: #4c9ef3; color: #ffffff; }
.chapter-icon.danger { color: #ff7f8b; border-color: #613843; }
.chapter-icon.chapter-indent {
  grid-column: 3 / 5;
  width: 100%;
  color: #8be0b0;
  border-color: #357154;
  font-size: 9px;
  font-weight: 800;
}
.chapter-icon.chapter-indent:hover { border-color: #4dba7d; }
.chapter-icon.chapter-outdent {
  grid-column: 3 / 5;
  width: 100%;
  color: #ffd27a;
  border-color: #79602f;
  font-size: 9px;
  font-weight: 800;
}
.chapter-icon.chapter-outdent:hover { border-color: #d39b35; }
.chapter-meta-form {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
.chapter-name { min-width: 0; }
.chapter-name .field {
  width: 100%;
  height: 42px;
  min-height: 42px;
  line-height: 1.2;
}
.chapter-meta-form label {
  display: block;
  margin: 0 0 7px;
  color: #70b9ef;
  font: 700 10px Space Mono;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.chapter-field-heading {
  min-height: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.chapter-save-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #6f8ca4;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  transition: color .18s ease;
}
.chapter-save-status.is-saving { color: #70b9ef; }
.chapter-save-status.is-saved { color: #5fc68b; }
.chapter-save-status.is-error { color: #ff7f8b; }
.chapter-number label {
  display: block;
  margin: 0 0 7px;
  color: #70b9ef;
  font: 700 10px Space Mono;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.chapter-number-value {
  height: 56px;
  display: grid;
  place-items: center;
  border: 1px solid #2b435d;
  border-radius: 9px;
  background: #102131;
  color: #70bfff;
  font-weight: 800;
}
.chapter-text { min-width: 0; }
.chapter-text-preview {
  width: 100%;
  height: 106px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  padding: 13px 14px;
  border: 1px solid #2b435d;
  border-radius: 9px;
  background: #0c1723;
  color: #d7e7f8;
  text-align: left;
  line-height: 1.55;
  cursor: text;
}
.chapter-text-preview:hover { border-color: #38a5ef; box-shadow: 0 0 0 3px #2d9ce719; }
.chapter-text-preview.is-empty { color: var(--muted); font-style: italic; }

.chapter-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 22px;
  background: #020711d9;
  backdrop-filter: blur(7px);
}
.chapter-modal-dialog {
  width: min(1120px, 100%);
  height: min(820px, calc(100vh - 44px));
  max-height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #1d2d43;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #101b2a, #0d1521);
  color: var(--text);
  box-shadow: 0 30px 90px #000a;
}
.chapter-modal-dialog > form {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}
.chapter-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 10px 16px;
  border-bottom: 1px solid #24394d;
}
.chapter-modal-header > div { display: flex; flex-direction: column; gap: 2px; }
.chapter-modal-header strong { font-size: 15px; }
.chapter-modal-header small { color: #718da6; font-size: 11px; }
.chapter-modal-close {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: #cbe0f2;
  font-size: 27px;
  cursor: pointer;
}
.chapter-modal-body {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 30px 38px 20px;
}
.chapter-modal-body h2 { margin: 0; font-size: 25px; line-height: 1.3; }
.chapter-modal-body > p { margin: 8px 0 22px; color: #83a3bd; font-size: 13px; }
.chapter-format-toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid #263952;
  border-bottom: 0;
  border-radius: 9px 9px 0 0;
  background: #101d2c;
}
.chapter-format-toolbar button {
  width: 34px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #35506c;
  border-radius: 6px;
  background: #14263a;
  color: #dce9fa;
  font: 700 15px/1 Manrope, sans-serif;
  cursor: pointer;
}
.chapter-format-toolbar button:hover,
.chapter-format-toolbar button.is-active { border-color: #428ff1; background: #183b60; color: #fff; }
.chapter-format-toolbar > span { margin-left: 5px; color: #7796af; font-size: 11px; }
.chapter-modal-text {
  width: 100%;
  min-height: 180px;
  flex: 1;
  resize: vertical;
  padding: 28px 34px;
  border: 1px solid #263952;
  overflow: auto;
  white-space: pre-wrap;
  tab-size: 4;
  border-radius: 0 0 9px 9px;
  outline: 0;
  background: #0d1725;
  color: #dce9fa;
  font: 500 15px/1.55 Manrope, sans-serif;
}
.chapter-modal-text:focus { border-color: #428ff1; box-shadow: 0 0 0 3px #2c82ec18; }
.chapter-modal-meta {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 10px;
  color: #6e91aa;
  font-size: 11px;
}
#chapterModalSaveStatus.is-saving { color: #70b9ef; }
#chapterModalSaveStatus.is-saved { color: #55d79a; }
#chapterModalSaveStatus.is-error { color: #ff7f8b; }
.chapter-modal-footer {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 12px;
  padding: 18px 38px;
  border-top: 1px solid #24394d;
}
.chapter-modal-footer .btn { min-width: 130px; }

html[data-theme="light"] .report-settings[open] summary,
html[data-theme="light"] .add-chapter-panel[open] summary,
html[data-theme="light"] .chapters-heading,
html[data-theme="light"] .chapter-row,
html[data-theme="light"] .chapter-rail { border-color: #d8e2ed; }
html[data-theme="light"] .chapter-row.is-child { background: #f5f9fd; }
html[data-theme="light"] .chapter-icon { background: #f4f9ff; color: #23699f; border-color: #b7ccdf; }
html[data-theme="light"] .chapter-icon:hover { color: #084f8e; border-color: #3788cf; }
html[data-theme="light"] .chapter-icon.danger { color: #b93745; background: #fff7f8; border-color: #e1b6bc; }
html[data-theme="light"] .chapter-meta-form label { color: #286b9d; }
html[data-theme="light"] .chapter-number label { color: #286b9d; }
html[data-theme="light"] .chapter-save-status { color: #66788c; }
html[data-theme="light"] .chapter-save-status.is-saving { color: #286b9d; }
html[data-theme="light"] .chapter-save-status.is-saved { color: #238453; }
html[data-theme="light"] .chapter-save-status.is-error { color: #b93745; }
html[data-theme="light"] .chapter-number-value {
  color: #075bb2;
  background: #f4f9ff;
  border-color: #b7ccdf;
}
html[data-theme="light"] .chapter-text-preview {
  background: #ffffff;
  color: #25364a;
  border-color: #c4d3e1;
}
html[data-theme="light"] .chapter-text-preview.is-empty { color: #66788c; }
html[data-theme="light"] .chapter-modal-dialog {
  background: linear-gradient(145deg, #ffffff, #f9fbfd);
  color: var(--text);
  border-color: #d6e0eb;
  box-shadow: 0 28px 80px #253b5540;
}
html[data-theme="light"] .chapter-modal-header,
html[data-theme="light"] .chapter-modal-footer { border-color: #d8e2ed; }
html[data-theme="light"] .chapter-modal-header small,
html[data-theme="light"] .chapter-modal-body > p,
html[data-theme="light"] .chapter-modal-meta { color: var(--muted); }
html[data-theme="light"] .chapter-modal-close { color: #42566d; }
html[data-theme="light"] .chapter-modal-text {
  background: #ffffff;
  color: #172235;
  border-color: #c7d4e2;
}
html[data-theme="light"] .chapter-format-toolbar { background: #f3f7fb; border-color: #c7d4e2; }
html[data-theme="light"] .chapter-format-toolbar button { background: #fff; color: #24384d; border-color: #b9cadd; }
html[data-theme="light"] .chapter-format-toolbar button:hover,
html[data-theme="light"] .chapter-format-toolbar button.is-active { background: #e8f3ff; color: #075bb2; border-color: #428ff1; }
html[data-theme="light"] .chapter-format-toolbar > span { color: #66788c; }
html[data-theme="light"] #chapterModalSaveStatus.is-saving { color: #286b9d; }
html[data-theme="light"] #chapterModalSaveStatus.is-saved { color: #238453; }
html[data-theme="light"] #chapterModalSaveStatus.is-error { color: #b93745; }

@media (max-width: 1150px) {
  .chapter-row { grid-template-columns: 230px minmax(0, 1fr); gap: 18px; }
  .chapter-rail { padding-right: 16px; }
}
@media (max-width: 800px) {
  .report-header-form { grid-template-columns: 1fr; }
  .report-header-form > .form-group,
  .report-header-form > .form-actions { grid-column: 1; }
  .report-header-form > .report-header-actions { grid-row: auto; }
  .chapters-heading { align-items: flex-start; flex-direction: column; }
  .chapter-row,
  .chapter-row.is-child { grid-template-columns: 1fr; padding: 16px; }
  .chapter-rail {
    width: min(100%, 250px);
    gap: 12px;
    padding: 0 0 14px;
    border-right: 0;
    border-bottom: 1px solid #1b2a3e;
  }
  .chapter-meta-form { grid-template-columns: 1fr; }
  .chapter-field-heading { align-items: center; }
  .chapter-modal { padding: 0; }
  .chapter-modal-dialog { width: 100%; max-height: 100vh; height: 100vh; border-radius: 0; }
  .chapter-modal-body { padding: 22px 18px 14px; }
  .chapter-modal-body h2 { font-size: 20px; }
  .chapter-modal-text { min-height: 120px; padding: 18px; }
  .chapter-modal-footer { padding: 14px 18px; }
}

.report-tree-editor { display:grid; grid-template-columns:minmax(270px, 350px) minmax(0, 1fr); min-height:680px; margin-bottom:18px; overflow:visible; }
.report-tree-panel { position:sticky; top:76px; align-self:start; max-height:calc(100vh - 96px); display:flex; flex-direction:column; border-right:1px solid var(--line); background:var(--surface); }
.report-tree-header { display:flex; align-items:center; justify-content:space-between; padding:18px 16px 10px; }
.report-tree-header h2 { margin:0; font-size:16px; }
.report-tree-header small { color:var(--muted); }
.report-tree-hide,.report-tree-show { border:1px solid var(--line); border-radius:7px; background:var(--surface2); color:var(--text); cursor:pointer; }
.report-tree-hide { width:32px; height:32px; }
.report-tree-show { align-self:start; margin:15px; padding:9px 12px; }
.report-tree-search { padding:0 14px 12px; }
.report-tree-search .field { min-height:38px; }
.report-tree-list { min-height:120px; overflow:auto; padding:4px 8px 12px; }
.report-tree-editor.is-tree-menu-open,
.report-tree-editor.is-tree-menu-open .report-tree-panel { z-index:1000; }
.report-tree-editor.is-tree-menu-open .report-tree-list { overflow:visible; position:relative; z-index:1001; }
.report-tree-editor.is-tree-menu-open .report-tree-row:has(.report-tree-menu[open]) { z-index:1002; }
.report-tree-row { position:relative; }
.report-tree-indent { display:flex; align-items:center; min-width:0; padding-left:calc(var(--tree-depth) * 18px); border-radius:8px; }
.report-tree-row.is-active > .report-tree-indent { background:color-mix(in srgb, var(--blue) 15%, var(--surface2)); box-shadow:inset 3px 0 var(--blue); }
.report-tree-chevron,.report-tree-chevron-spacer { width:26px; height:34px; flex:0 0 26px; }
.report-tree-chevron { border:0; background:transparent; color:var(--muted); cursor:pointer; font-size:22px; transition:transform .15s; }
.report-tree-chevron.is-open { transform:rotate(90deg); }
.report-tree-select { min-width:0; flex:1; display:flex; gap:8px; padding:9px 4px; border:0; background:transparent; color:var(--text); cursor:pointer; text-align:left; }
.report-tree-select [data-section-name] { overflow:hidden; text-overflow:ellipsis; }
.report-tree-select .report-tree-complete { flex:0 0 auto; align-self:flex-start; width:16px; height:16px; display:grid; place-items:center; margin-top:1px; border-radius:50%; background:#28a96b; color:#fff; font-size:10px; font-weight:900; line-height:1; }
.report-tree-menu { position:relative; }
.report-tree-menu summary { width:30px; padding:6px 4px; color:var(--muted); cursor:pointer; list-style:none; text-align:center; }
.report-tree-menu summary::-webkit-details-marker { display:none; }
.report-tree-menu-popover { position:absolute; z-index:1003; right:0; top:30px; width:220px; padding:7px; border:1px solid var(--line); border-radius:9px; background:var(--surface); box-shadow:0 15px 40px #0005; }
.report-tree-menu-popover button { width:100%; padding:8px 9px; border:0; border-radius:5px; background:transparent; color:var(--text); cursor:pointer; text-align:left; }
.report-tree-menu-popover button:hover { background:var(--surface2); }
.report-tree-menu-popover button.danger { color:#ff7f8b; }
.report-tree-parent-form { padding:6px 8px; border-block:1px solid var(--line); }
.report-tree-parent-form label { display:block; margin-bottom:4px; color:var(--muted); font-size:10px; }
.report-tree-parent-form select { width:100%; margin-bottom:4px; }
.report-tree-add { margin:12px 14px 16px; }
.report-section-workspace { min-width:0; padding:28px 30px; }
.report-section-placeholder { min-height:560px; display:grid; place-items:center; color:var(--muted); text-align:center; }
.report-section-form > header { display:flex; align-items:flex-start; justify-content:space-between; gap:20px; margin-bottom:22px; }
.report-section-form > header h2 { margin:5px 0 0; }
.report-section-form > header [data-editor-status] { color:var(--muted); font-size:12px; }
.report-section-form > header .is-saving { color:#70b9ef; }
.report-section-form > header .is-saved { color:#55c98b; }
.report-section-form > header .is-error { color:#ff7f8b; }
.report-section-text { min-height:450px; padding:25px 28px; border:1px solid #cfd8e3; border-radius:0 0 9px 9px; outline:0; background:#fff; color:#172235; font:500 15px/1.55 Manrope,sans-serif; white-space:pre-wrap; tab-size:4; box-shadow:0 8px 24px #10233b12; }
.report-section-text:focus { border-color:var(--blue); box-shadow:0 0 0 3px color-mix(in srgb,var(--blue) 12%,transparent); }
.report-section-text > .is-compact { margin-block:0; line-height:1.2; }
.report-section-form footer { display:flex; align-items:center; justify-content:space-between; padding-top:12px; color:var(--muted); font-size:11px; }
.chapter-format-toolbar .compact-paragraphs { width:auto; padding-inline:12px; font-size:11px; }
.report-add-dialog { width:min(520px,calc(100% - 30px)); padding:22px; border:1px solid var(--line); border-radius:12px; background:var(--surface); color:var(--text); }
.report-add-dialog::backdrop { background:#020711b8; backdrop-filter:blur(4px); }
.report-add-dialog h2 { margin-top:0; }
.report-add-dialog .form-actions { margin-top:18px; justify-content:flex-end; }
.report-tree-editor.is-tree-hidden { grid-template-columns:auto minmax(0,1fr); }

@media (max-width:800px) {
  .report-tree-editor { grid-template-columns:1fr; min-height:0; }
  .report-tree-panel { position:relative; top:auto; max-height:55vh; border-right:0; border-bottom:1px solid var(--line); }
  .report-section-workspace { padding:20px 14px; }
  .report-section-placeholder { min-height:260px; }
  .report-section-text { min-height:380px; padding:18px; }
  .report-tree-editor.is-tree-hidden { grid-template-columns:1fr; }
}
.report-chatgpt-tip {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--blue) 28%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--blue) 6%, var(--surface));
}

.report-chatgpt-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--blue);
  background: color-mix(in srgb, var(--blue) 12%, var(--surface2));
  font-size: 17px;
}

.report-chatgpt-tip strong {
  display: block;
  font-size: 12px;
}

.report-chatgpt-tip p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

@media (max-width: 800px) {
  .report-chatgpt-tip {
    grid-template-columns: 38px 1fr;
  }
  .report-chatgpt-tip .btn {
    grid-column: 1 / -1;
  }
}
