:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #172126;
  --muted: #6e7a81;
  --line: #dfe5e8;
  --soft: #eef3f4;
  --accent: #1f6b58;
  --accent-dark: #164f42;
  --danger: #9e3d3d;
  --shadow: 0 14px 40px rgba(16, 34, 40, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }
button, input, select, textarea { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 68px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--text);
  color: #fff;
  font-weight: 800;
  letter-spacing: .05em;
}
.nav { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.nav a { padding: 9px 12px; border-radius: 10px; color: #46535a; font-size: 14px; }
.nav a:hover { background: var(--soft); color: var(--text); }

.page-shell { width: min(1600px, calc(100% - 36px)); margin: 0 auto; padding: 30px 0 70px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 22px; margin-bottom: 24px; }
.page-head h1 { margin: 3px 0 4px; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.03em; }
.page-head p { margin: 0; }
.section-head { display: flex; align-items: end; justify-content: space-between; margin: 30px 0 14px; }
.section-head h2 { margin: 0 0 4px; }
.eyebrow { text-transform: uppercase; letter-spacing: .13em; font-size: 12px; font-weight: 800; color: var(--accent); }
.muted { color: var(--muted); }
.head-actions, .form-actions, .service-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.btn {
  border: 0;
  border-radius: 11px;
  padding: 11px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 750;
  transition: .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-dark { background: var(--text); color: #fff; }
.btn-ghost { background: #fff; border: 1px solid var(--line); color: var(--text); }
.btn-danger-soft { background: #fff0f0; color: var(--danger); border: 1px solid #f0cece; }
.btn-small { padding: 8px 11px; border-radius: 9px; font-size: 13px; }

.alert { padding: 13px 15px; border-radius: 12px; margin-bottom: 16px; border: 1px solid; }
.alert-success { background: #eef8f4; color: #245f50; border-color: #cde8de; }
.alert-error { background: #fff2f2; color: #8b3434; border-color: #efcccc; }

.search-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 20px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: 15px;
  box-shadow: 0 8px 24px rgba(16,34,40,.04);
}
.search-strip input { border: 0; outline: none; padding: 10px 12px; min-width: 0; background: transparent; }
.search-large { margin-top: 6px; }
.result-summary { margin: 16px 0; color: var(--muted); }

.table-card, .list-card, .form-card, .note-card, .empty-state, .service-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.table-card { overflow: hidden; }
.table-scroll { overflow: auto; max-width: 100%; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 11px 12px; white-space: nowrap; font-size: 13px; text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 5; background: #edf3ef; color: #355048; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: 0; }
th:last-child, td:last-child { border-right: 0; }
tbody tr:hover td { background: #fbfcfc; }
.clients-table { min-width: 1900px; }
.search-table { min-width: 980px; }
.strong-cell { font-weight: 800; }
.service-name { max-width: 210px; overflow: hidden; text-overflow: ellipsis; }
.empty-cell { color: #a7b0b5; }
.sticky-col { position: sticky; z-index: 8; background: #fff; }
th.sticky-col { background: #e9f0ec; z-index: 12; }
.sticky-company { left: 0; min-width: 180px; max-width: 220px; }
.sticky-contact { left: 180px; min-width: 180px; max-width: 220px; box-shadow: 8px 0 16px rgba(16,34,40,.04); }

.form-card { padding: 24px; max-width: 900px; }
.compact-card { max-width: 560px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.form-stack { display: grid; gap: 15px; }
.form-grid label, .form-stack label { display: grid; gap: 7px; font-weight: 700; font-size: 14px; }
.full { grid-column: 1 / -1; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cfd8dc;
  border-radius: 11px;
  background: #fff;
  padding: 12px 13px;
  color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #6f9f91; box-shadow: 0 0 0 3px rgba(31,107,88,.09); }
textarea { resize: vertical; }
.check { grid-template-columns: auto 1fr !important; align-items: center; justify-content: start; }
.check input { width: auto; }

.auth-wrap { min-height: calc(100vh - 170px); display: grid; place-items: center; }
.auth-card { width: min(440px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 22px; padding: 30px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 42px; margin: 4px 0 8px; letter-spacing: -.04em; }
.wide-card { width: min(560px, 100%); }

.empty-state { padding: 42px 24px; text-align: center; }
.empty-state h2 { margin-top: 0; }
.note-card { padding: 18px 20px; margin-bottom: 24px; }
.note-card p { margin-bottom: 0; }

.service-list { display: grid; gap: 14px; }
.service-card { padding: 20px; }
.service-card-main { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.service-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.service-title-row h3 { margin: 0; }
.service-metrics { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; margin-top: 18px; }
.service-metrics > div { background: var(--soft); border-radius: 12px; padding: 13px; }
.service-metrics span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 800; }
.badge-active { color: #23604f; background: #e7f6f0; }
.badge-expired { color: #8b4c4c; background: #f9e9e9; }

.catalog-grid { display: grid; grid-template-columns: minmax(280px, 420px) minmax(0, 1fr); gap: 20px; align-items: start; }
.list-card { overflow: hidden; }
.simple-list-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.simple-list-row:last-child { border-bottom: 0; }
.simple-list-row > div { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

@media (max-width: 800px) {
  .topbar { padding: 12px 16px; align-items: flex-start; }
  .nav { gap: 4px; }
  .nav a { padding: 7px 8px; font-size: 12px; }
  .page-shell { width: min(100% - 20px, 1600px); padding-top: 20px; }
  .page-head { flex-direction: column; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .service-card-main { flex-direction: column; }
  .service-metrics { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .catalog-grid { grid-template-columns: 1fr; }
  .sticky-contact { left: 150px; }
  .sticky-company { min-width: 150px; max-width: 150px; }
  .sticky-contact { min-width: 150px; max-width: 150px; }
}

@media (max-width: 520px) {
  .topbar { position: static; flex-direction: column; }
  .nav { width: 100%; justify-content: flex-start; }
  .search-strip { grid-template-columns: 1fr; }
  .service-metrics { grid-template-columns: 1fr 1fr; }
  .auth-card, .form-card { padding: 20px; }
}
