:root {
  --brand: #1f3a5f;
  --brand-dark: #152a45;
  --accent: #f2a900;
  --ink: #14181f;
  --muted: #5a626e;
  --line: #dde2e8;
  --bg: #f5f7fa;
  --card: #ffffff;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Header and footer */

.site-header { background: var(--brand); color: #fff; }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 16px; }
.brand { color: #fff; font-weight: 800; font-size: 1.15rem; text-decoration: none; letter-spacing: -0.01em; }
.brand::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 2px; background: var(--accent); }
.site-header nav { display: flex; gap: 18px; }
.site-header nav a { color: #dbe5f1; text-decoration: none; font-size: 0.95rem; }
.site-header nav a:hover { color: #fff; }

.site-footer { margin-top: 56px; padding: 28px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; }
.site-footer a { color: var(--muted); }

/* Hero */

.hero { padding: 36px 16px 20px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.15; letter-spacing: -0.02em; }
.lead { margin: 0 0 16px; max-width: 760px; color: var(--muted); font-size: 1.08rem; }
.doc-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.doc-links a {
  display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink); text-decoration: none; font-size: 0.9rem;
}
.doc-links a[aria-current="page"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Tool layout */

.tool { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }

.tool-form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

.tool-preview { position: sticky; top: 16px; }
.preview-head { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

.doc-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin-bottom: 18px; background: var(--bg); border-radius: 8px; }
.doc-tabs button {
  padding: 9px 6px; border: 0; border-radius: 6px; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; cursor: pointer;
}
.doc-tabs button[aria-pressed="true"] { background: var(--card); color: var(--brand); box-shadow: 0 1px 3px rgba(20, 24, 31, 0.12); }

fieldset { margin: 0 0 18px; padding: 0; border: 0; }
legend { padding: 0; margin-bottom: 10px; font-weight: 700; font-size: 1rem; }

label { display: block; margin-bottom: 10px; font-size: 0.88rem; font-weight: 600; color: #2a313c; }
.opt { font-weight: 400; color: var(--muted); }

input, textarea, select {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid #c9d0d9; border-radius: 7px; background: #fff; color: var(--ink);
  font: inherit; font-size: 0.95rem;
}
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(31, 58, 95, 0.35); outline-offset: 0; border-color: var(--brand); }
textarea { resize: vertical; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }

.logo-field { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.logo-field img { max-width: 90px; max-height: 44px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; padding: 3px; background: #fff; }

/* Line items */

.items-head, .item-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 64px 92px 88px 30px; gap: 6px; align-items: center;
}
.items-head { margin-bottom: 4px; color: var(--muted); font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.items-head .r, .item-amount { text-align: right; }
.item-row { margin-bottom: 6px; }
.item-row input { margin-top: 0; padding: 8px; }
.item-amount { font-size: 0.9rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--muted);
  font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: #fde8e8; color: #b42318; }

.items-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 8px; }
.items-actions select { margin-top: 0; }

.form-total { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; padding: 12px 14px; border-radius: 8px; background: var(--bg); font-weight: 700; }
.form-total output { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

/* Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 18px;
  border: 1px solid var(--brand); border-radius: 8px; background: var(--brand); color: #fff;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--brand); }
.btn-secondary:hover { background: var(--bg); }
.btn-small { padding: 7px 12px; font-size: 0.88rem; margin: 0; }
.btn-big { width: 100%; padding: 14px 18px; font-size: 1.05rem; background: var(--accent); border-color: var(--accent); color: #1b1300; }
.btn-big:hover { background: #dc9900; }

.link-btn { padding: 0; border: 0; background: none; color: var(--brand); font: inherit; text-decoration: underline; cursor: pointer; }

.actions { display: grid; gap: 10px; }
.fine { margin: 10px 0 0; color: var(--muted); font-size: 0.85rem; }

/* Paper preview */

.paper {
  min-height: 560px; padding: 32px; border: 1px solid var(--line); border-radius: 4px; background: #fff;
  box-shadow: 0 10px 30px rgba(20, 24, 31, 0.08); font-size: 0.82rem; color: #2a313c;
}
.p-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.p-logo { display: block; max-width: 140px; max-height: 52px; margin-bottom: 8px; object-fit: contain; }
.p-biz-name { font-size: 1.05rem; font-weight: 700; color: var(--ink); }
.p-meta { text-align: right; white-space: nowrap; }
.p-meta span { color: var(--muted); margin-right: 6px; }
.p-title { margin-bottom: 6px; color: var(--brand); font-size: 1.5rem; font-weight: 800; letter-spacing: 0.02em; }
.p-party { margin-bottom: 16px; }
.p-label { margin-bottom: 3px; color: var(--muted); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.p-cust { font-weight: 700; color: var(--ink); }
.p-table { width: 100%; border-collapse: collapse; }
.p-table th { padding: 7px 8px; background: var(--brand); color: #fff; font-size: 0.75rem; text-align: left; }
.p-table td { padding: 7px 8px; border-bottom: 1px solid #edf0f3; vertical-align: top; }
.p-table tbody tr:nth-child(even) td { background: #f7f9fb; }
.p-table .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.p-sums { width: 260px; max-width: 100%; margin: 12px 0 0 auto; }
.sum-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.sum-row.strong { padding-top: 6px; border-top: 1px solid var(--line); color: var(--ink); font-size: 0.95rem; font-weight: 700; }
.p-notes { margin-top: 20px; color: var(--muted); }
.p-sign { display: flex; gap: 40px; margin-top: 36px; }
.p-sign span { flex: 1; padding-top: 6px; border-top: 1px solid #a0a6af; color: var(--muted); font-size: 0.72rem; }
.p-sign span:last-child { flex: 0 0 120px; }
.p-foot { margin-top: 28px; color: #9aa1ab; font-size: 0.7rem; }
.ph { color: #a6adb7; font-style: italic; }

/* Guide content */

.content { max-width: 820px; margin-top: 48px; }
.content h2 { margin: 36px 0 10px; font-size: 1.45rem; line-height: 1.25; letter-spacing: -0.01em; }
.content h3 { margin: 24px 0 8px; font-size: 1.12rem; }
.content p, .content li { font-size: 1.02rem; }
.content table { width: 100%; border-collapse: collapse; margin: 12px 0; background: var(--card); font-size: 0.95rem; }
.content th, .content td { padding: 8px 10px; border: 1px solid var(--line); text-align: left; }
.content td.r, .content th.r { text-align: right; }
.faq details { margin-bottom: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.faq summary { font-weight: 700; cursor: pointer; }
.faq details p { margin: 8px 0 0; }

.related { margin-top: 40px; }
.related h2 { font-size: 1.2rem; }
.trade-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; padding: 0; list-style: none; }
.trade-grid li { padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.trade-grid strong { display: block; margin-bottom: 4px; }
.trade-grid a { margin-right: 10px; font-size: 0.92rem; }

/* Pro dialog */

dialog { max-width: 420px; width: calc(100% - 32px); padding: 0; border: 0; border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(20, 24, 31, 0.5); }
.dialog-inner { padding: 24px; }
.dialog-inner h2 { margin: 0 0 8px; }
.dialog-inner ul { padding-left: 20px; }
.dialog-inner .price { font-size: 1.3rem; font-weight: 800; color: var(--brand); }
.dialog-inner .btn { margin: 4px 8px 0 0; }
.muted { color: var(--muted); }

/* Small screens */

@media (max-width: 980px) {
  .tool { grid-template-columns: minmax(0, 1fr); }
  .tool-preview { position: static; }
}

@media (max-width: 560px) {
  .tool-form { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .items-head { display: none; }
  .item-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 30px;
    padding: 8px; border: 1px solid var(--line); border-radius: 8px;
  }
  .item-row .item-desc { grid-column: 1 / -1; }
  .paper { padding: 18px; min-height: 0; font-size: 0.76rem; }
  .p-head { flex-direction: column; }
  .p-meta { text-align: left; }
  .site-header nav a:first-child { display: none; }
}

@media print {
  .site-header, .hero, .tool-form, .content, .related, .site-footer, .preview-head { display: none; }
  .tool { display: block; }
  .paper { box-shadow: none; border: 0; }
}
