:root {
  color-scheme: light; font-family: Inter, "Segoe UI", Arial, sans-serif; color: #26363b; background: #f4f3ef; font-synthesis: none; text-rendering: optimizeLegibility;
  --ink: #26363b; --ink-strong: #1b2c32; --muted: #718087; --muted-light: #96a0a3; --line: #e5e8e5; --line-strong: #d5ddda; --surface: #fff; --canvas: #f4f3ef;
  --accent: #367e78; --accent-hover: #286d67; --accent-soft: #e8f2f0; --navy: #172b36; --navy-soft: #213a46; --success: #30765d; --success-bg: #e8f4ed; --warning: #986b22;
  --warning-bg: #fbf2de; --danger: #a54e4b; --danger-bg: #faecea; --radius-sm: 7px; --radius: 11px; --radius-lg: 16px;
  --shadow-card: 0 2px 8px rgb(31 48 48 / 4%), 0 1px 2px rgb(31 48 48 / 3%);
}

*,
*::before,
*::after { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; background: var(--canvas); scroll-behavior: smooth; }

body { min-width: 320px; min-height: 100vh; margin: 0; color: var(--ink); background: var(--canvas); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

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

button,
select { cursor: pointer; }

button:disabled,
input:disabled,
select:disabled,
textarea:disabled { cursor: not-allowed; opacity: .58; }

button,
a,
input,
select,
textarea,
iframe { -webkit-tap-highlight-color: transparent; }

a { color: var(--accent); text-decoration: none; }

a:hover { color: var(--accent-hover); }

svg { width: 18px; height: 18px; flex: 0 0 auto; stroke: currentColor; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; display: flex; width: 224px; flex-direction: column; padding: 24px 14px 16px; color: #d9e3e5; background: var(--navy); }

.brand { display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 0 9px; color: #fff; font-size: 15px; font-weight: 650; letter-spacing: -.02em; }

.brand-mark {
  display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border: 1px solid rgb(255 255 255 / 16%); border-radius: 10px; color: #fff;
  background: #315c62;
}

.brand-mark svg { width: 19px; height: 19px; }

.brand-subtitle { display: block; margin-top: 1px; color: #aababe; font-size: 11px; font-weight: 400; letter-spacing: 0; }

.sidebar nav { display: grid; gap: 5px; margin-top: 36px; }

.nav-link {
  display: flex; min-height: 42px; align-items: center; gap: 12px; padding: 0 12px; border-radius: 8px; color: #c1cdd0; font-size: 13px; font-weight: 500;
  transition: color .16s ease, background .16s ease;
}

.nav-link:hover { color: #fff; background: rgb(255 255 255 / 6%); }

.nav-link.active { color: #fff; background: var(--navy-soft); box-shadow: inset 2px 0 #72aaa3; }

.nav-icon { display: grid; width: 20px; height: 20px; place-items: center; color: #9eafb2; }

.nav-link.active .nav-icon { color: #a5d3cb; }

.sidebar-footer { margin-top: auto; padding: 15px 10px 0; border-top: 1px solid rgb(255 255 255 / 10%); color: #aababe; font-size: 11px; }

.workspace { width: calc(100% - 224px); min-width: 0; min-height: 100vh; margin-left: 224px; }

.topbar {
  position: sticky; z-index: 10; top: 0; display: flex; min-height: 62px; align-items: center; justify-content: space-between; gap: 18px; padding: 0 34px;
  border-bottom: 1px solid var(--line); background: rgb(255 255 255 / 92%); backdrop-filter: blur(12px);
}

.breadcrumb,
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.breadcrumb { min-width: 0; color: var(--muted); font-size: 12px; }

.breadcrumb > :last-child { overflow: hidden; color: var(--ink-strong); font-weight: 550; text-overflow: ellipsis; white-space: nowrap; }

.topbar-actions { flex: 0 0 auto; }

.connection-badge { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }

.connection-badge::before,
.integration-status::before { width: 7px; height: 7px; border-radius: 50%; background: var(--success); content: ""; }

main#content { width: 100%; max-width: 1600px; margin: 0 auto; padding: 34px clamp(20px, 3.2vw, 48px) 56px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 25px; }

.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }

h1,
h2,
h3,
p { margin-top: 0; }

h1 { margin-bottom: 6px; color: var(--ink-strong); font-size: clamp(23px, 2.5vw, 30px); font-weight: 640; letter-spacing: -.035em; line-height: 1.2; }

.page-description { max-width: 680px; margin-bottom: 0; color: var(--muted); font-size: 13px; }

.page-actions,
.split-header,
.row-actions { display: flex; align-items: center; gap: 8px; }

.page-actions,
.row-actions { flex-wrap: wrap; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }

.stat-card,
.panel,
.template-card,
.integration-card,
.source-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-card); }

.stat-card { min-width: 0; padding: 18px 20px; }

.stat-value { display: block; margin-bottom: 4px; color: var(--ink-strong); font-size: 25px; font-weight: 650; letter-spacing: -.035em; line-height: 1.1; }

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

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 0 0 14px; }

.search { width: min(100%, 330px); min-width: 180px; }

.filter-tabs { display: flex; max-width: 100%; gap: 4px; overflow-x: auto; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: #eeefec; scrollbar-width: thin; }

.filter-tabs button { min-height: 30px; padding: 0 11px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 11px; white-space: nowrap; }

.filter-tabs button:hover { color: var(--ink); }

.filter-tabs button.active { color: var(--ink-strong); background: #fff; box-shadow: 0 1px 3px rgb(25 42 41 / 10%); }

.document-table { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-card); }

.table-wrap { overflow-x: auto; overscroll-behavior-x: contain; }

table { width: 100%; border-collapse: collapse; text-align: left; }

.document-table table { min-width: 720px; }

th,
td { padding: 13px 17px; border-bottom: 1px solid var(--line); vertical-align: middle; }

th { color: var(--muted); background: #fafbf9; font-size: 10px; font-weight: 650; letter-spacing: .045em; text-transform: uppercase; white-space: nowrap; }

td { color: #48585d; font-size: 12px; }

tbody tr:last-child td { border-bottom: 0; }

tbody tr:hover { background: #fbfcfa; }

.document-title { display: block; color: var(--ink-strong); font-weight: 570; }

.document-meta { display: block; margin-top: 2px; color: var(--muted-light); font-size: 10px; }

.badge {
  display: inline-flex; min-height: 23px; align-items: center; padding: 2px 8px; border-radius: 999px; color: var(--muted); background: #f0f2f0; font-size: 10px;
  font-weight: 600; line-height: 1.25; white-space: nowrap;
}

.badge.draft,
.badge.pending { color: var(--warning); background: var(--warning-bg); }

.badge.issued,
.badge.approved { color: var(--success); background: var(--success-bg); }

.badge.error { color: var(--danger); background: var(--danger-bg); }

.button {
  display: inline-flex; min-height: 36px; align-items: center; justify-content: center; gap: 7px; padding: 0 13px; border: 1px solid transparent; border-radius: 8px;
  font-size: 12px; font-weight: 570; line-height: 1.2; text-align: center; text-decoration: none; white-space: nowrap;
  transition: color .15s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.button svg { width: 16px; height: 16px; }

.button.primary { color: #fff; background: var(--accent); box-shadow: 0 1px 2px rgb(24 65 61 / 12%); }

.button.primary:hover { background: var(--accent-hover); }

.button.secondary { border-color: var(--line-strong); color: var(--ink); background: #fff; }

.button.secondary:hover,
.button.ghost:hover { border-color: #c7d2cf; color: var(--ink-strong); background: #f7f9f7; }

.button.ghost { border-color: transparent; color: var(--muted); background: transparent; }

.button.danger { border-color: #efd6d3; color: var(--danger); background: #fff; }

.button.danger:hover { background: var(--danger-bg); }

.button.small { min-height: 29px; gap: 5px; padding: 0 9px; border-radius: 7px; font-size: 11px; }

:where(button, a, input, select, textarea, iframe, summary):focus-visible { outline: 3px solid rgb(54 126 120 / 35%); outline-offset: 2px; }

.empty-state { display: grid; min-height: 220px; place-items: center; padding: 32px 20px; color: var(--muted); text-align: center; }

.empty-state > div { max-width: 390px; }

.empty-state svg { width: 34px; height: 34px; margin-bottom: 10px; color: #9aa9a6; }

.empty-state h2,
.empty-state h3 { margin-bottom: 5px; color: var(--ink-strong); font-size: 15px; }

.empty-state p { margin-bottom: 14px; font-size: 12px; }

.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(310px, .78fr); align-items: start; gap: 20px; }

.editor-form { display: grid; min-width: 0; gap: 14px; }

.panel { min-width: 0; overflow: hidden; }

.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); }

.panel-title { margin: 0; color: var(--ink-strong); font-size: 13px; font-weight: 630; }

.panel-body { display: grid; gap: 16px; padding: 18px; }

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

.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; }

.field.full { grid-column: 1 / -1; }

.field label { color: #4d5d61; font-size: 11px; font-weight: 600; }

.field input,
.field select,
.field textarea,
.search input {
  width: 100%; min-width: 0; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 7px; color: var(--ink-strong); background: #fff;
  font-size: 12px; transition: border-color .15s ease, box-shadow .15s ease;
}

.field input:hover,
.field select:hover,
.field textarea:hover,
.search input:hover { border-color: #bbc9c5; }

.field input:focus,
.field select:focus,
.field textarea:focus,
.search input:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px rgb(54 126 120 / 13%); }

.field textarea { min-height: 92px; resize: vertical; }

.field input::placeholder,
.field textarea::placeholder,
.search input::placeholder { color: #a2acad; }

.field input[type="checkbox"][data-field-key] { width: 17px; min-height: 17px; align-self: flex-start; margin: 5px 0; padding: 0; accent-color: var(--accent); }
.field :is(input,textarea)[readonly], .field select:disabled { border-color: var(--line); color: #59686b; background: #f3f5f3; cursor: default; }
.template-field-card { min-width: 0; }
.template-field-card > summary { cursor: pointer; list-style: none; }
.template-field-card > summary::-webkit-details-marker { display: none; }
.template-field-card > summary::before { content: '▸'; color: var(--muted); }
.template-field-card[open] > summary::before { transform: rotate(90deg); }
.template-field-card:not([open]) > summary { border-bottom: 0; }
.template-field-card .panel-header { flex-wrap: wrap; }
.template-field-card .panel-title { flex: 1; }

.hint { color: var(--muted); font-size: 10px; line-height: 1.4; }

.preview-panel { position: sticky; top: 82px; }

.preview-panel .panel-body { display: block; padding: 12px; background: #edf0ee; }

.preview-panel iframe {
  display: block; width: 100%; height: min(72vh, 1020px); min-height: 480px; border: 1px solid #dce1df; border-radius: 3px; background: #fff;
  box-shadow: 0 3px 12px rgb(28 43 43 / 9%);
}

.line-item {
  display: grid; min-width: 0; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff;
}

#line-items { display: grid; min-width: 0; gap: 10px; container-type: inline-size; }

.line-title,
.line-details,
.line-options,
.line-options > *,
.line-options .field { min-width: 0; }

.line-options {
  display: grid; grid-template-columns: minmax(104px, 1.15fr) minmax(104px, 1.05fr) minmax(74px, .72fr) minmax(82px, .85fr) minmax(88px, .9fr) 32px; align-items: end; gap: 9px;
}

.line-options .field:has(input[type="checkbox"]) label { display: flex; min-height: 38px; align-items: center; gap: 7px; }

.line-options input[type="checkbox"] { width: 16px; min-height: 16px; flex: 0 0 auto; margin: 0; padding: 0; accent-color: var(--accent); }

.line-total { display: flex; min-width: 0; min-height: 38px; flex-direction: column; justify-content: flex-end; overflow-wrap: anywhere; color: var(--ink-strong); font-size: 12px; font-weight: 620; }

.line-total::before { color: var(--muted); content: "Итого"; font-size: 11px; font-weight: 600; }

.remove-line { display: grid; width: 32px; height: 36px; place-items: center; justify-self: end; border: 1px solid transparent; border-radius: 7px; color: var(--muted); background: transparent; }

.remove-line:hover { border-color: #efd6d3; color: var(--danger); background: var(--danger-bg); }

.totals { display: grid; gap: 9px; margin-left: auto; padding-top: 14px; border-top: 1px solid var(--line); }

.totals > div { display: flex; justify-content: space-between; gap: 20px; color: var(--muted); font-size: 12px; }

.totals .grand-total { margin-top: 2px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--ink-strong); font-size: 15px; font-weight: 650; }

details.advanced { border: 1px solid var(--line); border-radius: 9px; background: #fff; }

details.advanced summary { padding: 12px 14px; color: var(--ink-strong); font-size: 12px; font-weight: 570; cursor: pointer; }

details.advanced[open] summary { border-bottom: 1px solid var(--line); }

details.advanced > :not(summary) { margin: 14px; }

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

.template-card { min-width: 0; overflow: hidden; transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease; }

.template-card:hover { transform: translateY(-2px); border-color: #c5d4d0; box-shadow: 0 5px 16px rgb(31 48 48 / 8%); }

.template-preview { display: grid; min-height: 176px; place-items: center; padding: 22px; background: #eef1ee; }

.template-preview > * { width: min(100%, 180px); min-height: 126px; padding: 14px; border: 1px solid #e4e8e4; background: #fff; box-shadow: 0 2px 7px rgb(22 40 38 / 7%); }

.template-card-body { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 15px; }

.template-card-body h2,
.template-card-body h3 { margin: 0 0 3px; color: var(--ink-strong); font-size: 12px; font-weight: 620; }

.template-card-body p { margin: 0; color: var(--muted); font-size: 10px; }

.template-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(190px, 260px); gap: 15px; }

textarea.code-editor {
  width: 100%; min-height: 420px; padding: 15px; border: 1px solid #dbe1de; border-radius: 9px; color: #dbe7e4; background: #1c2c32;
  font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; line-height: 1.65; tab-size: 2; resize: vertical;
}

.variable-list { display: flex; align-content: flex-start; flex-wrap: wrap; gap: 7px; }

.variable-chip {
  display: inline-flex; min-height: 25px; align-items: center; padding: 3px 8px; border: 1px solid #dce8e4; border-radius: 6px; color: #376d66; background: #f1f7f4;
  font-family: "Cascadia Code", Consolas, monospace; font-size: 10px;
}

.modal-overlay {
  position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; overflow-y: auto; padding: 20px; background: rgb(17 31 36 / 48%); backdrop-filter: blur(2px);
}

.modal {
  width: min(100%, 540px); max-height: min(90vh, 760px); overflow: auto; border: 1px solid rgb(255 255 255 / 60%); border-radius: var(--radius-lg); background: #fff;
  box-shadow: 0 24px 70px rgb(16 29 32 / 22%);
}

.modal-header,
.modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; }

.modal-header { border-bottom: 1px solid var(--line); }

.modal-header h2 { margin: 0; color: var(--ink-strong); font-size: 15px; }

.modal-body { display: grid; gap: 16px; padding: 20px; }

.modal-footer { justify-content: flex-end; border-top: 1px solid var(--line); background: #fbfcfa; }

.toast {
  position: fixed; z-index: 60; right: 22px; bottom: 22px; display: flex; max-width: min(420px, calc(100vw - 32px)); align-items: center; gap: 10px; padding: 12px 15px;
  border: 1px solid #cfe2d7; border-radius: 9px; color: #285f4b; background: #f4faf6; box-shadow: 0 8px 26px rgb(26 47 42 / 14%); font-size: 12px;
}

.toast.error { border-color: #efd3d0; color: var(--danger); background: #fff7f6; }

.integration-card { display: grid; align-content: start; gap: 12px; padding: 18px; }

.integration-card h2,
.integration-card h3 { margin: 0; color: var(--ink-strong); font-size: 13px; }

.integration-card p { margin: 0; color: var(--muted); font-size: 11px; }

.integration-status { display: inline-flex; align-items: center; gap: 7px; color: var(--success); font-size: 11px; font-weight: 600; }

.integration-status.disconnected::before { background: #adb6b6; }

.notice { padding: 12px 14px; border: 1px solid #d7e5df; border-radius: 8px; color: #426457; background: #f1f7f3; font-size: 12px; }

.notice.warning { border-color: #eeddb6; color: #806022; background: #fcf7e9; }

.notice.success { border-color: #cfe3d5; color: #38674e; background: #f0f8f2; }

.notice.error { border-color: #efd2cf; color: #8c4642; background: #fff5f3; }

.source-card { display: flex; align-items: flex-start; gap: 13px; padding: 16px; }

.source-card > svg { color: var(--accent); }

.source-card h2,
.source-card h3 { margin: 0 0 4px; color: var(--ink-strong); font-size: 12px; }

.source-card p { margin: 0; color: var(--muted); font-size: 11px; }

.version-list { display: grid; gap: 0; }

.version-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--line); }

.version-row:last-child { border-bottom: 0; }

.split-header { justify-content: space-between; margin-bottom: 18px; }

.split-header h2,
.split-header h3 { margin: 0; color: var(--ink-strong); font-size: 14px; }

.muted { color: var(--muted); }

.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: .92em; }

.visually-hidden {
  position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important; white-space: nowrap !important;
}

.hidden { display: none !important; }

.loading {
  position: relative; min-height: 80px; overflow: hidden; border-radius: 7px; background: linear-gradient(90deg, #eff1ee 25%, #f8f9f7 38%, #eff1ee 63%);
  background-size: 400% 100%; animation: loading-shimmer 1.4s ease infinite;
}

@keyframes loading-shimmer {
  to { background-position: -100% 0; }
}

.mobile-menu { display: none; }

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .template-grid,
  .integration-grid,
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1000px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr); }

  .preview-panel { position: static; }

  .preview-panel iframe { height: min(75vh, 1000px); }

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

@media (max-width: 700px) {
  .sidebar { display: none; }

  .app-shell.menu-open .sidebar { display: flex; width: min(280px, calc(100vw - 48px)); box-shadow: 15px 0 40px rgb(9 20 24 / 23%); }

  .workspace { width: 100%; margin-left: 0; }

  .topbar { min-height: 56px; gap: 10px; padding: 0 16px; }

  .mobile-menu {
  display: inline-grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fff;
  }

  .connection-badge { display: none; }

  main#content { padding: 25px 17px 40px; }

  .page-header { align-items: flex-start; flex-direction: column; gap: 14px; margin-bottom: 19px; }

  .page-actions { width: 100%; }

  .stats-grid { gap: 10px; }

  .stat-card { padding: 14px; }

  .stat-value { font-size: 21px; }

  .toolbar { align-items: stretch; flex-direction: column; }

  .search { width: 100%; }

  .filter-tabs { width: 100%; }

  .document-table { overflow-x: auto; }

  .table-wrap { border-radius: inherit; }

  .sidebar.open { display: flex; z-index: 40; box-shadow: 0 0 0 100vw rgb(0 0 0 / 25%); }

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

  .field.full { grid-column: auto; }

  .template-grid,
  .integration-grid,
  .settings-grid { grid-template-columns: minmax(0, 1fr); }

  .template-preview { min-height: 150px; }

  .panel-header,
  .panel-body { padding-right: 14px; padding-left: 14px; }

  .modal-overlay { align-items: end; padding: 10px; }

  .modal { max-height: 92vh; border-radius: 14px; }

  .toast { right: 12px; bottom: 12px; left: 12px; max-width: none; }
}

@media (max-width: 380px) {
  main#content { padding-right: 13px; padding-left: 13px; }

  .page-actions .button { flex: 1 1 auto; padding-right: 9px; padding-left: 9px; }

  .stats-grid { gap: 8px; }

  .stat-card { padding: 12px 10px; }

  .stat-label { font-size: 10px; }

  .modal-header,
  .modal-footer { padding-right: 14px; padding-left: 14px; }

  .modal-footer .button { flex: 1 1 0; min-width: 0; padding-right: 7px; padding-left: 7px; white-space: normal; }
}

@container (max-width: 560px) {
  .line-options { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
}

@container (max-width: 370px) {
  .line-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
