:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #1f4e8c;
  --danger: #c0392b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar__title { display: flex; gap: 10px; align-items: baseline; }
.topbar__title strong { font-size: 16px; }
.topbar__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* buttons */
.btn {
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { filter: brightness(1.1); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn--ghost:hover { background: #f0f2f5; }
.btn--small { padding: 6px 12px; font-size: 13px; }
.icon-btn {
  border: 0; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--muted); padding: 2px 6px;
}
.icon-btn:hover { color: var(--danger); }

/* layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  max-width: 1600px; margin: 0 auto;
}
.form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; }

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

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }

input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-color: var(--accent);
}
.hint { font-size: 12px; min-height: 1em; }
.hint.ok { color: #1e8e3e; }
.hint.err { color: var(--danger); }

/* company preview */
.company-preview {
  display: flex; gap: 16px; align-items: center;
  padding: 12px; border-radius: 8px;
  background: #f8f9fb; border-left: 4px solid var(--accent);
}
.company-preview img { width: 140px; height: auto; flex: none; }
.company-preview dl { margin: 0; font-size: 12px; display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; }
.company-preview dt { color: var(--muted); }
.company-preview dd { margin: 0; }

/* items */
.items-wrap { overflow-x: auto; margin-bottom: 10px; }
.items { width: 100%; border-collapse: collapse; min-width: 720px; }
.items th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line);
}
.items td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.items input, .items select { padding: 5px 6px; }
.items input.desc { margin-top: 4px; font-size: 12px; color: var(--muted); }
.items .c-lp { width: 32px; color: var(--muted); padding-top: 12px; }
.items .c-unit { width: 64px; }
.items .c-num { width: 96px; text-align: right; }
.items .c-num input { text-align: right; }
.items .c-vat { width: 74px; }
.items .c-act { width: 32px; }
.items .out { padding-top: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.totals {
  margin-top: 14px; margin-left: auto; max-width: 380px;
  font-variant-numeric: tabular-nums;
}
.totals table { width: 100%; border-collapse: collapse; font-size: 13px; }
.totals th, .totals td { padding: 4px 6px; text-align: right; }
.totals th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.totals tr.sum td { border-top: 1px solid var(--line); font-weight: 700; }
.totals .grand {
  margin-top: 8px; padding: 10px 12px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: flex; justify-content: space-between; font-weight: 700; font-size: 15px;
}

/* preview */
.preview {
  position: sticky; top: 72px;
  height: calc(100vh - 92px);
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.preview__bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.preview iframe { flex: 1; width: 100%; border: 0; background: #525659; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .preview { position: static; height: 80vh; }
}
@media (max-width: 640px) {
  .layout { padding: 12px; }
  .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .company-preview { flex-direction: column; align-items: flex-start; }
  .topbar { padding: 10px 12px; }
  .topbar__title .muted { display: none; }
}
