[hidden] { display: none !important; }

.first-screen { align-content: start; }

.site-header { height: 48px; position: sticky; top: 0; }

@page { size: A4; margin: 12mm; }

:root {
  --ink: #1d2421;
  --ink-soft: #3e4943;
  --muted: #6d675c;
  --paper: #e7e1d6;
  --sheet: #fffdf8;
  --card: #f7f4ee;
  --line: #d5cec1;
  --accent: #9d3b22;
  --ok: #1d6b45;
  --danger: #8d2b2b;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Malgun Gothic", "Microsoft YaHei", sans-serif;
  --serif: Georgia, "Iowan Old Style", Palatino, "Palatino Linotype", "Songti SC", "Hiragino Mincho ProN", "Yu Mincho", "PMingLiU", serif;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
}

.site-header {
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--ink);
  color: #f4f0e6;
  box-sizing: border-box;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-size: 15px;
}

.brand svg { display: block; }

.lang-menu { position: relative; }

.lang-menu summary {
  list-style: none;
  cursor: pointer;
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid rgba(244, 240, 230, 0.4);
  border-radius: 4px;
  font-size: 13px;
}

.lang-menu summary::-webkit-details-marker { display: none; }

.lang-list {
  position: absolute;
  right: 0;
  top: 36px;
  min-width: 148px;
  margin: 0;
  padding: 4px;
  background: var(--sheet);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(40, 32, 20, 0.12);
}

.lang-list a {
  display: block;
  padding: 6px 8px;
  color: inherit;
  text-decoration: none;
  border-radius: 3px;
}

.lang-list a:hover,
.lang-list a[aria-current="page"] { background: #efeae1; }

.lang-list a[aria-current="page"] { font-weight: 700; }

.first-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: calc(100vh - 48px);
  height: calc(100dvh - 48px);
  min-height: 0;
  overflow: hidden;
}

.first-screen > h1 {
  margin: 0;
  padding: 6px 14px 4px;
  font-size: 20px;
  line-height: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.studio {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 580px;
  gap: 12px;
  padding: 0 12px 8px;
}

.editor {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

fieldset {
  margin: 0;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 6px;
  padding: 6px 8px 8px;
}

legend {
  padding: 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.party-grid,
.notes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.fields,
.meta-grid {
  display: grid;
  gap: 6px 8px;
}

.fields { grid-template-columns: 1fr 1fr; }

.meta-grid { grid-template-columns: 1.15fr 1fr 1fr 1.15fr; }

.span-2 { grid-column: span 2; }

.field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: 11px;
  color: var(--ink-soft);
}

.client-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.client-row select { flex: 1; min-width: 0; }

input,
select,
textarea,
button,
.file-btn {
  font: inherit;
  color: var(--ink);
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 28px;
  border: 1px solid #cfc6b8;
  border-radius: 3px;
  background: white;
  padding: 0 6px;
  font-size: 13px;
}

textarea {
  height: 44px;
  padding: 4px 6px;
  resize: none;
}

.items {
  min-height: 0;
}

.items table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.items th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding: 0 4px 4px;
}

.items td { padding: 2px; }

.items .num,
.item-total { text-align: right; font-variant-numeric: tabular-nums; }

.col-qty { width: 72px; }
.col-price { width: 108px; }
.col-amount { width: 108px; }
.col-remove { width: 76px; }

.item-remove {
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
}

.add-item { margin-top: 6px; }

.adjust {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px;
}

.discount-controls { display: flex; gap: 6px; }
.discount-controls select { width: 46%; }
.discount-controls input { width: 54%; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

button,
.file-btn {
  white-space: nowrap;
  height: 30px;
  padding: 0 10px;
  border-radius: 4px;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 28px;
}

button.primary {
  background: var(--ink);
  color: #f4f0e6;
}

.file-btn { display: inline-flex; align-items: center; }

.status {
  flex: 1 1 180px;
  min-width: 140px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ok);
}

.status.is-error { color: var(--danger); }

.preview-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.sheet-sizer {
  --scale: 0.62;
  width: calc(794px * var(--scale));
  height: calc(1123px * var(--scale));
  position: relative;
  flex: 0 0 auto;
}

.sheet {
  width: 794px;
  height: 1123px;
  position: absolute;
  left: 0;
  top: 0;
  transform: scale(var(--scale));
  transform-origin: top left;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 14px 40px rgba(40, 32, 20, 0.14);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: var(--serif);
}

.sheet-stripe {
  height: 8px;
  background: var(--accent);
  flex: 0 0 auto;
}

.sheet-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 28px 40px 32px;
}

.sheet-head,
.parties {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.kicker {
  margin: 0 0 4px;
  font-family: var(--font);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.sheet-brand {
  margin: 0 0 6px;
  font-size: 30px;
  line-height: 1.05;
  font-weight: 700;
}

.sheet p { margin: 0; }

.sheet .prose,
.party p,
.bill-block p,
.sheet-meta p,
.sheet-block {
  display: block;
}

.sheet .prose,
.party p,
.bill-block p,
.sheet-meta p {
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.35;
}

.doc-title {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.muted { color: #8a8174; }

.sheet-meta { text-align: right; min-width: 210px; }

.sheet-meta .k {
  display: inline-block;
  min-width: 92px;
  margin-right: 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.rule {
  height: 2px;
  margin: 14px 0;
  background: var(--ink);
  border: 0;
}

.parties { margin-bottom: 14px; }

.party { flex: 1; min-width: 0; }

.party-name {
  font-family: var(--serif);
  font-size: 18px;
  margin-bottom: 2px;
}

.sheet table {
  width: 100%;
  border-collapse: collapse;
}

.sheet th {
  text-align: left;
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1.5px solid var(--ink);
  padding: 0 4px 6px;
}

.sheet td {
  padding: 7px 4px;
  border-bottom: 1px solid #e6dfd2;
  font-size: 14px;
  vertical-align: top;
}

.sheet .num {
  text-align: right;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  width: 18%;
}

.totals {
  width: 320px;
  margin: 16px 0 0 auto;
  font-family: var(--font);
}

.tot-row,
.grand {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
}

.tot-row { padding: 3px 0; font-size: 14px; }

.grand {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--ink);
  color: #f4f0e6;
  font-weight: 700;
  font-size: 16px;
}

.grand strong {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.calc-note {
  margin: 6px 0 0;
  text-align: right;
  color: var(--muted);
  font-family: var(--font);
  font-size: 11px;
}

.sheet-bottom { margin-top: auto; padding-top: 18px; }

.sheet-block + .sheet-block { margin-top: 12px; }

.below-fold {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 16px 8px;
}

.below-fold h2 {
  margin: 0 0 12px;
  font-size: 22px;
  line-height: 1.2;
}

.feature-grid,
.partner-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.feature-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.feature-grid article,
.partner-card,
.ftc-disclosure {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.feature-grid h3,
.partner-card h3 { margin: 0 0 6px; font-size: 15px; }

.feature-grid p,
.partner-card p,
.ftc-disclosure,
.faq p { margin: 0; }

.faq { padding-top: 8px; }

.faq details {
  border-top: 1px solid var(--line);
  padding: 8px 0;
}

.faq summary { cursor: pointer; font-weight: 600; }

.faq p { padding: 6px 0 2px; color: var(--ink-soft); }

.ftc-disclosure { margin-bottom: 12px; font-size: 13px; line-height: 1.45; }

.partner-card a { color: var(--ink); font-weight: 700; }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 3px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.site-footer {
  box-sizing: border-box;
  min-height: 28px;
  padding: 6px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.miss { max-width: 640px; padding: 36px 16px 72px; }

.miss h1 { white-space: normal; font-size: 28px; line-height: 1.2; margin: 0 0 8px; }

.miss a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

@media (max-width: 1100px) {
  .first-screen {
    display: block;
    height: auto;
    overflow: visible;
  }

  .first-screen > h1 { white-space: normal; }

  .studio {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .preview-col { height: 72vh; order: -1; }

  .editor { overflow: visible; }

  .party-grid,
  .notes-grid,
  .meta-grid,
  .adjust,
  .feature-grid,
  .partner-grid { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4; margin: 12mm; }

  .site-header,
  .site-footer,
  .editor,
  .toolbar,
  .below-fold,
  .first-screen > h1,
  .noscript,
  .lang-menu {
    display: none !important;
  }

  html,
  body,
  main,
  .first-screen,
  .studio,
  .preview-col,
  .sheet-sizer {
    display: block !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
    position: static !important;
    box-shadow: none !important;
  }

  .sheet {
    position: static !important;
    transform: none !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    box-shadow: none !important;
    background: white !important;
  }

  .sheet-inner { min-height: 0 !important; padding: 0 !important; }

  .sheet,
  .sheet-stripe,
  .grand {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .grand,
  .sheet-bottom,
  .sheet tr { break-inside: avoid; }
}
