:root {
  --bg: #080a0a;
  --fg: #f3f4ed;
  --primary: #b7ff00;
  --primary-hover: #c9ff52;
  --primary-dark: #9ce300;
  --accent: #ffd600;
  --accent-soft: #ffe24d;
  --surface-1: #111414;
  --surface-2: #171b19;
  --surface-3: #1f2421;
  --surface-4: #2a312d;
  --muted: #a7ada7;
  --danger: #ff5c5c;
  --danger-dark: #d13434;
  --wa: #25d366;
  --tg: #229ed9;
  --border: #2a312d;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, h4 { font-family: "Manrope", "Inter", sans-serif; }
h1 { font-size: 26px; margin: 0 0 6px; }
h3 { margin: 0 0 10px; }
h4 { margin: 14px 0 6px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.hidden { display: none; }

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

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  font-family: "Manrope", sans-serif;
  font-weight: 800; font-size: 22px; letter-spacing: 1px;
  color: var(--fg); margin-bottom: 24px; padding: 0 10px;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--fg); background: var(--surface-2); }
.nav a.active { color: #0c1000; background: var(--primary); font-weight: 700; }
.main { flex: 1; padding: 28px 32px; width: 100%; max-width: 1760px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header .sub { color: var(--muted); }

.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.metric-value { font-family: "Manrope", sans-serif; font-size: 30px; font-weight: 800; color: var(--primary); }
.metric-value.yellow { color: var(--accent); }
.metric-label { color: var(--muted); font-size: 13px; margin-top: 2px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.filters select, .filters input[type="text"], .filters input[type="number"] { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--fg); font: inherit; }
.check { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--muted); font-size: 13px; }
.check input { accent-color: var(--primary); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.inline-form { display: inline; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border: none; border-radius: 8px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 13px;
  background: var(--primary); color: #0c1000; text-decoration: none;
}
.btn:hover { background: var(--primary-hover); color: #0c1000; }
.btn-ghost { background: var(--surface-3); color: var(--fg); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-4); color: var(--fg); }
.btn-danger { background: var(--danger); color: #1a0505; }
.btn-danger:hover { background: var(--danger-dark); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

.table-wrap { overflow-x: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
table.clinics { width: 100%; border-collapse: collapse; }
table.clinics th, table.clinics td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.clinics th { background: var(--surface-1); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); white-space: nowrap; }
table.clinics tr:hover td { background: var(--surface-3); }
table.clinics .col-name { min-width: 260px; }
table.clinics th:first-child, table.clinics td:first-child { width: 34px; }
table.clinics .wrap { word-break: break-all; }
.col-name .small { word-break: break-all; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-cat { background: var(--surface-4); color: var(--primary); }
.badge-wa { background: var(--wa); color: #04160a; }
.badge-tg { background: var(--tg); color: #041018; }
.badge-work { background: var(--accent); color: #1a1200; }
.badge-exported { background: var(--surface-4); color: var(--accent); cursor: help; }
.badge-project { background: var(--surface-3); color: var(--primary); }

.company-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.badge-company { background: var(--surface-3); color: var(--muted); }
.badge-company-active { background: var(--primary); color: #0c1000; }

.export-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-bottom: 16px; }
.export-summary .metric { min-width: 170px; }
.export-selected-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 720px; }
.export-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.limit-label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.limit-label input { width: 120px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--fg); font: inherit; }
.format-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 6px 0 10px; }

.tz-select { min-height: 76px; }
.filters .tz-select { min-width: 170px; }
.tz-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.tz-group-label { color: var(--muted); font-size: 13px; }

/* Обратные звонки: модалка, тосты, блок в карточке */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal-backdrop.hidden { display: none; }
.modal { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.modal-close:hover { color: var(--fg); }
.modal-sub { margin: 4px 0 12px; }
.modal-hint { margin: 6px 0 10px; }
.callback-block { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.callback-overdue td { background: #2a1414; }
.badge-overdue { background: var(--danger); color: #fff; }
.toast-box { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 1100; max-width: 380px; }
.toast { background: var(--surface-3); border: 1px solid var(--accent); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; color: var(--fg); font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); }

.quick-status { padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; background: var(--surface-2); color: var(--fg); }

.pagination { display: flex; gap: 14px; align-items: center; margin: 16px 0; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 12px; border: 1px solid transparent; }
.flash-success { background: #0d1f0d; color: #c9ff52; border-color: #2a4d14; }
.flash-error { background: #1f0d0d; color: #ffb3b3; border-color: #5c1f1f; }

.form label { display: block; margin-bottom: 12px; font-weight: 600; }
.form input[type="text"], .form input[type="number"], .form input[type="email"], .form input[type="password"], .form select, .form textarea {
  display: block; width: 100%; margin-top: 5px; padding: 9px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: var(--surface-2); color: var(--fg);
}
.form textarea { min-height: 90px; }
.row2 { display: flex; gap: 12px; flex-wrap: wrap; }
.row2 label { flex: 1; min-width: 200px; }

.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv td:first-child { color: var(--muted); width: 150px; font-size: 12px; }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.block { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; background: var(--surface-2); }
.block-title { font-family: "Manrope", sans-serif; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin: 0 0 10px; }
.cta-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

.messenger-list { margin: 0; padding-left: 18px; font-size: 13px; }

table.logs { width: 100%; border-collapse: collapse; }
table.logs th, table.logs td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 12px; }
table.logs th { color: var(--muted); }

.progress { height: 10px; background: var(--surface-4); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress-bar { height: 100%; background: var(--primary); transition: width 0.3s; }

.ok { color: var(--primary); font-weight: 600; }
.warn { color: var(--accent); font-weight: 600; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tab-btn { padding: 9px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font: inherit; color: var(--muted); }
.tab-btn:hover { color: var(--fg); }
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: #0c1000; }
.tab-panels { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.tab-panel.hidden { display: none; }

.sub-block { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.sub-block details { margin-top: 8px; }
.sub-block summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.secret-mask { font-family: monospace; margin-right: 8px; }

.email-preview { white-space: pre-wrap; font-family: inherit; margin: 0; }

.empty-state { text-align: center; padding: 44px; color: var(--muted); }

/* ===== Улучшения компоновки: меню, таблица, роли ===== */

.main { min-width: 0; }

/* Боковая панель: фиксированная высота, прокручиваемое меню, закреплённый низ */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 10px;
  overflow: hidden;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { font-family: "Manrope", sans-serif; font-weight: 800; font-size: 22px; letter-spacing: 1px; color: var(--fg); padding: 0 10px; margin: 0; }
.sidebar-toggle { background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); border-radius: 8px; cursor: pointer; font: inherit; font-size: 14px; line-height: 1; padding: 6px 10px; }
.sidebar-toggle:hover { color: var(--fg); background: var(--surface-3); }
.nav { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1 1 auto; min-height: 0; padding-right: 4px; }
.nav-section { margin: 10px 12px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.user-box { border-top: 1px solid var(--border); padding: 10px 10px 0; margin-top: 6px; flex-shrink: 0; }
.user-name { font-weight: 600; }
.user-box .btn { margin-top: 8px; }

/* Компактный режим: панель скрывается, появляется кнопка открытия */
.sidebar-reopen { display: none; position: fixed; top: 14px; left: 14px; z-index: 1200; }
body.sidebar-collapsed .sidebar { display: none; }
body.sidebar-collapsed .sidebar-reopen { display: inline-flex; }
body.sidebar-collapsed .sidebar-reopen { align-items: center; justify-content: center; padding: 9px 14px; border: none; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; font-size: 13px; background: var(--primary); color: #0c1000; }

/* Таблица: горизонтальная прокрутка, закреплённый заголовок и колонка «Организация» */
.table-wrap { max-width: 100%; }
table.clinics { min-width: 1120px; }
table.clinics th { position: sticky; top: 0; z-index: 3; }
table.clinics .col-name { position: sticky; left: 0; z-index: 2; background: var(--surface-2); }
table.clinics th.col-name { z-index: 4; background: var(--surface-1); }
body.role-employee table.clinics .col-name { left: 0; }
body.role-admin table.clinics .col-name { left: 34px; }
body.role-admin table.clinics td:first-child,
body.role-admin table.clinics th:first-child { position: sticky; left: 0; z-index: 2; background: var(--surface-2); }
body.role-admin table.clinics th:first-child { z-index: 4; background: var(--surface-1); }
table.clinics tr:hover td.col-name { background: var(--surface-3); }
body.role-admin table.clinics tr:hover td:first-child { background: var(--surface-3); }
table.clinics .col-resp { min-width: 150px; }

.badge-owner { background: var(--primary); color: #0c1000; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); overflow: visible; }
  .nav { flex-direction: row; flex-wrap: wrap; overflow: visible; }
  .main { padding: 18px; }
  .sidebar-toggle { display: none; }
  table.clinics .col-name,
  body.role-admin table.clinics td:first-child,
  body.role-admin table.clinics th:first-child { position: static; left: auto; }
  table.clinics { min-width: 0; }
}

