:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --fg: #1a1a1a;
  --fg-2: #444444;
  --fg-3: #6b6b6b;
  --line: #d6d6d2;
  --accent: #c0392b;
  --accent-fg: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fff4e5;
  --warn-fg: #7a4100;
  --paper-bg: #e9e9ec;
  --fs-body: 15px;
  --radius: 4px;
  /* ラベルの文字（端末に入っているフォント。Web フォントは読み込まない） */
  --label-font: "BIZ UDPGothic", "BIZ UDGothic", "Yu Gothic UI", "Yu Gothic", "Meiryo", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* 画面全体はスクロールさせず、左の入力欄と右のプレビューをそれぞれの中でスクロールさせる */
html, body { height: 100%; }
html { overflow: hidden; }
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: var(--fs-body)/1.5 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}
body.busy { cursor: progress; }
body.busy .topbar button, body.busy .workspace button { pointer-events: none; }

h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
code { font-size: 14px; background: #ececea; padding: 1px 4px; border-radius: 4px; }

button {
  font: inherit;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  white-space: nowrap;
}
button.secondary { background: var(--surface); color: var(--accent); }
button.small { padding: 3px 10px; font-size: 13px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input, select, textarea {
  font: inherit;
  font-size: 16px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  min-width: 0;
}
textarea { resize: vertical; width: 100%; }

/* ---------- 上部バー ---------- */
.topbar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.folder-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.folder-status { color: var(--fg-3); font-size: 13px; overflow-wrap: anywhere; }

.alert, .intro, .demo-banner { flex: none; margin: 12px 16px 0; padding: 10px 14px; border-radius: var(--radius); }
.alert { background: #fdecea; color: var(--danger); }
.intro { background: var(--surface); border: 1px solid var(--line); }
.intro p { margin: 4px 0; }
.demo-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--warn-bg);
  color: var(--warn-fg);
  font-size: 14px;
}

/* ---------- 作業領域: 左に入力、右にプレビュー ---------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
}
.side {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-right: 1px solid var(--line);
}
.panel { display: flex; flex-direction: column; gap: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.loaded-from { margin: 0; color: var(--fg-3); font-size: 13px; min-height: 1.5em; }

.jobs { display: flex; flex-direction: column; gap: 10px; }
.job {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.job-head { display: flex; align-items: center; gap: 8px; }
.job-head h3 { flex: none; }
.job-actions { margin-left: auto; display: flex; gap: 6px; }
.tag { font-size: 12px; color: var(--fg-2); background: #ececea; padding: 1px 6px; border-radius: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.party-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.field { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--fg-2); }
.field.wide { grid-column: 1 / -1; }
.field > input, .field > select, .field > textarea { width: 100%; }
.job-row { display: grid; grid-template-columns: 1fr 6em; gap: 8px; }
.from-wrap { display: flex; flex-direction: column; gap: 6px; }
.from-custom { padding-left: 10px; border-left: 3px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 2px 10px;
  font-size: 13px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
}

.entry-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.entry { display: flex; align-items: stretch; gap: 6px; }
.entry-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  padding: 5px 10px;
  background: var(--surface);
  color: var(--fg);
  border-color: var(--line);
}
.entry.current .entry-main { border-color: var(--accent); }
.entry-title { font-weight: 600; font-size: 14px; }
.entry-sub { font-size: 12px; color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-note { font-size: 13px; color: var(--fg-3); }
.load-errors { font-size: 12px; color: var(--danger); overflow-wrap: anywhere; }

/* ---------- プレビュー ---------- */
.preview { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.printbar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.summary { font-weight: 600; min-width: 16em; }
.inline-field { display: inline-flex; align-items: center; gap: 4px; }
.inline-field input { width: 5em; }
.print-hint { flex-basis: 100%; margin: 0; color: var(--fg-2); font-size: 13px; }
.warn { flex: none; padding: 0 16px; color: var(--danger); font-size: 13px; min-height: 1.6em; line-height: 1.6em; overflow-wrap: anywhere; }
.pages-wrap { flex: 1; min-height: 0; overflow: auto; background: var(--paper-bg); }
.pages { padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 16px; }

/* ---------- 用紙（A4 横に 2 枚）。寸法は src/app/render.ts（template.html から移したもの） ---------- */
.sheet { position: relative; width: 297mm; height: 210mm; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); overflow: hidden; flex: none; color: #111; font-family: var(--label-font); }
.shift { position: absolute; inset: 0; }
.shift > svg { position: absolute; left: 0; top: 0; width: 297mm; height: 210mm; font-family: var(--label-font); }
.piece { position: absolute; }
.slot-guide { position: absolute; border: 1px dashed #c8c8c8; color: #b0b0b0; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.f { position: absolute; overflow: hidden; white-space: nowrap; line-height: 1.2; display: flex; align-items: center; }
.f > span { display: block; min-width: 0; white-space: inherit; }
.f.bottom { align-items: flex-end; }
.f.bold { font-weight: 700; }
.f.empty::before { content: attr(data-ph); color: #c4c4c4; }

/* ---------- 一時通知・ダイアログ ---------- */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #333;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; max-width: min(560px, calc(100vw - 32px)); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog fieldset { border: 1px solid var(--line); border-radius: var(--radius); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* 狭い画面では縦に並べる */
@media screen and (max-width: 820px) {
  html { overflow: auto; }
  body { height: auto; overflow: visible; }
  .workspace { display: block; }
  .side { border-right: 0; padding: 12px 16px; }
  .pages-wrap { overflow-x: auto; }
}

/* ---------- 印刷: 用紙だけを実寸で刷る ---------- */
@page { size: A4 landscape; margin: 0; }
@media print {
  html, body { height: auto; overflow: visible; display: block; background: #fff; }
  .topbar, .alert, .intro, .demo-banner, .side, .printbar, .warn, .toast, .slot-guide { display: none !important; }
  .workspace, .preview, .pages-wrap { display: block; overflow: visible; background: #fff; }
  .pages { display: block; padding: 0; gap: 0; zoom: 1 !important; }
  .sheet { box-shadow: none; break-after: page; }
  .sheet:last-child { break-after: auto; }
  .f.empty::before { content: none; }
}
