/* Модуль рецептов: масштаб и контейнер (остальной портал — styles.css) */
html:has(body.page-rx) {
  zoom: 0.9;
}

body.page-rx.auth-locked main.container.rx-main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

body.page-rx:not(.auth-locked) main.container.rx-main {
  max-width: min(1280px, 100%);
  margin: 0 auto;
  padding: 16px 20px 40px;
}

/* Вход */
.rx-auth-card {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.rx-auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rx-auth-form .rx-field input {
  font-size: 16px;
  padding: 11px 12px;
}

.rx-auth-submit {
  margin-top: 4px;
}

/* Карточки шагов */
.rx-clinic-panel,
.rx-pharmacy-panel,
.rx-list-panel {
  margin-top: 16px;
}

.rx-help-details {
  margin: 0 0 16px;
  border: 1px solid var(--ui-border, #dbe2ea);
  border-radius: var(--ui-radius-sm, 8px);
  background: var(--ui-surface-soft, #f8fafc);
  padding: 0 12px;
}

.rx-help-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--ui-primary, #2563eb);
  padding: 10px 0;
  list-style: none;
}

.rx-help-details summary::-webkit-details-marker {
  display: none;
}

.rx-help-details summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s ease;
}

.rx-help-details[open] summary::before {
  transform: rotate(90deg);
}

.rx-help-details__body {
  padding: 0 0 12px;
  font-size: 14px;
  color: var(--ui-text-muted, #64748b);
  line-height: 1.5;
}

.rx-help-details__body p {
  margin: 0;
}

.rx-card {
  border: 1px solid var(--ui-border, #dbe2ea);
  border-radius: var(--ui-radius-md, 12px);
  background: var(--ui-surface-soft, #fafbfc);
  padding: 16px 18px 18px;
  margin-bottom: 14px;
  box-shadow: var(--ui-shadow-sm, 0 1px 3px rgba(15, 23, 42, 0.06));
}

.rx-step__title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ui-text, #1f2937);
}

.rx-step__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ui-primary, #2563eb);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.rx-step__lead {
  margin: 0 0 12px;
}

.rx-subtitle {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--ui-text, #1f2937);
}

/* Поля */
.rx-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.rx-field__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-text-muted, #64748b);
  letter-spacing: 0.02em;
}

.rx-field__label--phantom {
  visibility: hidden;
}

.rx-field--grow {
  min-width: 0;
}

.rx-field--full {
  grid-column: 1 / -1;
}

.rx-field input,
.rx-field select,
.rx-field textarea {
  width: 100%;
  border: 1px solid var(--ui-border-strong, #cbd5e1);
  border-radius: var(--ui-radius-sm, 8px);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ui-text, #1f2937);
}

.rx-field input:focus,
.rx-field select:focus,
.rx-field textarea:focus {
  outline: none;
  box-shadow: var(--ui-focus, 0 0 0 3px rgba(37, 99, 235, 0.2));
  border-color: var(--ui-primary, #2563eb);
}

.rx-field textarea {
  min-height: 88px;
  resize: vertical;
}

.rx-field--btn {
  align-self: end;
}

.rx-btn-block {
  width: 100%;
}

.rx-form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.rx-form-actions--primary {
  justify-content: flex-end;
  margin-top: 8px;
}

.rx-form-actions .primary-btn {
  min-width: min(100%, 280px);
}

.rx-result {
  margin-top: 10px;
}

.rx-stock-inline {
  margin: 10px 0 0;
}

/* Сетки */
.rx-grid {
  display: grid;
  gap: 10px 12px;
  margin-bottom: 0;
}

.rx-grid--search {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.rx-grid--patient {
  grid-template-columns: repeat(2, minmax(160px, 1fr));
}

.rx-grid--rx {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.rx-grid--pharm-disp {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.rx-grid--pharm-defer {
  grid-template-columns: 1fr 2fr auto;
  align-items: end;
}

.rx-modal .rx-grid {
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  margin-bottom: 10px;
}

/* Тулбар рецептов */
.rx-toolbar {
  display: grid;
  grid-template-columns: 200px minmax(200px, 1fr) 220px 140px;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  padding: 14px 16px;
  background: var(--ui-surface-soft, #f1f5f9);
  border: 1px solid var(--ui-border, #dbe2ea);
  border-radius: var(--ui-radius-md, 12px);
}

.rx-toolbar__field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.rx-toolbar__field--grow {
  min-width: 0;
}

.rx-toolbar__label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ui-text-muted, #64748b);
}

.rx-toolbar__field input,
.rx-toolbar__field select {
  width: 100%;
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-sm);
  padding: 9px 10px;
  font-size: 14px;
  background: #fff;
}

.rx-toolbar__actions {
  align-items: stretch;
}

/* Таблица */
.rx-table-scroll {
  max-height: min(62vh, 720px);
  overflow: auto;
  border: 1px solid var(--ui-border, #dbe2ea);
  border-radius: var(--ui-radius-md, 12px);
  background: var(--ui-surface, #fff);
  box-shadow: inset 0 1px 0 rgba(148, 163, 184, 0.12);
}

.rx-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

.rx-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(180deg, #e2e8f0 0%, #eef2f7 100%);
  box-shadow: 0 1px 0 var(--ui-border-strong, #cbd5e1);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #475569;
}

.rx-table th,
.rx-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
  text-align: left;
}

.rx-table tbody tr:nth-child(even) td {
  background: rgba(248, 250, 252, 0.65);
}

.rx-table tbody tr:hover td {
  background: rgba(239, 246, 255, 0.9);
}

.rx-col-actions {
  width: 1%;
  white-space: nowrap;
}

.rx-table td:first-child {
  font-weight: 600;
  word-break: break-word;
  max-width: 200px;
}

/* Статусы */
.rx-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #e2e8f0;
  color: #334155;
}

.rx-status--active {
  background: #dcfce7;
  color: #166534;
}

.rx-status--danger {
  background: #fee2e2;
  color: #991b1b;
}

.rx-status--draft {
  background: #e0e7ff;
  color: #3730a3;
}

.rx-status--paused {
  background: #fef3c7;
  color: #92400e;
}

.rx-status--pending {
  background: #fce7f3;
  color: #9d174d;
}

.rx-stock-pill {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

.rx-stock-pill--green {
  background: #dcfce7;
  color: #166534;
}
.rx-stock-pill--yellow {
  background: #fef9c3;
  color: #854d0e;
}
.rx-stock-pill--orange {
  background: #ffedd5;
  color: #9a3412;
}
.rx-stock-pill--red {
  background: #fee2e2;
  color: #991b1b;
}

/* Меню действий в строке */
.rx-actions-cell {
  position: relative;
}

.rx-row-actions {
  position: relative;
  display: inline-block;
  text-align: right;
}

.rx-row-actions__toggle {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--ui-radius-sm, 8px);
  border: 1px solid var(--ui-border-strong, #cbd5e1);
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--ui-text, #1f2937);
  user-select: none;
}

.rx-row-actions__toggle::-webkit-details-marker {
  display: none;
}

.rx-row-actions__toggle::after {
  content: "▾";
  font-size: 10px;
  opacity: 0.7;
}

.rx-row-actions__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 240px;
  padding: 8px;
  border-radius: var(--ui-radius-sm, 10px);
  border: 1px solid var(--ui-border-strong, #cbd5e1);
  background: #fff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.15);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rx-row-actions__item {
  width: 100%;
  text-align: left !important;
  justify-content: flex-start !important;
}

/* Поиск пациента */
.patient-search-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 4px 0 0;
  max-height: 260px;
  overflow: auto;
  padding: 6px 4px 8px 0;
}

/* Во flex-колонке с max-height дети по умолчанию flex-shrink:1 — карточки сжимаются и обрезают вторую строку; следующий блок «наезжает» визуально. */
.patient-search-results > * {
  flex-shrink: 0;
}

.patient-search-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  height: auto !important;
  min-height: 0;
  flex-shrink: 0;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--ui-border-strong, #e2e8f0);
  border-radius: var(--ui-radius-sm, 8px);
  background: #fff;
  color: #0f172a;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  line-height: 1.35;
  white-space: normal;
  overflow: visible;
  box-shadow: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.patient-search-item:hover {
  background: #f8fafc;
  border-color: var(--ui-primary, #2563eb);
}

.patient-search-item strong {
  display: block;
  margin-bottom: 6px;
  color: #0f172a;
  font-weight: 600;
}

.patient-search-item .hint {
  display: block;
  width: 100%;
  color: #64748b;
  font-weight: 400;
  font-size: 13px;
  line-height: 1.4;
}

.page-header .top-actions .rx-header-qa-btn {
  height: auto;
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Модалка */
.rx-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.rx-modal.hidden {
  display: none;
}

.rx-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.rx-modal__panel {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  max-height: min(90vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--ui-panel-bg, #fff);
  border-radius: var(--ui-radius-md, 12px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  padding: 20px 22px 18px;
  border: 1px solid var(--ui-border-strong, #e2e8f0);
}

.rx-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  padding-bottom: 4px;
}

.rx-modal__head h3 {
  margin: 0;
  font-size: 1.15rem;
}

.rx-modal__close {
  flex-shrink: 0;
}

.rx-modal__filters {
  margin-bottom: 12px;
}

.rx-modal__check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  align-self: center;
}

.rx-modal__table {
  flex: 1;
  min-height: 200px;
  overflow: auto;
  margin-bottom: 10px;
  border-radius: var(--ui-radius-sm, 8px);
  border: 1px solid var(--ui-border, #e2e8f0);
}

.rx-table--compact th,
.rx-table--compact td {
  padding: 7px 9px;
  font-size: 13px;
}

.rx-modal__foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  padding-top: 8px;
}

.rx-modal__error {
  margin-top: 8px;
  color: #991b1b;
}

@media (max-width: 1100px) {
  .rx-grid--patient,
  .rx-grid--rx,
  .rx-grid--pharm-disp {
    grid-template-columns: 1fr;
  }

  .rx-grid--search {
    grid-template-columns: 1fr;
  }

  .rx-grid--pharm-defer {
    grid-template-columns: 1fr;
  }

  .rx-toolbar {
    grid-template-columns: 1fr;
  }

  .rx-modal .rx-grid {
    grid-template-columns: 1fr;
  }

  .rx-form-actions--primary {
    justify-content: stretch;
  }

  .rx-form-actions--primary .primary-btn {
    width: 100%;
    min-width: 0;
  }
}
