:root {
  --bg: #eef2f0;
  --bg-accent: #dfe8e2;
  --surface: #fbfcfb;
  --ink: #1c2421;
  --muted: #5d6b65;
  --line: #c9d4ce;
  --primary: #1f6b4a;
  --primary-hover: #17553a;
  --danger: #9b2c2c;
  --success: #1f6b4a;
  --info: #2a4f66;
  --shadow: 0 10px 30px rgba(28, 36, 33, 0.06);
  --radius: 14px;
  --font: "IBM Plex Sans", sans-serif;
  --display: "IBM Plex Serif", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(31, 107, 74, 0.08), transparent 28%),
    linear-gradient(180deg, var(--bg-accent), var(--bg));
}

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

a:hover {
  text-decoration: underline;
}

.page {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
}

.content {
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  flex: 1 1 280px;
}

.top-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.top-nav-link {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 500;
}

.top-nav-link:hover {
  background: #f3f7f4;
  color: var(--ink);
  text-decoration: none;
}

.brand {
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
}

.quota-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f7faf8;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}

.quota-chip:hover {
  text-decoration: none;
  border-color: #bddbc8;
  background: #eaf6ef;
}

.quota-chip.quota-done {
  background: #eaf6ef;
  border-color: #9fceb0;
}

.quota-overdue {
  color: #9a5b00;
  font-size: 0.85rem;
}

.briefing-banner {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid #cfe0d5;
  background: #f3faf5;
}

.briefing-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-users {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.settings-user-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  align-items: end;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}

.settings-user-card h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.settings-quota-form {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.settings-quota-form label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  color: var(--muted);
}

.settings-quota-form input {
  width: 120px;
}

.user-name {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.panel-login {
  max-width: 420px;
  margin: 48px auto 0;
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.login-form .btn {
  margin-top: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

.btn-secondary {
  background: white;
  border-color: var(--line);
  color: var(--ink);
}

.btn-secondary:hover,
.btn-ghost:hover {
  text-decoration: none;
  background: #f3f7f4;
}

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

.btn-small {
  padding: 7px 10px;
  font-size: 0.9rem;
}

.upload-form input[type="file"] {
  display: none;
}

.panel {
  background: var(--surface);
  border: 1px solid rgba(201, 212, 206, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  min-width: 0;
}

.panel-list {
  overflow: visible;
}

.panel + .panel,
.detail-layout .panel + .panel {
  margin-top: 16px;
}

.panel-head {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(420px, 920px) minmax(80px, 1fr);
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

.panel-head > :first-child {
  justify-self: start;
}

.panel-head .search-form {
  justify-self: center;
  width: 100%;
  max-width: 920px;
  justify-content: center;
}

.list-toolbar {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.list-toolbar-top h1 {
  margin-bottom: 4px;
}

.list-filters {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7faf8;
}

.list-filters-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.list-filters-row select {
  width: 100%;
  min-width: 0;
}

.list-filters-search {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.list-filters-search input[type="search"] {
  flex: 1 1 240px;
  min-width: 0;
  width: auto;
}

.list-filters-search .btn {
  flex: 0 0 auto;
}

h1, h2 {
  font-family: var(--display);
  margin: 0 0 6px;
  font-weight: 600;
}

.muted, .cell-sub, .label, .comment-meta {
  color: var(--muted);
}

.search-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: white;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.search-form input[type="search"] {
  min-width: 220px;
  flex: 1 1 220px;
}

.search-form select {
  width: auto;
  min-width: 160px;
  flex: 0 1 200px;
  cursor: pointer;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  margin: 0 -4px;
  padding: 0 4px 6px;
}

.data-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.95rem;
  word-break: break-word;
}

.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.data-table .col-name {
  width: 22%;
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  box-shadow: 4px 0 8px -6px rgba(28, 36, 33, 0.35);
}

.data-table thead .col-name {
  z-index: 2;
}

.data-table .col-region { width: 11%; }
.data-table .col-status { width: 10%; }
.data-table .col-phone { width: 10%; white-space: nowrap; }
.data-table .col-email { width: 12%; }
.data-table .col-rating { width: 8%; white-space: nowrap; }
.data-table .col-index { width: 6%; }
.data-table .col-partners { width: 7%; }
.data-table .col-source { width: 8%; }
.data-table .col-actions { width: 8%; }

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.data-table tbody tr:hover,
.data-table tbody tr:hover .col-name {
  background: #f3f8f5;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e7efe9;
  color: var(--primary);
  font-size: 0.85rem;
}

.badge-import {
  background: #e4eef5;
  color: var(--info);
}

.badge-manual {
  background: #e7efe9;
  color: var(--primary);
}

.badge-status-new {
  background: #e8f1f8;
  color: #234e6d;
}

.badge-status-in_progress {
  background: #eef6e8;
  color: #2f5d1f;
}

.badge-status-correspondence {
  background: #eaf4ff;
  color: #1f4f7a;
}

.badge-status-thinking {
  background: #f4eef8;
  color: #5a3d72;
}

.badge-status-waiting_meeting {
  background: #fff4e5;
  color: #8a5a12;
}

.badge-status-contract {
  background: #e8f7f2;
  color: #1a5c48;
}

.badge-status-closed_rejected,
.badge-status-rejected {
  background: #fdecec;
  color: #9b2c2c;
}

.badge-status-closed_success {
  background: #e7f6ea;
  color: #1f6b3a;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 0;
}

.tab {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: white;
  text-decoration: none;
  font-size: 0.92rem;
  white-space: nowrap;
}

.tab:hover {
  text-decoration: none;
  background: #f3f7f4;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.sort-link {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.sort-link:hover {
  color: var(--primary);
  text-decoration: none;
}

.meta-forms,
.partners-form {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.meta-forms {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.inline-form label,
.partners-form label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 500;
}

select {
  width: 100%;
  max-width: 320px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: white;
  color: var(--ink);
}

.partners-form .full {
  max-width: none;
}

.partners-form select,
.partners-form textarea {
  max-width: none;
}

.progress {
  width: 100%;
  max-width: 72px;
  height: 8px;
  background: #e5ece7;
  border-radius: 999px;
  overflow: hidden;
}

.progress.large {
  width: 160px;
  height: 10px;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #2f8f63, #1f6b4a);
}

.flash {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.flash-success {
  background: #e8f6ee;
  border-color: #b7dfc7;
  color: #145239;
}

.flash-error {
  background: #fdecec;
  border-color: #f0c2c2;
  color: var(--danger);
}

.flash-info {
  background: #eaf3f8;
  border-color: #c5dae8;
  color: var(--info);
}

.empty {
  padding: 40px 10px;
  text-align: center;
}

.form-panel h1 {
  margin-bottom: 4px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.form-grid label,
.info-grid .label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 500;
}

.form-grid .full,
.info-grid .full,
.form-actions.full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.detail-layout {
  display: grid;
  gap: 16px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

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

.info-grid .label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.actions-list {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.action-block {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7faf8;
}

.action-block.done {
  background: #eaf6ef;
  border-color: #bddbc8;
}

.action-item {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.action-item.done {
  background: transparent;
  border-color: transparent;
}

.action-item .checkbox-row {
  flex: 1 1 180px;
  min-width: 160px;
}

.action-item select {
  flex: 0 1 200px;
  min-width: 160px;
  max-width: 240px;
}

.action-item input[type="text"] {
  flex: 1 1 220px;
  min-width: 180px;
}

.action-item .btn {
  flex: 0 0 auto;
}

.action-meta {
  font-size: 0.86rem;
}

.action-templates {
  display: grid;
  gap: 8px;
}

.action-template-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.checkbox-row input {
  width: auto;
}

.panel-head-simple {
  grid-template-columns: 1fr;
}

.templates-filter {
  margin: 0 0 18px;
}

.templates-grid {
  display: grid;
  gap: 14px;
}

.template-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  padding: 14px;
}

.template-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.template-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.template-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.template-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f7faf8;
  border: 1px solid #e4ece7;
  border-radius: 10px;
  padding: 12px;
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.45;
}

.step-create-card,
.step-admin-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  padding: 18px 20px;
  display: grid;
  gap: 14px;
}

.step-create-card {
  margin: 20px 0 28px;
}

.step-create-card h2 {
  margin: 0;
  font-size: 1.05rem;
}

.step-create-card label,
.step-edit-form label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  color: var(--muted);
}

.step-create-card input[type="text"],
.step-create-card input:not([type]),
.step-edit-form input[type="text"],
.step-edit-form input:not([type]) {
  width: 100%;
}

.step-option {
  margin-top: 2px;
  color: var(--text);
  font-weight: 500;
}

.step-option span {
  line-height: 1.35;
}

.steps-admin-list {
  display: grid;
  gap: 16px;
}

.step-admin-card {
  align-items: start;
}

.step-edit-form {
  display: grid;
  gap: 12px;
  width: 100%;
}

.step-admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

.step-admin-card > form:last-child {
  margin-top: -4px;
}

.comment-form {
  display: grid;
  gap: 10px;
  margin: 14px 0 18px;
}

.comments {
  display: grid;
  gap: 10px;
}

.comment {
  padding: 12px;
  border-left: 3px solid var(--primary);
  background: #f7faf8;
  border-radius: 0 10px 10px 0;
}

.comment-meta {
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.comment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.comment-edit-form {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.comment-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.pagination-pages {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.page-link {
  min-width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.92rem;
}

.page-link:hover {
  background: #f3f7f4;
  text-decoration: none;
}

.page-link.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.page-ellipsis {
  color: var(--muted);
  padding: 0 2px;
}

.btn.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(28, 36, 33, 0.45);
  backdrop-filter: blur(2px);
}

.loader-overlay[hidden] {
  display: none;
}

.loader-card {
  width: min(360px, calc(100% - 32px));
  padding: 28px 24px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.loader-card h2 {
  margin: 16px 0 8px;
}

.loader-card p {
  margin: 0;
  color: var(--muted);
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid #d5e3db;
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

body.loading {
  overflow: hidden;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1100px) {
  .page {
    padding: 18px;
  }

  .panel {
    padding: 16px;
  }

  .list-filters-row {
    grid-template-columns: 1fr 1fr;
  }

  .data-table {
    min-width: 980px;
  }

  .data-table .col-email,
  .data-table .col-source {
    display: none;
  }
}

@media (max-width: 800px) {
  .page {
    padding: 12px;
  }

  .brand {
    font-size: 1.3rem;
  }

  .topbar,
  .panel-head,
  .detail-head,
  .form-grid,
  .info-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .panel-head .search-form {
    justify-self: stretch;
    max-width: none;
  }

  .topbar {
    align-items: stretch;
  }

  .topbar-actions,
  .search-form,
  .form-actions {
    width: 100%;
  }

  .topbar-actions {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions .btn,
  .topbar-actions .quota-chip,
  .topbar-actions .user-chip {
    flex: 1 1 auto;
  }

  .list-filters-row {
    grid-template-columns: 1fr 1fr;
  }

  .search-form input[type="search"],
  .search-form select {
    min-width: 0;
    flex: 1 1 100%;
  }

  .action-item {
    display: flex;
  }

  .panel-list {
    overflow: visible;
  }

  .table-wrap {
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  .data-table,
  .data-table tbody {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    margin-bottom: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f7faf8;
  }

  .data-table tbody tr:hover,
  .data-table tbody tr:hover .col-name {
    background: #eef6f1;
  }

  .data-table th,
  .data-table td {
    display: block;
    width: auto !important;
    padding: 0;
    border: 0;
    font-size: 0.95rem;
  }

  .data-table .col-name {
    grid-column: 1 / -1;
    position: static;
    box-shadow: none;
    background: transparent;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 4px;
  }

  .data-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    font-weight: 600;
  }

  .data-table .col-name::before {
    display: none;
  }

  .data-table .col-email,
  .data-table .col-source {
    display: block;
  }

  .progress {
    max-width: 100%;
  }
}

@media (max-width: 520px) {
  .topbar-actions {
    grid-template-columns: 1fr;
  }

  .list-filters-row {
    grid-template-columns: 1fr;
  }

  .list-filters-search {
    flex-direction: column;
    align-items: stretch;
  }

  .data-table tbody tr {
    grid-template-columns: 1fr;
  }
}
