/*
 * components.css — KPI-плитки, статус-чипы, цепочка шагов, drawer, «телефон»,
 * вкладки, кнопки, план/факт-полоски, toast.
 *
 * Правило: скругления/тени только там, где объект реально отдельный
 * (KPI-плитка, рамка телефона, drawer, toast). Плоские таблицы и панели —
 * без скруглений и теней, только линии-разделители из tokens.css.
 */

/* ---------- KPI-плитки ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}

.kpi-tile__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.kpi-tile__value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  line-height: 1.1;
  color: var(--ink);
}

.kpi-tile__value.is-accent { color: var(--accent); }
.kpi-tile__value.is-good { color: var(--good); }
.kpi-tile__value.is-bad { color: var(--bad); }
.kpi-tile__value.is-warn { color: var(--warn); }

.kpi-tile__sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
}

.kpi-tile__multi {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}

.kpi-tile__multi b {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
}

/* ---------- Статус-чипы ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  background: var(--paper-2);
  color: var(--ink-soft);
  border: 1px solid transparent;
}

.chip--neutral { background: var(--paper-2); color: var(--ink-soft); }
.chip--accent  { background: var(--accent-soft); color: var(--accent); }
.chip--good    { background: var(--good-soft); color: var(--good); }
.chip--bad     { background: var(--bad-soft); color: var(--bad); }
.chip--warn    { background: var(--warn-soft); color: var(--warn); }

.chip__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------- Цепочка шагов (EMS.ui.steps) ---------- */

.ems-steps {
  display: flex;
  align-items: flex-start;
  gap: 0;
  overflow-x: auto;
  padding: 8px 2px 4px;
}

.ems-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 84px;
  position: relative;
  flex: 1 1 0;
  text-align: center;
}

.ems-step::before {
  content: '';
  position: absolute;
  top: 13px;
  left: -50%;
  width: 100%;
  height: 2px;
  background: var(--line);
  z-index: 0;
}

.ems-step:first-child::before {
  display: none;
}

.ems-step__circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-faint);
  z-index: 1;
}

.ems-step__label {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  line-height: 1.25;
  padding: 0 4px;
}

.ems-step__reason {
  margin-top: 4px;
  font-size: 10px;
  color: var(--bad);
  font-weight: 600;
  padding: 0 4px;
}

.ems-step.is-done .ems-step__circle {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}

.ems-step.is-done::before { background: var(--good); }

.ems-step.is-current .ems-step__circle {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ems-step.is-current .ems-step__label {
  color: var(--ink);
  font-weight: 700;
}

.ems-step.is-returned .ems-step__circle {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

.ems-step.is-returned .ems-step__label {
  color: var(--bad);
  font-weight: 700;
}

/* ---------- Drawer (выдвижная карточка справа) ---------- */

.ems-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 33, 28, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 90;
}

.ems-drawer-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.ems-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--drawer-width);
  max-width: 92vw;
  background: var(--surface);
  box-shadow: var(--shadow-drawer);
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 91;
  display: flex;
  flex-direction: column;
}

.ems-drawer.is-open {
  transform: translateX(0);
}

.ems-drawer__head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.ems-drawer__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  line-height: 1.25;
}

.ems-drawer__close {
  border: none;
  background: var(--paper-2);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  min-width: 28px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--ink-soft);
}

.ems-drawer__close:hover {
  background: var(--line);
}

.ems-drawer__body {
  padding: 16px 18px 32px;
  overflow-y: auto;
  flex: 1 1 auto;
}

/* ---------- Рамка «телефона» (Telegram Mini App) ---------- */

.phone-frame {
  width: var(--phone-width);
  max-width: 100%;
  height: var(--phone-height);
  max-height: 82vh;
  background: var(--ink);
  border-radius: 34px;
  padding: 10px;
  box-shadow: var(--shadow-card);
  margin: 0 auto;
}

.phone-screen {
  background: var(--paper);
  width: 100%;
  height: 100%;
  border-radius: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.phone-statusbar {
  height: 26px;
  flex: 0 0 auto;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}

.phone-app {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 14px 20px;
}

.phone-app__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  margin-bottom: 10px;
}

.phone-tabs {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex: 0 0 auto;
}

.phone-tabs button {
  flex: 1 1 0;
  border: none;
  background: transparent;
  padding: 9px 4px 10px;
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-faint);
  cursor: pointer;
}

.phone-tabs button.is-active {
  color: var(--accent);
}

.phone-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}

.phone-photo-stub {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--paper-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink-faint);
  font-size: 9px;
  text-align: center;
  margin-right: 6px;
}

/* ---------- Вкладки (веб-панель) ---------- */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-top: 20px;
  overflow-x: auto;
}

.tab {
  border: none;
  background: transparent;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
  padding-top: 14px;
}

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

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { border-color: var(--line-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:hover { background: #A94D18; border-color: #A94D18; }

.btn--secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

.btn--danger {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}

.btn--danger:hover { background: var(--bad); color: #fff; }

.btn--sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn--block { width: 100%; }

/* ---------- План/факт полоски в ячейках таблицы ---------- */

.bar-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 110px;
}

.bar-cell__nums {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
}

.bar-track {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--paper-2);
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  border-radius: 3px;
  background: var(--good);
}

.bar-fill.is-under { background: var(--warn); }
.bar-fill.is-over { background: var(--bad); }
.bar-fill.is-accent { background: var(--accent); }

/* ---------- Toast ---------- */

.ems-toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.ems-toast {
  background: var(--ink);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-card);
  max-width: 320px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.ems-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Подсветка по ?work= ---------- */

.is-highlighted {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft) !important;
  animation: ems-flash 1.4s ease 2;
}

@keyframes ems-flash {
  0%, 100% { background-color: var(--accent-soft); }
  50% { background-color: var(--paper-2); }
}

/* ---------- Карточки-строки (напр. очередь на оплату) ---------- */

.list-card {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.list-card__top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}

@media (max-width: 420px) {
  .kpi-tile__value { font-size: 22px; }
  .phone-frame { height: 640px; }
}
