:root {
  --bg: #0e1726;
  --bg-2: #14203360;
  --panel: #16223a;
  --panel-2: #1c2c49;
  --line: #28395c;
  --ink: #eaf0fb;
  --ink-soft: #9fb0cc;
  --accent: #34d8a8;
  --accent-deep: #1fae86;
  --blue: #5b9bff;
  --neg: #ff7a85;
  --radius: 14px;
  --a4-w: 210mm;
  --a4-h: 297mm;
}
/* ===== 3-way theme (Light/Dark/System) — base :root above = native DARK. ===== */
:root[data-theme="light"]{
  --bg: #f5f7fb;
  --bg-2: #eaeef5;
  --panel: #ffffff;
  --panel-2: #f3f6fb;
  --line: #dde4ee;
  --ink: #16213a;
  --ink-soft: #5b6b86;
  --accent: #0e9f6e;
  --accent-deep: #0a754e;
  --blue: #2563eb;
  --neg: #dc2640;
}
:root[data-theme="light"] body{
  background:
    radial-gradient(1000px 600px at 85% -10%, rgba(14,159,110,.07) 0%, transparent 55%),
    radial-gradient(800px 500px at -5% 110%, rgba(37,99,235,.06) 0%, transparent 50%),
    var(--bg);
}
.theme-switch{
  --theme-switch-bg:var(--panel); --theme-switch-border:var(--line); --theme-switch-fg:var(--ink);
  --theme-switch-active-bg:var(--accent); --theme-switch-active-fg:#06231b; --theme-switch-radius:10px;
}

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

body {
  font-family: "Inter", system-ui, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background:
    radial-gradient(1000px 600px at 85% -10%, #1a2c4a 0%, transparent 55%),
    radial-gradient(800px 500px at -5% 110%, #15314a 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
b, h1, h2, h3, legend { font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.i18n-switch {
  --i18n-switch-bg: rgba(255,255,255,.06);
  --i18n-switch-border: var(--line);
  --i18n-switch-fg: var(--ink);
  --i18n-switch-active-bg: rgba(52,216,168,.2);
  --i18n-switch-active-fg: var(--accent);
  --i18n-switch-menu-bg: var(--panel-2);
  --i18n-switch-menu-border: var(--line);
}

/* ===== Topbar ===== */
.topbar { max-width: 1200px; margin: 0 auto; padding: 22px clamp(16px, 3vw, 28px) 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-size: 22px; font-weight: 700; color: #06231b;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep));
  box-shadow: 0 10px 26px -12px rgba(52,216,168,.7);
}
.brand h1 { font-size: 21px; letter-spacing: -.01em; }
.brand p { font-size: 12.5px; color: var(--ink-soft); }
.basis { color: var(--accent); }
.switchers { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.privacy-badge {
  font-size: 12px; font-weight: 600; letter-spacing: .02em; white-space: nowrap;
  color: var(--accent); background: rgba(52,216,168,.12);
  border: 1px solid rgba(52,216,168,.35); border-radius: 999px; padding: 5px 10px;
}
:root[data-theme="light"] .privacy-badge { background: rgba(14,159,110,.1); border-color: rgba(14,159,110,.3); }

/* ===== Layout: form (left) + A4 preview (right) ===== */
.wrap { max-width: 1200px; margin: 0 auto; padding: 8px clamp(16px, 3vw, 28px) 60px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; align-items: start; }

/* ===== Form pane ===== */
.form-pane { position: sticky; top: 12px; }
.mobile-tabs { display: none; gap: 6px; margin-bottom: 12px; }
.mtab {
  flex: 1; border: 1px solid var(--line); background: var(--panel); color: var(--ink-soft);
  font-family: inherit; font-size: 14px; font-weight: 600; padding: 10px; border-radius: 999px; cursor: pointer;
}
.mtab.is-active { background: var(--accent); color: #06231b; border-color: var(--accent); }
.form-scroll { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: grid; gap: 12px;
}
.card legend { font-size: 13px; color: var(--accent); padding: 0; letter-spacing: .01em; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--ink-soft); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type="text"], input[type="email"], input[type="number"], input[type="date"], select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink); font-family: inherit; font-size: 14px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52,216,168,.16); }
input[type="date"] { color-scheme: dark; }
:root[data-theme="light"] input[type="date"] { color-scheme: light; }
input::placeholder { color: var(--ink-soft); opacity: .6; }

.link-btn {
  justify-self: start; background: transparent; border: 0; color: var(--blue); cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600; padding: 2px 0;
}
.link-btn:hover { text-decoration: underline; }

/* ===== Items table ===== */
.items-head, .item-row {
  display: grid; grid-template-columns: minmax(0, 2.4fr) 64px minmax(0, 1.2fr) minmax(0, 1.2fr) 30px;
  gap: 8px; align-items: center;
}
/* Mobile: widen the numeric tracks so the computed line-total (₩1,500,000) fits its
   cell instead of overflowing onto the × delete button. */
@media (max-width: 520px) {
  .items-head, .item-row { grid-template-columns: minmax(0, 1fr) 44px 64px 84px 30px; gap: 5px; }
  .item-row input { font-size: 12px; padding: 6px 7px; }
  .item-line { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
}
.items-head { font-size: 12px; color: var(--ink-soft); padding: 0 2px 2px; text-transform: uppercase; letter-spacing: .04em; }
.items-head span:nth-child(2), .items-head span:nth-child(3), .items-head span:nth-child(4) { text-align: right; }
.items-body { display: flex; flex-direction: column; gap: 8px; }
.item-row { gap: 8px; }
.item-row input { padding: 8px 10px; font-size: 13.5px; }
.item-row input[name="qty"], .item-row input[name="price"] { text-align: right; font-family: "IBM Plex Mono", monospace; }
.item-line { font-family: "IBM Plex Mono", monospace; font-size: 13px; color: var(--ink); text-align: right; min-width: 0; white-space: nowrap; }
.item-del {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  color: var(--neg); cursor: pointer; font-size: 16px; line-height: 1; display: grid; place-items: center;
}
.item-del:hover { border-color: var(--neg); }
.add-btn {
  justify-self: start; background: var(--bg); border: 1px dashed var(--accent); color: var(--accent);
  font-family: inherit; font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 10px; cursor: pointer;
}
.add-btn:hover { background: rgba(52,216,168,.08); }

/* ===== Totals ===== */
.total-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.totals-summary { display: flex; flex-direction: column; gap: 7px; border-top: 1px solid var(--line); padding-top: 12px; }
.t-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
.t-row span { color: var(--ink-soft); }
.t-row b { font-family: "IBM Plex Mono", monospace; font-weight: 600; }
.t-row.total { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 9px; }
.t-row.total span { color: var(--ink); font-weight: 700; }
.t-row.total b { color: var(--accent); font-size: 17px; }

/* ===== Actions ===== */
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.primary-btn {
  flex: 1; min-width: 160px; border: 0; cursor: pointer;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep)); color: #06231b;
  font-family: inherit; font-size: 15px; font-weight: 700; padding: 13px 18px; border-radius: 12px;
  box-shadow: 0 10px 24px -12px rgba(52,216,168,.8);
}
.primary-btn:hover { filter: brightness(1.05); }
.ghost-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-soft); cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600; padding: 13px 18px; border-radius: 12px;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--ink-soft); }

.toast {
  font-size: 13px; color: var(--accent); background: rgba(52,216,168,.1);
  border: 1px solid rgba(52,216,168,.3); border-radius: 10px; padding: 10px 14px;
}

/* ===== A4 preview pane ===== */
.preview-pane { display: flex; justify-content: center; }
.a4 {
  width: var(--a4-w); max-width: 100%; min-height: var(--a4-h);
  background: #ffffff; color: #1a2233; border-radius: 6px;
  box-shadow: 0 18px 50px -20px rgba(0,0,0,.5);
  font-family: "Inter", system-ui, "Apple SD Gothic Neo", sans-serif;
  padding: 18mm 16mm; box-sizing: border-box; line-height: 1.45;
}
/* 미리보기용 살짝 축소(큰 화면에서 1:1이면 오버플로) — 인쇄 시 원본 크기 */
@media screen and (min-width: 901px) {
  .a4 { transform-origin: top center; }
}
:root[data-theme="dark"] .a4 { box-shadow: 0 18px 50px -16px rgba(0,0,0,.65); }

/* preview document internals — always on white "paper" */
.pv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.pv-doc-title { font-size: 26px; font-weight: 700; letter-spacing: .04em; color: #0e9f6e; }
.pv-meta-right { text-align: right; font-size: 12.5px; color: #55607a; min-width: 0; }
.pv-meta-right b { color: #1a2233; font-weight: 600; }
.pv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 18px 0 4px; }
.pv-party h4 { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #8b95ad; margin-bottom: 5px; font-weight: 700; }
.pv-party .pv-name { font-size: 15px; font-weight: 700; color: #1a2233; }
.pv-party .pv-line { font-size: 12.5px; color: #55607a; word-break: break-word; }
.pv-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 12.5px; }
.pv-table th { text-align: left; background: #f3f6fb; color: #4a5468; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; padding: 9px 10px; border-bottom: 2px solid #dde4ee; }
.pv-table th.num, .pv-table td.num { text-align: right; }
.pv-table td { padding: 9px 10px; border-bottom: 1px solid #eef2f8; vertical-align: top; color: #2a3245; }
.pv-table td.desc { color: #1a2233; }
.pv-totals { margin-left: auto; width: 260px; font-size: 13px; margin-top: 6px; }
.pv-totals .pv-tr { display: flex; justify-content: space-between; padding: 5px 0; color: #55607a; }
.pv-totals .pv-tr b { color: #1a2233; font-family: "IBM Plex Mono", monospace; }
.pv-totals .pv-tr.due { border-top: 2px solid #1a2233; margin-top: 6px; padding-top: 10px; font-size: 16px; color: #0e9f6e; font-weight: 700; }
.pv-totals .pv-tr.due b { color: #0e9f6e; font-size: 18px; }
.pv-foot { margin-top: 22px; padding-top: 12px; border-top: 1px solid #eef2f8; font-size: 11.5px; color: #8b95ad; text-align: center; }
.pv-empty { color: #8b95ad; font-size: 13px; text-align: center; padding: 60px 0; }

/* ===== Info / FAQ / footer (screen only) ===== */
.disclaimer { margin-top: 26px; font-size: 12px; color: var(--ink-soft); line-height: 1.6; text-align: center; }
.ad-slot { display: none; margin: 22px 0; }
.ad-slot.is-live, .ad-slot.is-preview { display: block; }
.ad-label { display: block; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); opacity: .7; margin-bottom: 4px; text-align: center; }
.ad-ph { display: none; align-items: center; justify-content: center; min-height: 90px; padding: 18px; border: 1px dashed var(--line); border-radius: 12px; background: rgba(255,255,255,.02); color: var(--ink-soft); font-size: 12px; opacity: .6; text-align: center; }
.ad-slot.is-preview .ad-ph { display: flex; }
.ad-slot.is-preview .adsbygoogle { display: none !important; }
.ad-slot.is-live .ad-ph { display: none; }
.info { margin-top: 36px; color: var(--ink-soft); font-size: 14px; line-height: 1.7; }
.info h2 { font-size: 15px; color: var(--ink); margin: 22px 0 8px; }
.info > h2:first-child { margin-top: 0; }
.info p { margin-bottom: 8px; }
.faq { margin: 4px 0 8px; }
.faq dt { color: var(--ink); font-weight: 600; margin-top: 12px; }
.faq dd { margin: 4px 0 0; }
.sources { list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.foot { max-width: 1200px; margin: 0 auto; padding: 0 clamp(16px, 3vw, 28px) 80px; text-align: center; }
.foot a { color: var(--ink-soft); font-size: 12px; text-decoration: none; }
.foot a:hover { color: var(--ink); text-decoration: underline; }

/* ===== Responsive: stack + mobile tab (form <-> preview) ===== */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .form-pane { position: static; }
  .mobile-tabs { display: flex; }
  .preview-pane { display: none; }
  .form-pane.show-preview { display: none; }
  .form-pane.show-preview + .preview-pane { display: flex; }
  .a4 { width: 100%; min-height: auto; padding: 10mm 7mm; }
}

/* ===== PRINT / PDF — A4, form hidden, only the .a4 page ===== */
@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #ffffff !important; }
  .topbar, .mobile-tabs, .form-pane, .disclaimer, .ad-slot, .info, .foot,
  .pmp-fab, #pmp-support-loader, .toast { display: none !important; }
  .wrap { max-width: none; padding: 0; margin: 0; }
  .layout { display: block; }
  .preview-pane { display: flex; justify-content: center; padding: 0; }
  .a4 {
    width: var(--a4-w); min-height: var(--a4-h);
    box-shadow: none; border-radius: 0; transform: none;
    page-break-after: always; page-break-inside: avoid;
  }
  /* keep table rows together; avoid mid-row split */
  .pv-table tr { page-break-inside: avoid; }
}
