/* ==========================================================================
   ERP Доставка — оформление панели
   Mobile-first. Без внешних CDN: файл кладётся рядом с приложением и
   отдаётся через /static/app.css, чтобы панель открывалась на мобильном
   интернете даже там, где внешние CDN недоступны или медленные.
   ========================================================================== */

/* --- Переменные ---------------------------------------------------------- */
:root {
  --bg:            #f4f6fa;
  --surface:       #ffffff;
  --surface-2:     #eef1f7;
  --border:        #dde3ec;
  --text:          #16202e;
  --text-dim:      #64748b;
  --text-faint:    #94a3b8;

  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-soft:  #e3ebfd;

  --ok:            #059669;
  --ok-soft:       #d8f3e6;
  --warn:          #b45309;
  --warn-soft:     #fdf0d5;
  --danger:        #dc2626;
  --danger-soft:   #fde4e4;
  --info:          #4f46e5;
  --info-soft:     #e7e5fd;
  --muted-soft:    #e9edf4;

  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 1px 2px rgba(16, 32, 46, .06), 0 4px 12px rgba(16, 32, 46, .05);
  --shadow-lg:     0 8px 30px rgba(16, 32, 46, .18);

  --nav-h:         64px;   /* высота нижней навигации */
  --tap:           48px;   /* минимальная высота элементов касания */
  --maxw:          1100px;
}

/* Тёмная тема — по настройке телефона, без переключателя */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0e141d;
    --surface:     #182130;
    --surface-2:   #212c3d;
    --border:      #2b384b;
    --text:        #e8edf5;
    --text-dim:    #9aa8bd;
    --text-faint:  #6b7a90;

    --primary:     #4f83f1;
    --primary-dark:#3f6fd8;
    --primary-soft:#1c2b47;

    --ok-soft:     #12362a;
    --warn-soft:   #3a2c12;
    --danger-soft: #3d1a1a;
    --info-soft:   #232145;
    --muted-soft:  #232e3f;

    --shadow:      0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
    --shadow-lg:   0 8px 30px rgba(0,0,0,.55);
  }
}

/* --- База ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 8px);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

small { font-size: .8rem; }

/* --- Каркас -------------------------------------------------------------- */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
}

.topbar-title {
  font-weight: 650;
  font-size: 1rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-sub {
  display: block;
  font-size: .72rem;
  font-weight: 400;
  color: var(--text-dim);
}

.topbar-actions { display: flex; gap: 6px; align-items: center; }

main { padding: 14px 0 24px; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 12px;
}

.page-head h1 { margin: 0; }
.page-head .count { color: var(--text-dim); font-size: .85rem; }

/* --- Карточка ------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.card-head h2, .card-head h3 { margin: 0; }

.card-flush { padding: 0; overflow: hidden; }

/* --- Сетка метрик на дашборде -------------------------------------------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric-label {
  font-size: .75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.metric.is-warn   .metric-value { color: var(--warn); }
.metric.is-danger .metric-value { color: var(--danger); }
.metric.is-ok     .metric-value { color: var(--ok); }

/* --- Метки статуса ------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 650;
  letter-spacing: .02em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--muted-soft);
  color: var(--text-dim);
}

.badge-pending          { background: var(--warn-soft);   color: var(--warn); }
.badge-in_progress      { background: var(--primary-soft);color: var(--primary-dark); }
.badge-cancel_timeout   { background: var(--danger-soft); color: var(--danger); }
.badge-dispute_pending  { background: var(--info-soft);   color: var(--info); }
.badge-dispute_override { background: var(--info-soft);   color: var(--info); }
.badge-ok               { background: var(--ok-soft);     color: var(--ok); }
.badge-off              { background: var(--muted-soft);  color: var(--text-faint); }

/* --- Карточка заказа (телефон) ------------------------------------------- */
.order-list { display: flex; flex-direction: column; gap: 10px; }

.order {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-faint);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.order-st-pending          { border-left-color: var(--warn); }
.order-st-in_progress      { border-left-color: var(--primary); }
.order-st-cancel_timeout   { border-left-color: var(--danger); }
.order-st-dispute_pending  { border-left-color: var(--info); }
.order-st-dispute_override { border-left-color: var(--info); }

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

.order-id {
  font-weight: 650;
  font-size: 1rem;
  word-break: break-all;
}

.order-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  font-size: .8rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.order-meta b {
  display: block;
  color: var(--text);
  font-weight: 600;
  font-size: .9rem;
}

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

.order-actions form { flex: 1 1 auto; margin: 0; }
.order-actions .btn { width: 100%; }

/* --- Таймер SLA ---------------------------------------------------------- */
.sla {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  margin-bottom: 10px;
  background: var(--muted-soft);
  color: var(--text-dim);
}

.sla-label { font-size: .72rem; font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.sla-time  { font-size: 1.05rem; }

.sla.is-ok      { background: var(--ok-soft);     color: var(--ok); }
.sla.is-warn    { background: var(--warn-soft);   color: var(--warn); }
.sla.is-danger  { background: var(--danger-soft); color: var(--danger); }
.sla.is-over    { background: var(--danger); color: #fff; }

/* Пульсация, когда времени почти не осталось */
@keyframes sla-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .55; }
}
.sla.is-danger .sla-time,
.sla.is-over   .sla-time { animation: sla-pulse 1.1s ease-in-out infinite; }

/* --- Кнопки -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active { transform: scale(.985); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(1.08); }

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm {
  min-height: 38px;
  padding: 6px 12px;
  font-size: .85rem;
}

.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Формы --------------------------------------------------------------- */
.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.field .hint {
  display: block;
  font-size: .75rem;
  color: var(--text-dim);
  font-weight: 400;
  margin-top: 4px;
}

input[type="text"], input[type="password"], input[type="search"],
input[type="number"], input[type="datetime-local"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* 16px — iOS не зумит при фокусе */
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}

textarea { min-height: 84px; resize: vertical; line-height: 1.45; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* Кнопка «ввод» в поиске */
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input { flex: 1; }
.search-row .btn { flex: 0 0 auto; }

/* --- Строка списка курьера ----------------------------------------------- */
.contractor {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.contractor:last-child { border-bottom: none; }

.contractor-main { flex: 1; min-width: 0; }

.contractor-name {
  font-weight: 650;
  font-size: .95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contractor-sub {
  font-size: .76rem;
  color: var(--text-dim);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.contractor-quota {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.contractor-quota .free { font-weight: 700; font-size: 1.05rem; }
.contractor-quota .free.ok { color: var(--ok); }
.contractor-quota .free.zero { color: var(--danger); }
.contractor-quota .of { font-size: .72rem; color: var(--text-dim); }

/* Переключатель трафика */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
}

.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background .18s;
  pointer-events: none;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .18s;
}

.switch input:checked + .switch-track { background: var(--ok); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--primary-soft); }

/* --- Таблицы (включаются только на широком экране) ----------------------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

table.data th, table.data td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data th {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  background: var(--surface-2);
  font-weight: 650;
  position: sticky;
  top: 0;
}

table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Пустое состояние ---------------------------------------------------- */
.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-dim);
}

.empty svg { width: 40px; height: 40px; opacity: .4; margin-bottom: 10px; }
.empty p { margin: 0; font-size: .9rem; }

/* --- Сообщения ----------------------------------------------------------- */
.alert {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: .9rem;
  border: 1px solid transparent;
}

.alert-error   { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert-success { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok); }
.alert-info    { background: var(--primary-soft);color: var(--primary-dark); border-color: var(--primary); }
.alert-warn    { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn); }

/* --- Вкладки ------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 10px 14px;
  font-size: .88rem;
  font-weight: 600;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* --- Нижняя навигация (телефон) ------------------------------------------ */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 900;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -2px 12px rgba(16,32,46,.07);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-h);
  padding: 6px 2px;
  color: var(--text-faint);
  font-size: .68rem;
  font-weight: 600;
  text-decoration: none;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav a:hover { text-decoration: none; }
.bottom-nav a.active { color: var(--primary); }

.bottom-nav svg { width: 22px; height: 22px; }

.bottom-nav .pip {
  position: absolute;
  top: 6px;
  right: 50%;
  transform: translateX(18px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .65rem;
  line-height: 18px;
  text-align: center;
  font-weight: 700;
}

/* --- Выдвижная панель фильтров ------------------------------------------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 30, .5);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

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

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1001;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .25s ease;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.sheet.open { transform: translateY(0); }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.sheet-head h3 { margin: 0; }

.sheet-body { padding: 14px 16px 20px; }

.sheet-grab {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 8px auto 0;
}

/* Кнопка «Фильтры» над списком */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.filter-bar .active-count {
  font-size: .75rem;
  color: var(--primary);
  font-weight: 650;
}

/* --- Окно подтверждения -------------------------------------------------- */
dialog.confirm {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(440px, 92vw);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

dialog.confirm::backdrop { background: rgba(10, 18, 30, .55); }

dialog.confirm .dlg-body { padding: 18px; }
dialog.confirm .dlg-body h3 { margin-top: 0; }
dialog.confirm .dlg-text { font-size: .9rem; color: var(--text-dim); margin: 0 0 14px; }

dialog.confirm .dlg-actions {
  display: flex;
  gap: 10px;
  padding: 12px 18px 18px;
}

dialog.confirm .dlg-actions .btn { flex: 1; }

/* --- Вход ---------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  padding-bottom: 24px;
}

.login-box {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
}

.login-logo {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}

.login-logo svg { width: 30px; height: 30px; }

.login-title { text-align: center; margin-bottom: 4px; }
.login-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: .85rem;
  margin-bottom: 22px;
}

.code-input {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: .3em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
}

/* --- Журнал действий ----------------------------------------------------- */
.log-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.log-item:last-child { border-bottom: none; }

.log-dot {
  flex: 0 0 8px;
  width: 8px; height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--primary);
}

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

.log-title { font-size: .9rem; font-weight: 600; }
.log-desc  { font-size: .82rem; color: var(--text-dim); margin-top: 2px; word-break: break-word; }
.log-time  { font-size: .72rem; color: var(--text-faint); margin-top: 4px; font-variant-numeric: tabular-nums; }

.log-diff {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: .78rem;
  margin-top: 6px;
  flex-wrap: wrap;
}

.log-diff .from { text-decoration: line-through; color: var(--text-faint); }
.log-diff .to   { color: var(--ok); font-weight: 650; }

/* --- Пагинация ----------------------------------------------------------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px 0 8px;
}

.pager .info {
  font-size: .82rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* --- Утилиты ------------------------------------------------------------- */
.muted   { color: var(--text-dim); }
.faint   { color: var(--text-faint); }
.tiny    { font-size: .75rem; }
.mono    { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.row     { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }

/* Только телефон или только компьютер */
.only-mobile  { display: block; }
.only-desktop { display: none; }

/* --- Планшет и компьютер ------------------------------------------------- */
@media (min-width: 768px) {
  body { padding-bottom: 24px; }

  .bottom-nav { display: none; }

  h1 { font-size: 1.6rem; }

  main { padding: 20px 0 32px; }

  .metrics { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .metric-value { font-size: 2rem; }

  /* Список заказов превращается в таблицу */
  .only-mobile  { display: none; }
  .only-desktop { display: block; }

  .contractor { padding: 14px 18px; }

  .sheet {
    left: auto;
    right: 16px;
    bottom: auto;
    top: 76px;
    width: 420px;
    border-radius: var(--radius);
    transform: translateY(-12px);
    opacity: 0;
    pointer-events: none;
  }

  .sheet.open { transform: translateY(0); opacity: 1; pointer-events: auto; }
  .sheet-grab { display: none; }

  .order-actions form { flex: 0 0 auto; }
  .order-actions .btn { width: auto; }
}

@media (min-width: 1024px) {
  .wrap { padding: 0 20px; }
}

/* Уважение к системной настройке «уменьшить движение» */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* Печать (иногда нужно распечатать накладную) */
@media print {
  .bottom-nav, .topbar-actions, .filter-bar, .btn { display: none !important; }
  body { padding: 0; background: #fff; }
  .card, .order { box-shadow: none; border-color: #ccc; }
}


/* ==========================================================================
   ЭКРАН «НАСТРОЙКИ КУРЬЕРА»
   Добавлено поверх основного оформления. Те же переменные, что и выше.
   ========================================================================== */

/* --- Крупный переключатель потока заказов -------------------------------- */
.traffic {
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.traffic-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.traffic-state {
  flex: 1;
  min-width: 0;
}

.traffic-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
}

.traffic-note {
  font-size: .78rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Кружок-индикатор состояния */
.traffic-dot {
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-faint);
}

.traffic.is-on    .traffic-dot { background: var(--ok);    box-shadow: 0 0 0 4px var(--ok-soft); }
.traffic.is-off   .traffic-dot { background: var(--danger);box-shadow: 0 0 0 4px var(--danger-soft); }
.traffic.is-blocked .traffic-dot { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }

.traffic.is-on  { border-color: var(--ok); }
.traffic.is-off { border-color: var(--danger); }
.traffic.is-blocked { border-color: var(--warn); }

/* Большая кнопка: удобно нажимать с телефона */
.traffic-btn {
  width: 100%;
  min-height: 60px;
  font-size: 1.02rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.traffic-btn svg { width: 22px; height: 22px; }

/* Вращение значка, пока идёт запрос */
@keyframes spin { to { transform: rotate(360deg); } }
.traffic-btn .spin { animation: spin .8s linear infinite; }

/* --- Баланс квоты -------------------------------------------------------- */
.quota {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.quota-cell { text-align: center; }

.quota-cell .label {
  font-size: .72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 4px;
}

.quota-cell .value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.quota-cell .unit { font-size: .7rem; color: var(--text-faint); font-weight: 500; }

.quota-cell.is-negative .value { color: var(--danger); }
.quota-cell.is-warn     .value { color: var(--warn); }
.quota-cell.is-ok       .value { color: var(--ok); }

/* Предупреждение об овердрафте */
.overdraft {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  font-size: .88rem;
  margin-bottom: 12px;
}

.overdraft svg { flex: 0 0 20px; width: 20px; height: 20px; }
.overdraft b { font-variant-numeric: tabular-nums; }

/* --- Выбор метода: карточки-радио ---------------------------------------- */
.method-pick {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.method-opt {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}

.method-opt:active { background: var(--surface-2); }

.method-opt input[type="radio"] {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  min-height: 20px;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

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

.method-name { display: block; font-weight: 650; font-size: .92rem; }
.method-desc { display: block; font-size: .78rem; color: var(--text-dim); margin-top: 2px; }
.method-eg   { display: block; font-size: .75rem; color: var(--text-faint); margin-top: 3px; font-family: ui-monospace, Menlo, monospace; }

.method-opt:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* --- Поля ввода с маской ------------------------------------------------- */
.mask-field { position: relative; }

.mask-field input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .06em;
  font-size: 1.02rem;
}

.mask-ok {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ok);
  pointer-events: none;
}

.mask-ok svg { width: 18px; height: 18px; }

/* --- Два поля в строку --------------------------------------------------- */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 380px) {
  .field-row { grid-template-columns: 1fr; }
  .quota { grid-template-columns: 1fr; }
  .quota-cell { text-align: left; display: flex; align-items: baseline; justify-content: space-between; }
  .quota-cell .label { margin-bottom: 0; }
}

/* --- Карточка канала отгрузки -------------------------------------------- */
.channel {
  border: 1px solid var(--border);
  border-left: 4px solid var(--ok);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--surface);
}

.channel:last-child { margin-bottom: 0; }
.channel.is-off { border-left-color: var(--text-faint); opacity: .72; }

.channel-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.channel-name {
  font-weight: 650;
  font-size: .95rem;
  flex: 1;
  min-width: 0;
}

.channel-op {
  font-size: .78rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.channel-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .82rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.channel-rows .row-item {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.channel-rows b {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.channel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.channel-actions .label {
  flex: 1;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-dim);
}

/* --- Сводка перед созданием ---------------------------------------------- */
.form-note {
  font-size: .8rem;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 14px;
}

/* --- Заголовок раздела --------------------------------------------------- */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 0 10px;
}

.section-title h2 { margin: 0; font-size: 1.05rem; }
.section-title .count { font-size: .8rem; color: var(--text-dim); }

/* --- Пояснение под полем ------------------------------------------------- */
.warn-text { color: var(--warn); font-weight: 600; }
