* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: #f4f6f8;
  color: #1f2937;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: #0f2b46; }
code {
  background: #eef2f7; padding: 1px 5px; border-radius: 4px;
  font-family: monospace; font-size: 13px;
}
.muted { color: #94a3b8; font-size: 13px; font-weight: 400; }

/* Header */
header {
  background: #0f2b46;
  color: #fff;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(15,43,70,.15);
}
header .logo { font-weight: 700; font-size: 18px; }
nav a {
  color: #cbd5e1;
  text-decoration: none;
  margin-left: 20px;
  font-size: 14px;
  padding: 6px 0;
  border-bottom: 2px solid transparent;
  transition: .15s;
}
nav a:hover { color: #fff; }
nav a.active { color: #fff; border-bottom-color: #4da3ff; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px; }

/* Page head */
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 24px; color: #0f2b46; margin-bottom: 4px; }
.page-head p { color: #64748b; font-size: 14px; }

/* Hero */
.hero {
  background: linear-gradient(135deg, #0f2b46 0%, #1a3f63 100%);
  color: #fff;
  border-radius: 16px;
  padding: 40px;
  margin-bottom: 24px;
  box-shadow: 0 8px 24px rgba(15,43,70,.15);
}
.hero h1 { font-size: 26px; margin-bottom: 8px; font-weight: 700; }
.hero p { color: #cbd5e1; font-size: 15px; margin-bottom: 20px; }
.hero-small { padding: 24px; }

.search-box { display: flex; gap: 8px; }
.search-box input {
  flex: 1;
  padding: 14px 18px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  background: rgba(255,255,255,.95);
  color: #1f2937;
}
.search-box input:focus { box-shadow: 0 0 0 3px rgba(77,163,255,.4); }
.search-box button {
  background: #4da3ff;
  color: #fff;
  border: none;
  padding: 14px 28px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
.search-box button:hover { background: #2b8ae6; }

/* Cards */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  margin-bottom: 20px;
}
.card h2 { font-size: 17px; margin-bottom: 16px; color: #0f2b46; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  text-align: center;
}
.stat-icon { font-size: 28px; margin-bottom: 8px; }
.stat-num { font-size: 28px; font-weight: 700; color: #0f2b46; }
.stat-lbl { font-size: 13px; color: #64748b; }

/* Quick links */
.quick-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.quick-link {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  transition: .15s;
}
.quick-link:hover {
  box-shadow: 0 4px 16px rgba(15,43,70,.12);
  transform: translateY(-2px);
}
.ql-icon { font-size: 32px; }
.ql-title { font-weight: 600; color: #0f2b46; margin-bottom: 2px; }
.ql-count { font-size: 13px; color: #64748b; }

/* Result (search) */
.result {
  display: flex;
  gap: 16px;
  padding: 16px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  border: 1px solid transparent;
  transition: .15s;
}
.result:hover { background: #f8fafc; border-color: #eef2f7; }
.result-icon {
  font-size: 24px;
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  border-radius: 10px;
}
.result-body { flex: 1; min-width: 0; }
.result .title { font-weight: 600; color: #0f2b46; margin-bottom: 4px; font-size: 15px; }
.result .meta { font-size: 12px; color: #64748b; margin-bottom: 6px; }
.result .snippet { font-size: 13px; color: #334155; line-height: 1.5; }
mark { background: #fff3a3; padding: 0 2px; border-radius: 2px; }

/* Badges */
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-right: 6px;
  font-weight: 500;
}
.badge.actual { background: #dcfce7; color: #166534; }
.badge.archive { background: #fee2e2; color: #991b1b; }
.badge.project { background: #fef3c7; color: #92400e; }

/* Templates list */
.tpl-list { display: flex; flex-direction: column; gap: 8px; }
.tpl-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid #eef2f7;
  border-radius: 10px;
  transition: .15s;
}
.tpl-item:hover { border-color: #4da3ff; background: #f8fbff; }
.tpl-icon {
  font-size: 24px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  border-radius: 10px;
  flex: none;
}
.tpl-info { flex: 1; min-width: 0; }
.tpl-name { font-weight: 600; color: #0f2b46; margin-bottom: 2px; }
.tpl-desc { font-size: 13px; color: #64748b; }
.tpl-actions { display: flex; gap: 8px; flex: none; }

/* Docs list */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid #eef2f7;
  border-radius: 10px;
  transition: .15s;
}
.doc-item:hover { border-color: #4da3ff; background: #f8fbff; }
.doc-item-icon {
  font-size: 24px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: #f1f5f9; border-radius: 10px; flex: none;
}
.doc-item-body { flex: 1; min-width: 0; }
.doc-item-title {
  font-weight: 600;
  color: #0f2b46;
  text-decoration: none;
  font-size: 15px;
  display: block;
  margin-bottom: 4px;
}
.doc-item-title:hover { color: #4da3ff; }
.doc-item-meta { font-size: 12px; color: #64748b; }
.doc-item-actions { display: flex; gap: 8px; flex: none; }

/* Tabs */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 8px 16px;
  border-radius: 8px;
  background: #fff;
  color: #475569;
  text-decoration: none;
  font-size: 14px;
  border: 1px solid #eef2f7;
  transition: .15s;
}
.tab:hover { background: #f8fafc; }
.tab.active { background: #0f2b46; color: #fff; border-color: #0f2b46; }

/* Document view */
.doc-header {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  margin-bottom: 20px;
}
.doc-header-top { display: flex; gap: 20px; align-items: flex-start; }
.doc-icon {
  font-size: 32px;
  width: 60px; height: 60px;
  display: flex; align-items: center; justify-content: center;
  background: #f1f5f9; border-radius: 12px; flex: none;
}
.doc-header h1 { font-size: 22px; color: #0f2b46; margin-bottom: 8px; }
.doc-meta {
  display: flex; flex-wrap: wrap; gap: 6px 12px;
  font-size: 13px; color: #64748b; align-items: center;
}
.meta-item { display: inline-block; }
.doc-info {
  margin-top: 16px; padding-top: 16px; border-top: 1px solid #eef2f7;
  display: flex; gap: 24px; flex-wrap: wrap; font-size: 14px; color: #475569;
}

.doc-card { padding: 32px; }
.doc-content {
  font-size: 15px;
  line-height: 1.7;
  color: #1f2937;
  max-width: 800px;
}
.doc-content p { margin-bottom: 12px; }
.doc-content p.doc-num { padding-left: 0; }

.file-attach {
  display: flex; align-items: center; gap: 8px; font-size: 14px;
}
.file-link { color: #0f2b46; text-decoration: none; font-weight: 500; }
.file-link:hover { text-decoration: underline; }

.doc-actions {
  display: flex; justify-content: space-between; gap: 10px; margin-bottom: 20px;
}

/* Forms */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-row.full { grid-template-columns: 1fr; }
.form-row label {
  display: block; font-size: 13px; color: #475569;
  margin-bottom: 6px; font-weight: 500;
}
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: .15s;
  background: #fff;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  border-color: #4da3ff;
  box-shadow: 0 0 0 3px rgba(77,163,255,.15);
}
.form-row textarea { resize: vertical; min-height: 80px; }
.form-actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;
  padding-top: 16px; border-top: 1px solid #eef2f7;
}

/* Buttons */
.btn, .btn-primary, .btn-secondary, .btn-danger {
  display: inline-block;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: .15s;
  white-space: nowrap;
}
.btn { background: #4da3ff; color: #fff; padding: 8px 16px; font-size: 13px; }
.btn:hover { background: #2b8ae6; }
.btn-primary { background: #0f2b46; color: #fff; }
.btn-primary:hover { background: #1a3f63; }
.btn-secondary { background: #eef2f7; color: #334155; }
.btn-secondary:hover { background: #dbe4ee; }
.btn-danger { background: #fee2e2; color: #991b1b; padding: 8px 16px; font-size: 13px; }
.btn-danger:hover { background: #fecaca; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* Empty state */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: #94a3b8;
  font-size: 14px;
}
.empty .big { font-size: 48px; margin-bottom: 16px; }

/* Responsive */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-links { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .container { padding: 16px; }
  header { padding: 12px 16px; }
  nav a { margin-left: 12px; font-size: 13px; }
  .hero { padding: 24px; }
  .hero h1 { font-size: 20px; }
  .form-row { grid-template-columns: 1fr; }
  .doc-header-top { flex-direction: column; }
  .tpl-item, .doc-item { flex-wrap: wrap; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media print {
  header, footer, nav, .no-print, .doc-actions, .tabs { display: none !important; }
  .container { padding: 0; max-width: 100%; }
  .card { box-shadow: none; padding: 0; margin: 0; }
  body { background: #fff; }
}
/* Форматирование содержимого документа */
.doc-content { font-size: 15px; line-height: 1.7; color: #1f2937; max-width: 850px; }
.doc-content h1 { font-size: 22px; margin: 24px 0 12px; color: #0f2b46; }
.doc-content h2 { font-size: 19px; margin: 22px 0 10px; color: #0f2b46; }
.doc-content h3 { font-size: 17px; margin: 20px 0 10px; color: #0f2b46; }
.doc-content h4 { font-size: 15px; margin: 18px 0 8px; color: #0f2b46; }
.doc-content h4.doc-h { font-weight: 700; }
.doc-content p { margin: 0 0 12px; }
.doc-content ul, .doc-content ol { margin: 0 0 12px 24px; }
.doc-content li { margin-bottom: 6px; }
.doc-content table.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13px;
}
.doc-content table.doc-table th,
.doc-content table.doc-table td {
  border: 1px solid #cbd5e1;
  padding: 6px 10px;
  vertical-align: top;
  text-align: left;
}
.doc-content table.doc-table th {
  background: #eef2f7;
  font-weight: 600;
}
/* Панель поиска по документу */
.doc-search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  position: sticky;
  top: 12px;
  z-index: 10;
}
.doc-search-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.doc-search-bar input:focus {
  border-color: #4da3ff;
  box-shadow: 0 0 0 3px rgba(77,163,255,.15);
}
.doc-search-bar button {
  width: 38px;
  height: 38px;
  border: none;
  background: #eef2f7;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  color: #334155;
  transition: .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.doc-search-bar button:hover { background: #dbe4ee; }
.doc-search-count {
  font-size: 13px;
  color: #64748b;
  min-width: 80px;
  text-align: center;
}

/* Подсветка совпадений в документе */
mark.doc-match {
  background: #fff3a3;
  padding: 1px 3px;
  border-radius: 3px;
  scroll-margin-top: 100px;
}
mark.doc-match-active {
  background: #ffb300;
  color: #000;
  box-shadow: 0 0 0 2px #ff8f00;
}

/* Результаты поиска */
.search-summary {
  background: #fff;
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 16px;
  font-size: 14px;
  color: #475569;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.search-result-card { padding: 20px; }
.src-head { display: flex; gap: 16px; margin-bottom: 12px; }
.src-icon {
  font-size: 24px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: #f1f5f9; border-radius: 10px; flex: none;
}
.src-body { flex: 1; min-width: 0; }
.src-title {
  font-weight: 600; color: #0f2b46; font-size: 16px;
  text-decoration: none; display: block; margin-bottom: 4px;
}
.src-title:hover { color: #4da3ff; }
.src-meta { font-size: 12px; color: #64748b; margin-bottom: 6px; }
.src-count { font-size: 13px; color: #334155; }
.src-snippets {
  background: #f8fafc;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.src-snippet {
  font-size: 13px;
  color: #334155;
  line-height: 1.6;
  padding: 4px 0;
  border-bottom: 1px dashed #e2e8f0;
}
.src-snippet:last-child { border-bottom: none; }
.src-snippet mark { background: #fff3a3; padding: 0 2px; border-radius: 2px; }
.src-actions { display: flex; gap: 8px; }
/* Конструктор шаблонов */
.constructor-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  background: #f8fafc;
  border-radius: 10px;
  margin-bottom: 16px;
}

.constructor-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
}

.constructor-editor {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 20px;
  min-height: 400px;
}

.constructor-editor .editable {
  outline: none;
  min-height: 300px;
}
.constructor-editor .editable:focus { box-shadow: 0 0 0 3px rgba(77,163,255,.15); border-radius: 6px; }
.constructor-editor .html-mode {
  font-family: monospace;
  font-size: 12px;
  white-space: pre-wrap;
  color: #475569;
}

.constructor-sidebar {
  background: #f8fafc;
  border-radius: 10px;
  padding: 16px;
  height: fit-content;
  max-height: 600px;
  overflow-y: auto;
}
.constructor-sidebar h3 {
  font-size: 14px;
  margin-bottom: 12px;
  color: #0f2b46;
}

.fields-list { display: flex; flex-direction: column; gap: 8px; }
.field-item {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.field-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.field-item-head b { color: #0f2b46; }
.field-item-head .btn-danger {
  padding: 2px 8px;
  font-size: 11px;
}
.field-item-meta { font-size: 11px; color: #94a3b8; }
.field-item-meta code { font-size: 11px; }

/* Подсветка полей в редакторе */
.tpl-field {
  background: #dbeafe;
  color: #1e40af;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
  font-size: 13px;
  border: 1px solid #93c5fd;
  display: inline-block;
  cursor: default;
}

/* Модалка */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,43,70,.55);
  z-index: 100;
  padding: 24px;
  overflow-y: auto;
}
.modal-bg.open { display: flex; align-items: flex-start; justify-content: center; }
.modal {
  background: #fff;
  border-radius: 12px;
  max-width: 800px;
  width: 100%;
  padding: 24px;
  margin-top: 24px;
}
.modal h3 { margin-bottom: 4px; color: #0f2b46; }
.modal .sub { font-size: 13px; color: #64748b; margin-bottom: 16px; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #eef2f7;
}

@media (max-width: 900px) {
  .constructor-layout { grid-template-columns: 1fr; }
}