:root {
  --navy: #0d3878;
  --blue: #144ea2;
  --blue-soft: #e8f0fc;
  --ink: #191919;
  --ink-2: #4b5563;
  --ink-3: #6b7280;
  --line: #e5e7eb;
  --line-2: #d1d5db;
  --blue-line: #b9cff0;
  --blue-line-2: #c7daf4;
  --focus: #9dc3ff;
  --warn-bg: #fff3e0;
  --warn-ink: #b45309;
  --warn-line: #f5c98a;
  --tag-green-bg: #e7f5ec; --tag-green-ink: #1f7a3f;
  --tag-gray-bg: #f1f2f4;  --tag-gray-ink: #4b5563;
  --tag-red-bg: #fdecec;   --tag-red-ink: #c8102e;
  --bg: #f0f2f5;
  --card: #f6f7f9;
  --sans: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --page-w: 210mm;
  --page-h: 297mm;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--navy); min-width: 0; white-space: nowrap; }
.topbar-brand img { display: block; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
#btn-print .short { display: none; }
.save-status { font-size: 12px; color: var(--ink-3); margin-right: 6px; font-family: var(--mono); max-width: 46ch; text-align: right; }

button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  line-height: 1.2;
}
button:hover { background: var(--blue-soft); border-color: var(--blue-line); }
button.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
button.primary:hover { background: var(--navy); border-color: var(--navy); }
button.small { padding: 5px 10px; font-size: 12px; }
button:disabled { opacity: 0.55; cursor: default; }

.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  display: flex; flex-direction: column; gap: 2px; min-width: 160px;
  background: #fff; border: 1px solid var(--line-2); border-radius: 10px; padding: 6px;
  box-shadow: 0 8px 24px rgba(13, 56, 120, 0.14);
}
.menu-panel[hidden] { display: none; }
.menu-panel button { border: 0; text-align: left; padding: 9px 12px; }

/* Mobile tab bar (hidden on wide screens where both panes are visible) */
.tabbar { display: none; flex: none; background: #fff; border-bottom: 1px solid var(--line); }
.tabbar .tab {
  flex: 1; border: 0; border-radius: 0; padding: 12px; font-size: 14px; color: var(--ink-3);
  border-bottom: 2px solid transparent; background: #fff;
}
.tabbar .tab.active { color: var(--navy); border-bottom-color: var(--blue); }

/* ---------- workspace ---------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 440px 1fr;
}
@media (max-width: 900px) {
  html, body { overflow-x: hidden; }
  .topbar { height: auto; min-height: 52px; padding: 8px 12px; gap: 8px; }
  #btn-print .long { display: none; }
  #btn-print .short { display: inline; }
  .topbar-brand { font-size: 15px; }
  .topbar-brand img { width: 24px; height: 24px; }
  .save-status { display: none; }
  button { padding: 10px 14px; font-size: 14px; }
  button.small { padding: 8px 12px; font-size: 13px; }
  .tabbar { display: flex; }
  .workspace { display: block; }
  .workspace[data-tab="editor"] .preview { display: none; }
  .workspace[data-tab="preview"] .editor { display: none; }
  .editor { padding: 14px; border-right: 0; height: 100%; }
  .preview { padding: 12px; height: 100%; }
  .row { grid-template-columns: 1fr 1fr; gap: 8px; }
  input[type="text"], input[type="date"], textarea, select { font-size: 16px; padding: 11px 12px; }
  .entry-tools button { padding: 8px 12px; font-size: 13px; }
}

.editor {
  overflow-y: auto;
  padding: 20px;
  background: #fff;
  border-right: 1px solid var(--line);
}
.group { padding: 16px 0 20px; border-bottom: 1px solid var(--line); }
.group:first-child { padding-top: 4px; }
.group:last-child { border-bottom: 0; }
.group-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.group-title { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--navy); letter-spacing: 0.02em; }
.group-head .group-title { margin-bottom: 0; }
.hint { margin: 0 0 12px; font-size: 12px; color: var(--ink-3); }
.hint code { font-family: var(--mono); background: var(--card); padding: 1px 4px; border-radius: 4px; }
.group-ai { background: var(--blue-soft); margin: 0 -20px; padding: 16px 20px 18px; border-bottom: 0; }
.group-ai .group-title { display: flex; align-items: center; gap: 6px; }
.ai-badge { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; background: var(--blue); color: #fff; border-radius: 4px; padding: 2px 5px; }
.group-ai textarea { background: #fff; }
.ai-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ai-status { font-size: 12px; color: var(--ink-2); line-height: 1.4; }
.ai-status[data-kind="error"] { color: var(--tag-red-ink); }
.ai-status[data-kind="ok"] { color: var(--tag-green-ink); }
.ai-status[data-kind="busy"]::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid var(--blue-line); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 900px) { .group-ai { margin: 0 -14px; padding: 14px; } }
.group-ai .group-title { font-size: 15px; }
.ai-actions .field-inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.ai-actions .field-inline input[type="date"] { width: auto; }
.ai-actions { justify-content: space-between; }
.ai-status { margin: 10px 0 0; }
.ai-status:empty { display: none; }
.advanced { margin-top: 8px; }
.advanced > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-3); padding: 10px 0; list-style: none; }
.advanced > summary::before { content: "▸ "; }
.advanced[open] > summary::before { content: "▾ "; }
.advanced > summary::-webkit-details-marker { display: none; }
.empty-hint { border: 0.4mm dashed var(--line-2); border-radius: 3mm; padding: 8mm 6mm; text-align: center; color: var(--ink-3); font-size: 10.5pt; }
.empty-hint b { color: var(--blue); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; min-width: 0; }
.field .label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.field .label em { font-style: normal; font-weight: 400; color: var(--ink-3); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input[type="text"], input[type="date"], textarea, select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--blue); }

.entry { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.entry-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.entry-index { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--blue); }
.entry-tools { display: flex; gap: 4px; }
.entry-tools button { padding: 3px 8px; font-size: 11px; }
.entry .field { margin-bottom: 8px; }
.entry .field:last-child { margin-bottom: 0; }
.entries-empty { font-size: 13px; color: var(--ink-3); padding: 14px; text-align: center; border: 1px dashed var(--line-2); border-radius: 10px; }

/* ---------- preview ---------- */
.preview { overflow: auto; padding: 24px; }
.preview-bar { max-width: calc(var(--page-w) + 2px); margin: 0 auto 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.preview-hint { font-size: 12px; color: var(--ink-3); }
.preview-actions { max-width: calc(var(--page-w) + 2px); margin: 16px auto 0; display: flex; gap: 8px; justify-content: center; }
@media (min-width: 901px) { #btn-zoom { display: none; } }

/* Inline editing affordances (screen only) */
[data-edit] { cursor: text; border-radius: 1mm; outline: 0.3mm dashed transparent; outline-offset: 0.6mm; transition: outline-color 0.15s; min-width: 4mm; display: inline-block; }
.card-place[data-edit], .card-body[data-edit], .title[data-edit], .summary[data-edit], .kicker[data-edit], .meta-value[data-edit] { display: block; }
.page:hover [data-edit] { outline-color: var(--blue-line); }
[data-edit]:hover { outline-color: var(--blue); background: var(--blue-soft); }
[data-edit]:focus, [data-edit].editing { outline: 0.4mm solid var(--blue); background: #fff; }
[data-edit]:empty::before { content: attr(data-placeholder); color: var(--line-2); font-weight: 400; }
.tag[data-edit]:empty { background: transparent; border: 0.3mm dashed var(--line-2); color: var(--line-2); }
.tag[data-edit]:empty::before { color: var(--ink-3); }
[data-edit="date"] { cursor: pointer; }
.preview-warning {
  max-width: calc(var(--page-w) + 2px); margin: 0 auto 16px;
  background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line);
  border-radius: 8px; padding: 10px 14px; font-size: 13px; font-weight: 600; line-height: 1.5;
}
.pages { display: flex; flex-direction: column; align-items: flex-start; align-items: safe center; gap: 24px; }
.page-slot { flex: none; }
.page-scale { transform-origin: top left; }

/* ---------- report page ---------- */
.page {
  width: var(--page-w);
  height: var(--page-h);
  background: #fff;
  padding: 8mm;
  box-shadow: 0 2px 14px rgba(13, 56, 120, 0.12);
  color: var(--ink);
  font-size: 10.5pt;
  line-height: 1.55;
  overflow: hidden;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.frame {
  height: 100%;
  border: 0.7mm solid var(--navy);
  border-radius: 7mm;
  box-shadow: inset 0 0 0 1.2mm #fff, inset 0 0 0 1.7mm var(--navy);
  padding: 9mm 11mm 8mm;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.page-head { flex: none; }
.page-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.page-foot { flex: none; }

.brand-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9mm; }
.brand {
  display: inline-flex; align-items: center; gap: 2.4mm;
  background: var(--navy); color: #fff;
  border-radius: 2.2mm; padding: 2.2mm 4mm 2.2mm 3mm;
  font-weight: 800; font-size: 13pt; letter-spacing: -0.01em;
}
.brand-mark { width: 6.5mm; height: 6.5mm; background: #fff; border-radius: 1.4mm; display: grid; place-items: center; }
.brand-mark img { width: 5mm; height: 5mm; display: block; }
.badge-outline {
  font-family: var(--mono); font-weight: 700; font-size: 8pt; letter-spacing: 0.12em;
  color: var(--blue); border: 0.5mm solid var(--blue); border-radius: 99px; padding: 1.4mm 4.5mm;
}

.kicker { font-family: var(--mono); font-weight: 700; font-size: 8.5pt; letter-spacing: 0.22em; color: var(--blue); margin: 0 0 2.5mm; }
.title { font-size: 26pt; font-weight: 800; letter-spacing: -0.03em; line-height: 1.2; margin: 0 0 3mm; color: var(--ink); }
.summary { color: var(--ink-3); font-size: 10.5pt; margin: 0 0 6mm; min-height: 1em; }

.meta {
  display: grid; grid-template-columns: 1fr 1fr;
  border: 0.3mm solid var(--line-2); border-radius: 2.5mm; overflow: hidden;
  margin-bottom: 8mm;
}
.meta-cell { padding: 3.2mm 5mm; border-right: 0.3mm solid var(--line-2); border-bottom: 0.3mm solid var(--line-2); min-width: 0; }
.meta-cell:nth-child(2n) { border-right: 0; }
.meta-cell:nth-last-child(-n+2) { border-bottom: 0; }
.meta-label { font-size: 8pt; color: var(--ink-3); margin-bottom: 1.2mm; }
.meta-value { font-family: var(--mono); font-weight: 700; font-size: 12.5pt; color: var(--ink); letter-spacing: -0.01em; }
.meta-value.sans { font-family: var(--sans); font-size: 12pt; }

.section-head { display: flex; align-items: center; gap: 3.2mm; margin: 0 0 4.5mm; }
.section-num {
  font-family: var(--mono); font-weight: 700; font-size: 8.5pt; color: #fff;
  background: var(--blue); border-radius: 1.6mm; width: 6.4mm; height: 6.4mm;
  display: grid; place-items: center;
}
.section-title { font-size: 12pt; font-weight: 800; color: var(--ink); }
.section-count { font-family: var(--mono); font-size: 8pt; color: var(--ink-3); margin-left: auto; }

.timeline { display: flex; flex-direction: column; gap: 5mm; position: relative; padding-left: 6mm; }
.timeline::before {
  content: ""; position: absolute; left: 1.6mm; top: 6mm; bottom: 6mm;
  width: 0.7mm; background: var(--blue-line-2); border-radius: 1mm;
}

.card {
  position: relative;
  display: grid; grid-template-columns: 30mm 1fr auto; gap: 5mm; align-items: center;
  border: 0.3mm solid var(--line); border-left: 1.5mm solid var(--navy);
  border-radius: 3mm; padding: 5.5mm 5mm 5.5mm 6mm; background: #fff;
}
.card::before {
  content: ""; position: absolute; left: -7.2mm; top: 50%; transform: translateY(-50%);
  width: 3.8mm; height: 3.8mm; border-radius: 50%;
  background: #fff; border: 0.8mm solid var(--blue); box-shadow: 0 0 0 0.6mm #fff;
}
.card-time { font-family: var(--mono); font-weight: 700; font-size: 12.5pt; color: var(--blue); line-height: 1.3; letter-spacing: -0.01em; }
.card-time .end { display: block; }
.card-place { font-weight: 800; font-size: 11.5pt; margin: 0 0 1.5mm; }
.card-body { margin: 0; color: var(--ink-2); font-size: 10.2pt; line-height: 1.6; }
.card-body strong { color: var(--ink); font-weight: 800; }
.tag {
  font-weight: 800; font-size: 8.5pt; border-radius: 1.8mm; padding: 2mm 3.2mm;
  max-width: 34mm; text-align: center; line-height: 1.35;
}
.tag-green { background: var(--tag-green-bg); color: var(--tag-green-ink); }
.tag-blue { background: var(--blue-soft); color: var(--blue); }
.tag-gray { background: var(--tag-gray-bg); color: var(--tag-gray-ink); }
.tag-amber { background: var(--warn-bg); color: var(--warn-ink); }
.tag-red { background: var(--tag-red-bg); color: var(--tag-red-ink); }

.note {
  margin-top: auto; padding-top: 6mm;
}
.note-box {
  border: 0.4mm dashed var(--line-2); border-radius: 2.5mm; padding: 4.5mm 5mm;
  font-size: 10.2pt; color: var(--ink-2); line-height: 1.65;
}
.note-box .note-label { font-weight: 800; color: var(--blue); margin-right: 2mm; }
.note-box strong { color: var(--ink); font-weight: 800; }
.clipped { outline: 0.6mm dashed var(--tag-red-ink); outline-offset: 1mm; }

.page-foot {
  margin-top: 5mm; padding-top: 4.5mm; border-top: 0.3mm solid var(--line);
  display: flex; justify-content: space-between; align-items: flex-end; gap: 6mm;
}
.foot-phone { font-weight: 800; color: var(--blue); font-size: 10.5pt; display: flex; align-items: center; gap: 1.6mm; }
.foot-phone svg { width: 3.6mm; height: 3.6mm; fill: var(--ink-2); }
.foot-disclaimer { font-size: 7.5pt; color: var(--ink-3); margin-top: 1mm; }
.foot-right { text-align: right; font-family: var(--mono); font-size: 7.5pt; color: var(--ink-3); line-height: 1.7; max-width: 60mm; flex: none; }

.continued { font-size: 9pt; color: var(--ink-3); font-family: var(--mono); letter-spacing: 0.08em; }
.page-head.compact .brand-row { margin-bottom: 5mm; }
.page-head.compact .compact-title { display: flex; align-items: baseline; justify-content: space-between; gap: 4mm; padding-bottom: 4mm; margin-bottom: 5mm; border-bottom: 0.3mm solid var(--line); }
.page-head.compact .compact-title .t { font-weight: 800; font-size: 13pt; }

/* ---------- print ---------- */
@page { size: A4; margin: 0; }
@media print {
  html, body { height: auto; background: #fff; }
  body { display: block; }
  .topbar, .tabbar, .editor { display: none !important; }
  .workspace { display: block; }
  .preview { overflow: visible; padding: 0; }
  .pages { display: block; }
  .preview-warning, .preview-bar, .preview-actions, .empty-hint { display: none; }
  [data-edit] { outline: none !important; background: transparent !important; }
  [data-edit]:empty { display: none; }
  .card-time .end:has(> [data-edit]:empty) { display: none; }
  .page-slot { width: auto !important; height: auto !important; }
  .page-scale { transform: none !important; }
  .page { box-shadow: none; break-after: page; }
  .page-slot:last-child .page { break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
