.editor { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.bar { flex: none; height: 60px; display: flex; align-items: center; gap: 20px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--bg); }
.bar .status { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.bar .status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #5c8a6b; }
.bar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.bar-actions label.btn { cursor: pointer; }
#btn-pro.is-pro { border-color: var(--accent); color: var(--accent); cursor: default; }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 440px 1fr; }
.workspace > * { min-width: 0; }
.mobile-only { display: none; }
.bar .status.error::before { background: #9b2c2c; }

.panel { overflow-y: auto; padding: 8px 28px 40px; border-right: 1px solid var(--line); background: var(--surface); }
.panel fieldset { border: 0; margin: 0; padding: 24px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.panel legend { float: left; width: 100%; padding: 0; margin-bottom: 16px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.panel legend + * { clear: both; }
.panel-foot { font-size: 12.5px; color: var(--muted); margin: 20px 0 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; min-width: 0; }
.grid-2 .field { margin-bottom: 0; }
.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }

input, select, textarea {
  font: inherit; font-size: 14px; color: var(--ink);
  width: 100%; min-width: 0;
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(21, 20, 15, .06); }
input[type="color"] { padding: 3px; height: 40px; cursor: pointer; }
input[type="color"]:disabled { cursor: not-allowed; opacity: .5; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2374726a' stroke-width='1.4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }

.items { display: grid; gap: 10px; }
.item { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 8px; position: relative; }
.item input { border-color: transparent; background: transparent; padding: 6px 8px; }
.item input:hover { border-color: var(--line); }
.item input:focus { border-color: var(--ink); background: var(--paper); }
.item .desc { font-weight: 500; }
.item .note { font-size: 13px; color: var(--ink-2); }
.item-nums { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; align-items: center; }
.item-nums .line-total { font-size: 13px; color: var(--ink-2); text-align: right; padding-right: 30px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item-nums label { font-size: 12px; color: var(--muted); min-width: 0; }
.item-nums .line-total { white-space: normal; overflow-wrap: anywhere; max-width: 140px; }
.item-del { position: absolute; right: 10px; bottom: 15px; width: 24px; height: 24px; border: 0; background: none; color: var(--muted); border-radius: 6px; cursor: pointer; font-size: 18px; line-height: 1; }
.item-del:hover { background: var(--bg); color: var(--ink); }
.add-line { margin-top: 10px; width: 100%; height: 42px; border: 1px dashed var(--line-strong); border-radius: 10px; background: transparent; font: 500 13.5px var(--sans); color: var(--ink-2); cursor: pointer; }
.add-line:hover { border-color: var(--ink); color: var(--ink); }
.sum { margin-top: 16px; display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

.pro-tag { font-size: 10px; letter-spacing: .1em; padding: 2px 7px; border-radius: 99px; background: var(--ink); color: var(--bg); }
.pro-tag.on { background: var(--accent); }

.templates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.templates button { border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 10px; display: grid; gap: 8px; font: 500 12.5px var(--sans); color: var(--ink-2); cursor: pointer; text-align: left; transition: border-color .15s; }
.templates button:hover { border-color: var(--line-strong); }
.templates button.active { border-color: var(--ink); color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.templates button.locked { color: var(--muted); }
.templates button.locked::after { content: "Pro"; font-size: 10px; color: var(--muted); justify-self: start; margin-top: -4px; }
.tp { display: block; aspect-ratio: 3 / 4; border-radius: 4px; background: #fff; border: 1px solid var(--line); position: relative; overflow: hidden; }
.tp::before, .tp::after { content: ""; position: absolute; left: 14%; right: 14%; height: 3px; background: #d9d6cc; border-radius: 2px; }
.tp::before { top: 18%; width: 38%; height: 6px; background: #15140f; }
.tp::after { top: 46%; box-shadow: 0 8px 0 #e6e3da, 0 16px 0 #e6e3da, 0 24px 0 #e6e3da; }
.tp-modern { background: linear-gradient(var(--accent) 0 30%, #fff 30%); }
.tp-modern::before { background: #fff; }
.tp-mono::before { border-radius: 0; height: 4px; }
.tp-mono { border-top: 3px solid var(--accent); }

.logo-row { display: flex; gap: 8px; align-items: center; height: 40px; }
.logo-row label.btn { cursor: pointer; }
[data-locked="true"] { cursor: not-allowed !important; opacity: .5; }

.preview { overflow-y: auto; padding: 48px clamp(24px, 5vw, 80px); background: var(--bg); }
.preview .sheet-fit { max-width: 760px; margin: 0 auto; }

/* Modal */
.modal { border: 0; padding: 0; border-radius: 18px; width: min(480px, 100% - 32px); background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(21, 20, 15, .35); }
.modal::backdrop { background: rgba(21, 20, 15, .35); backdrop-filter: blur(3px); }
.modal-inner { padding: 40px; position: relative; display: grid; }
#pro-heading { font-size: 36px; }
.modal-x { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; font-size: 22px; color: var(--muted); cursor: pointer; }
.modal-x:hover { background: var(--bg); color: var(--ink); }
.modal-list { list-style: none; padding: 0; margin: 24px 0 28px; display: grid; gap: 8px; color: var(--ink-2); font-size: 14.5px; }
.modal-list li { display: flex; gap: 10px; }
.modal-list li::before { content: ""; width: 14px; height: 1px; background: currentColor; margin-top: 11px; opacity: .6; flex: none; }
.divider { display: flex; align-items: center; gap: 12px; margin: 28px 0 14px; font-size: 12.5px; color: var(--muted); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.license-row { display: flex; gap: 8px; }
.license-msg { min-height: 20px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.license-msg.err { color: #9b2c2c; }
.license-msg.ok { color: var(--accent); }

.print-root { display: none; }

@media (max-width: 960px) {
  .editor { height: auto; overflow: visible; }
  .workspace { grid-template-columns: 1fr; }
  .panel { border-right: 0; overflow: visible; }
  .preview { overflow: visible; padding: 32px 16px 64px; }
  .bar { position: sticky; top: 0; z-index: 10; gap: 12px; padding: 0 14px; }
  .bar { flex-wrap: wrap; height: auto; padding-block: 10px; }
  .bar-actions { flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .bar .status { display: inline-flex; font-size: 12px; }
  .mobile-only { display: inline-flex; }
  input, select, textarea { font-size: 16px; }
  .panel { padding-inline: 16px; }
  .modal-inner { padding: 32px 20px; }
  .bar .btn { min-height: 40px; }
}

@media print {
  @page { size: A4; margin: 14mm 0; }
  @page :first { margin: 0 0 14mm; }
  html, body { background: #fff !important; height: auto !important; overflow: visible !important; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .print-root .sheet { transform: none !important; position: static; box-shadow: none; border: 0; border-radius: 0; width: 210mm; min-height: 282mm; height: auto; overflow: visible; }
  .doc-table tr, .doc-totals, .doc-notes { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
