:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --line: #dfe3e8;
  --text: #1d2228;
  --muted: #6b7480;
  --accent: #1a73e8;
  --accent-ink: #fff;
  --accent-soft: #e8f0fd;
  --danger: #c62828;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- верхняя панель ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.logo { font-size: 20px; color: var(--accent); }
.group { display: flex; align-items: center; gap: 4px; }
.doc-name {
  flex: 1; min-width: 120px; max-width: 420px;
  border: 1px solid transparent; border-radius: 6px;
  padding: 6px 8px; background: transparent; font-weight: 500;
}
.doc-name:hover { border-color: var(--line); }
.doc-name:focus { border-color: var(--accent); outline: none; background: #fff; }
.topbar .primary { margin-left: auto; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #f4f6f8; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; padding: 6px 18px; }
.btn.primary:hover { background: #1765cc; }
.btn.icon { width: 32px; padding: 6px 0; text-align: center; }
.btn.small { padding: 4px 8px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- раскладка ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 250px 1fr 290px; min-height: 0; }
.panel { background: var(--panel); overflow-y: auto; }
.panel.left { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.panel.right { border-left: 1px solid var(--line); padding: 14px; }
.panel section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel section.grow { flex: 1; border-bottom: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
h3 { margin: 0 0 12px; font-size: 16px; }
h4 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 8px; cursor: pointer; text-align: left;
}
.tool span { width: 20px; text-align: center; font-weight: 700; color: var(--accent); }
.tool:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- поля ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; width: 100%;
}
.field textarea { resize: vertical; min-height: 60px; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.help { font-size: 12px; color: var(--muted); }
.size-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: end; }
.size-row .swap { margin-bottom: 10px; }
.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; }
.check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-size: 13px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg-btn { flex: 1; border: 0; background: #fff; padding: 5px 4px; cursor: pointer; font-size: 13px; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; }
.btnrow.sep { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.el-error { background: #fdecea; color: var(--danger); border-radius: 6px; padding: 8px 10px; margin: 4px 0 8px; font-size: 13px; }
.placeholder p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- список элементов ---------- */
.layers { list-style: none; margin: 0; padding: 0; }
.layers .empty { color: var(--muted); font-size: 13px; }
.layer { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.layer:hover { background: #f4f6f8; }
.layer.active { background: var(--accent-soft); }
.layer .ico { width: 18px; text-align: center; color: var(--muted); font-weight: 700; }
.layer .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.layer .err { color: #fff; background: var(--danger); border-radius: 50%; width: 16px; height: 16px; font-size: 11px; text-align: center; line-height: 16px; font-weight: 700; }
.layer .err:empty { display: none; }

/* ---------- холст ---------- */
.stage-col { display: flex; flex-direction: column; min-width: 0; }
.stage-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; }
.badge { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.zoom-val { width: 48px; text-align: center; font-size: 12px; color: var(--muted); }
.stage { flex: 1; overflow: auto; display: grid; place-items: center; padding: 24px; min-height: 0; }
.canvas-wrap { padding: 0; }
#canvas {
  display: block; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 6px 20px rgba(0,0,0,.08);
  border-radius: 2px; touch-action: none;
}
.stage-foot { text-align: center; padding: 6px 0 10px; }

/* ---------- данные ---------- */
.source { background: #f6f8fa; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 10px; }
.source-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 6px 0 10px; }
.chips-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.chip {
  border: 1px solid #c9d8f5; background: var(--accent-soft); color: #174ea6; border-radius: 999px;
  padding: 1px 9px; font-size: 12px; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover { background: #d6e4fb; }
.chip.builtin { background: #f1f3f4; border-color: var(--line); color: var(--muted); }
#dataPanel .check { margin-bottom: 8px; }
p.warn { margin: 0 0 10px; }
.row-nav { display: flex; align-items: center; gap: 4px; }
.row-nav input { width: 64px; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; text-align: center; }
.row-nav[hidden] { display: none; }

.field .radio, .radio { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text) !important; cursor: pointer; padding: 2px 0; }
.radio input[type="radio"] { width: auto; flex: none; margin: 0; }
.radio.range input[type="text"] { flex: 1; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.radio.range input.invalid { border-color: var(--danger); }
.warn-text { color: #8a4b00; }
#printTotal { margin: -2px 0 6px; }

.dialog.wide { width: min(1000px, 94vw); }
.table-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.table-head h2 { margin: 0; }
.table-head input { flex: 1; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
.table-wrap { max-height: 65vh; overflow: auto; margin-top: 10px; border: 1px solid var(--line); border-radius: 6px; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 13px; }
.table-wrap th { position: sticky; top: 0; background: #f6f8fa; text-align: left; font-weight: 600; }
.table-wrap th, .table-wrap td { padding: 5px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-wrap td.num { color: var(--muted); text-align: right; }
.table-wrap tbody tr { cursor: pointer; }
.table-wrap tbody tr:hover { background: #f4f6f8; }
.table-wrap tbody tr.cur { background: var(--accent-soft); }

/* ---------- диалог печати ---------- */
.dialog { border: 0; border-radius: 12px; padding: 20px 22px; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(20, 24, 30, .35); }
.dialog h2 { font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); margin-bottom: 4px; }
.dialog .muted { margin-bottom: 14px; }
.hint { background: #f4f6f8; border-radius: 6px; padding: 10px; font-size: 13px; color: #3a424c; margin: 4px 0 10px; }
.warn { background: #fff4e5; border-radius: 6px; padding: 10px; font-size: 13px; color: #8a4b00; margin: 0 0 10px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }
.spacer { flex: 1; }

.printer-status { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #e8f5e9; color: #1b5e20; border-radius: 6px; padding: 6px 10px; font-size: 13px; margin-bottom: 10px; }
.printer-status[hidden] { display: none; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input { flex: 1; padding: 0 !important; border: 0 !important; box-shadow: none !important; }
.range-val { width: 20px; text-align: center; font-weight: 600; }

.progress { position: fixed; right: 18px; bottom: 18px; width: 280px; background: #fff; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.2); padding: 12px 14px; z-index: 55; font-size: 13px; }
.progress[hidden] { display: none; }
.progress-track { height: 6px; background: #e6e9ed; border-radius: 3px; margin-top: 8px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- уведомления ---------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: #222a33; color: #fff; padding: 9px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); transition: opacity .4s; font-size: 13px; }
.toast.error { background: var(--danger); }
.toast.hide { opacity: 0; }

.drop-hint { display: none; position: fixed; inset: 0; background: rgba(26,115,232,.12); border: 3px dashed var(--accent); z-index: 60; place-items: center; font-size: 20px; color: var(--accent); font-weight: 600; pointer-events: none; }
body.dropping .drop-hint { display: grid; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 210px 1fr 250px; }
  .brand { display: none; }
}
