:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --ink: #1a242c;
  --muted: #5c6b76;
  --line: #c9d4dc;
  --line-strong: #8fa0ad;
  --accent: #0d6e6e;
  --accent-soft: #d7efef;
  --header-teal: #9fd4d0;
  --header-extra: #b8c9e0;
  --header-gray: #b8c0c7;
  --auto-bg: #f3f6f8;
  --input-bg: #fffdf5;
  --danger: #a33a3a;
  --ok: #1f6b3a;
  --warn: #8a6d1d;
  --shadow: 0 1px 2px rgba(26, 36, 44, 0.06), 0 8px 24px rgba(26, 36, 44, 0.06);
  --radius: 10px;
  --font: "Segoe UI", "PT Sans", "Helvetica Neue", sans-serif;
  --mono: "Cascadia Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9eceb 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #dce4f0 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #0d6e6e, #1a8f8a);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: #f4f7f8; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: #0b5c5c; }

.btn-sm {
  padding: 4px 10px;
  font-size: 0.85rem;
}

.btn-file { display: inline-flex; align-items: center; }

.btn-icon {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 6px;
}

.btn-icon:hover { background: #f0e4e4; color: var(--danger); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 22px 0;
  overflow-x: auto;
}

.tab {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 16px;
  border-radius: 10px 10px 0 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

main { padding: 0 22px 28px; }

.panel { display: none; }
.panel.active { display: block; }

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 14px;
  overflow: hidden;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfcfd, #f3f6f8);
}

.block-head h2 {
  margin: 0;
  font-size: 1rem;
}

.block-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.year-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.input-inline,
.sheet input,
.sheet select {
  font: inherit;
  color: var(--ink);
  border: 1px solid transparent;
  background: transparent;
  border-radius: 4px;
  padding: 4px 6px;
  width: 100%;
  min-width: 0;
}

.input-inline {
  border-color: var(--line);
  background: #fff;
  width: 140px;
}

.sheet input:focus,
.sheet select:focus,
.input-inline:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.sheet input.num {
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--input-bg);
  border-color: #ebe4c8;
}

.sheet input.money {
  text-align: right;
  font-variant-numeric: tabular-nums;
  background: var(--input-bg);
  border-color: #ebe4c8;
}

.table-wrap {
  overflow: auto;
  max-height: min(70vh, 820px);
}

.sheet {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.sheet.compact { min-width: 480px; }

.sheet th,
.sheet td {
  border: 1px solid var(--line);
  padding: 5px 6px;
  vertical-align: middle;
}

.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--header-gray);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
  font-size: 0.78rem;
  white-space: nowrap;
}

.sheet thead .group-input { background: #d9e8c8; }
.sheet thead .group-auto { background: #cfe0ea; }

.sheet tbody tr:nth-child(even) { background: #fafbfc; }
.sheet tbody tr:hover { background: #f0f7f7; }

.sheet tfoot td {
  background: #e8eef2;
  font-weight: 700;
}

.col-n { width: 34px; text-align: center; }
.col-name { min-width: 130px; }
.col-date { width: 108px; }
.col-money { width: 110px; }
.col-act { width: 32px; }

.price-sheet {
  width: 100%;
  min-width: 480px;
  table-layout: fixed;
}

.price-sheet col.col-n { width: 48px; }
.price-sheet col.col-price-name { width: auto; }
.price-sheet col.col-money { width: 140px; }
.price-sheet col.col-act { width: 40px; }

.price-sheet .cell-name {
  text-align: left;
}

.price-sheet .cell-money {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.price-sheet .cell-money .money-formatted,
.price-sheet input.money-formatted {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.92rem;
}

.price-sheet .section-row td {
  letter-spacing: 0.01em;
}

body.prices-locked .price-sheet tbody tr:not(.section-row):hover {
  background: #f7fafb;
}

.patients-block .sheet {
  width: 100%;
  min-width: 620px;
  table-layout: fixed;
  font-size: 0.9rem;
}

.patients-block .sheet th,
.patients-block .sheet td {
  padding: 3px 4px;
}

.patients-block .sheet thead th {
  font-size: 0.7rem;
  padding: 4px 3px;
}

.patients-block col.col-n { width: 34px; }
.patients-block col.col-name { width: 18%; }
.patients-block col.col-date { width: 108px; }
.patients-block col.col-lens,
.patients-block col.col-auto { width: 5.5%; }
.patients-block col.col-act { width: 32px; }

.patients-block .col-lens,
.patients-block thead th.col-lens,
.patients-block thead th.col-auto {
  padding-left: 2px;
  padding-right: 2px;
}

.patients-block .sheet input.num {
  padding: 3px 1px;
  font-size: 0.8rem;
  width: 100%;
}

.patients-block .sheet input[type="text"],
.patients-block .sheet input[type="date"] {
  padding: 3px 4px;
  font-size: 0.85rem;
}

.patients-block .cell-auto {
  font-size: 0.85rem;
  padding: 5px 2px;
}

.cell-n { text-align: center; color: var(--muted); }
.cell-auto {
  text-align: center;
  background: var(--auto-bg);
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.85rem;
}
.cell-auto.on { color: var(--ok); font-weight: 700; background: #e5f4ea; }
.cell-money {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cell-center { text-align: center; }

.section-row td {
  background: var(--header-teal) !important;
  font-weight: 700;
  text-align: left;
}

.section-row.extra td {
  background: var(--header-extra) !important;
}

.calc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 1.15fr);
  gap: 14px;
  align-items: stretch;
}

.patients-block {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  /* Высота по правой колонке (итоги/ЗП); свой контент не раздувает ряд */
  height: 0;
  min-height: 100%;
  overflow: hidden;
}

.patients-block > .desktop-patients {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
}

.patients-block > .mobile-patients {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.side-panels {
  display: flex;
  flex-direction: column;
}

.side-panels .block:first-child { margin-top: 14px; }

.summary {
  padding: 8px 0;
}

.summary-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  align-items: baseline;
}

.summary-row:last-child { border-bottom: none; }

.summary-row .label {
  color: var(--muted);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.summary-row .value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-family: var(--mono);
  font-size: 0.95rem;
}

.summary-row.total {
  background: #eef7f7;
}

.summary-row.total .label,
.summary-row.total .value {
  color: var(--accent);
  font-size: 1.05rem;
  font-weight: 700;
}

.summary-row.salary {
  background: linear-gradient(90deg, #e7f3e9, #f7fbf8);
}

.summary-row.salary .label,
.summary-row.salary .value {
  color: var(--ok);
  font-size: 1.15rem;
  font-weight: 800;
}

.salary-breakdown {
  margin: 12px 16px 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7fafb;
}

.salary-breakdown h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.salary-breakdown h4 {
  margin: 12px 0 6px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.breakdown-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 0.88rem;
  border-bottom: 1px dashed #e2e8ec;
}

.breakdown-line:last-child { border-bottom: none; }

.breakdown-line.strong {
  font-weight: 700;
  margin-top: 4px;
}

.breakdown-line.salary-line {
  margin-top: 8px;
  padding: 8px 0 0;
  border-bottom: none;
  border-top: 1px solid var(--line);
  color: var(--ok);
  font-weight: 800;
}

.breakdown-math {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* Autocomplete FIO */
.ac-wrap {
  position: relative;
  width: 100%;
}

.ac-input {
  width: 100%;
}

.ac-list {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow: auto;
}

.ac-list-fixed {
  position: fixed;
  right: auto;
}

.ac-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 0.9rem;
}

.ac-item:hover,
.ac-item:focus {
  background: var(--accent-soft);
}

.registry-toolbar {
  padding: 12px 16px 0;
}

.registry-list {
  padding: 12px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.registry-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fbfcfd;
}

.registry-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.registry-card-head h3 {
  margin: 0;
  font-size: 1rem;
}

.registry-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.registry-note {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.registry-note textarea {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
  min-height: 52px;
  background: #fff;
}

.registry-note-value {
  color: var(--ink);
  font-size: 0.9rem;
}

.revenue-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid var(--line);
}

.revenue-grid .summary-row {
  border-right: 1px solid var(--line);
}

.revenue-grid .summary-row:nth-child(2n) {
  border-right: none;
}

.footer {
  padding: 8px 22px 24px;
  color: var(--muted);
  font-size: 0.8rem;
}

.row-section-title {
  font-weight: 700;
  background: var(--header-teal) !important;
}

.input-month { width: 150px; }

.view-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 10px 22px 0;
  padding: 10px 14px;
  border: 1px solid #c9b27a;
  border-radius: var(--radius);
  background: #fff8e8;
  color: #5c4a1e;
}

.view-banner[hidden] {
  display: none !important;
}

.view-banner-text { flex: 1; min-width: 220px; font-size: 0.9rem; }
.view-banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.view-banner-session {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.view-banner-label {
  color: #8a7340;
  font-size: 0.85rem;
}

.view-banner-session strong {
  font-size: 1.05rem;
  color: #3d3214;
}

.view-banner-role {
  color: #8a7340;
  font-size: 0.85rem;
}

.btn-danger {
  border-color: #c98989;
  color: var(--danger);
}
.btn-danger:hover { background: #f8eaea; }

.archive-list {
  padding: 12px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.archive-empty {
  margin: 8px 0;
  color: var(--muted);
}

.archive-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
}

.archive-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.archive-card h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.archive-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 8px 0 4px;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.85rem;
}

.salary-stat {
  color: var(--ok);
  font-weight: 700;
}

.frozen-hint {
  margin-top: 6px !important;
  font-size: 0.8rem !important;
}

.archive-card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 120px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal[hidden] { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 36, 44, 0.45);
}

.modal-card {
  position: relative;
  width: min(440px, 100%);
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
}

.modal-card-wide {
  width: min(720px, 100%);
}

.excel-import-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 12px 0;
}

.excel-paste-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

#excel-paste {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.35;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
  min-height: 180px;
  background: #fff;
  color: var(--ink);
}

#excel-paste:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

#excel-preview {
  margin: 8px 0 0;
}

.modal-card h3 { margin: 0 0 8px; }

.modal-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 14px 0;
}

.modal-fields label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.modal-check {
  flex-direction: row !important;
  align-items: flex-start;
  gap: 8px !important;
  color: var(--ink) !important;
}

.modal-check input { margin-top: 3px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.print-only { display: none; }

body.is-readonly .sheet input.num,
body.is-readonly .sheet input.money {
  background: transparent;
  border-color: transparent;
}

/* ===== Auth gate ===== */
.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 20% 0%, #d9eceb 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 10%, #dce4f0 0%, transparent 50%),
    var(--bg);
}

/* display:grid выше перебивает нативный [hidden] — принудительно скрываем */
.auth-gate[hidden],
#auth-gate[hidden],
body.is-authenticated #auth-gate {
  display: none !important;
}

#app-shell[hidden] {
  display: none !important;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.auth-brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form[hidden] {
  display: none !important;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-form input[type="password"],
.auth-form input[type="text"],
.auth-form select,
.user-create-form input,
.user-create-form select {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.auth-form input[type="password"]:focus,
.auth-form input[type="text"]:focus,
.auth-form select:focus,
.user-create-form input:focus,
.user-create-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.workspace-switch {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--muted);
}

.workspace-switch select {
  font: inherit;
  min-width: 180px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
}

.users-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 16px;
  padding: 16px;
}

@media (max-width: 900px) {
  .users-layout { grid-template-columns: 1fr; }
}

.user-create-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
}

.user-create-form h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

.user-create-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.user-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.view-banner-admin {
  border-color: #7aa0c4;
  background: #eef4fa;
  color: #1e3a55;
}

#save-status.is-error { color: var(--danger); }

.auth-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.auth-server-error {
  margin-top: 14px;
  padding: 10px 12px;
  background: #f8eaea;
  border-radius: 8px;
  line-height: 1.45;
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 10px 12px;
}

#modal-password .auth-form {
  margin-top: 8px;
}

#modal-password .modal-actions {
  margin-top: 4px;
}

/* ===== Mobile layout ===== */
.btn-menu {
  display: none;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
}

.mobile-patients { display: none; }

.tab-short { display: none; }

.patients-cards {
  padding: 12px;
  flex-direction: column;
  gap: 10px;
}

.patient-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}

.patient-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.patient-card-n {
  font-weight: 700;
  color: var(--muted);
  font-size: 0.85rem;
}

.patient-card-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(118px, 132px);
  gap: 8px;
  align-items: end;
}

.patient-card-total {
  background: #e8eef2;
  font-size: 0.9rem;
  gap: 4px;
}

.mobile-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 0;
}

.mobile-field input,
.mobile-field .mobile-field-value,
.mobile-field > span + span {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 42px;
  width: 100%;
  max-width: 100%;
  background: var(--input-bg);
}

.mobile-field .mobile-field-value,
.mobile-field > span + span {
  display: flex;
  align-items: center;
  background: #f3f6f8;
}

.patient-lens-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.patient-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.patient-chips.muted {
  color: var(--muted);
  font-size: 0.8rem;
}

.chip {
  background: #e5f4ea;
  color: var(--ok);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

@media screen and (max-width: 1100px) {
  html {
    overflow-x: clip;
  }

  body {
    overflow-x: clip;
  }

  .calc-layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
  }

  /* Итоги сверху — сразу видно ЗП */
  .side-panels {
    display: contents;
  }

  .summary-block {
    order: -2;
    margin-top: 14px;
  }

  .patients-block {
    order: -1;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .patients-block > .desktop-patients {
    display: none !important;
  }

  .patients-block > .mobile-patients {
    display: flex !important;
    max-height: none;
    overflow: visible;
  }

  .side-panels > .block:not(.summary-block) {
    order: 1;
  }

  main,
  .panel,
  .block,
  .table-wrap {
    min-width: 0;
    max-width: 100%;
  }

  .sheet,
  .sheet.compact,
  .price-sheet,
  .panel .sheet:not(.compact) {
    min-width: 0 !important;
    width: 100%;
  }

  .topbar {
    flex-wrap: wrap;
    align-items: center;
    padding: 10px 12px;
    gap: 8px;
  }

  .brand {
    flex: 1;
    min-width: 0;
  }

  .brand h1 {
    font-size: 1rem;
    line-height: 1.25;
  }

  .brand p {
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
  }

  .btn-menu {
    display: inline-grid;
    place-items: center;
  }

  .topbar-actions {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding-top: 4px;
  }

  body.menu-open .topbar-actions {
    display: flex;
  }

  .topbar-actions .btn,
  .topbar-actions .btn-file {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  .workspace-switch {
    width: 100%;
  }

  .workspace-switch select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
  }

  .tabs {
    padding: 8px 10px 0;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar { display: none; }

  .tab {
    flex: 0 0 auto;
    padding: 9px 12px;
    font-size: 0.88rem;
    white-space: nowrap;
  }

  .tab-full { display: none; }
  .tab-short { display: inline; }

  main {
    padding: 0 10px 28px;
  }

  .view-banner {
    margin: 8px 10px 0;
    font-size: 0.85rem;
  }

  .block-head {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }

  .block-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .block-actions .year-label {
    grid-column: 1 / -1;
  }

  .block-actions .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .year-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
  }

  .input-inline,
  .input-month {
    width: 100%;
    min-height: 42px;
  }

  .table-wrap {
    max-height: none;
    overflow-x: visible;
  }

  /* Карточки вместо широких таблиц в правой колонке */
  .side-panels > .block .sheet.compact thead {
    display: none;
  }

  .side-panels > .block .sheet.compact,
  .side-panels > .block .sheet.compact tbody,
  .side-panels > .block .sheet.compact tfoot {
    display: block;
    width: 100%;
  }

  .side-panels > .block .sheet.compact tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: #fff;
  }

  .side-panels > .block .sheet.compact tbody tr:not(.section-row) {
    margin: 0;
  }

  .side-panels > .block .sheet.compact tr.section-row {
    display: block;
    background: var(--header-gray);
    font-weight: 700;
    padding: 8px 12px;
  }

  .side-panels > .block .sheet.compact tr.section-row td {
    border: none;
    padding: 0;
  }

  .side-panels > .block .sheet.compact td {
    display: flex;
    flex-direction: column;
    gap: 3px;
    border: none;
    padding: 0;
    min-width: 0;
    background: transparent !important;
  }

  .side-panels > .block .sheet.compact td[data-label]::before {
    content: attr(data-label);
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 600;
  }

  .side-panels > .block .sheet.compact td[data-label=""]:not(.cell-actions),
  .side-panels > .block .sheet.compact td.cell-n {
    display: none;
  }

  .side-panels > .block .sheet.compact td:nth-child(2) {
    grid-column: 1 / -1;
  }

  .side-panels > .block #extras-table td:nth-child(2),
  .side-panels > .block #extras-table td:nth-child(4) {
    grid-column: 1 / -1;
  }

  .side-panels > .block .sheet.compact td.cell-actions {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: flex-end;
  }

  .side-panels > .block .sheet.compact tfoot tr {
    background: #e8eef2;
    grid-template-columns: 1fr auto;
  }

  .side-panels > .block .sheet.compact tfoot td {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .side-panels > .block .sheet.compact tfoot td[colspan] {
    grid-column: 1;
  }

  .side-panels > .block .sheet.compact input,
  .side-panels > .block .sheet.compact select {
    width: 100%;
    min-width: 0;
    min-height: 40px;
  }

  .price-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .price-sheet {
    min-width: 0 !important;
    table-layout: fixed;
  }

  .price-sheet col.col-money { width: 110px; }
  .price-sheet col.col-n { width: 36px; }

  .revenue-grid {
    grid-template-columns: 1fr;
  }

  .revenue-grid .summary-row {
    border-right: none;
  }

  .summary-row {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px 12px;
  }

  .archive-card-actions {
    flex-direction: row;
    width: 100%;
  }

  .archive-card-actions .btn {
    flex: 1;
    min-height: 44px;
  }

  .modal {
    padding: 8px;
    align-items: end;
  }

  .modal-card,
  .modal-card-wide {
    width: 100%;
    max-height: min(92vh, 900px);
    overflow: auto;
    border-radius: 16px 16px 10px 10px;
  }

  .modal-actions {
    flex-wrap: wrap;
  }

  .modal-actions .btn {
    flex: 1;
    min-height: 44px;
  }

  .auth-gate {
    padding: 16px;
    align-items: center;
    justify-items: center;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .auth-card {
    width: 100%;
  }

  .footer {
    padding: 8px 12px calc(20px + env(safe-area-inset-bottom));
  }

  .registry-list,
  .users-layout {
    min-width: 0;
  }
}

@media screen and (max-width: 640px) {
  html, body {
    font-size: 15px;
  }

  .patient-card-meta {
    grid-template-columns: 1fr;
  }

  .patient-lens-grid {
    grid-template-columns: 1fr 1fr;
  }

  .mobile-field input,
  .mobile-field .mobile-field-value {
    font-size: 16px; /* без автозума iOS */
  }

  .summary-row .value {
    font-size: 1.05rem;
  }

  .block-actions {
    grid-template-columns: 1fr;
  }

  .block-actions .btn {
    grid-column: 1 / -1;
  }
}

/* ===== Print ===== */
@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10px !important;
  }

  .no-print,
  .topbar,
  .tabs,
  .footer,
  .modal,
  .view-banner,
  .btn,
  .btn-icon,
  .block-actions {
    display: none !important;
  }

  .print-only { display: block !important; }

  .print-title {
    margin: 0 0 8px;
  }

  .print-title h1 {
    margin: 0;
    font-size: 16px;
  }

  .print-title p {
    margin: 2px 0 0;
    color: #444;
  }

  main { padding: 0 !important; }

  .panel { display: none !important; }
  .panel.active.print-root,
  #tab-calc.print-root {
    display: block !important;
  }

  .block {
    box-shadow: none !important;
    border: 1px solid #999 !important;
    break-inside: avoid;
    margin-top: 8px !important;
  }

  .block-head {
    background: #eee !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .table-wrap {
    max-height: none !important;
    overflow: visible !important;
  }

  /* Список пациентов: сброс экранной вёрстки (height:0 / mobile hide) */
  .patients-block {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    display: block !important;
  }

  .patients-block > .desktop-patients,
  .desktop-patients {
    display: block !important;
    flex: none !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .mobile-patients {
    display: none !important;
  }

  .sheet {
    min-width: 0 !important;
    width: 100% !important;
  }

  .sheet thead th {
    position: static !important;
    background: #ddd !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .sheet th,
  .sheet td {
    border-color: #999 !important;
    padding: 2px 4px !important;
  }

  .calc-layout {
    display: block !important;
  }

  .side-panels {
    display: flex !important;
    flex-direction: column !important;
  }

  .summary-block,
  .patients-block,
  .side-panels > .block {
    order: initial !important;
  }

  .side-panels .block { page-break-inside: avoid; }

  .summary-row.salary,
  .summary-row.total,
  .section-row td,
  .cell-auto.on {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .col-act { display: none !important; }

  .salary-breakdown {
    break-inside: avoid;
    background: #f5f5f5 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .ac-list { display: none !important; }
}
