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

:root {
  --bg: #0d0f14;
  --bg2: #141720;
  --bg3: #1c2030;
  --border: #252a3a;
  --accent: #4f6ef7;
  --accent2: #3a56e0;
  --orange: #ff9800;
  --orange-rgb: 255, 152, 0;
  --text: #e4e8f5;
  --text2: #8a93b2;
  --text3: #545e7a;
  --green: #2dd67a;
  --red: #f74f4f;
  --yellow: #f7c84f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  letter-spacing: 0.5px;
}

.logo-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(79,110,247,0.15); color: var(--accent); }

/* ===== MAIN ===== */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  background: var(--bg);
}

.page { display: none; }
.page.active { display: block; }

/* ===== PAGE HEADER ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-title { font-size: 24px; font-weight: 700; }
.page-subtitle { font-size: 14px; color: var(--text2); margin-top: 4px; }

/* ===== CARDS ===== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-label {
  font-size: 12px;
  color: var(--text2);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.card-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.card-sub { font-size: 12px; color: var(--text3); }

/* ===== CHART CARD ===== */
.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 28px;
}

.chart-title { font-size: 15px; font-weight: 600; margin-bottom: 20px; }
.chart-wrap { height: 180px; position: relative; }

/* ===== TABLE ===== */
.table-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.table-title { font-size: 15px; font-weight: 600; }

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

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 14px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  /* white-space: nowrap; - Убираем, чтобы текст переносился */
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.link { color: var(--accent); cursor: pointer; font-weight: 500; }
.link:hover { text-decoration: underline; }

/* ===== FILTERS ===== */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  width: 280px;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }

select.search-input { cursor: pointer; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost { background: var(--bg3); color: var(--text2); }
.btn-ghost:hover { color: var(--text); background: var(--border); }
.btn-danger { background: rgba(247,79,79,0.1); color: var(--red); }
.btn-danger:hover { background: rgba(247,79,79,0.2); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ===== FORM ===== */
.form-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-input, .form-select, .form-textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
}

.form-textarea { resize: vertical; min-height: 80px; }
.form-select { cursor: pointer; }

.form-input[type="number"] { text-align: right; }

.number-block {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.number-display {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.number-manual-toggle {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.checkbox-row label { font-size: 14px; color: var(--text2); cursor: pointer; }

.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
}

.input-rub {
  position: relative;
}

.input-rub .form-input {
  padding-right: 32px;
}

.input-rub::after {
  content: '₽';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  font-size: 14px;
  pointer-events: none;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 28px;
}

/* ===== AUTOCOMPLETE ===== */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}

.autocomplete-item:hover { background: var(--border); }
.autocomplete-item .sub { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ===== BADGE ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-tc { background: rgba(79,110,247,0.15); color: var(--accent); }
.badge-bc { background: rgba(45,214,122,0.15); color: var(--green); }
.badge-other { background: rgba(138,147,178,0.15); color: var(--text2); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 480px;
  max-width: 90vw;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-lg {
  width: 900px;
  max-width: 95vw;
}

.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 500;
  z-index: 2000;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.25s;
  box-shadow: var(--shadow);
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ===== EMPTY STATE ===== */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text3);
}

.empty-state svg { width: 48px; height: 48px; fill: var(--text3); margin-bottom: 16px; }
.empty-state h3 { font-size: 16px; color: var(--text2); margin-bottom: 8px; }
.empty-state p { font-size: 13px; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ===== ACTION BUTTONS ===== */
.action-btns { display: flex; gap: 6px; }
.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text2);
  transition: all 0.15s;
}

.icon-btn svg { width: 14px; height: 14px; fill: currentColor; }
.icon-btn:hover { color: var(--text); background: var(--border); }
.icon-btn.del:hover { color: var(--red); border-color: var(--red); }

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.nav-item.loading svg {
  animation: spin 1s linear infinite;
}

/* ===== YEAR TABS ===== */
.year-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.year-tab {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
  transition: all 0.15s;
}

.year-tab:hover { border-color: var(--accent); color: var(--accent); }
.year-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== THEME SWITCHER ===== */
.sidebar-footer {
  flex-shrink: 0;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.theme-switcher {
  display: flex;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px;
}

.theme-btn {
  flex: 1;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-btn svg { width: 14px; height: 14px; fill: currentColor; }
.theme-btn:hover { color: var(--text2); }
.theme-btn.active { background: var(--bg2); color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
  --bg: #f5f7fa;
  --bg2: #ffffff;
  --bg3: #edf1f7;
  --border: #e1e6ef;
  --text: #1a1d23;
  --text2: #64748b;
  --text3: #94a3b8;
  --shadow: 0 4px 20px rgba(0,0,0,0.05);
}

[data-theme="light"] tr:hover td { background: rgba(0,0,0,0.01); }
[data-theme="light"] .theme-btn.active { box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
[data-theme="light"] .modal-overlay { background: rgba(0,0,0,0.3); }
[data-theme="light"] .number-display { color: var(--accent); }
[data-theme="light"] .form-input:focus, [data-theme="light"] .form-select:focus, [data-theme="light"] .form-textarea:focus { background: var(--bg2); }
.autocomplete-item.active { background: var(--accent); color: white; }
.autocomplete-item.active .sub { color: rgba(255,255,255,0.7); }

/* ===== CP PRINT STYLES (Common for Print & PDF) ===== */
.cp-page {
  padding: 5mm;
  font-family: Arial, sans-serif;
  color: #000;
  background: white;
}

.cp-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 40px;
  border-bottom: 2px solid #333;
  padding-bottom: 20px;
}

.cp-logo { font-size: 32px; font-weight: 800; color: #4f6ef7; }
.cp-logo img { height: 24px; width: auto; }
.cp-company-info { text-align: right; font-size: 7pt; line-height: 1.2; color: #000; }

.cp-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 30px;
  text-transform: none;
  color: #000;
}

.cp-details { margin-bottom: 30px; color: #000; }
.cp-detail-row { margin-bottom: 8px; font-size: 14px; }
.cp-detail-label { font-weight: 700; width: 150px; display: inline-block; }

.cp-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 30px;
}

.cp-table th, .cp-table td {
  border: 1px solid #333;
  padding: 4px 8px;
  font-size: 13px;
  text-align: left;
  color: #000;
}

.cp-table th { background: #f0f0f0; }
.cp-table .num { text-align: center; }
.cp-table .right { text-align: right; }

.cp-total {
  text-align: right;
  font-size: 18px;
  font-weight: 700;
  margin-top: 20px;
  color: #000;
}

.cp-footer {
  margin-top: 60px;
  display: flex;
  justify-content: space-between;
  color: #000;
}

.cp-sign {
  border-top: 1px solid #000;
  width: 200px;
  text-align: center;
  padding-top: 5px;
  font-size: 12px;
  margin-top: 40px;
}

/* ===== PRINT STYLES ===== */
@media print {
  body { background: white; color: black !important; overflow: visible; height: auto; }
  .sidebar, .main, .modal-overlay, .toast, .btn, .icon-btn, .filters { display: none !important; }
  #app { display: block; height: auto; }
  .print-only { display: block !important; visibility: visible; position: static; width: 100%; }
}

.print-only { display: none; }

/* ===== PRINT DOCUMENTS (KS-2, KS-3, ACT) ===== */
.print-doc { font-family: Arial, sans-serif; color: #000; line-height: 1.2; padding: 20px; }

/* ===== KS-2 UNIFIED FORM STYLES ===== */
.ks2-unified { font-size: 10px; line-height: 1.1; color: #000; }
.ks2-unified td, .ks2-unified th { border: none; padding: 2px 4px; }
.ks2-unified .ks-border { border: 1px solid #000 !important; }
.ks2-unified .ks-center { text-align: center; }
.ks2-unified .ks-right { text-align: right; }
.ks2-unified .ks-bold { font-weight: bold; }

.ks2-top-right { text-align: right; font-size: 8px; margin-bottom: 10px; }
.ks2-header-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.ks2-header-table .ks-label { font-size: 9px; vertical-align: bottom; }
.ks2-header-table .ks-label-okpo { text-align: right; font-size: 9px; padding-right: 10px; }
.ks2-header-table .ks-field-row { border-bottom: 1px solid #000; padding-top: 5px; }
.ks2-header-table .ks-value { font-weight: bold; }

.ks2-contract-info { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.ks2-contract-info .ks-label { font-size: 9px; text-align: right; padding-right: 5px; }

.ks2-doc-meta { display: flex; justify-content: flex-end; margin-bottom: 20px; }
.ks2-meta-table { border-collapse: collapse; }
.ks2-meta-table th, .ks2-meta-table td { border: 1px solid #000 !important; text-align: center; padding: 4px; }
.ks2-meta-table thead th { background: #f0f0f0; font-weight: normal; }

.ks2-title { text-align: center; font-weight: bold; font-size: 14px; margin-bottom: 20px; line-height: 1.2; }

.ks2-data-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; table-layout: fixed; }
.ks2-data-table th, .ks2-data-table td { border: 1px solid #000 !important; font-size: 9px; word-wrap: break-word; overflow: hidden; padding: 4px 3px; }
.ks2-data-table thead th { background: #f0f0f0; font-weight: bold; vertical-align: middle; padding: 6px 2px; text-align: center; line-height: 1.1; }
.ks2-data-table .ks-col-nums td { text-align: center; background: #f9f9f9; height: 15px; font-size: 8px; color: #555; }
.ks2-data-table .ks-section-row td { background: #e8e8e8; font-weight: bold; padding: 5px; }
.ks2-data-table .ks-total-row td { padding: 5px 3px; }
.ks2-data-table .ks-final { background: #f5f5f5; }

.ks2-total-row td { border-top: 2px solid #000 !important; padding: 4px; }
.ks2-total-row.ks-final td { border-bottom: 2px solid #000 !important; }

/* Force landscape orientation for specific forms */
@page landscape-page {
  size: A4 landscape;
  margin: 10mm;
}

.print-landscape {
  page: landscape-page;
}

/* Container for PDF generation to ensure correct sizing */
.pdf-export-container {
  background: white;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100000; /* High z-index to be on top */
  box-sizing: border-box;
  visibility: visible;
  box-shadow: 0 0 100px rgba(0,0,0,0.5); /* Visual cue */
}
.pdf-export-container.landscape {
  width: 297mm;
  padding: 10mm;
}
.pdf-export-container.portrait {
  width: 210mm;
  padding: 10mm;
}

@media print {
  body.print-landscape {
    width: 100%;
  }
  .ks2-unified {
    width: 100% !important;
  }
}

.ks-footer-note { font-size: 9px; margin-bottom: 30px; }

/* Act Editor Table Styles (mimicking KS-2 print form) */
.ks2-editor-table table { border-collapse: collapse; width: 100%; border: 2px solid #000; table-layout: fixed; background: #fff; }
.ks2-editor-table th, .ks2-editor-table td { border: 1px solid #000 !important; padding: 4px; font-size: 11px; vertical-align: middle; color: #000 !important; }
.ks2-editor-table thead th { background: #f2f2f2; font-weight: bold; text-align: center; line-height: 1.2; padding: 8px 4px; }
.ks2-editor-table .ks-col-nums td { background: #fff; text-align: center; height: 18px; font-size: 10px; }
.ks2-editor-table .is-section td { background: #f0f0f0 !important; font-weight: bold; border-top: 2px solid #000 !important; }
.ks2-editor-table .est-input { background: transparent; border: 1px solid transparent; width: 100%; font-size: 11px; padding: 2px 4px; }
.ks2-editor-table .est-input:focus { border-color: var(--accent); background: #fff; }
.ks2-editor-table .row-num { text-align: center; font-weight: bold; }
.ks2-editor-table .ks-right { text-align: right; }
.ks2-editor-table .autocomplete-wrap { position: relative; }
.ks2-editor-table .type-badge { transform: scale(0.8); cursor: pointer; }
.ks2-editor-table .move-btns-wrap { opacity: 0.3; transition: opacity 0.2s; }
.ks2-editor-table tr:hover .move-btns-wrap { opacity: 1; }
.ks2-editor-table .action-btn { opacity: 0.5; }
.ks2-editor-table tr:hover .action-btn { opacity: 1; }

.ks2-signatures { width: 100%; border-collapse: collapse; margin-top: 20px; }
.ks2-signatures td { padding: 5px; }

/* ===== KS-3 UNIFIED FORM STYLES ===== */
.ks3-unified { font-size: 10px; line-height: 1.1; color: #000; }
.ks3-unified td, .ks3-unified th { border: none; padding: 2px 4px; }
.ks3-unified .ks-border { border: 1px solid #000 !important; }
.ks3-unified .ks-center { text-align: center; }
.ks3-unified .ks-right { text-align: right; }
.ks3-unified .ks-bold { font-weight: bold; }

.ks-top-right { text-align: right; font-size: 8px; margin-bottom: 10px; }
.ks-header-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.ks-header-table .ks-label { font-size: 9px; vertical-align: bottom; }
.ks-header-table .ks-label-okpo { text-align: right; font-size: 9px; padding-right: 10px; }
.ks-header-table .ks-field-row { border-bottom: 1px solid #000; padding-top: 5px; }
.ks-header-table .ks-value { font-weight: bold; }

.ks-contract-info { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.ks-contract-info .ks-label { font-size: 9px; text-align: right; padding-right: 5px; }

.ks-doc-meta { display: flex; justify-content: flex-end; margin-bottom: 20px; }
.ks-meta-table { border-collapse: collapse; }
.ks-meta-table th, .ks-meta-table td { border: 1px solid #000 !important; text-align: center; padding: 4px; }
.ks-meta-table thead th { background: #f0f0f0; font-weight: normal; }

.ks-title { text-align: center; font-weight: bold; font-size: 14px; margin-bottom: 20px; line-height: 1.2; }

.ks3-data-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; table-layout: fixed; }
.ks3-data-table th, .ks3-data-table td { border: 1px solid #000 !important; font-size: 9px; word-wrap: break-word; }
.ks3-data-table thead th { background: #f0f0f0; font-weight: normal; vertical-align: middle; padding: 4px 2px; }
.ks3-data-table .ks-col-nums td { text-align: center; background: #f9f9f9; height: 15px; }

.ks3-data-table tfoot td { padding: 6px; }

.ks-signatures { width: 100%; border-collapse: collapse; margin-top: 20px; }
.ks-signatures td { padding: 5px; }

.ks-header-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; font-size: 12px; }
.ks-meta-table { border-collapse: collapse; margin: 0 auto; font-size: 11px; }
.ks-meta-table th, .ks-meta-table td { border: 1px solid #000; padding: 4px 8px; text-align: center; }
.ks-data-table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: 11px; }
.ks-data-table th, .ks-data-table td { border: 1px solid #000; padding: 4px; }
.type-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  user-select: none;
}

.type-badge:hover { transform: scale(1.05); }
.type-badge:active { transform: scale(0.95); }

.type-badge.work {
  background: rgba(var(--accent-rgb), 0.15);
  color: var(--accent);
  border: 1px solid rgba(var(--accent-rgb), 0.3);
}

.type-badge.material {
  background: rgba(var(--orange-rgb), 0.15);
  color: var(--orange);
  border: 1px solid rgba(var(--orange-rgb), 0.3);
}

.est-item-row.is-section {
  background: rgba(var(--accent-rgb), 0.03);
}

.est-item-row:hover {
  background: rgba(255,255,255,0.02);
}
.ks-signatures { margin-top: 40px; display: flex; justify-content: space-between; font-size: 12px; }
.sig-block { width: 45%; }
.sig-line { border-bottom: 1px solid #000; margin-top: 20px; padding-bottom: 4px; }

/* ===== ESTIMATE SPECIFIC ===== */
.est-item-row.is-section { background: rgba(79, 110, 247, 0.1); font-weight: 700; }
.est-item-row.is-section td { border-bottom: 2px solid var(--accent); }
.row-actions { display: flex; gap: 4px; }
.move-btns-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.move-row-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1;
  border-radius: 3px;
  transition: all 0.2s;
}
.move-row-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ===== ESTIMATE SPECIFIC ===== */
.est-table {
  width: 100%;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.est-table th { background: var(--bg3); }
.est-table td { padding: 8px 12px; }

.est-input {
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  min-width: 0;
}

.est-input:focus { border-color: var(--accent); background: var(--bg3); }
.est-input[type="number"] { text-align: right; min-width: 0; }

/* Ячейки таблицы сметы не переполняются */
#est-items-table td { overflow: hidden; }
.work-qty-input, .work-weight-input, .work-price-input, .work-discount-input { min-width: 0; width: 100%; }
.work-unit-input { min-width: 0; width: 100%; text-align: center; }

.est-item-row[data-type="work"] .work-weight-input {
  visibility: hidden;
}

.est-total-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 20px;
  margin-top: 20px;
  padding: 16px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
}

.est-total-label { font-size: 14px; font-weight: 600; color: var(--text2); }
.est-total-value { font-size: 20px; font-weight: 700; color: var(--accent); }

.badge-status-draft { background: rgba(138,147,178,0.15); color: var(--text2); }
.badge-status-approved { background: rgba(45,214,122,0.15); color: var(--green); }
.badge-status-contract { background: rgba(79,110,247,0.15); color: var(--accent); }

/* ===== LOGIN SCREEN & LOGOUT ===== */
.login-screen {
  display: none;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
  width: 100%;
}
.login-screen.active {
  display: flex;
}
.login-card {
  width: 380px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-top: 12px;
}
.login-subtitle {
  font-size: 13px;
  color: var(--text2);
  margin-top: 4px;
}
.btn-login {
  width: 100%;
  justify-content: center;
  height: 42px;
  font-size: 14px;
  margin-top: 24px;
}
.btn-logout {
  width: 100%;
  border: none;
  background: transparent;
  cursor: pointer;
  margin-bottom: 12px;
  color: var(--red) !important;
  transition: all 0.15s;
}
.btn-logout:hover {
  background: rgba(247, 79, 79, 0.1) !important;
  color: var(--red) !important;
}

/* ===== ESTIMATE CARD MODAL ===== */
.est-card-grid {
  display: grid;
  grid-template-columns: 2fr 1.2fr;
  gap: 24px;
  margin-top: 8px;
}
.est-card-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.est-card-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.est-card-calc-panel {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.est-card-calc-title {
  margin: 0 0 4px 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.est-card-metric-label {
  font-size: 11px;
  color: var(--text2);
  margin-bottom: 2px;
}
.est-card-metric-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.est-card-metric-value.large {
  font-size: 22px;
  font-weight: 700;
}
.est-card-metric-value.green {
  color: var(--green);
}
.est-card-metric-value.orange {
  color: var(--orange);
}
.est-card-metric-value.red {
  color: var(--red);
}
.est-card-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}
.est-card-badges-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.card-btn svg {
  transition: transform 0.2s ease;
}
.card-btn:hover svg {
  transform: scale(1.15);
}

/* ===== MODAL HEADER CLOSE CROSS STYLE ===== */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header .modal-title {
  margin-bottom: 0;
}

/* ============ VIEWER READ-ONLY ROLE ADJUSTMENTS ============ */
body.role-viewer .btn-primary:not(.btn-close),
body.role-viewer .icon-btn.del,
body.role-viewer button.del,
body.role-viewer .btn-danger,
body.role-viewer button[onclick*="delete"],
body.role-viewer button[onclick*="showBulkUpdateModal"],
body.role-viewer button[onclick*="showUserModal"],
body.role-viewer button[onclick*="showMaterialModal"],
body.role-viewer button[onclick*="showOurOrgModal"],
body.role-viewer button[onclick*="showWorkModal"],
body.role-viewer button[onclick*="showOrgModal"],
body.role-viewer button[onclick*="showObjModal"],
body.role-viewer button[onclick*="save"],
body.role-viewer button.add-row-btn,
body.role-viewer button.delete-row-btn,
body.role-viewer .estimate-actions button:not(.btn-secondary),
body.role-viewer #contract-form-el button[type="submit"],
body.role-viewer #estimate-form-el button[type="submit"],
body.role-viewer .form-actions button:not(.btn-secondary) {
  display: none !important;
}

body.role-viewer input:disabled,
body.role-viewer select:disabled,
body.role-viewer textarea:disabled {
  background-color: var(--bg2) !important;
  color: var(--text2) !important;
  cursor: not-allowed;
  opacity: 0.85;
  border-color: var(--border) !important;
}

/* ===== DOCUMENTATION (ABOUT) SECTION ===== */
.doc-layout {
  display: flex;
  gap: 28px;
  align-items: stretch;
  min-height: 550px;
}
.doc-sidebar {
  width: 240px;
  border-right: 1px solid var(--border);
  padding-right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.doc-tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text2);
  padding: 10px 16px;
  text-align: left;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.doc-tab-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  opacity: 0.8;
}
.doc-tab-btn:hover {
  background: var(--bg3);
  color: var(--text);
}
.doc-tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.doc-content {
  flex: 1;
  padding-left: 10px;
  overflow-y: auto;
  max-height: 750px;
}
.doc-section {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}
.doc-section.active {
  display: block;
}
.doc-h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.doc-h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text2);
  margin-top: 24px;
  margin-bottom: 12px;
}
.doc-p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text2);
  margin-bottom: 16px;
}
.doc-list {
  padding-left: 20px;
  margin-bottom: 16px;
  color: var(--text2);
  font-size: 14px;
  line-height: 1.6;
}
.doc-list li {
  margin-bottom: 8px;
}
.doc-feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 20px;
  margin-bottom: 24px;
}
.doc-feature-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.doc-feature-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.doc-badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  margin-right: 6px;
}


/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Credential Card Printing Styles */
.credential-card-print {
  width: 140mm;
  height: 95mm;
  border: 1.5px dashed #4f6ef7;
  border-radius: 8px;
  padding: 15px;
  box-sizing: border-box;
  background: #ffffff;
  color: #000000;
  font-family: 'Inter', Arial, sans-serif;
  position: relative;
  overflow: hidden;
  margin: 40px auto;
  page-break-inside: avoid;
  box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.card-border-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background: linear-gradient(90deg, #4f6ef7 0%, #2dd67a 100%);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 8px;
  margin-top: 5px;
}

.logo-icon-print {
  background: #4f6ef7;
  color: #ffffff;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.header-text-print h2 {
  font-size: 11px;
  font-weight: 700;
  margin: 0;
  color: #1e293b;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.header-text-print p {
  font-size: 8px;
  color: #64748b;
  margin: 0;
  line-height: 1.2;
}

.card-title-print {
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  margin: 4px 0 12px 0;
  color: #0f172a;
  letter-spacing: 1px;
}

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

.info-grid-print {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.info-row {
  display: flex;
  align-items: baseline;
  font-size: 10px;
  line-height: 1.4;
}

.info-row.divider {
  border-top: 1px solid #f1f5f9;
  margin: 4px 0;
  height: 0;
}

.info-label {
  width: 100px;
  color: #475569;
  font-weight: 500;
  flex-shrink: 0;
}

.info-value {
  color: #0f172a;
  font-weight: 600;
  word-break: break-all;
}

.info-value.company-name {
  font-size: 10px;
  font-weight: 700;
  color: #0f172a;
}

.info-value.code-font {
  font-family: monospace;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  border: 1px solid #e2e8f0;
}

.info-value.url-font {
  font-family: monospace;
  color: #2563eb;
  font-size: 9px;
  font-weight: 700;
}

.info-value.login-font {
  font-weight: 700;
  font-size: 10px;
}

.info-value.password-font {
  font-family: monospace;
  font-weight: 700;
  font-size: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 1px 4px;
  border-radius: 3px;
}

.qr-code-container-print {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid #e2e8f0;
  padding: 6px;
  border-radius: 6px;
  background: #ffffff;
  flex-shrink: 0;
}

.qr-code-img {
  width: 60px;
  height: 60px;
}

.card-footer-print {
  margin-top: 10px;
  border-top: 1px dashed #e2e8f0;
  padding-top: 8px;
}

.card-footer-print h3 {
  font-size: 8px;
  font-weight: 700;
  margin: 0 0 4px 0;
  color: #475569;
}

.card-footer-print ol {
  margin: 0;
  padding-left: 12px;
  font-size: 8px;
  color: #64748b;
  line-height: 1.3;
}

.card-footer-print li {
  margin-bottom: 2px;
}

.support-footer {
  font-size: 7px;
  color: #94a3b8;
  margin-top: 6px;
  text-align: center;
}

@media print {
  .credential-card-print {
    margin: 20mm auto;
    border: 1.5px dashed #4f6ef7 !important;
    box-shadow: none !important;
    page-break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
