:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --row-alt: #f8fafc;
  --topbar-bg: #0f172a;
  --topbar-border: #1e293b;
  /* Layout breakpoints (reference for media queries below) */
  --bp-sm: 768px;
  --bp-md: 1024px;
  --touch-min: 44px;
  --contract-tabs-sticky-h: 52px;
  --sticky-thead-top: 0px;
}

body:has(.contract-tabs-sticky) {
  --sticky-thead-top: var(--contract-tabs-sticky-h);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.45; }

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  background: var(--topbar-bg);
  color: #fff;
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 0 20px;
  min-height: 48px;
  gap: 12px 24px;
  position: relative;
  z-index: 100;
}
.topbar .brand {
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
  text-decoration: none;
}
.topbar .brand:hover { text-decoration: none; color: #fff; }

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-lockup__mark {
  flex-shrink: 0;
}
.brand-lockup__svg {
  display: block;
  vertical-align: middle;
}
.brand-lockup__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  gap: 1px;
  min-width: 0;
}
.brand-lockup__primary {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-lockup__secondary {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.88;
}
.brand-lockup__badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #5eead4;
  margin-top: 2px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  margin-bottom: 4px;
}
.auth-brand .brand-lockup {
  flex-direction: column;
  align-items: center;
  color: #f8fafc;
}
.auth-brand .brand-lockup:hover {
  color: #fff;
  text-decoration: none;
}
.auth-brand .brand-lockup__secondary {
  color: rgba(248, 250, 252, 0.82);
}
.auth-brand__tagline {
  margin: 0;
  font-size: 13px;
  color: rgba(241, 245, 249, 0.85);
  max-width: 22rem;
  line-height: 1.35;
}

.login-shell {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.login-form__title {
  font-size: 20px;
  margin: 0 0 8px;
  text-align: center;
  color: var(--text);
}

.auth-site-footer {
  font-size: 13px;
  color: rgba(241, 245, 249, 0.78);
  text-align: center;
  line-height: 1.45;
}
.auth-site-footer__link {
  color: #5eead4;
  text-decoration: none;
}
.auth-site-footer__link:hover {
  color: #99f6e4;
  text-decoration: underline;
}
.auth-site-footer__sep { margin: 0 6px; opacity: 0.7; }

.site-footer {
  margin-top: 24px;
  padding: 14px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--card);
}
.site-footer__inner {
  max-width: 1400px;
  margin: 0 auto;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}
.site-footer__link {
  color: var(--primary);
  font-weight: 500;
}
.site-footer__link:hover {
  color: var(--primary-hover);
}
.site-footer__sep { opacity: 0.55; }
.site-footer__meta { color: var(--muted); }
.topbar-panel {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 24px;
  min-width: 0;
}

.topbar-panel .user {
  margin-left: auto;
}

.topbar .user {
  color: #d1d5db;
  font-size: 13px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.topbar .user a { color: #5eead4; }
.topbar .user a:hover { color: #99f6e4; text-decoration: underline; }

.global-search {
  position: relative;
  flex: 0 1 240px;
  max-width: 320px;
  min-width: 140px;
}
.global-search input {
  width: 100%;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #374151;
  background: #1f2937;
  color: #fff;
  font-size: 13px;
}
.global-search input::placeholder { color: #9ca3af; }
.global-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  max-height: min(70vh, 420px);
  overflow-y: auto;
  z-index: 200;
}
.global-search-results[hidden] { display: none !important; }
.global-search-group-title {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--row-alt);
  border-bottom: 1px solid var(--border);
}
.global-search a.global-search-item {
  display: block;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.global-search a.global-search-item:hover,
.global-search a.global-search-item:focus {
  background: #ccfbf1;
  outline: none;
}
.global-search-item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.nav-toggle {
  display: none;
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid #4b5563;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-toggle:hover { background: #374151; }

/* Container */
.container { max-width: 1400px; margin: 0 auto; padding: 16px 20px 40px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin: 0 0 16px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head > div { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tabs */
.tabs {
  display: flex; gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.tabs a {
  padding: 8px 14px;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.tabs a:hover { background: var(--bg); text-decoration: none; }
.tabs a.active { background: var(--primary); color: #fff; }

/* Sticky strip: договорные вкладки под топбаром (Акты, Накопительный, …) */
.contract-tabs-sticky {
  position: sticky;
  top: 0;
  z-index: 95;
  margin: 0 0 16px;
  padding-top: 4px;
  padding-bottom: 8px;
  background: var(--bg);
  box-shadow: 0 6px 8px -6px rgba(0, 0, 0, 0.08);
}

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin: 0 0 16px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; }

/* Tables */
.data { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.data th, .data td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.data th { background: #f9fafb; font-weight: 600; font-size: 13px; color: var(--muted); }
.data tr:nth-child(even) td { background: var(--row-alt); }
.data tr:hover td { background: #ecfdf5; }
.data.tight th, .data.tight td { padding: 4px 8px; font-size: 12px; }
.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data .empty { text-align: center; color: var(--muted); padding: 24px; font-style: italic; }

/* Level highlighting in work items */
tr.lvl-1 td { font-weight: 700; background: #fef3c7 !important; }
tr.lvl-2 td { font-weight: 600; background: #fef9e7 !important; }
tr.lvl-3 td { font-weight: 500; background: #fefce8 !important; }
tr.lvl-4 td { font-weight: 400; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: #f9fafb; border: 1px solid var(--border); border-radius: 6px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi b { font-size: 17px; font-variant-numeric: tabular-nums; }
.dashboard-kpis { margin-bottom: 16px; }
.dashboard-kpis .kpi b { font-size: 15px; }

.dashboard-chart-wrap {
  position: relative;
  width: 100%;
  min-height: 220px;
}
.dashboard-chart-wrap canvas:not([hidden]) {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 220px;
}
.dashboard-chart-empty { margin-top: 8px; }

.platform-slice-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.totp-qr-wrap {
  margin: 12px 0 16px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-block;
}
.totp-qr-wrap img {
  display: block;
}
.totp-manual-key { margin: 8px 0; word-break: break-all; }
.totp-secret-key {
  font-family: ui-monospace, monospace;
  font-size: 14px;
  letter-spacing: 0.04em;
}

/* Быстрые действия (главная) */
.home-quick-actions {
  margin: 0 0 20px;
}

.home-quick-actions__heading {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--text);
}

.quick-actions-sprite-host {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.home-quick-actions__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 14px;
}

.quick-action-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 112px;
  padding: 14px 14px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.quick-action-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.18);
  color: inherit;
  text-decoration: none;
  transform: translateY(-1px);
}

.quick-action-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.quick-action-card--primary {
  border-color: #99f6e4;
  background: linear-gradient(180deg, #f0fdfa 0%, var(--card) 52%);
}

.quick-action-card__icon-wrap {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--row-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.quick-action-card--primary .quick-action-card__icon-wrap {
  background: #ccfbf1;
}

.quick-action-card__icon {
  width: 22px;
  height: 22px;
  display: block;
}

.quick-action-card__title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.25;
  color: var(--text);
}

.quick-action-card__desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  margin: 0;
}

@media (max-width: 480px) {
  .home-quick-actions__grid {
    grid-template-columns: 1fr;
  }
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.text-warn { color: var(--warn); }

.wizard-steps {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.wizard-steps span {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
}
.wizard-steps span.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.wizard-steps span.done {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}
.wizard-items input[type="number"] {
  max-width: 100%;
}

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff; color: var(--text);
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18); }
.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; padding-top: 4px; }

.inline-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.inline-form input, .inline-form select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff;
}

/* Filters */
.filters { display: flex; gap: 12px; align-items: end; margin-bottom: 12px; flex-wrap: wrap; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filters input, .filters select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.sort-link { color: inherit; font-weight: 600; text-decoration: none; }
.sort-link:hover { color: var(--primary); text-decoration: underline; }
.col-pin { width: 36px; padding: 4px 6px !important; }
.pin-form { margin: 0; }
.btn-icon {
  padding: 2px 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--warn);
}
.btn-icon:hover { transform: scale(1.15); }
tr.row-pinned td { background: #fffbeb !important; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn.sm { padding: 3px 8px; font-size: 12px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: #e5e7eb;
  color: #374151;
  text-transform: lowercase;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-completed { background: #ccfbf1; color: #115e59; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-suspended { background: #fef3c7; color: #92400e; }
.badge-paid { background: #d1fae5; color: #065f46; }
.badge-approved { background: #ccfbf1; color: #115e59; }
.badge-draft { background: #f3f4f6; color: #374151; }
.badge-submitted { background: #fef3c7; color: #92400e; }
.badge-to-pay { background: #fef3c7; color: #92400e; }
.badge-partially_paid { background: #e0e7ff; color: #3730a3; }

.badge.alert-severity-critical {
  background: #fee2e2;
  color: #991b1b;
  text-transform: none;
}
.badge.alert-severity-warning {
  background: #fef3c7;
  color: #92400e;
  text-transform: none;
}
.badge.alert-severity-info {
  background: #e0f2fe;
  color: #0369a1;
  text-transform: none;
}

.workflow-actions { margin-top: 16px; display: flex; flex-direction: column; gap: 16px; }
.workflow-form { max-width: 520px; }

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--border);
  margin-left: 10px;
}
.timeline li {
  position: relative;
  padding: 10px 0 10px 18px;
}
.timeline li::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent, var(--primary));
}
.timeline-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.timeline-comment { font-size: 13px; margin-top: 6px; color: var(--text); }

/* DL */
dl.kv { display: grid; grid-template-columns: 200px 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; }
dl.kv dd { margin: 0; font-size: 14px; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.alert.error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert.ok { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }

.user-inactive td { opacity: 0.65; }
.user-edit-form, .user-pw-form { margin: 4px 0; }
.user-pw-form { padding-top: 6px; border-top: 1px dashed var(--border); }
label.chk { flex-direction: row !important; align-items: center; gap: 6px; color: var(--text) !important; }
.muted { color: var(--muted); font-size: 12px; }
code.audit-payload {
  display: block;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 420px;
}
.org-banner { margin: 0; border-radius: 0; text-align: center; }
.org-pill { background: #374151; padding: 2px 10px; border-radius: 12px; font-size: 12px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Login */
.login-page {
  background: linear-gradient(155deg, #0f172a 0%, #134e4a 42%, #115e59 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 24px 16px;
}
.login-form {
  background: #fff;
  padding: 32px 28px;
  border-radius: 12px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 22px 48px rgba(15, 23, 42, 0.28);
  border: 1px solid rgba(226, 232, 240, 0.75);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-form h1 { font-size: 20px; margin: 0 0 6px; text-align: center; }
.login-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-form input { padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.login-form button { padding: 10px; background: var(--primary); color: #fff; border: none; border-radius: 6px; font: inherit; cursor: pointer; font-weight: 600; }
.login-form button:hover { background: var(--primary-hover); }
.hint { color: var(--muted); font-size: 12px; margin: 0; text-align: center; }
.hint ul { text-align: left; padding-left: 18px; }
.hint code { background: #f3f4f6; padding: 1px 5px; border-radius: 3px; font-size: 11px; }

/* Billing plans */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.plan-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}
.plan-card h3 { margin: 0; font-size: 16px; }
.plan-price { font-size: 20px; font-weight: 700; margin: 0; color: var(--primary); }
.plan-card label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.plan-card input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.alert.warn { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

.plan-checkout-block { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 16px; }
.plan-checkout-block:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.payment-tabs { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.payment-option { border: 1px solid var(--border); border-radius: 8px; padding: 0 12px 12px; background: var(--bg); }
.payment-option summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
.legal-form label, .inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; margin-top: 8px; }
.legal-form input, .inline-form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }

.platform-bar {
  background: linear-gradient(90deg, #0f172a 0%, #1e293b 50%, #0f766e 160%);
}
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }
.stats-grid > div { text-align: center; padding: 12px; background: var(--bg); border-radius: 8px; }
.stats-grid strong { display: block; font-size: 28px; }
.stats-grid span { color: var(--muted); font-size: 12px; }

/* Horizontal scroll for wide tables (wrapper added by app.js) */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 16px;
  max-width: 100%;
}
.table-scroll .data { min-width: 520px; }

/* Шапка таблицы под топбаром (и под липкими вкладками договора, см. :root / body:has) */
.table-scroll:not(.stack-cards-sm) .data thead th {
  position: sticky;
  top: var(--sticky-thead-top);
  z-index: 30;
  background: #f9fafb;
  box-shadow: 0 1px 0 var(--border);
}

/* Этапы: Gantt-lite по месяцам */
.gantt-scroll {
  margin-bottom: 0;
}
.gantt-lite {
  --gantt-months: 12;
  width: max(100%, calc(200px + var(--gantt-months) * 40px));
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card);
}
.gantt-head {
  display: grid;
  grid-template-columns: minmax(140px, 200px) minmax(0, 1fr);
  gap: 0 10px;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  background: #f9fafb;
}
.gantt-corner {
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  position: sticky;
  left: 0;
  z-index: 4;
  background: #f9fafb;
  border-right: 1px solid var(--border);
}
.gantt-months {
  display: grid;
  grid-template-columns: repeat(var(--gantt-months), minmax(36px, 1fr));
  text-align: center;
}
.gantt-month-cell {
  padding: 8px 4px;
  font-size: 11px;
  color: var(--muted);
  border-left: 1px solid var(--border);
}
.gantt-month-cell:first-child {
  border-left: none;
}
.gantt-month-cell.is-today {
  background: #fef3c7;
  color: var(--text);
  font-weight: 600;
}
.gantt-empty {
  padding: 12px 16px;
  margin: 0;
}
.gantt-row {
  display: grid;
  grid-template-columns: minmax(140px, 200px) minmax(0, 1fr);
  gap: 0 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.gantt-row:last-child {
  border-bottom: none;
}
.gantt-row--overdue {
  background: #fef2f2;
}
.gantt-row--overdue .gantt-label {
  box-shadow: inset 3px 0 0 var(--danger);
}
.gantt-label {
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.35;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card);
  border-right: 1px solid var(--border);
}
.gantt-row--overdue .gantt-label {
  background: #fef2f2;
}
.gantt-label .badge {
  display: inline-block;
  margin-top: 4px;
}
.gantt-track {
  position: relative;
  height: 42px;
  margin: 6px 8px 6px 0;
  background-image: repeating-linear-gradient(
    to right,
    transparent 0,
    transparent calc(100% / var(--gantt-months) - 1px),
    var(--border) calc(100% / var(--gantt-months) - 1px),
    var(--border) calc(100% / var(--gantt-months))
  );
}
.gantt-bar {
  position: absolute;
  height: 13px;
  border-radius: 3px;
  min-width: 4px;
  box-sizing: border-box;
}
.gantt-bar--plan {
  top: 5px;
}
.gantt-bar--fact {
  top: 22px;
}
/* План: контур; факт: заливка */
.gantt-bar--plan.stage-planned {
  background: rgba(148, 163, 184, 0.25);
  border: 2px solid #64748b;
}
.gantt-bar--fact.stage-planned {
  background: #64748b;
}
.gantt-bar--plan.stage-in_progress {
  background: rgba(37, 99, 235, 0.2);
  border: 2px solid var(--primary);
}
.gantt-bar--fact.stage-in_progress {
  background: var(--primary);
}
.gantt-bar--plan.stage-completed {
  background: rgba(5, 150, 105, 0.2);
  border: 2px solid var(--ok);
}
.gantt-bar--fact.stage-completed {
  background: var(--ok);
}
.gantt-bar--plan.stage-on_hold {
  background: rgba(217, 119, 6, 0.2);
  border: 2px solid var(--warn);
}
.gantt-bar--fact.stage-on_hold {
  background: var(--warn);
}
.gantt-no-dates {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
}
.gantt-legend-plan { color: #64748b; letter-spacing: -2px; }
.gantt-legend-fact { color: var(--primary); letter-spacing: -2px; }
.badge-stage-planned { background: #e2e8f0; color: #334155; }
.badge-stage-in_progress { background: #ccfbf1; color: #115e59; }
.badge-stage-completed { background: #d1fae5; color: #065f46; }
.badge-stage-on_hold { background: #fef3c7; color: #92400e; }

/* ——— Tablet / narrow desktop (breakpoint --bp-md) ——— */
@media (max-width: 1024px) {
  .container {
    padding-left: 16px;
    padding-right: 16px;
  }
  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }
}

/* ——— Mobile (breakpoint --bp-sm) ——— */
@media (max-width: 768px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  .topbar {
    padding: 8px 12px;
    gap: 8px;
    align-items: center;
  }
  .topbar .brand-lockup {
    max-width: calc(100% - 56px);
    min-width: 0;
  }
  .brand-lockup__text {
    overflow: hidden;
  }
  .brand-lockup__primary {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }
  .topbar-panel {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0;
    padding: 8px 0 4px;
    border-top: 1px solid #374151;
    margin-top: 4px;
  }
  .topbar.is-open .topbar-panel { display: flex; }
  .global-search {
    width: 100%;
    max-width: none;
    flex: none;
    padding: 8px 4px;
    border-bottom: 1px solid #1f2937;
  }
  .topbar-panel .user {
    margin-left: 0;
  }
  .topbar .user {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 4px 4px;
    border-top: 1px solid #374151;
  }
  .topbar .user a { padding: 8px 0; }
  .org-pill { max-width: none; }

  .container { padding: 12px 12px 48px; }
  .org-banner { font-size: 12px; padding: 8px 12px; }

  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-head h1 { font-size: 18px; line-height: 1.3; }
  .page-head > div { width: 100%; }
  .page-head .btn,
  .page-head form .btn { flex: 1; min-width: 0; text-align: center; justify-content: center; }

  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 2px;
    padding: 4px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a {
    flex-shrink: 0;
    white-space: nowrap;
    min-height: var(--touch-min);
    padding: 10px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }

  .contract-tabs-sticky .tabs a {
    min-height: var(--touch-min);
  }

  /* Отчёты / блоки вида «показатель (th) — значение (td)» без thead */
  table.data.report-kv-table {
    border: none;
    background: transparent;
    overflow: visible;
  }
  table.data.report-kv-table tbody {
    display: block;
  }
  table.data.report-kv-table tr {
    display: block;
    margin-bottom: 10px;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  table.data.report-kv-table th,
  table.data.report-kv-table td {
    display: block;
    width: 100%;
    border: none;
    padding: 4px 0;
    text-align: left !important;
    background: transparent !important;
  }
  table.data.report-kv-table th {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    padding-bottom: 4px;
  }

  .card { padding: 14px 16px; }
  .card h2 { font-size: 15px; }

  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 10px; }
  .kpi b { font-size: 15px; }

  dl.kv {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }
  dl.kv dt {
    margin-top: 10px;
    font-weight: 600;
    color: var(--text);
  }
  dl.kv dt:first-child { margin-top: 0; }
  dl.kv dd { padding-bottom: 4px; border-bottom: 1px solid var(--border); }
  dl.kv dd:last-child { border-bottom: none; }

  .form-grid { grid-template-columns: 1fr; }
  .inline-form,
  .filters {
    flex-direction: column;
    align-items: stretch;
  }
  .inline-form label,
  .filters label,
  .form-grid label { width: 100%; }
  .inline-form input,
  .inline-form select,
  .filters input,
  .filters select,
  .form-grid input,
  .form-grid select,
  .form-grid textarea {
    width: 100%;
    font-size: 16px;
    min-height: 44px;
  }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; text-align: center; }

  .btn {
    min-height: 44px;
    padding: 10px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }
  .btn.sm {
    min-height: var(--touch-min);
    padding: 10px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .global-search input {
    min-height: var(--touch-min);
    padding: 10px 12px;
  }

  .pin-form .btn-icon {
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
  }

  /* Широкие таблицы → карточки-строки (без горизонтального скролла списка) */
  .stack-cards-sm.table-scroll {
    overflow-x: visible;
    -webkit-overflow-scrolling: auto;
  }
  .stack-cards-sm.table-scroll > .data {
    min-width: 0 !important;
    width: 100%;
    border: none;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }
  .stack-cards-sm.table-scroll > .data thead {
    display: none;
  }
  .stack-cards-sm.table-scroll > .data tbody tr {
    display: block;
    margin-bottom: 12px;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  .stack-cards-sm.table-scroll > .data tbody tr.row-pinned {
    border-left: 4px solid var(--warn);
  }
  .stack-cards-sm.table-scroll > .data tbody td {
    display: grid;
    grid-template-columns: minmax(92px, 36%) 1fr;
    gap: 4px 12px;
    align-items: start;
    padding: 8px 0;
    border: none;
    font-size: 14px;
    text-align: left !important;
    word-break: break-word;
  }
  .stack-cards-sm.table-scroll > .data tbody td:last-child {
    padding-bottom: 0;
  }
  .stack-cards-sm.table-scroll > .data tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 12px;
    color: var(--muted);
    word-break: break-word;
  }
  .stack-cards-sm.table-scroll > .data tbody td:not([data-label])::before,
  .stack-cards-sm.table-scroll > .data tbody td[data-label='']::before {
    content: none;
  }
  .stack-cards-sm.table-scroll > .data tbody td.empty {
    display: block;
    text-align: center !important;
    padding: 24px;
    font-style: italic;
    color: var(--muted);
  }
  .stack-cards-sm.table-scroll > .data tbody td.empty::before {
    display: none;
  }
  .stack-cards-sm.table-scroll > .data tbody td.col-pin::before {
    content: 'Закрепить';
  }

  /* Ячейки с несколькими кнопками — без двухколоночной сетки */
  .stack-cards-sm.table-scroll > .data tbody td[data-label='Экспорт'],
  .stack-cards-sm.table-scroll > .data tbody td[data-label='Действия'] {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .stack-cards-sm.table-scroll > .data tbody td[data-label='Экспорт'] form,
  .stack-cards-sm.table-scroll > .data tbody td[data-label='Действия'] form {
    display: inline-block;
  }

  .stack-cards-sm.table-scroll > .data tfoot {
    display: block;
    margin-top: 4px;
  }
  .stack-cards-sm.table-scroll > .data tfoot tr {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  .stack-cards-sm.table-scroll > .data tfoot th {
    flex: 1 1 calc(50% - 10px);
    min-width: 120px;
    margin: 0;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 13px;
    text-align: left !important;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-variant-numeric: tabular-nums;
  }
  .stack-cards-sm.table-scroll > .data tfoot th[colspan] {
    flex: 1 1 100%;
    font-size: 14px;
  }
  .stack-cards-sm.table-scroll > .data tfoot .num {
    text-align: right !important;
  }

  /* Уровни ведомости / накопительного на карточках */
  .stack-cards-sm.table-scroll > .data tbody tr[class*='lvl-'] td {
    background: transparent !important;
  }
  .stack-cards-sm.table-scroll > .data tbody tr.lvl-1 {
    border-left: 4px solid #d97706;
    background: #fef3c7;
  }
  .stack-cards-sm.table-scroll > .data tbody tr.lvl-2 {
    border-left: 4px solid #fbbf24;
    background: #fef9e7;
  }
  .stack-cards-sm.table-scroll > .data tbody tr.lvl-3 {
    border-left: 4px solid #fde68a;
    background: #fefce8;
  }

  .data th, .data td { padding: 8px 8px; font-size: 12px; }
  .data .num { font-size: 11px; }

  .plan-grid { grid-template-columns: 1fr; }
  .stats-grid strong { font-size: 22px; }

  .user-role { display: none; }
  .login-form { padding: 24px 20px; max-width: 100%; }
  .login-form input { font-size: 16px; min-height: 44px; }
  .login-form button { min-height: 48px; font-size: 16px; }
}

@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr; }
}

/* План/факт оплат на отчётах */
.h3-tight {
  margin: 1rem 0 0.35rem;
  font-size: 1.05rem;
}
.payment-timeline-wrap {
  margin: 0.75rem 0 1rem;
}
.payment-timeline-bar {
  position: relative;
  height: 36px;
  margin-bottom: 8px;
}
.payment-timeline-axis {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  background: linear-gradient(90deg, var(--border), var(--muted));
  border-radius: 3px;
}
.payment-timeline-marker {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  text-align: center;
}
.payment-timeline-marker.plan .payment-timeline-dot {
  background: #0d9488;
  border-color: #0f766e;
}
.payment-timeline-marker.fact .payment-timeline-dot {
  background: #059669;
  border-color: #047857;
}
.payment-timeline-dot {
  display: block;
  width: 12px;
  height: 12px;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid #111827;
  box-sizing: border-box;
}
.payment-timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
}
.payment-timeline-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.payment-timeline-swatch.plan {
  background: #0d9488;
}
.payment-timeline-swatch.fact {
  background: #059669;
}
.payment-timeline-range {
  margin-left: auto;
}
.payment-timeline-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
}
.payment-timeline-list li {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.payment-timeline-list li:last-child {
  border-bottom: none;
}
.badge-plan {
  background: #ccfbf1;
  color: #115e59;
}
.badge-fact {
  background: #d1fae5;
  color: #065f46;
}
.muted.small {
  font-size: 12px;
}
