* {
  box-sizing: border-box;
}

* {
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* IE / Edge */
}

*::-webkit-scrollbar {
  display: none;                /* Chrome / Safari */
}

html, body {
  margin: 0;
  padding: 0;
  font-family: Inter, Arial, sans-serif;
  background: #f4f7fb;
  color: #0f172a;
}

body {
  min-height: 100vh;
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: linear-gradient(180deg, #0f172a 0%, #172554 100%);
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: 6px 0 24px rgba(15, 23, 42, 0.08);
}

.logo {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav a {
  color: rgba(255, 255, 255, 0.88);
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 600;
  transition: 0.2s ease;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 28px;
}

.page-shell {
  max-width: 1400px;
  margin: 0 auto;
}

h1, h2, h3 {
  margin-top: 0;
}

button {
  font-family: inherit;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.18);
}

.btn-primary:hover {
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.22);
}

.btn-secondary {
  background: #eef2f7;
  color: #0f172a;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.btn-danger:hover {
  background: #fecaca;
}

.card-btn {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  font-size: 12px;
  border-radius: 10px;
}

.input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border: 1px solid #dbe3ef;
  border-radius: 12px;
  background: #fff;
  color: #0f172aa9;
  font-size: 14px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
  background: #fff;
}

.panel {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.view-switch {
  display: flex;
  gap: 6px;
  background: #f1f5f9;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
}

.view-btn {
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  background: transparent;
  color: #475569;
}

.view-btn.active {
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.patients-grid {
  display: grid;
  grid-template-columns: repeat(4, 340px);
  gap: 18px;
  justify-content: start;
}

.patient-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

.interactive-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  cursor: pointer;
}

.interactive-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.10);
  border-color: #93c5fd;
}

.patient-avatar {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, #dbeafe, #eff6ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.patient-name {
  font-size: 21px;
  font-weight: 800;
  color: #0f172a;
}

.patient-owner {
  margin-top: 4px;
  color: #64748b;
  font-size: 14px;
}

.patient-code-badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.patient-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.patient-list-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
}

.info-chip {
  background: #f8fafc;
  border: 1px solid #edf2f7;
  border-radius: 14px;
  padding: 10px 12px;
}

.info-chip-label {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 4px;
}

.info-chip-value {
  font-size: 14px;
  color: #0f172a;
  font-weight: 700;
}

.patient-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  color: #64748b;
  font-size: 13px;
  padding-top: 4px;
  gap: 10px;
  flex-wrap: wrap;
}

.patient-meta strong {
  color: #334155;
}

.patient-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  margin-top: 2px;
}

.patient-actions > * {
  flex: 1;
  min-width: 0;
}

.empty-state {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  padding: 30px;
  text-align: center;
  color: #64748b;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-box {
  width: 920px;
  max-width: 100%;
  background: #ffffff;
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 28px;
  border-bottom: 1px solid #eef2f7;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.modal-title {
  font-size: 24px;
  font-weight: 800;
  color: #0f172a;
}

.modal-subtitle {
  margin-top: 6px;
  color: #64748b;
  font-size: 14px;
}

.icon-btn {
  border: none;
  background: #f1f5f9;
  color: #334155;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
}

.modal-body {
  padding: 28px;
}

.modal-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.section-card {
  background: #fcfcfd;
  border: 2px solid #eceff4;
  border-radius: 20px;
  padding: 20px;
}

.section-blue {
  background: #ffffff;
  border: 2px solid #e5eef9;
}

.section-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 16px;
}

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

.field-label {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 6px;
}

.readonly-box {
  padding: 12px 14px;
  border: 1px solid #dbe3ef;
  border-radius: 12px;
  background: #ffffff;
  color: #0f172a;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 5px;
}

@media (max-width: 1200px) {
  .patients-grid {
    grid-template-columns: repeat(2, 340px);
    justify-content: start;
  }
}

@media (max-width: 1100px) {
  .patient-list-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
  .modal-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
  }
  .content {
    padding: 18px;
  }
}

@media (max-width: 700px) {
  .patient-info-grid,
  .patient-list-grid {
    grid-template-columns: 1fr;
  }
  .patient-meta {
    flex-direction: column;
    align-items: flex-start;
  }
  .patient-actions {
    flex-direction: column;
    flex-wrap: wrap;
  }
  .patients-grid {
    grid-template-columns: 1fr;
  }
}

/* ─────────────────────────────────────────────────────────────
   АМБУЛАТОРНАЯ КАРТА
   ───────────────────────────────────────────────────────────── */

.ambulatory-page {
  padding: 8px 0 24px 0;
}

.ambulatory-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.ambulatory-header-left {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  flex-wrap: wrap;
}

.ambulatory-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 2px;
}

.ambulatory-page-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748b;
}

.ambulatory-main-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  line-height: 1.15;
}

.ambulatory-main-line-centered {
  min-height: 44px;
}

.ambulatory-main-name,
.ambulatory-main-owner {
  font-size: 30px;
  font-weight: 800;
  color: #0f172a;
}

.ambulatory-main-separator {
  font-size: 26px;
  color: #94a3b8;
  font-weight: 700;
}

.ambulatory-subline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: #64748b;
  font-size: 14px;
}

.ambulatory-header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.ambulatory-layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.ambulatory-sidebar {
  display: grid;
  gap: 18px;
}

.ambulatory-main {
  display: grid;
  gap: 18px;
}

.ambulatory-card-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 16px;
}

.ambulatory-profile-top {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ambulatory-avatar {
  width: 64px;
  height: 64px;
  font-size: 28px;
  border-radius: 18px;
}

.ambulatory-profile-name {
  font-size: 24px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.1;
}

.ambulatory-info-stack {
  display: grid;
  gap: 10px;
}

.ambulatory-drive-box {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #eef2f7;
}

.ambulatory-muted-text {
  color: #64748b;
  font-size: 14px;
  line-height: 1.5;
}

.ambulatory-section-card {
  min-height: 280px;
}

.ambulatory-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.ambulatory-section-title {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
}

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

.ambulatory-empty-state {
  min-height: 210px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

@media (max-width: 1100px) {
  .ambulatory-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .ambulatory-main-name,
  .ambulatory-main-owner {
    font-size: 24px;
  }
  .ambulatory-main-separator {
    display: none;
  }
}

/* ─────────────────────────────────────────────────────────────
   СТРАНИЦА ПРИЁМА
   ───────────────────────────────────────────────────────────── */

.appointment-page {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.unsaved-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 14px;
  color: #92400e;
}

.appointment-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding: 20px;
  background: white;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.appointment-header-left {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex: 1;
}

.appointment-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.appointment-header-right {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}

.weight-field-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.weight-input-row {
  display: flex;
  gap: 8px;
}

.weight-input {
  width: 100px;
}

.appointment-header-actions {
  display: flex;
  gap: 8px;
}

.appointment-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.appointment-type-panel {
  padding: 20px;
  background: white;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.appt-type-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.appt-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 13px;
}

.appt-type-btn:hover {
  border-color: #cbd5e1;
  background: #f1f5f9;
}

.appt-type-btn.active {
  background: #dbeafe;
  border-color: #2563eb;
}

.appt-type-icon {
  font-size: 24px;
}

.appt-type-label {
  font-weight: 600;
  color: #0f172a;
}

.appt-type-desc {
  font-size: 12px;
  color: #64748b;
}

.copy-recs-panel {
  padding: 12px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 6px;
}

.appointment-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.appointment-field-panel {
  padding: 20px;
  background: white;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.appt-textarea {
  min-height: 200px;
  resize: vertical;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ─────────────────────────────────────────────────────────────
   ПАНЕЛЬ ШАБЛОНОВ (БОКОВАЯ)
   ───────────────────────────────────────────────────────────── */

.templates-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 998;
}

.templates-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.templates-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  background: white;
  border-left: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s;
  z-index: 999;
}

.templates-panel.open {
  transform: translateX(0);
}

.templates-panel-header {
  flex-shrink: 0;
  padding: 16px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.templates-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 0;
}

.templates-panel-footer {
  flex-shrink: 0;
  padding: 12px;
  border-top: 1px solid #e2e8f0;
  background: white;
}

.templates-loading {
  text-align: center;
  color: #64748b;
  padding: 24px;
  font-size: 14px;
}

.templates-empty {
  text-align: center;
  color: #94a3b8;
  padding: 32px 16px;
}

.template-group {
  margin-bottom: 12px;
  background: #f8fafc;
  border-radius: 8px;
  overflow: hidden;
}

.template-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600;
  font-size: 13px;
}

.template-group-name {
  flex: 1;
  color: #0f172a;
}

.template-group-actions {
  display: flex;
  gap: 4px;
}

.template-list {
  padding: 8px;
}

.template-item {
  padding: 8px;
  margin-bottom: 8px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}

.template-item-name {
  font-size: 13px;
  font-weight: 500;
  color: #0f172a;
  margin-bottom: 8px;
}

.template-item-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* Предпросмотр шаблона */
.template-preview-box {
  display: none;
  margin-top: 8px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 12px;
  color: #334155;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
}

.template-preview-box.open {
  display: block;
}

/* ─────────────────────────────────────────────────────────────
   МОДАЛКИ
   ───────────────────────────────────────────────────────────── */

.modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.show {
  display: flex;
}

.modal-box {
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  width: 560px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px;
  border-bottom: 1px solid #e2e8f0;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
}

.modal-subtitle {
  font-size: 13px;
  color: #64748b;
  margin-top: 4px;
}

.modal-body {
  padding: 20px;
}

.modal-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.section-card {
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.section-card.section-blue {
  background: #feffff;
  border-color: var(--pumpkin-lt);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

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

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: #0f172a;
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e2e8f0;
}

.weight-empty {
  text-align: center;
  color: #94a3b8;
  padding: 40px 20px;
}

/* ─────────────────────────────────────────────────────────────
   СПИСОК ПРИЁМОВ (patient_detail.html)
   ───────────────────────────────────────────────────────────── */

.appointments-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.appt-list-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.appt-list-item:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.appt-list-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.appt-list-body {
  flex: 1;
  min-width: 0;
}

.appt-list-type {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 4px;
}

.appt-list-preview {
  font-size: 13px;
  color: #64748b;
  line-height: 1.4;
  white-space: normal;
  word-break: break-word;
}

.appt-list-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  flex-shrink: 0;
}

.appt-list-date {
  font-size: 12px;
  color: #94a3b8;
}

.appt-list-weight {
  font-size: 12px;
  color: #2563eb;
  font-weight: 500;
}

/* ─────────────────────────────────────────────────────────────
   УТИЛИТЫ
   ───────────────────────────────────────────────────────────── */

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: #f1f5f9;
}

.view-toggle {
  display: flex;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
}

.view-toggle-btn {
  padding: 6px 10px;
  background: #fff;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #94a3b8;
  transition: all 0.2s;
}

.view-toggle-btn:hover {
  background: #f1f5f9;
}

.view-toggle-btn.active {
  background: #eff6ff;
  color: #2563eb;
}

.appt-accordion-item {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}

.appt-accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  background: #f8fafc;
  transition: background 0.2s;
}

.appt-accordion-header:hover {
  background: #f1f5f9;
}

.appt-accordion-arrow {
  font-size: 12px;
  color: #94a3b8;
}

.appt-accordion-body {
  padding: 16px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}

.appt-accordion-section {
  margin-bottom: 12px;
}

.appt-accordion-label {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.appt-accordion-text {
  font-size: 14px;
  color: #0f172a;
  line-height: 1.5;
  white-space: pre-wrap;
}

.template-preview-box {
  display: none;
  margin-top: 8px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 12px;
  color: #334155;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
}

.template-preview-box.open {
  display: block;
}

/* ИСТОРИЯ ПРИЁМОВ - боковая панель */
.history-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 998;
}
.history-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.history-panel {
  position: fixed;
  top: 0; left: 0;
  width: 400px;
  height: 100vh;
  background: white;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s;
  z-index: 999;
}
.history-panel.open {
  transform: translateX(0);
}
.history-panel-header {
  flex-shrink: 0;
  padding: 16px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 0;
}
.history-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.history-item:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}
.history-item.current {
  background: #dbeafe;
  border-color: #2563eb;
}
.history-item-icon {
  font-size: 22px;
  flex-shrink: 0;
}
.history-item-body {
  flex: 1;
  min-width: 0;
}
.history-item-type {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 2px;
}
.history-item-preview {
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}
.history-item-date {
  font-size: 11px;
  color: #94a3b8;
}
.history-item-weight {
  font-size: 11px;
  color: #2563eb;
  font-weight: 500;
}

/* МОДАЛКА ПРОСМОТРА ПРИЁМА ИЗ ИСТОРИИ */
.appt-view-section {
  margin-bottom: 16px;
}
.appt-view-label {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.appt-view-text {
  font-size: 14px;
  color: #0f172a;
  line-height: 1.6;
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px;
}

/* ─────────────────────────────────────────────
   DASHBOARD
   ───────────────────────────────────────────── */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 18px;
}

.dashboard-card {
  min-height: 260px;
}

.dashboard-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.dashboard-link {
  color: #2563eb;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.dashboard-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dashboard-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
}

.dashboard-item-title {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.dashboard-item-subtitle {
  font-size: 13px;
  color: #64748b;
}

.dashboard-empty {
  color: #94a3b8;
  padding: 28px 8px;
  text-align: center;
}

/* ─────────────────────────────────────────────
   STATUS BADGES / SUBSCRIPTIONS
   ───────────────────────────────────────────── */

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-success {
  background: #dcfce7;
  color: #166534;
}

.status-warning {
  background: #fef3c7;
  color: #92400e;
}

.status-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.subscription-card-highlight {
  border-color: #93c5fd !important;
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.08);
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

/* ─────────────────────────────────────────────
   CALENDAR
   ───────────────────────────────────────────── */

.calendar-page {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.calendar-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  flex-wrap: wrap;
}

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

.calendar-grid-wrap {
  overflow-x: auto;
}

.calendar-grid {
  display: grid;
  gap: 16px;
}

.calendar-grid-1 {
  grid-template-columns: 1fr;
}

.calendar-grid-7 {
  grid-template-columns: repeat(7, minmax(220px, 1fr));
}

.calendar-day-col {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.calendar-day-head {
  padding: 14px 16px;
  border-bottom: 1px solid #eef2f7;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.calendar-day-title {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
}

.calendar-day-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.calendar-empty-day {
  color: #94a3b8;
  font-size: 14px;
  text-align: center;
  padding: 40px 10px;
}

.calendar-event-card {
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  border: 1px solid transparent;
}

.calendar-event-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
}

.calendar-event-primary {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.calendar-event-repeat {
  background: #f5f3ff;
  border-color: #ddd6fe;
}

.calendar-event-consultation {
  background: #ecfeff;
  border-color: #a5f3fc;
}

.calendar-event-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.calendar-event-time {
  font-size: 12px;
  font-weight: 800;
  color: #0f172a;
}

.calendar-event-status {
  font-size: 11px;
  color: #64748b;
}

.calendar-event-title {
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 4px;
}

.calendar-event-subtitle {
  font-size: 12px;
  color: #475569;
}

/* ─────────────────────────────────────────────
   REMINDERS
   ───────────────────────────────────────────── */

.reminders-page {
  display: flex;
  flex-direction: column;
}

.done-reminder-card {
  opacity: 0.8;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

/* ─────────────────────────────────────────────
   METRICS
   ───────────────────────────────────────────── */

.metric-card {
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  padding: 16px;
  background: #fcfdff;
  margin-bottom: 14px;
}

.metric-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.metric-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
}

.metric-unit {
  color: #64748b;
  font-weight: 700;
  font-size: 14px;
}

.metric-chart-wrap {
  background: #fff;
  border: 1px solid #eef2f7;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
}

.metric-records-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.metric-record-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
}

.metric-record-value {
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
}

.metric-record-date {
  font-size: 12px;
  color: #64748b;
}

/* ─────────────────────────────────────────────
   PRINT LINKS / SMALL HELPERS
   ───────────────────────────────────────────── */

.text-link-btn {
  text-decoration: none;
}

@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .calendar-grid-7 {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }
}

@media (max-width: 700px) {
  .calendar-grid-7,
  .calendar-grid-1 {
    grid-template-columns: 1fr;
  }

  .calendar-topbar-actions {
    width: 100%;
  }

  .calendar-topbar-actions > * {
    width: 100%;
  }
}

/* ─────────────────────────────────────────────
   INTAKES
   ───────────────────────────────────────────── */

.intakes-page {
  display: flex;
  flex-direction: column;
}

/* ─────────────────────────────────────────────
   CALENDAR V2
   ───────────────────────────────────────────── */

.calendar-v2-page {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.calendar-v2-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  flex-wrap: wrap;
}

.calendar-v2-title {
  margin: 0;
  font-size: 32px;
  line-height: 1.1;
  color: #0f172a;
  font-weight: 800;
}

.calendar-v2-subtitle {
  margin-top: 8px;
  color: #64748b;
  font-size: 15px;
}

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

.calendar-board-wrap {
  overflow-x: auto;
}

.calendar-grid-v2 {
  display: grid;
  min-width: 980px;
  border: 1px solid #dbe3ef;
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
}

.calendar-corner-head,
.calendar-day-head-v2 {
  background: linear-gradient(135deg, #2c4a6e, #2b476b);
  color: #fff;
  padding: 14px 12px;
  border-right: 1px solid rgba(255,255,255,0.12);
  font-weight: 800;
}

.calendar-day-head-v2 {
  text-align: center;
}

.calendar-day-week {
  font-size: 14px;
  opacity: 0.95;
}

.calendar-day-date {
  font-size: 18px;
  margin-top: 4px;
}

.calendar-time-col {
  border-right: 1px solid #e2e8f0;
}

.calendar-time-cell {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #64748b;
  border-top: 1px solid #eef2f7;
  background: #fff;
}

.calendar-day-col-v2 {
  position: relative;
  border-right: 1px solid #e2e8f0;
  min-height: 1056px;
  background: #fff;
}

.calendar-slot-cell {
  border-top: 1px solid #eef2f7;
  background: #fff;
  cursor: pointer;
}

.calendar-slot-cell:hover {
  background: #f8fbff;
}

.calendar-event-v2 {
  position: absolute;
  left: 8px;
  right: 8px;
  border-radius: 14px;
  padding: 10px 10px 18px 10px;
  overflow: hidden;
  cursor: grab;
  z-index: 3;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
  border: 1px solid transparent;
}

.calendar-event-v2-primary {
  background: #eaf3ff;
  border-color: #bfdbfe;
}

.calendar-event-v2-repeat {
  background: #f3edff;
  border-color: #d8b4fe;
}

.calendar-event-v2-consultation {
  background: #e9fcff;
  border-color: #a5f3fc;
}

.calendar-event-subscription {
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18), 0 10px 20px rgba(15, 23, 42, 0.08);
}

.calendar-event-v2-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.calendar-event-v2-title {
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
}

.calendar-event-v2-owner {
  margin-top: 4px;
  font-size: 12px;
  color: #334155;
}

.calendar-event-v2-type {
  margin-top: 6px;
  font-size: 12px;
  color: #475569;
  font-weight: 700;
}

.calendar-notes-icon {
  font-size: 12px;
}

.calendar-mini-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.calendar-mini-dot-green {
  background: #22c55e;
}

.calendar-event-resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 8px;
  cursor: ns-resize;
  background: rgba(15, 23, 42, 0.08);
}

.patient-search-results {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
}

.patient-search-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.patient-search-item:hover {
  background: #eff6ff;
}

.patient-search-name {
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
}

.patient-search-meta {
  font-size: 12px;
  color: #64748b;
}

.selected-patient-box {
  margin-top: 14px;
  background: #f8fbff;
  border: 1px solid #dbeafe;
  border-radius: 12px;
  padding: 12px;
}

.selected-patient-name {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
}

.selected-patient-meta {
  font-size: 13px;
  color: #64748b;
  margin-top: 4px;
}

.calendar-context-menu {
  position: fixed;
  z-index: 9999;
  background: #fff;
  border: 1px solid #dbe3ef;
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.14);
  display: none;
  min-width: 220px;
  overflow: hidden;
}

.calendar-context-menu button {
  width: 100%;
  border: none;
  background: #fff;
  text-align: left;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 14px;
  color: #0f172a;
}

.calendar-context-menu button:hover {
  background: #f8fafc;
}

/* ─────────────────────────────────────────────
   PATIENT SUBSCRIPTION PAW
   ───────────────────────────────────────────── */

.patient-avatar-subscription {
  background: linear-gradient(135deg, #e8854a, #c8652a) !important;
  color: #fff !important;
  box-shadow: 0 10px 24px rgba(200, 101, 42, 0.14);
}

/* ─────────────────────────────────────────────
   METRICS DRAWER
   ───────────────────────────────────────────── */

.metrics-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.28);
  z-index: 70;
  display: none;
}

.metrics-drawer-overlay.open {
  display: block;
}

.metrics-drawer {
  position: fixed;
  top: 0;
  right: -520px;
  width: 500px;
  max-width: calc(100vw - 24px);
  height: 100vh;
  background: #fff;
  z-index: 80;
  box-shadow: -18px 0 40px rgba(15, 23, 42, 0.16);
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
}

.metrics-drawer.open {
  right: 0;
}

.metrics-drawer-header {
  padding: 16px 18px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.metrics-drawer-body {
  padding: 16px;
  overflow-y: auto;
}

.compact-metric-card {
  padding: 12px;
  border-radius: 14px;
}

.compact-metric-chart {
  padding: 8px;
  margin-bottom: 10px;
}

/* ─────────────────────────────────────────────
   SETTINGS
   ───────────────────────────────────────────── */

.workdays-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.weekday-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #dbe3ef;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 14px;
  color: #0f172a;
  font-weight: 700;
}

@media (max-width: 900px) {
  .metrics-drawer {
    display: none;
    width: 100%;
    max-width: 100%;
  }
}

/* ─────────────────────────────────────────────
   SETTINGS V2
   ───────────────────────────────────────────── */

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

.settings-page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  flex-wrap: wrap;
}

.settings-page-title {
  margin: 0;
  font-size: 32px;
  line-height: 1.1;
  color: #0f172a;
  font-weight: 800;
}

.settings-page-subtitle {
  margin-top: 8px;
  color: #64748b;
  font-size: 15px;
}

.settings-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.settings-sidebar-menu {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 20px;
}

.settings-menu-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: #f8fafc;
  color: #334155;
  font-size: 14px;
  font-weight: 700;
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  transition: 0.18s ease;
}

.settings-menu-btn:hover {
  background: #eff6ff;
  color: #1d4ed8;
}

.settings-menu-btn.active {
  background: linear-gradient(135deg, #e8854a, #c8652a);
  color: #fff;
  box-shadow: 0 10px 24px rgba(200, 101, 42, 0.14);
}

.settings-main {
  min-width: 0;
}

.settings-section {
  display: none;
}

.settings-section.active {
  display: block;
  animation: settings-fade-in 0.22s ease forwards;
}

@keyframes settings-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.settings-panel {
  padding: 20px;
}

.settings-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}

.settings-subtabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.settings-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}

.settings-toolbar-text {
  color: #64748b;
  font-size: 14px;
}

.settings-empty-box {
  padding: 18px;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  color: #64748b;
  text-align: center;
  background: #fcfdff;
}

.settings-library-row {
  display: grid;
  grid-template-columns: 2fr 180px auto;
  gap: 12px;
  align-items: end;
}

.settings-template-row {
  display: grid;
  grid-template-columns: 2fr 100px 100px 120px 120px auto;
  gap: 12px;
  align-items: end;
}

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

.settings-checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-muted-hint {
  display: none;
  margin-top: 8px;
  color: #94a3b8;
  font-size: 12px;
}

.settings-static-input {
  display: flex;
  align-items: center;
  min-height: 42px;
  background: #f8fafc;
}

.settings-template-preview-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-preview-card {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  background: #f8fafc;
}

.settings-preview-card-title {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 8px;
}

.settings-preview-card-box {
  border: 1px solid #cbd5e1;
  background: white;
  border-radius: 8px;
}

.settings-doc-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(380px, 480px);
  gap: 20px;
  align-items: start;
}

.settings-doc-form {
  min-width: 0;
}

.settings-footer-textarea {
  min-height: 120px;
  resize: vertical;
}

.settings-logo-box {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: #f8fbff;
}

.settings-logo-controls {
  align-items: end;
}

.settings-logo-current {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
}

.settings-logo-current img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  padding: 4px;
}

.settings-doc-preview-wrap {
  min-width: 0;
}

.settings-doc-preview-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.doc-preview-page-title {
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 20px;
}

.doc-header-preview {
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.doc-preview-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.doc-preview-header-row.reverse {
  flex-direction: row-reverse;
}

.doc-preview-header-top {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  text-align: center;
}

.doc-preview-logo-top-wrap {
  display: flex;
  justify-content: center;
}

.doc-preview-logo-side-wrap {
  flex-shrink: 0;
}

.doc-preview-logo {
  object-fit: contain;
  max-width: 100%;
  height: auto;
}

.doc-preview-doctor-block {
  min-width: 0;
  flex: 1;
}

.doc-preview-clinic {
  font-size: 14px;
  font-weight: 700;
  color: #2563eb;
  margin-bottom: 6px;
}

.doc-preview-doctor-name {
  font-size: 22px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
}

.doc-preview-doctor-specialty {
  margin-top: 4px;
  font-size: 15px;
  color: #334155;
  font-weight: 600;
}

.doc-preview-contacts {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: #334155;
}

.doc-patient-preview {
  margin-bottom: 18px;
}

.doc-patient-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-size: 14px;
  color: #0f172a;
}

.doc-preview-block {
  margin-bottom: 18px;
}

.doc-preview-label {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 8px;
}

.doc-preview-text {
  font-size: 14px;
  line-height: 1.6;
  color: #334155;
  white-space: pre-wrap;
}

.doc-footer-preview {
  margin-top: 22px;
}

.doc-preview-footer-text {
  font-size: 13px;
  color: #64748b;
  line-height: 1.6;
  white-space: pre-wrap;
  border-top: 1px solid #e2e8f0;
  padding-top: 14px;
}

.doc-signature-preview {
  margin-top: 24px;
}

.doc-preview-sign-name {
  font-size: 16px;
  font-weight: 800;
  color: #0f172a;
}

.doc-preview-sign-spec {
  margin-top: 4px;
  color: #475569;
  font-size: 14px;
}

@media (max-width: 1200px) {
  .settings-doc-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1020px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }

  .settings-sidebar-menu {
    position: static;
  }
}

@media (max-width: 900px) {
  .settings-two-col {
    grid-template-columns: 1fr;
  }

  .settings-library-row,
  .settings-template-row {
    grid-template-columns: 1fr;
  }

  .doc-patient-preview-grid {
    grid-template-columns: 1fr;
  }

  .doc-preview-header-row,
  .doc-preview-header-row.reverse {
    flex-direction: column;
  }
}

/* ─────────────────────────────────────────────
   APPOINTMENT AUTOSAVE / HISTORY V2
   ───────────────────────────────────────────── */

.appointment-save-status {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  margin-top: -8px;
  margin-bottom: -4px;
}

.appointment-save-status.saved {
  background: #dcfce7;
  color: #166534;
}

.appointment-save-status.saving {
  background: #dbeafe;
  color: #1d4ed8;
}

.appointment-save-status.error {
  background: #fee2e2;
  color: #b91c1c;
}

.appointment-save-status.dirty {
  background: #fef3c7;
  color: #92400e;
}

.appt-view-section {
  margin-bottom: 16px;
}

.appt-view-label {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.appt-view-text {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.6;
  color: #0f172a;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 14px;
}

/* ─────────────────────────────────────────────
   APPOINTMENT / TEMPLATE POPOVER POLISH
   ───────────────────────────────────────────── */

.appointment-header {
  border-radius: 20px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.05);
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
}

.appointment-type-panel {
  border-radius: 20px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
}

.appointment-field-panel {
  border-radius: 20px;
  border: 1px solid #dbe4f0;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.045);
  background:
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.04), transparent 28%),
    linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.appointment-field-panel:hover {
  border-color: #c7d7ee;
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.07);
}

.appointment-inline-tool {
  padding: 8px 12px;
  min-height: 36px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 800;
  background: #f8fafc;
  border: 1px solid #dbe3ef;
  color: #334155;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9);
}

.appointment-inline-tool:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
  box-shadow:
    0 8px 18px rgba(37, 99, 235, 0.08),
    inset 0 1px 0 rgba(255,255,255,0.95);
}

.dynamic-appt-field {
  min-height: 210px;
  border-radius: 16px;
  border: 1px solid #d9e2ef;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  padding: 16px 18px;
  line-height: 1.65;
  font-size: 14px;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease;
}

.dynamic-appt-field:hover {
  border-color: #c7d7ee;
}

.dynamic-appt-field:focus {
  border-color: #60a5fa;
  box-shadow:
    0 0 0 4px rgba(59, 130, 246, 0.10),
    0 12px 30px rgba(37, 99, 235, 0.08);
  background: #ffffff;
}

/* активная карточка поля при фокусе textarea */
.appointment-field-panel:has(.dynamic-appt-field:focus) {
  border-color: #93c5fd;
  box-shadow:
    0 0 0 4px rgba(59, 130, 246, 0.08),
    0 18px 40px rgba(37, 99, 235, 0.08);
}

/* если :has не поддерживается — всё равно будет красиво через сам textarea */

/* ─────────────────────────────────────────────
   TEMPLATE POPOVER
   ───────────────────────────────────────────── */

#fieldTemplatePopover {
  animation: templatePopoverIn 0.16s ease-out;
}

@keyframes templatePopoverIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#fieldTemplatePopover > .panel {
  border-radius: 20px !important;
  border: 1px solid #dbe3ef !important;
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.05), transparent 32%),
    linear-gradient(180deg, #ffffff 0%, #fcfdff 100%) !important;
  box-shadow:
    0 24px 60px rgba(15, 23, 42, 0.16),
    0 8px 22px rgba(15, 23, 42, 0.08) !important;
  backdrop-filter: blur(8px);
}

#fieldTemplatePopoverFieldLabel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #64748b !important;
  font-weight: 600;
}

#fieldTemplateSearch,
#fieldTemplateGroupFilter {
  border-radius: 14px;
  min-height: 44px;
}

#fieldTemplatePopoverBody {
  padding-right: 2px;
  scrollbar-width: thin;
}

#fieldTemplatePopoverBody::-webkit-scrollbar {
  width: 8px;
}

#fieldTemplatePopoverBody::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

#fieldTemplatePopoverBody .panel {
  border-radius: 14px !important;
  border: 1px solid #e2e8f0 !important;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%) !important;
  box-shadow: none !important;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

#fieldTemplatePopoverBody .panel:hover {
  transform: translateY(-1px);
  border-color: #bfdbfe !important;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.08) !important;
}

#fieldTemplatePopoverBody .btn {
  white-space: nowrap;
}

#fieldTemplatePopoverBody .btn-primary {
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.16);
}

#fieldTemplatePopoverBody .btn-secondary {
  background: #eef2ff;
  color: #334155;
}

/* ─────────────────────────────────────────────
   HISTORY PANEL / LEFT DRAWER POLISH
   ───────────────────────────────────────────── */

.history-panel {
  width: 420px;
  border-right: 1px solid #e2e8f0;
  box-shadow: 18px 0 40px rgba(15, 23, 42, 0.12);
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
}

.history-panel-header {
  padding: 18px 18px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.history-item {
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.history-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
}

.history-item.current {
  background: linear-gradient(180deg, #eef6ff 0%, #dbeafe 100%);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.10);
}

/* ─────────────────────────────────────────────
   SETTINGS / TEXT TEMPLATES POLISH
   ───────────────────────────────────────────── */

#settingsTemplatesBoard > .panel {
  border-radius: 20px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.05);
}

#settingsTemplatesBoard .panel .panel {
  border-radius: 16px !important;
  border: 1px solid #e2e8f0 !important;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%) !important;
  box-shadow: none !important;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

#settingsTemplatesBoard .panel .panel:hover {
  transform: translateY(-1px);
  border-color: #bfdbfe !important;
  box-shadow: 0 12px 22px rgba(37, 99, 235, 0.06) !important;
}

#settingsTemplateFieldBindingWrap {
  margin-top: 10px;
  padding: 14px;
  border: 1px solid #dbe3ef;
  border-radius: 16px;
  background: linear-gradient(180deg, #fbfdff 0%, #f8fbff 100%);
}

#settingsTemplateFieldBindingList .weekday-chip {
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

#settingsTemplateFieldBindingList .weekday-chip:hover {
  background: #eef6ff;
  border-color: #bfdbfe;
  transform: translateY(-1px);
}

#settingsTemplateFieldBindingList input[type="checkbox"] {
  accent-color: #2563eb;
}

/* ─────────────────────────────────────────────
   SETTINGS MENU / PANELS LITTLE UPGRADE
   ───────────────────────────────────────────── */

.settings-panel {
  border-radius: 22px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.05);
}

.settings-menu-btn {
  border: 1px solid transparent;
}

.settings-menu-btn:hover {
  border-color: #dbeafe;
}

.settings-preview-card {
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.settings-preview-card-box {
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

/* ─────────────────────────────────────────────
   SMALL RESPONSIVE IMPROVEMENTS
   ───────────────────────────────────────────── */

@media (max-width: 1100px) {
  .appointment-header {
    flex-direction: column;
    align-items: stretch;
  }

  .appointment-header-right {
    flex-direction: column;
    align-items: stretch;
  }

  .appointment-header-actions {
    flex-wrap: wrap;
  }

  .appointment-header-actions > * {
    flex: 1 1 auto;
  }
}

@media (max-width: 700px) {
  .appointment-field-panel {
    padding: 16px;
    border-radius: 18px;
  }

  .dynamic-appt-field {
    min-height: 180px;
    padding: 14px 15px;
  }

  #fieldTemplatePopover {
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
  }

  .history-panel {
    width: min(92vw, 420px);
  }

  .appointment-inline-tool {
    width: 100%;
    justify-content: center;
  }
}

/* ─────────────────────────────────────────────
   INTAKES WORKSPACE V2
   ───────────────────────────────────────────── */

.intakes-workspace {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.intakes-title {
  margin: 0;
  font-size: 32px;
  line-height: 1.1;
  color: #0f172a;
  font-weight: 800;
}

.intakes-subtitle {
  margin-top: 8px;
  color: #64748b;
  font-size: 15px;
}

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

.intakes-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.intakes-toolbar-left,
.intakes-toolbar-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.intake-search-input {
  width: 320px;
  max-width: 100%;
}

.intake-filter-select {
  width: 180px;
  max-width: 100%;
}

.intakes-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 6px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
}

.intakes-tab {
  border: none;
  background: transparent;
  color: #475569;
  font-size: 14px;
  font-weight: 800;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: 0.18s ease;
}

.intakes-tab:hover {
  background: #fff;
  color: #0f172a;
}

.intakes-tab.active {
  background: #fff;
  color: #0f172a;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

.intakes-tab-panel {
  display: none;
}

.intakes-tab-panel.active {
  display: block;
}

.intakes-two-col {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

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

.intakes-section-title {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
}

.intakes-section-text {
  margin-top: 6px;
  color: #64748b;
  font-size: 14px;
}

.intake-card-list {
  display: grid;
  gap: 14px;
}

.intake-form-card,
.intake-link-card,
.intake-submission-card {
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  padding: 16px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.intake-form-card:hover,
.intake-link-card:hover,
.intake-submission-card:hover {
  transform: translateY(-1px);
  border-color: #bfdbfe;
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.06);
}

.intake-form-card.active {
  border-color: #93c5fd;
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.10);
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.intake-form-card-top,
.intake-link-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.intake-form-card-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
}

.intake-form-card-text {
  margin-top: 6px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.intake-metric-row,
.intake-link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.intake-form-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.intake-form-card-actions > * {
  flex: 1;
  min-width: 0;
}

.intake-editor-panel {
  min-height: 680px;
}

.intakes-editor-empty {
  min-height: 620px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #64748b;
  text-align: center;
  padding: 30px;
}

.intakes-editor-empty-icon {
  font-size: 56px;
  margin-bottom: 10px;
}

.intakes-editor-empty-title {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 6px;
}

.intakes-editor-empty-text {
  max-width: 420px;
  line-height: 1.6;
}

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

.intake-editor-title {
  font-size: 24px;
  font-weight: 800;
  color: #0f172a;
}

.intake-editor-subtitle {
  margin-top: 6px;
  color: #64748b;
  font-size: 14px;
}

.intake-editor-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.intake-builder-layout {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: start;
}

.intake-builder-col {
  min-width: 100%;
}

.intake-builder-card {
  border: 1px solid #e2e8f0;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  padding: 18px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

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

.intake-builder-card-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
}

.intake-builder-card-text {
  margin-top: 4px;
  color: #64748b;
  font-size: 13px;
}

.intake-builder-list {
  display: grid;
  gap: 12px;
}

.intake-builder-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  background: #fff;
  padding: 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.intake-builder-item:hover {
  border-color: #bfdbfe;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.06);
  transform: translateY(-1px);
}

.intake-builder-drag {
  color: #94a3b8;
  font-weight: 900;
  line-height: 1;
  padding-top: 4px;
  user-select: none;
  cursor: grab;
}

.intake-builder-main {
  min-width: 0;
}

.intake-builder-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.intake-builder-name {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
}

.intake-builder-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.intake-builder-meta {
  margin-top: 8px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.intake-builder-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
  min-width: max-content;
}

.intake-preview-shell {
  background: linear-gradient(180deg, #f8fbff 0%, #f1f6fd 100%);
  border: 1px solid #e2e8f0;
  border-radius: 22px;
  padding: 14px;
}

.intake-preview-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.04);
}

.intake-preview-title {
  font-size: 24px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 8px;
}

.intake-preview-subtitle {
  color: #64748b;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 18px;
}

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

.intake-preview-item.width-100 {
  grid-column: span 2;
}

.intake-preview-item.width-50 {
  grid-column: span 1;
}

.intake-preview-label {
  font-size: 13px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 6px;
}

.intake-preview-help {
  color: #64748b;
  font-size: 12px;
  margin-bottom: 8px;
  line-height: 1.5;
}

.intake-preview-info {
  border: 1px solid #dbeafe;
  background: #f8fbff;
  color: #1e3a8a;
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
}

.intake-preset-groups {
  display: grid;
  gap: 16px;
}

.intake-preset-group {
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  padding: 16px;
}

.intake-preset-group-title {
  font-size: 16px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 12px;
}

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

.intake-preset-card {
  text-align: left;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: #fff;
  padding: 14px;
  cursor: pointer;
  transition: 0.18s ease;
}

.intake-preset-card:hover {
  border-color: #bfdbfe;
  background: #f8fbff;
  transform: translateY(-1px);
}

.intake-preset-card-title {
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 6px;
}

.intake-preset-card-text {
  font-size: 12px;
  color: #64748b;
}

.intake-one-time-note {
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.intake-submission-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 16px;
  align-items: start;
}

.intake-submission-main,
.intake-submission-side {
  min-width: 0;
}

@media (max-width: 1180px) {
  .intakes-two-col {
    grid-template-columns: 1fr;
  }

  .intake-builder-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .intake-submission-view {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .intakes-toolbar {
    align-items: stretch;
  }

  .intakes-toolbar-right {
    width: 100%;
  }

  .intake-search-input,
  .intake-filter-select {
    width: 100%;
  }

  .intake-metric-row,
  .intake-link-grid,
  .intake-preset-grid,
  .intake-preview-grid {
    grid-template-columns: 1fr;
  }

  .intake-preview-item.width-100,
  .intake-preview-item.width-50 {
    grid-column: span 1;
  }

  .intake-form-card-actions {
    flex-direction: column;
  }
}

@keyframes nav-glow {
  0%   { background-color: var(--blue-deep); }
  50%  { background-color: rgba(135, 135, 135, 0.147); }
  100% { background-color: var(--blue-deep); }
}

.nav a.nav-active {
  background-color: var(--blue-deep);
  color: #efefef;
  animation: nav-glow 4.4s ease-in-out infinite;
}