/* ============================================================
   «Договоры» — минималистичный дизайн
   ============================================================ */

:root {
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --text: #18181B;
  --muted: #71717A;
  --border: #E7E5E4;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-soft: #EEF2FF;
  --danger: #DC2626;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(24, 24, 27, .04), 0 4px 16px rgba(24, 24, 27, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.02em; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 24px; }
.container-narrow { max-width: 760px; }

/* ---------- Шапка ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, .85);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { color: var(--text); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--text);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}

.brand-name { font-size: 18px; font-weight: 650; }

.main-nav { display: flex; align-items: center; gap: 6px; }

.nav-link {
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 15px;
}
.nav-link:hover { color: var(--text); background: rgba(24, 24, 27, .05); }
.nav-link.active { color: var(--text); background: rgba(24, 24, 27, .07); }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: rgba(24, 24, 27, .04); color: var(--text); }

.btn-sm { min-height: 38px; padding: 8px 16px; font-size: 14px; border-radius: 10px; }

/* ---------- Страница ---------- */

.page { min-height: calc(100vh - 68px - 72px); padding: 48px 0 72px; }

.hero { max-width: 640px; padding: 40px 0 32px; }

.hero-title { font-size: 44px; line-height: 1.1; letter-spacing: -0.03em; }
.hero-sub { margin: 18px 0 28px; color: var(--muted); font-size: 18px; max-width: 520px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.section { margin-top: 40px; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-title { font-size: 24px; }
.page-title { font-size: 30px; }
.page-meta { margin-top: 6px; color: var(--muted); }

.link { font-weight: 500; }
.back-link { display: inline-block; margin-bottom: 8px; }

/* ---------- Карточки ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.counterparty-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  color: var(--text);
  transition: transform .12s, box-shadow .12s;
}
.counterparty-card:hover {
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(24, 24, 27, .09);
}

.card-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 18px;
}

.card-body { min-width: 0; flex: 1 1 auto; }
.card-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { margin-top: 2px; color: var(--muted); font-size: 14px; }
.card-arrow { color: var(--muted); font-size: 18px; }

/* ---------- Пустое состояние ---------- */

.empty {
  text-align: center;
  padding: 56px 24px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}
.empty-title { font-size: 20px; font-weight: 650; }
.empty-sub { margin: 8px 0 20px; color: var(--muted); }

/* ---------- Детали ---------- */

.row-actions { display: flex; gap: 10px; align-items: center; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 16px; }

.detail-block { padding: 24px; }
.detail-title { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 16px; }

.kv { margin: 0; }
.kv-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: 0; }
.kv-row dt { color: var(--muted); font-size: 14px; flex: 0 0 40%; }
.kv-row dd { margin: 0; text-align: right; font-weight: 500; overflow-wrap: anywhere; }

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

/* ---------- Форма ---------- */

.form { display: flex; flex-direction: column; gap: 20px; }

.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.form-section-title { font-size: 17px; margin-bottom: 18px; }

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 550;
  color: var(--text);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.inn-row { display: flex; gap: 10px; align-items: center; }
.inn-row .input { flex: 1 1 auto; }

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

.contracts-list { margin-top: 14px; }

.card-note {
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
}

/* ---------- Футер ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* ---------- Вкладки ресурсов ---------- */

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab {
  padding: 8px 14px;
  border-radius: 10px 10px 0 0;
  color: var(--muted);
  font-weight: 550;
  font-size: 15px;
  border: 1px solid transparent;
  border-bottom: none;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); background: #F4F4F2; }
.tab.active {
  color: var(--primary);
  background: var(--surface);
  border-color: var(--border);
  border-bottom: 1px solid var(--surface);
}

.ai-block { border: 1px solid var(--primary-soft); background: #FBFAFF; }
.ai-block .form-section-title { display: flex; align-items: center; gap: 8px; }

/* ---------- Счётчики ---------- */

.alert-warn { background: #FFFBEB; border-color: #FDE68A; color: #92400E; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 560px;
}
.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.data-table thead th {
  background: #FAFAF9;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #FCFCFB; }
.data-table tfoot td {
  background: #FAFAF9;
  font-weight: 650;
  border-top: 1px solid var(--border);
}
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .col-month { white-space: nowrap; }
.data-table .col-common { background: var(--primary-soft); }
.data-table tbody tr:hover .col-common { background: #E7ECFF; }
.data-table .col-total { font-weight: 600; }
.data-table .col-mop { font-weight: 600; }

.th-sub { font-size: 11px; color: var(--muted); font-weight: 500; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); }
.cell-empty { color: #D4D4D8; }
.estimated .cell-main { color: #B45309; }
.neg { color: var(--danger); }

.badge-warn { background: #FFFBEB; color: #92400E; }

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.month-nav .input { padding: 6px 10px; }

.bulk-date { margin-bottom: 14px; }
.bulk-date .small { font-size: 12px; margin-top: 6px; }

.entry-table .input { width: 130px; padding: 7px 10px; }
.entry-table .value-input { text-align: right; font-variant-numeric: tabular-nums; }
.entry-table .date-input { width: 160px; }
.delta-cell { font-weight: 600; }

.table-hint { margin-top: 12px; font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.small { font-size: 12px; }
.muted.small { font-size: 12px; }

/* ---------- Рыбы договоров ---------- */

.alert {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid transparent;
}
.alert-ok { background: #ECFDF5; border-color: #A7F3D0; color: #065F46; }
.alert-error { background: #FEF2F2; border-color: #FECACA; color: #991B1B; }

.tpl-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }

.tpl-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tpl-main { min-width: 0; }
.tpl-name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tpl-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tpl-ph { margin-top: 6px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tpl-ph code {
  background: var(--primary-soft);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 12px;
}
.tpl-ph code.ph-unknown { background: #FEF3C7; }
.warn-text { color: #B45309; }
.tpl-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.tpl-actions form { margin: 0; }

.badge {
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge-ok { background: #ECFDF5; color: #065F46; }

.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

.upload-form {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
}
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 10px; }

.ph-help { margin-top: 14px; font-size: 14px; }
.ph-help summary { cursor: pointer; color: var(--primary); }
.ph-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; margin-top: 10px; }
.ph-item { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.ph-item code { font-size: 12px; }

.gen-form { flex-wrap: wrap; }

@media (max-width: 640px) {
  .tpl-row { flex-direction: column; }
  .tpl-actions { justify-content: flex-start; }
  .ph-grid { grid-template-columns: 1fr; }
}

/* ---------- Мобильные ---------- */

@media (max-width: 640px) {
  .hero-title { font-size: 34px; }
  .grid-2 { grid-template-columns: 1fr; }
  .header-inner { height: 60px; }
  .nav-link { display: none; }
  .section-head { flex-direction: column; align-items: flex-start; }
  .detail-grid { grid-template-columns: 1fr; }
}
