:root {
  --ink: #1a1f24;
  --ink-soft: #3d4752;
  --paper: #f7f3ea;
  --paper-edge: #e4dcc8;
  --chrome: #12161a;
  --chrome-2: #1c2329;
  --chrome-3: #273038;
  --line: #2e3842;
  --accent: #c45c26;
  --accent-soft: #e8a06a;
  --ok: #3d8b6e;
  --warn: #c9a227;
  --xml: #5b8fbf;
  --format: #9a7b4f;
  --select: rgba(196, 92, 38, 0.22);
  --select-border: #c45c26;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "DM Sans", system-ui, sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
  --sidebar: 260px;
  --sections: 200px;
  --props: 280px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: #e8edf2;
  background: var(--chrome);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--chrome-2);
  border-right: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.sidebar-head {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.9rem;
}
.brand-mark {
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.15rem;
  border-radius: 4px;
}
.brand-name { font-weight: 600; letter-spacing: -0.02em; font-size: 0.95rem; }
.brand-sub {
  font-size: 0.68rem;
  color: #8a96a3;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#filter {
  width: 100%;
  background: var(--chrome);
  border: 1px solid var(--line);
  color: #e8edf2;
  padding: 0.45rem 0.6rem;
  border-radius: 4px;
  font: 500 0.85rem var(--sans);
  outline: none;
}
#filter:focus { border-color: var(--accent-soft); }
#btnNewReport {
  margin-top: 0.65rem;
}

.file-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.4rem 0;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #4a5560 var(--chrome);
}
.file-list::-webkit-scrollbar {
  width: 10px;
}
.file-list::-webkit-scrollbar-track {
  background: var(--chrome);
}
.file-list::-webkit-scrollbar-thumb {
  background: #4a5560;
  border-radius: 5px;
  border: 2px solid var(--chrome);
}
.file-list::-webkit-scrollbar-thumb:hover {
  background: #6a7682;
}
.file-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.65rem;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.file-item:hover { background: rgba(255,255,255,0.03); }
.file-item.active {
  background: rgba(196, 92, 38, 0.12);
  border-left-color: var(--accent);
}
.file-item .fname {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: #d5dde6;
}
.file-item .ftitle {
  grid-column: 2;
  font-size: 0.72rem;
  color: #8a96a3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kind-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  margin-top: 0.35rem;
  background: #5a6570;
}
.kind-dot.xml { background: var(--xml); }
.kind-dot.format { background: var(--format); }

.sidebar-foot {
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.72rem;
  color: #7a8794;
  flex-shrink: 0;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--chrome);
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--chrome-2);
  min-height: 3.1rem;
}
.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
#docTitle {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.45rem;
  border-radius: 3px;
  background: var(--chrome-3);
  color: #b0bcc8;
}
.pill.xml { color: #9ec5e8; background: rgba(91,143,191,0.2); }
.pill.format { color: #d4b98a; background: rgba(154,123,79,0.22); }
.status { font-size: 0.75rem; color: #8a96a3; }
.status.dirty { color: var(--warn); }
.status.saved { color: var(--ok); }

.mode-tabs {
  display: flex;
  background: var(--chrome);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.mode-tab {
  font: 600 0.75rem var(--sans);
  background: transparent;
  border: none;
  color: #8a96a3;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}
.mode-tab.active {
  background: var(--chrome-3);
  color: #fff;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: #a8b4c0;
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--accent); }

.btn {
  font: 600 0.8rem var(--sans);
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 0.4rem 0.85rem;
  border-radius: 4px;
  cursor: pointer;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.08); }
.btn.ghost {
  background: transparent;
  color: #b0bcc8;
  border: 1px solid var(--line);
}
.btn.block { width: 100%; margin-top: 0.5rem; }

.panes {
  flex: 1;
  display: grid;
  min-height: 0;
  overflow: hidden;
}
.panes.design-mode {
  grid-template-columns: var(--sections) 1fr var(--props);
}
.panes.code-mode {
  grid-template-columns: var(--sections) 1fr minmax(280px, 38%);
}
.panes.design-mode .editor-pane,
.panes.design-mode .preview-pane { display: none; }
.panes.code-mode .canvas-pane,
.panes.code-mode .props-pane { display: none; }

.pane {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
}
.sections-pane, .props-pane, .preview-pane { background: var(--chrome-2); }
.pane-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #7a8794;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
#sectionSelect {
  max-width: 55%;
  background: var(--chrome);
  border: 1px solid var(--line);
  color: #d5dde6;
  font: 500 0.72rem var(--mono);
  padding: 0.2rem 0.3rem;
  border-radius: 3px;
}

#editor { flex: 1; }

.outline {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.35rem 0;
  scrollbar-width: thin;
  scrollbar-color: #4a5560 var(--chrome);
}
.outline-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #a8b4c0;
  font: 500 0.75rem var(--mono);
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  border-left: 2px solid transparent;
}
.outline-item:hover { background: rgba(255,255,255,0.04); color: #e8edf2; }
.outline-item.active {
  border-left-color: var(--accent);
  color: var(--accent-soft);
  background: rgba(196, 92, 38, 0.1);
}
.outline-item .otype {
  display: block;
  font-family: var(--sans);
  font-size: 0.65rem;
  color: #6a7682;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.1rem;
}
.outline-item.editable-section .otype::after {
  content: " · editable";
  color: var(--ok);
}
.outline-empty {
  padding: 1rem 0.75rem;
  font-size: 0.8rem;
  color: #6a7682;
  line-height: 1.4;
}

.canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--line);
  background: var(--chrome-2);
  flex-shrink: 0;
}
.tool {
  font: 600 0.72rem var(--sans);
  background: var(--chrome-3);
  border: 1px solid var(--line);
  color: #d5dde6;
  padding: 0.35rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
}
.tool:hover { border-color: var(--accent-soft); color: #fff; }
.tool.danger:hover { border-color: #c45c26; color: #ffb89a; }
.tool-sep {
  width: 1px;
  background: var(--line);
  margin: 0 0.25rem;
  align-self: stretch;
}

.canvas-scroll {
  flex: 1;
  overflow: auto;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(196,92,38,0.08), transparent 50%),
    linear-gradient(160deg, #0e1216, #161c22 40%, #12171c);
  padding: 1.25rem;
}
.paper {
  margin: 0 auto;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--paper-edge), 0 12px 40px rgba(0,0,0,0.45);
  min-height: 4rem;
}
.editable-paper { outline: none; position: relative; }
.canvas-empty {
  font-family: var(--sans);
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.5;
  padding: 2rem 1.5rem;
  text-align: center;
}
.canvas-notice {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--ink-soft);
  background: #efe8d8;
  border: 1px solid var(--paper-edge);
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.85rem;
  border-radius: 4px;
  line-height: 1.4;
}

.v-meta {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--paper-edge);
}
.v-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 0.75rem;
  font-family: var(--page-font, var(--serif));
  font-size: var(--value-size, 11pt);
}
.v-row { cursor: pointer; transition: background 0.1s; }
.v-row:hover td { background: rgba(196, 92, 38, 0.06); }
.v-row.selected td,
.v-cell.selected {
  background: var(--select) !important;
  box-shadow: inset 0 0 0 1.5px var(--select-border);
}
.v-cell { cursor: pointer; }
.v-row td {
  vertical-align: top;
  padding: 0.28rem 0.35rem;
  position: relative;
}
.v-prompt {
  font-weight: var(--prompt-weight, 700);
  font-size: var(--prompt-size, 11pt);
  margin-right: 0.35em;
}
.v-value {
  font-weight: 400;
  font-size: var(--value-size, 11pt);
}
.v-value.sample { color: #6b5344; font-style: italic; }
.v-header, .v-bold {
  font-weight: 700;
  font-size: var(--prompt-size, 11pt);
}
.v-separator {
  display: block;
  border-bottom: 1px solid var(--ink);
  height: 0;
  margin: 0.25rem 0;
}
.v-blank { display: block; height: 0.65em; }
.v-barcode {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.85em;
  letter-spacing: 0.12em;
  padding: 0.35rem 0.5rem 0.15rem;
  border: 2px solid var(--ink);
  background: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 5px, transparent 5px 8px);
  background-size: 100% 55%;
  background-repeat: no-repeat;
  background-position: top;
  text-align: center;
  min-width: 8rem;
}

.props-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #4a5560 var(--chrome);
}
.props-body::-webkit-scrollbar {
  width: 10px;
}
.props-body::-webkit-scrollbar-track {
  background: var(--chrome);
}
.props-body::-webkit-scrollbar-thumb {
  background: #4a5560;
  border-radius: 5px;
  border: 2px solid var(--chrome);
}
.props-body::-webkit-scrollbar-thumb:hover {
  background: #6a7682;
}
.props-micro {
  font-size: 0.72rem;
  color: #7a8794;
  line-height: 1.4;
  margin: -0.25rem 0 0.65rem;
}
.prop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.5rem;
  margin-bottom: 0.35rem;
}
.prop-grid .field-label { margin-bottom: 0.35rem; }
.size-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.25rem;
}
.size-row input {
  flex: 1;
  margin-top: 0;
  background: var(--chrome);
  border: 1px solid var(--line);
  color: #e8edf2;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  font: 500 0.85rem var(--sans);
  outline: none;
}
.size-row input:focus { border-color: var(--accent-soft); }
.size-unit {
  font-size: 0.75rem;
  color: #7a8794;
  min-width: 1.2rem;
}
.props-block {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.props-block h3 {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7a8794;
}
.field-label {
  display: block;
  font-size: 0.72rem;
  color: #a8b4c0;
  margin-bottom: 0.55rem;
}
.field-label input,
.field-label select,
.palette-filter {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  background: var(--chrome);
  border: 1px solid var(--line);
  color: #e8edf2;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  font: 500 0.85rem var(--sans);
  outline: none;
}
.field-label input:focus,
.field-label select:focus,
.palette-filter:focus { border-color: var(--accent-soft); }

.palette {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 280px;
  overflow: auto;
}
.palette-item {
  text-align: left;
  background: var(--chrome);
  border: 1px solid var(--line);
  color: #d5dde6;
  padding: 0.4rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
  font: 500 0.78rem var(--sans);
}
.palette-item:hover {
  border-color: var(--accent-soft);
  background: rgba(196, 92, 38, 0.1);
}
.palette-item small {
  display: block;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: #7a8794;
  margin-top: 0.1rem;
}
.palette-group {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6a7682;
  margin: 0.5rem 0 0.25rem;
}

.preview-scroll {
  flex: 1;
  overflow: auto;
  background: linear-gradient(160deg, #0e1216, #161c22);
  padding: 1.25rem;
}
.rpt { font-family: var(--serif); font-size: 11pt; line-height: 1.35; }
.rpt-meta {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--paper-edge);
}
.rpt table { width: 100%; border-collapse: collapse; table-layout: fixed; margin: 0 0 0.35rem; }
.rpt td { vertical-align: top; padding: 0.1rem 0.25rem; }
.rpt .prompt { font-weight: 700; margin-right: 0.35em; }
.rpt .value.sample { color: #6b5344; font-style: italic; }
.rpt .bold, .rpt .header { font-weight: 700; }
.rpt .separator { display: block; border-bottom: 1px solid var(--ink); height: 0; margin: 0.2rem 0; }
.rpt .blank { display: block; height: 0.7em; }
.rpt .barcode {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.85em;
  letter-spacing: 0.12em;
  padding: 0.35rem 0.5rem 0.15rem;
  border: 2px solid var(--ink);
  background: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 5px, transparent 5px 8px);
  background-size: 100% 55%;
  background-repeat: no-repeat;
  background-position: top;
  min-width: 8rem;
  text-align: center;
}
.fmt { font-family: var(--mono); font-size: 12px; line-height: 1.25; white-space: pre; overflow-x: auto; }
.fmt .field { background: rgba(196, 92, 38, 0.12); color: #7a3a14; border-radius: 2px; }
.fmt-title {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 0 0 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.fmt-block + .fmt-block { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--paper-edge); }
.preview-empty, .preview-error {
  font-family: var(--sans);
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.5;
}
.preview-error { color: #8b3a2a; }

.dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--chrome-2);
  color: #e8edf2;
  padding: 1.25rem;
  max-width: 360px;
  width: 90%;
}
.dialog::backdrop { background: rgba(0,0,0,0.55); }
.dialog h2 { margin: 0 0 1rem; font-size: 1rem; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

@media (max-width: 1000px) {
  :root { --sidebar: 220px; --props: 240px; --sections: 160px; }
}
