*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #f4f1ea;
  --panel: #fffcf7;
  --ink: #1f1a16;
  --muted: #6f655c;
  --line: #d9d0c3;
  --soft: #faf7f2;
  --accent: #0f766e;
  --accent-soft: #d9f3ef;
  --danger: #9f1239;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --todo: #b4472e;          /* brick red, warm like the rest of the palette */
  --todo-soft: #f8e7df;
  --shadow: 0 1px 0 rgba(31,26,22,0.04);
}
html, body { height: 100%; margin: 0; }
body {
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  line-height: 1.4;
}
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }

/* ---- layout (Data Entry Studio) ---------------------------------------- */
.app {
  display: grid;
  grid-template-columns: 280px minmax(360px, 1fr) minmax(480px, 1.3fr);
  height: 100%;
  min-height: 0;
}
.col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.col:last-child { border-right: 0; }
.col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  min-height: 3.9rem;
}
.col-head h1 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.col-sub {
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 400;
}
.col-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.85rem;
}
.head-actions { display: flex; gap: 0.35rem; align-items: center; }

/* ---- buttons -------------------------------------------------------------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
}
.icon-btn.small { width: 1.6rem; height: 1.6rem; border-radius: 7px; }
.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { cursor: not-allowed; opacity: 0.45; }
.icon-btn.toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn svg, .primary-btn svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.icon-btn.small svg { width: 0.95rem; height: 0.95rem; }
.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.38rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn:hover { background: #0b5f58; }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ghost-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  white-space: nowrap;
}
.ghost-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---- left column -------------------------------------------------------- */
.file-list { display: flex; flex-direction: column; gap: 0.5rem; }
.file-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.file-card:hover { border-color: #b8aea3; }
.file-card.active { border-color: var(--accent); background: var(--accent-soft); }
.file-card .name { font-weight: 600; font-size: 0.85rem; word-break: break-word; }
.file-card .meta { margin-top: 0.2rem; color: var(--muted); font-size: 0.72rem; }
.file-card .row-actions { margin-top: 0.45rem; display: flex; gap: 0.35rem; }
.file-card button.small {
  font-size: 0.7rem;
  padding: 0.18rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  color: var(--muted);
}
.file-card button.small:hover { color: var(--accent); border-color: var(--accent); }
.file-card button.small.danger:hover { color: var(--danger); border-color: #f3c5cf; background: #fff1f4; }
.template-card { cursor: default; }

/* project card: name + ⋮ menu on top, completed fields and review status below */
.project-card { position: relative; }
.project-card.active { background: #fff; box-shadow: inset 3px 0 0 var(--accent), var(--shadow); }
.card-top { display: flex; align-items: flex-start; gap: 0.35rem; }
.card-top .name { flex: 1; min-width: 0; }
.project-card .meta { display: flex; white-space: nowrap; }
.project-card .meta .tpl { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.project-card .meta .when { flex: 0 0 auto; }
.card-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin: -0.15rem -0.3rem 0 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
}
.card-more svg { width: 1rem; height: 1rem; fill: currentColor; pointer-events: none; }
.card-more:hover, .card-more[aria-expanded="true"] { background: var(--soft); border-color: var(--line); color: var(--ink); }
.card-menu {
  position: absolute;
  top: 2.1rem;
  right: 0.45rem;
  z-index: 5;
  min-width: 9.5rem;
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(31, 26, 22, 0.14);
}
.card-menu button {
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font-size: 0.8rem;
  text-align: left;
  padding: 0.38rem 0.6rem;
  cursor: pointer;
}
.card-menu button:hover { background: var(--soft); color: var(--accent); }
.card-menu button.danger { color: var(--danger); }
.card-menu button.danger:hover { background: #fbeef0; color: var(--danger); }

.card-state { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-top: 0.6rem; }
.done-count {
  border: 0;
  background: none;
  padding: 0;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.done-count:hover { color: var(--accent); text-decoration: underline; }
.done-count.complete { color: var(--accent); }
/* status pill: warm tones from the app palette; "done" is the app accent */
.status { position: relative; display: inline-flex; align-items: center; margin-left: auto; --c: var(--todo); --c-soft: var(--todo-soft); }
.status[data-status="review"] { --c: var(--warn); --c-soft: var(--warn-soft); }
.status[data-status="done"] { --c: var(--accent); --c-soft: var(--accent-soft); }
.status::before, .status::after { content: ""; position: absolute; pointer-events: none; }
.status::before { left: 0.5rem; width: 0.42rem; height: 0.42rem; border-radius: 50%; background: var(--c); }
.status::after {
  right: 0.5rem;
  width: 0.28rem;
  height: 0.28rem;
  border-right: 1.5px solid var(--c);
  border-bottom: 1.5px solid var(--c);
  transform: translateY(-1px) rotate(45deg);
}
.status select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid color-mix(in srgb, var(--c) 28%, transparent);
  border-radius: 999px;
  background: var(--c-soft);
  color: var(--c);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.12rem 1.15rem 0.12rem 1.1rem;
  cursor: pointer;
}
.status select:hover { border-color: color-mix(in srgb, var(--c) 55%, transparent); }
.status select:focus { outline: none; }
.status select:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent); }
.chips { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.4rem; }
.chip {
  font-size: 0.66rem;
  color: var(--muted);
  background: var(--soft);
  border: 1px solid #ebe3d8;
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  white-space: nowrap;
}
.side-section { margin-top: 1.2rem; }
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.side-head h2 {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.guide {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
  padding: 0.5rem 0.7rem;
  font-size: 0.74rem;
  color: var(--muted);
}
.guide summary { cursor: pointer; font-weight: 600; color: var(--ink); font-size: 0.76rem; }
.guide p { margin: 0.5rem 0; }
.guide dl { margin: 0; display: grid; grid-template-columns: auto; gap: 0.1rem; }
.guide dt { font-family: ui-monospace, Consolas, monospace; color: var(--accent); font-size: 0.7rem; margin-top: 0.35rem; }
.guide dd { margin: 0; }
.guide code { font-size: 0.68rem; }
.empty {
  color: var(--muted);
  font-size: 0.86rem;
  padding: 1rem 0.25rem;
  text-align: center;
}

/* ---- middle column ------------------------------------------------------ */
.form-head { align-items: flex-start; }
.form-title { flex: 1; min-width: 0; }
.title-input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-size: 0.98rem;
  font-weight: 650;
  color: var(--ink);
  padding: 0.12rem 0.3rem;
  margin-left: -0.3rem;
}
.title-input:hover:not(:disabled) { border-color: var(--line); background: #fff; }
.title-input:focus { outline: none; border-color: var(--accent); background: #fff; }
.save-state { font-size: 0.7rem; color: var(--muted); white-space: nowrap; padding-top: 0.35rem; }
.save-state.ok { color: var(--accent); }

.group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  margin-bottom: 0.75rem;
  overflow: clip;           /* unlike hidden, keeps the header sticky */
}
/* the chapter title stays pinned at the top while its options scroll */
.group > header {
  position: sticky;
  top: -0.85rem;            /* over the .col-body padding, flush with the top edge */
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: var(--soft);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
}
.group > header .g-title { flex: 1; min-width: 0; }
.group > header::after {
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  content: "";
  transform: rotate(225deg) translate(-1px, -1px);
  transition: transform 0.16s ease;
  flex: 0 0 auto;
}
.group.collapsed > header::after { transform: rotate(45deg) translate(-1px, -1px); }
.group.collapsed > .g-body { display: none; }
.group:not(.collapsed) > header { border-bottom: 1px solid var(--line); }
.badge {
  font-size: 0.66rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  white-space: nowrap;
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.g-body { padding: 0.35rem 0.8rem 0.6rem; }

.ctl { padding: 0.4rem 0; border-top: 1px dashed #ebe3d8; scroll-margin-top: 3.2rem; }
.g-body > .ctl:first-child, .ctl-children > .ctl:first-child { border-top: 0; }
.ctl-label {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.22rem;
}
.ctl input[type="text"], .ctl input[type="date"], .ctl select, .ctl textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.38rem 0.5rem;
  font-size: 0.86rem;
  color: var(--ink);
  background: #fff;
}
.ctl textarea { min-height: 4.5rem; resize: vertical; }
.ctl input:focus, .ctl select:focus, .ctl textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ctl input.required-empty, .ctl textarea.required-empty { border-color: #e9b949; background: #fffbeb; }
.ctl.flash { animation: ctlFlash 1.2s ease; }
@keyframes ctlFlash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }

.ctl-row { display: flex; align-items: center; gap: 0.55rem; min-height: 1.7rem; }
.ctl-title { flex: 1; min-width: 0; font-size: 0.84rem; cursor: pointer; }
.ctl-title .prefix { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; margin-right: 0.3rem; }
.ctl-row .inline-ctl { flex: 0 0 9.5rem; }
.ctl-row .inline-ctl select, .ctl-row .inline-ctl input { padding: 0.22rem 0.35rem; font-size: 0.78rem; }
.ctl-opt.is-off > .ctl-row .ctl-title { color: var(--muted); }
.ctl-opt.is-off > .ctl-row .inline-ctl { opacity: 0.4; pointer-events: none; }
.ctl-children {
  margin: 0.35rem 0 0.1rem 0.85rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--accent-soft);
}
/* a key used again: read-only copy of the value, leads back to the definition */
.ref-box {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.38rem 0.5rem;
  background: #efe9df;
  color: #5c534a;
  font-size: 0.86rem;
  text-align: left;
  cursor: pointer;
}
.ref-box:hover, .ref-box:focus-visible { outline: none; border-color: var(--accent); color: var(--ink); }
.ref-box:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
.ref-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-value.is-empty { font-style: italic; color: var(--muted); }
.ref-box svg { width: 0.9rem; height: 0.9rem; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: 0.55; }
.ref-box:hover svg { opacity: 1; color: var(--accent); }
.ref-where { display: block; margin-top: 0.2rem; font-size: 0.68rem; color: var(--muted); }
.ctl-check input[type="checkbox"] { width: 1rem; height: 1rem; accent-color: var(--accent); margin: 0; flex: 0 0 auto; }

/* toggle switch for optional parts */
.switch { position: relative; display: inline-block; width: 2.1rem; height: 1.2rem; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d6cec3;
  transition: background 0.15s ease;
  cursor: pointer;
}
.switch span::before {
  content: "";
  position: absolute;
  left: 0.15rem;
  top: 0.15rem;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 0.15s ease;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(0.9rem); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* variant pills */
.pills { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 0.78rem;
  padding: 0.28rem 0.7rem;
  cursor: pointer;
}
.pill:hover { border-color: var(--accent); }
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* pictogram gallery */
.picks-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.picks-count { font-size: 0.75rem; color: var(--accent); font-weight: 600; white-space: nowrap; }
.picks-filters { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.4rem 0 0.55rem; }
.picks-filters .pill { font-size: 0.7rem; padding: 0.16rem 0.55rem; }
.picks-filters .pill small { opacity: 0.75; margin-left: 0.2rem; }
.picks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.4rem, 1fr));
  gap: 0.4rem;
}
.pick-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.45rem 0.3rem 0.4rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.pick-tile img { width: 2.6rem; height: 2.6rem; object-fit: contain; opacity: 0.55; filter: grayscale(0.6); transition: inherit; }
.pick-tile .code { font-size: 0.64rem; font-weight: 700; color: var(--muted); }
.pick-tile .lbl { font-size: 0.64rem; line-height: 1.15; color: var(--muted); }
.pick-tile:hover { border-color: #b8aea3; }
.pick-tile:hover img { opacity: 0.85; }
.pick-tile.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.pick-tile.selected img { opacity: 1; filter: none; }
.pick-tile.selected .code, .pick-tile.selected .lbl { color: var(--ink); }
.pick-tile.selected::after {
  content: "✓";
  position: absolute;
  top: 0.2rem;
  right: 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
}
.picks-actions { display: flex; gap: 0.35rem; margin-top: 0.5rem; justify-content: flex-end; }

/* ---- right column: docx preview (from electrontest DocxViewer) ---------- */
.preview-host { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.docx-viewer-pages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #c5c9d1;
}
.docx-viewer-pages > .empty { color: #4b5563; padding-top: 3rem; }
.docx-viewer-pages .docx-wrapper {
  background: transparent;
  padding: 24px 16px 40px;
}
.docx-viewer-pages .docx-wrapper > section.docx {
  background: #fff;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
  color: #111;
  margin: 0 auto 28px;
}
.docx-viewer-pages .docx-wrapper > section.docx:last-child { margin-bottom: 0; }
.preview-staging {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}
.preview-busy .docx-viewer-pages { cursor: progress; }
.docx-viewer-pages .cf-flash {
  animation: cfFlash 1.6s ease;
  border-radius: 2px;
}
.docx-viewer-pages tr.cf-flash > td { animation: cfFlash 1.6s ease; }
@keyframes cfFlash {
  0%, 35% { background-color: rgba(15, 118, 110, 0.22); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.22); }
  100% { background-color: transparent; box-shadow: 0 0 0 3px transparent; }
}
.preview-error {
  margin: 1rem;
  border: 1px solid #f1a7b8;
  border-radius: 12px;
  background: #fff8fa;
  color: #61152a;
  padding: 0.8rem 0.9rem;
  font-size: 0.8rem;
}
.zoom { display: flex; align-items: center; gap: 0.15rem; margin-right: 0.35rem; }
.zoom-label {
  border: 0;
  background: none;
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 2.8rem;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.zoom-label:hover { color: var(--accent); }

/* ---- dialog / toast ----------------------------------------------------- */
dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.2rem;
  width: min(26rem, 92vw);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(31, 26, 22, 0.25);
}
dialog::backdrop { background: rgba(31, 26, 22, 0.35); }
dialog h3 { margin: 0 0 0.8rem; font-size: 1rem; }
dialog label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.7rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
dialog input, dialog select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.42rem 0.5rem;
  font-size: 0.88rem;
  color: var(--ink);
  background: #fff;
  text-transform: none;
  letter-spacing: normal;
}
dialog menu { display: flex; justify-content: flex-end; gap: 0.4rem; margin: 0.4rem 0 0; padding: 0; }
.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.8rem;
  opacity: 0;
  transform: translate(-50%, 6px);
  transition: 0.2s ease;
  pointer-events: none;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

@media (max-width: 1100px) {
  .app { grid-template-columns: 240px minmax(320px, 1fr) minmax(380px, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(480px, 1fr); height: auto; min-height: 100%; }
  .col { border-right: 0; border-bottom: 1px solid var(--line); max-height: 60vh; }
  .col:last-child { max-height: none; min-height: 80vh; }
}
