/* Кабинет вендора — расширение merchant.css.
   merchant.css подключается первым и не меняется: токены, сайдбар, карточки, бейджи, кнопки, таблицы.
   Здесь только то, чего у мерчанта нет: формы, вкладки, таймлайн, шторка и т.д.
   Обычный CSS без сборки и префикс m- — по правилам из docs/merchant-redesign-tz.md, п. 3.1. */

:root {
  --m-info: #1d5fa8;
  --m-info-bg: #e8f1fb;
}

/* --- Сайдбар: группы разделов --- */

.m-nav-group {
  padding: 0.9rem 0.75rem 0.3rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--m-text-subtle);
}
.m-nav-group:first-child { padding-top: 0.15rem; }

.m-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  color: #fff;
  background: var(--m-primary);
}
.m-count--danger { background: var(--m-danger); }

/* --- Заголовок страницы и секции --- */

.m-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 3.25rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--m-border);
}
.m-section-title { font-size: 0.875rem; font-weight: 600; color: #0f172a; }
.m-back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--m-text-muted);
}
.m-back:hover { color: var(--m-primary-dark); }

.m-link { font-weight: 600; color: var(--m-primary-dark); }
.m-link:hover { color: var(--m-primary); }

/* --- Поля форм: те же значения, что у полей входа мерчанта --- */

.m-label { display: block; margin-bottom: 0.375rem; font-size: 0.875rem; font-weight: 500; color: #334155; }
.m-label small { font-size: 0.8125rem; font-weight: 400; color: var(--m-text-subtle); }
.m-hint { margin-top: 0.375rem; font-size: 0.75rem; line-height: 1.45; color: var(--m-text-muted); }

.m-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--m-border-strong);
  border-radius: 8px;
  background: var(--m-surface);
  font-size: 0.875rem;
  color: #0f172a;
  box-shadow: var(--m-shadow-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.m-input:focus { border-color: var(--m-primary); box-shadow: 0 0 0 4px var(--m-primary-bg); }
.m-input--code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.04em; }
.m-input--lg { padding: 0.8rem 1rem; font-size: 1.0625rem; }
textarea.m-input { resize: vertical; }
input[type='file'].m-input { padding: 0.45rem 0.6rem; }
input[type='color'].m-input { height: 2.625rem; padding: 0.25rem; cursor: pointer; }

.m-check { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.875rem; color: #334155; cursor: pointer; }
.m-check input { margin-top: 0.15rem; width: 1rem; height: 1rem; flex-shrink: 0; accent-color: var(--m-primary); }
.m-check small { display: block; font-size: 0.75rem; color: var(--m-text-muted); }

/* --- Кнопки сверх мерчанта --- */

.m-btn--sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.m-btn--lg { padding: 0.75rem 1.25rem; font-size: 0.9375rem; }
.m-btn--ghost { color: var(--m-text-muted); }
.m-btn--ghost:hover:not(:disabled) { background: var(--m-bg); color: var(--m-text); }

/* --- Сегменты и вкладки --- */

.m-segmented {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  padding: 2px;
  border-radius: 8px;
  background: #e4e4e4;
  scrollbar-width: none;
}
.m-segmented a, .m-segmented button {
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--m-text-muted);
  transition: color 0.15s ease;
}
.m-segmented a:hover, .m-segmented button:hover { color: var(--m-text); }
.m-segmented [aria-current], .m-segmented [aria-selected='true'] {
  background: var(--m-surface);
  color: var(--m-text);
  font-weight: 600;
  box-shadow: var(--m-shadow-sm);
}

/* Разделы «Моих карт» на телефоне: на десктопе это пункты сайдбара */
.m-tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  margin: -0.5rem -1rem 1.25rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--m-border-strong);
  scrollbar-width: none;
}
.m-tabs::-webkit-scrollbar, .m-segmented::-webkit-scrollbar { display: none; }
.m-tabs a {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: -1px;
  padding: 0.6rem 0.625rem;
  border-bottom: 2px solid transparent;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--m-text-muted);
}
.m-tabs a[aria-current] { border-color: var(--m-primary); color: var(--m-primary-dark); font-weight: 600; }

/* --- Сообщения --- */

.m-alert {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.45;
}
.m-alert svg { flex-shrink: 0; margin-top: 0.1rem; width: 1rem; height: 1rem; }
.m-alert--danger { background: var(--m-danger-bg); color: var(--m-danger); }
.m-alert--warning { background: var(--m-warning-bg); color: #92400e; }
.m-alert--success { background: #ecfccb; color: var(--m-success); }
.m-alert--info { background: var(--m-info-bg); color: var(--m-info); }

.m-badge--info { background: var(--m-info-bg); color: var(--m-info); }
.m-badge--primary { background: var(--m-primary-bg); color: var(--m-primary-dark); }

/* --- Мелкие элементы --- */

.m-code {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: #f1f2f4;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: #334155;
  white-space: nowrap;
}

.m-kind-dot { display: inline-block; width: 0.5rem; height: 0.5rem; border-radius: 999px; flex-shrink: 0; }
.m-kind-bar { display: inline-block; width: 0.375rem; height: 2rem; border-radius: 999px; flex-shrink: 0; }

.m-empty { padding: 3.5rem 2rem; text-align: center; }
.m-empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--m-primary-bg);
  color: var(--m-primary);
}

/* Список-строки внутри карточки */
.m-rows > * { border-top: 1px solid #f1f2f4; }
.m-rows > *:first-child { border-top: none; }
.m-row-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1.25rem;
  transition: background-color 0.12s ease;
}
.m-row-link:hover { background: #fafafa; }

/* События карты и смены */
.m-timeline { display: flex; flex-direction: column; }
.m-timeline > li { position: relative; display: flex; gap: 0.75rem; padding-bottom: 0.875rem; }
.m-timeline > li:last-child { padding-bottom: 0; }
.m-timeline > li::before {
  content: '';
  position: absolute;
  top: 0.9rem;
  bottom: -0.2rem;
  left: 0.2rem;
  width: 1px;
  background: var(--m-border);
}
.m-timeline > li:last-child::before { display: none; }
.m-timeline-dot { flex-shrink: 0; width: 0.5rem; height: 0.5rem; margin-top: 0.35rem; border-radius: 999px; background: var(--m-border-strong); }
.m-timeline-dot--ok { background: #65a30d; }
.m-timeline-dot--bad { background: var(--m-danger); }

/* Выбор вида карты: тот же приём, что у .m-radio-card; .is-selected — запасной вариант без :has() (ТЗ, п. 3.7) */
.m-radio-card.is-selected { border-color: var(--m-primary); box-shadow: 0 0 0 3px var(--m-primary-bg); }

/* Штампы на карточке клиента */
.m-stamp { width: 2.25rem; height: 2.25rem; border-radius: 999px; border: 2px dashed var(--m-border-strong); }
.m-stamp--on { border: 2px solid var(--m-primary); background: var(--m-primary); }

/* Шторка «Ещё» на телефоне */
.m-sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(26, 31, 54, 0.4); }
.m-sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 41;
  max-height: 82dvh;
  overflow-y: auto;
  padding: 0.5rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-radius: 16px 16px 0 0;
  background: var(--m-surface);
  box-shadow: var(--m-shadow-lg);
}
.m-sheet-grip { width: 2.25rem; height: 0.25rem; margin: 0.25rem auto 0.5rem; border-radius: 999px; background: var(--m-border-strong); }

/* Таблица на телефоне: строки-карточки не вкладываем в ещё одну рамку */
@media (max-width: 767px) {
  .m-card .m-table tbody tr {
    margin: 0;
    padding: 0.75rem 1.25rem;
    border: none;
    border-bottom: 1px solid #f1f2f4;
    border-radius: 0;
    background: none;
  }
  .m-card .m-table tbody tr:last-child { border-bottom: none; }
  /* В merchant.css мобильное .m-table td проигрывает десктопному .m-table tbody td по специфичности */
  .m-table tbody td { padding: 0.15rem 0; border-bottom: none; }
  .m-table td > div { min-width: 0; text-align: right; }
  .m-table td[data-label-hide] > div { text-align: left; width: 100%; }
  .m-table td.m-hide-sm { display: none; }
}

/* Подсказка о сохранении в демо */
.m-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--m-bottomnav-h) + 1rem);
  z-index: 70;
  transform: translateX(-50%);
  max-width: calc(100vw - 2rem);
  padding: 0.625rem 1rem;
  border-radius: 8px;
  background: #1a1f36;
  color: #fff;
  font-size: 0.875rem;
  box-shadow: var(--m-shadow-lg);
  animation: mFadeIn 0.2s ease both;
}
@media (min-width: 1024px) { .m-toast { left: calc(50% + var(--m-sidebar-w) / 2); bottom: 1.5rem; } }

/* Панель демо: только в этом стенде, в прод не переносится */
.demo-panel { position: relative; font-size: 0.8125rem; }
.demo-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  background: #1a1f36;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
}
.demo-panel summary::-webkit-details-marker { display: none; }
.demo-panel-body {
  position: absolute;
  z-index: 50;
  width: 15rem;
  padding: 0.75rem;
  border-radius: 12px;
  background: #1a1f36;
  color: #e5e7eb;
  box-shadow: var(--m-shadow-lg);
}
.demo-panel--side .demo-panel-body { right: 0; bottom: calc(100% + 0.5rem); }
.demo-panel--top .demo-panel-body { right: 0; top: calc(100% + 0.5rem); }
.demo-panel-body p { margin-bottom: 0.25rem; font-size: 0.6875rem; color: #9ca3af; }
.demo-panel-body .demo-choice { display: flex; gap: 0.25rem; margin-bottom: 0.625rem; }
.demo-panel-body .demo-choice a { flex: 1; padding: 0.3rem 0.25rem; border-radius: 6px; text-align: center; background: #2b3150; color: #e5e7eb; }
.demo-panel-body .demo-choice a[aria-current] { background: var(--m-primary); color: #fff; font-weight: 600; }
.demo-panel-body > a { color: #fff; text-decoration: underline; }

.m-table tbody tr[hidden] { display: none; }

/* Сайдбар админки: группы сворачиваются, пунктов больше двадцати */
.m-nav-details + .m-nav-details { margin-top: 0.15rem; }
.m-nav-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  list-style: none;
  cursor: pointer;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--m-text-subtle);
  user-select: none;
}
.m-nav-summary::-webkit-details-marker { display: none; }
.m-nav-summary:hover { color: var(--m-text); }
.m-nav-chevron { transition: transform 0.15s ease; }
.m-nav-details[open] .m-nav-chevron { transform: rotate(90deg); }
.m-nav-details[open] .m-nav-summary-count { display: none; }

/* Окно поверх страницы */
.m-modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(26, 31, 54, 0.45); }
.m-modal[hidden] { display: none; }
.m-modal-box { width: 100%; max-width: 26rem; padding: 1.25rem; border-radius: 12px; background: var(--m-surface); box-shadow: var(--m-shadow-lg); }

/* В merchant.css .m-table thead th перебивает утилиту .text-right: заголовки числовых колонок уезжали влево */
.m-table thead th.text-right { text-align: right; }

/* Режим «Работать как»: полоса видна всегда и сдвигает оболочку вниз */
.m-actas { position: fixed; inset: 0 0 auto 0; z-index: 60; display: flex; align-items: center; justify-content: space-between; gap: .75rem; height: 44px; padding: 0 1rem; background: #1e293b; color: #fff; font-size: .8125rem; }
.m-actas-text { min-width: 0; display: flex; align-items: baseline; gap: .625rem; }
.m-actas-text b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-actas-text span { color: #cbd5e1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-actas-tag { flex-shrink: 0; border-radius: 999px; background: #fbbf24; color: #1e293b; font-size: .6875rem; font-weight: 700; padding: .05rem .5rem; }
.m-actas-exit { flex-shrink: 0; border-radius: .5rem; background: #fff; color: #1e293b; font-weight: 600; padding: .3rem .7rem; white-space: nowrap; }
.m-actas-exit:hover { background: #e2e8f0; }
body.has-actas { padding-top: 44px; }
body.has-actas .m-sidebar { top: 44px; }
body.has-actas header.sticky { top: 44px; }
@media (max-width: 640px) {
  .m-actas-text span { display: none; }
  .m-actas-exit-long { display: none; }
}

/* Поиск в админке */
.m-searchbar { position: relative; }
.m-searchbar svg { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--m-text-subtle); pointer-events: none; }
.m-searchbar input { padding-left: 2.25rem; }

/* Шаги мастера карт */
.m-step { display: flex; gap: .875rem; align-items: flex-start; padding: 1rem 1.25rem; }
.m-step + .m-step { border-top: 1px solid var(--m-border); }
.m-step-mark { flex-shrink: 0; display: flex; height: 1.75rem; width: 1.75rem; align-items: center; justify-content: center; border-radius: 999px; background: #f1f5f9; color: var(--m-text-muted); font-size: .75rem; font-weight: 700; }
.m-step--done .m-step-mark { background: var(--m-success-bg); color: var(--m-success); }
.m-step--current { background: var(--m-primary-bg); }
.m-step--current .m-step-mark { background: var(--m-primary); color: #fff; }

/* Вкладки карточки */
.m-tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--m-border); }
.m-tabs a { padding: .5rem .875rem; font-size: .875rem; font-weight: 600; color: var(--m-text-muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.m-tabs a[aria-current=page] { color: var(--m-primary-dark); border-bottom-color: var(--m-primary); }

/* Страницы, перенесённые из старой панели: логика прежняя, вид подстраивается под новую оболочку */
.m-legacy h1, .m-legacy h2.text-2xl { letter-spacing: -0.01em; }
.m-legacy .shadow, .m-legacy .shadow-sm, .m-legacy .shadow-md, .m-legacy .shadow-lg { box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); }
.m-legacy .rounded-2xl, .m-legacy .rounded-xl { border-radius: 14px; }
.m-legacy .overflow-hidden > table, .m-legacy table { width: 100%; }
.m-legacy thead th { font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--m-text-subtle); }
.m-legacy input:not([type=checkbox]):not([type=radio]):not([type=file]), .m-legacy select, .m-legacy textarea { border-radius: 10px; }
.m-legacy .table-scroll, .m-legacy .overflow-x-auto { -webkit-overflow-scrolling: touch; }
.m-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.m-legacy dd, .m-legacy dt, .m-legacy code { overflow-wrap: anywhere; }
.m-legacy .grid > *, .m-legacy .flex > * { min-width: 0; }
@media (max-width: 639px) {
  .m-legacy .justify-between { flex-wrap: wrap; row-gap: 8px; }
}
.m-legacy input, .m-legacy select { max-width: 100%; }
.m-legacy form.flex, .m-legacy .flex.items-end { flex-wrap: wrap; }
.m-legacy .inline-flex.rounded-lg { flex-wrap: wrap; max-width: 100%; }
