/* KARLUSON · Админка, этапы 2–8 (Заказы, Курьеры, Клиенты, Тарифы, KPI, Сотрудники, Выгрузки)
   Стиль наследует этап 1 (дашборд): те же токены --k-*, белые карточки, радиус 12–16. */

/* --- тулбар фильтров --- */
.ad-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.ad-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ad-field > span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--k-text-muted, #6b6b6b);
}
.ad-field--grow { flex: 1 1 240px; }
.ad-field .lk-input,
.ad-field .lk-select {
  width: 100%;
  box-sizing: border-box;
  height: 40px;
  min-height: 40px;
  padding: 0 40px 0 12px;
  font-size: 14px;
}
.ad-toolbar .lk-btn { min-height: 40px; }
.ad-toolbar__spacer { flex: 1 1 auto; }
.ad-hint { font-size: 13px; color: var(--k-text-muted, #6b6b6b); margin: 0; }

/* --- сетки карточек --- */
.ad-grid { display: grid; gap: 16px; }
.ad-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ad-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ad-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) {
  .ad-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .ad-grid--4, .ad-grid--3, .ad-grid--2 { grid-template-columns: 1fr; }
}

/* --- таблицы --- */
.ad-tablewrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(20, 24, 32, .10);
  border-radius: 12px;
  background: #fff;
}
.ad-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 14px;
}
.ad-table th,
.ad-table td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid rgba(20, 24, 32, .08);
}
.ad-table th {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #5f5f5f;
  background: #f6f7f9;
  white-space: nowrap;
}
.ad-table tbody tr:last-child td { border-bottom: 0; }
.ad-table tbody tr:hover { background: rgba(20, 24, 32, .025); }
.ad-table .ad-num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.ad-table .ad-right { text-align: right; }
.ad-table--tariffs { min-width: 620px; }
.ad-table--staff { min-width: 720px; }
.ad-table--kpi { min-width: 600px; }
.ad-empty {
  padding: 28px 16px;
  text-align: center;
  font-size: 14px;
  color: #5f5f5f;
}
.ad-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: #123;
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ad-link:hover { color: #1e4fa3; }
.ad-muted { color: #5f5f5f; font-size: 13px; }
.ad-nowrap { white-space: nowrap; }

/* чипы-статусы */
.ad-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.ad-chip--new { background: #e8f0fe; color: #17407c; }
.ad-chip--work { background: #fff2d8; color: #7d5100; }
.ad-chip--done { background: #e4f5e9; color: #1a5f2e; }
.ad-chip--cancel { background: #fdeaea; color: #98201f; }
.ad-chip--muted { background: #eef0f3; color: #4f5359; }
.ad-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ad-dot--on { background: #1f9d4d; }
.ad-dot--off { background: #b6bcc4; }
.ad-dot--busy { background: #e0a026; }

/* --- KPI-плитки --- */
.ad-kpi {
  background: #fff;
  border: 1px solid rgba(20, 24, 32, .10);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
}
.ad-kpi__l {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #5f5f5f;
}
.ad-kpi__v { font-size: 26px; font-weight: 800; line-height: 1.1; color: #12161c; }
.ad-kpi__d { font-size: 12px; font-weight: 700; }
.ad-kpi__d--up { color: #1a5f2e; }
.ad-kpi__d--down { color: #98201f; }
.ad-kpi__d--flat { color: #5f5f5f; }

/* --- графики --- */
.ad-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 190px;
  padding: 10px 0 0;
}
.ad-chart__col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  height: 100%;
}
.ad-chart__stack { display: flex; align-items: flex-end; gap: 2px; height: 100%; width: 100%; justify-content: center; }
.ad-chart__bar {
  width: 100%;
  max-width: 18px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #5b8bf5, #1e4fa3);
  min-height: 2px;
}
.ad-chart__bar--prev { background: #ccd6e6; }
.ad-chart__x { font-size: 10px; color: #5f5f5f; white-space: nowrap; }
.ad-legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: #5f5f5f; }
.ad-legend__i { display: inline-flex; align-items: center; gap: 6px; }
.ad-legend__k { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.ad-bars { display: flex; flex-direction: column; gap: 12px; }
.ad-bars__row {
  display: grid;
  grid-template-columns: 132px 1fr 56px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}
@media (max-width: 640px) {
  .ad-bars__row { grid-template-columns: 96px 1fr 44px; font-size: 12px; }
}
.ad-bars__track { background: #eef1f5; border-radius: 999px; height: 10px; overflow: hidden; }
.ad-bars__fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #5b8bf5, #1e4fa3); }
.ad-bars__v { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* --- карточки-панели внутри экрана --- */
.ad-panel {
  background: #fff;
  border: 1px solid rgba(20, 24, 32, .10);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.ad-panel__h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.ad-panel__t { font-size: 16px; font-weight: 800; margin: 0; color: #12161c; }

/* тарифы */
.ad-tariff {
  background: #fff;
  border: 1px solid rgba(20, 24, 32, .10);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ad-tariff.is-sel { border-color: #1e4fa3; box-shadow: 0 0 0 2px rgba(30, 79, 163, .16); }
.ad-tariff__n { font-size: 15px; font-weight: 800; }
.ad-tariff__p { font-size: 13px; color: #4a4f57; }
.ad-tariff__row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.ad-tariff__row b { font-variant-numeric: tabular-nums; }
.ad-tariff__f { margin-top: auto; }

/* ============ МОДАЛЬНОЕ ОКНО КАРТОЧКИ ============ */
.ad-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 13, 18, .55);
  backdrop-filter: blur(2px);
}
.ad-modal__card {
  background: #fff;
  border-radius: 16px;
  width: min(780px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .3);
}
.ad-modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(20, 24, 32, .1);
}
.ad-modal__title { font-size: 18px; font-weight: 800; margin: 0; color: #12161c; }
.ad-modal__sub { font-size: 13px; color: #5f5f5f; margin: 4px 0 0; }
.ad-modal__x {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #f0f1f4;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: #12161c;
}
.ad-modal__x:hover { background: #e3e5ea; }
.ad-modal__body {
  padding: 18px 20px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.ad-modal__foot {
  padding: 14px 20px;
  border-top: 1px solid rgba(20, 24, 32, .1);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
@media (max-width: 640px) {
  .ad-modal { padding: 0; align-items: flex-end; }
  .ad-modal__card { max-height: 92vh; width: 100%; border-radius: 16px 16px 0 0; }
  .ad-modal__foot .lk-btn { flex: 1 1 auto; }
}

.ad-kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; }
@media (max-width: 640px) { .ad-kv { grid-template-columns: 1fr; } }
.ad-kv__i { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ad-kv__k { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #5f5f5f; }
.ad-kv__v { font-size: 14px; font-weight: 600; color: #12161c; overflow-wrap: anywhere; }
.ad-sect { display: flex; flex-direction: column; gap: 10px; }
.ad-sect__h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 800;
  color: #12161c;
}
.ad-subtable { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 420px; }
.ad-subtable th,
.ad-subtable td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(20, 24, 32, .08);
  text-align: left;
  vertical-align: middle;
}
.ad-subtable th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #5f5f5f;
  background: #f6f7f9;
  white-space: nowrap;
}
.ad-subtable tr:last-child td { border-bottom: 0; }

/* матрица прав */
.ad-matrix { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
.ad-matrix th,
.ad-matrix td { padding: 10px 12px; border-bottom: 1px solid rgba(20, 24, 32, .08); text-align: center; }
.ad-matrix th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #5f5f5f; background: #f6f7f9; }
.ad-matrix th:first-child,
.ad-matrix td:first-child { text-align: left; font-weight: 600; }
.ad-matrix td { color: #12161c; }
.ad-check { width: 18px; height: 18px; accent-color: #1e4fa3; cursor: pointer; }

/* формы в модалке */
.ad-form { display: grid; gap: 14px; }
.ad-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; color: #5f5f5f; }
.ad-form .lk-input, .ad-form .lk-select { height: 40px; padding: 0 12px; font-size: 14px; width: 100%; box-sizing: border-box; }
.ad-ok {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  background: #e4f5e9;
  color: #14512a;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 12px;
}

/* мобилки: таблицы -> карточки */
@media (max-width: 640px) {
  .ad-tablewrap {
    border: 0;
    background: transparent;
    overflow: visible;
    border-radius: 0;
  }
  .ad-table { min-width: 0; display: block; }
  .ad-table thead { display: none; }
  .ad-table tbody, .ad-table tr, .ad-table td { display: block; width: auto; }
  .ad-table tr {
    background: #fff;
    border: 1px solid rgba(20, 24, 32, .10);
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 10px;
  }
  .ad-table td {
    border: 0;
    padding: 6px 0;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: space-between;
    font-size: 14px;
    text-align: right;
  }
  .ad-table td::before {
    content: attr(data-l);
    flex: 0 0 44%;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    color: #5f5f5f;
  }
  .ad-table td:empty { display: none; }
  .ad-table .ad-right { text-align: right; }
  .ad-tablewrap--sub { border: 1px solid rgba(20, 24, 32, .1); border-radius: 12px; }
}

/* ==== правки этапа 2 (приёмка) ==== */
/* 1. плашки статусов: текст по центру, без обрезки */
.ad-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  max-width: 100%;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}
.ad-table td .ad-chip { flex: 0 0 auto; }
.ad-table td:last-child { white-space: nowrap; }

/* 3. таймлайн истории статусов в карточке заказа */
.ad-tl { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0; }
.ad-tl__i {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  grid-template-areas: "dot t d" "dot w w";
  column-gap: 10px;
  row-gap: 2px;
  align-items: start;
  padding: 10px 0 12px 0;
  border-bottom: 1px solid rgba(20, 24, 32, .08);
  position: relative;
}
.ad-tl__i:last-child { border-bottom: 0; padding-bottom: 4px; }
.ad-tl__dot {
  grid-area: dot;
  width: 9px; height: 9px; margin-top: 4px;
  border-radius: 50%;
  background: #1e4fa3;
  position: relative;
}
.ad-tl__i:not(:last-child) .ad-tl__dot::after {
  content: "";
  position: absolute;
  left: 50%; top: 13px;
  width: 1px; height: calc(100% + 34px);
  transform: translateX(-50%);
  background: rgba(30, 79, 163, .25);
}
.ad-tl__t { grid-area: t; font-size: 14px; font-weight: 700; color: #12161c; }
.ad-tl__w { grid-area: w; font-size: 13px; color: #5f5f5f; }
.ad-tl__d { grid-area: d; font-size: 13px; color: #5f5f5f; white-space: nowrap; }
.ad-tl__empty { margin: 0; }

/* 4–5. мобильная раскладка 390 */
@media (max-width: 640px) {
  /* шапка: зазор между логотипом и «Выйти» */
  .lk-hdr, .lk-header, .ad-top, .lk-top, .lk-app__top { gap: 14px; }
  .lk-hdr__exit, .lk-hdr__out, .ad-top__exit, .lk-btn--ghost { margin-left: 12px; }

  /* карточки заказов: граница/фон/тень + зазор между парами «подпись — значение» */
  .ad-table tbody tr {
    border: 1px solid rgba(20, 24, 32, .12);
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(20, 24, 32, .07);
    background: #fff;
    margin: 0 0 12px 0;
    padding: 6px 0;
    overflow: hidden;
  }
  .ad-table tbody tr:last-child { margin-bottom: 0; }
  .ad-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(20, 24, 32, .06);
    min-width: 0;
  }
  .ad-table td:last-child { border-bottom: 0; }
  .ad-table td::before { flex: 0 0 42%; }
  .ad-table td > * { min-width: 0; }
  .ad-table td .ad-chip { white-space: normal; }

  /* селекты фильтров — в одну колонку, длинные значения без обрезки */
  .ad-toolbar { gap: 10px; }
  .ad-toolbar .ad-field { flex: 1 1 100%; width: 100%; }
  .ad-toolbar .ad-field .lk-select,
  .ad-toolbar .ad-field .lk-input { width: 100%; min-width: 0; max-width: 100%; text-overflow: ellipsis; }

  /* пагинация всегда достижима: липкий подвал списка */
  .ad-panel .lk-pager,
  .lk-pager {
    position: sticky;
    bottom: 0;
    z-index: 30;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
    margin-top: 10px;
    background: #fff;
    border-top: 1px solid rgba(20, 24, 32, .1);
    box-shadow: 0 -6px 16px rgba(20, 24, 32, .08);
  }
  .lk-pager__link { min-height: 44px; padding: 0 14px; }
  /* снять блокировку прокрутки страницы, из-за которой на 390 не добраться до пагинации */
  html.lk-lock, body.lk-lock { overflow-y: auto !important; }
  html.lk-lock .ad-modal, body.lk-lock .ad-modal { touch-action: auto; }
}

/* --- этап 2 (b): карточка заказа — история статусов влезает без обрезки --- */
.ad-modal__card{max-height:94vh}
.ad-modal__body{padding:14px 22px;gap:16px}
.ad-tl__i{padding:7px 0 9px}
.ad-tl__t{font-size:13.5px;line-height:1.3}
.ad-tl__w,.ad-tl__d{font-size:12.5px;line-height:1.3}
@media (max-width:640px){
  .ad-modal__card{max-height:94vh}
  .ad-modal__body{padding:12px 16px;gap:14px}
  .ad-modal__head{padding:14px 16px}
  .ad-modal__foot{padding:12px 16px}
  .ad-tl__i{padding:8px 0 10px;grid-template-columns:20px minmax(0,1fr)}
  .ad-tl__t{font-size:13px}
}

/* --- этап 2 (c): компактная карточка заказа, чтобы история статусов влезала целиком --- */
@media (min-width:641px){.ad-modal__card{width:min(880px,100%);max-height:96vh}}
.ad-modal__body{padding:12px 18px;gap:10px}
.ad-modal__body>section,.ad-modal__body>.ad-sect{margin:0;padding:8px 0}
.ad-modal__body .ad-sect__t,.ad-modal__body h3,.ad-modal__body h4{font-size:13px;margin:0 0 6px}
.ad-modal__body .ad-kv{gap:8px 16px}
.ad-modal__body .ad-subtable th{padding:6px 10px;font-size:10.5px}
.ad-modal__body .ad-subtable td{padding:6px 10px;font-size:12.5px}
.ad-tl__i{padding:6px 0 8px}
