:root {
    --bg: #f5f6f8;
    --fg: #1a1d23;
    --border: #d9dce1;
    --primary: #2563eb;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #d97706;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header__title { font-weight: 600; font-size: 18px; }
.app-header__user { font-size: 13px; display: flex; gap: 8px; align-items: center; }
.app-header__user a { color: var(--primary); text-decoration: none; }

.app-main { padding: 16px; max-width: 480px; margin: 0 auto; }

.flash-messages { padding: 8px 16px; }
.flash-message {
    background: #fef3c7; border: 1px solid var(--warning); border-radius: 8px;
    padding: 8px 12px; margin-bottom: 8px; font-size: 14px;
}

.card {
    background: white; border: 1px solid var(--border); border-radius: 12px;
    padding: 16px; margin-bottom: 12px;
}

.task-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px; border-bottom: 1px solid var(--border);
}
.task-item:last-child { border-bottom: none; }
.task-item.scanned { background: #f0fdf4; }

.status-badge {
    font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #e5e7eb;
}
.status-badge.pending { background: #fef3c7; color: var(--warning); }
.status-badge.completed { background: #dcfce7; color: var(--success); }

input[type="text"], input[type="password"], input[type="number"] {
    width: 100%; padding: 12px; font-size: 16px; border: 1px solid var(--border);
    border-radius: 8px; margin-bottom: 12px;
}

button, .btn {
    display: inline-block; padding: 12px 20px; font-size: 16px; border: none;
    border-radius: 8px; background: var(--primary); color: white; cursor: pointer;
    text-decoration: none; text-align: center;
}
button:disabled { background: #9ca3af; }
.btn-secondary { background: #6b7280; }

.step-container { display: none; }
.step-container.active { display: block; }

.slot-btn {
    display: inline-block; padding: 12px; margin: 4px; border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; background: white;
}
.slot-btn.selected { border-color: var(--primary); background: #eff6ff; }
.slot-barcode { font-size: 11px; color: #6b7280; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); font-size: 14px; }

.toast {
    position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
    padding: 10px 16px; border-radius: 8px; background: #1a1d23; color: white;
    font-size: 14px; z-index: 100;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.warning { background: var(--warning); }

/* ---------- ТСД: экран "полки -> позиции" (по образцу Assistant) ---------- */

.status-banner {
    padding: 10px 16px; border-radius: 10px; margin-bottom: 12px;
    font-weight: 600; text-align: center; background: #eff6ff; color: #1d4ed8;
}
.status-banner--warn { background: #fef3c7; color: #9a6a00; }
.status-banner--success { background: #dcfce7; color: #15803d; }
.status-banner--error { background: #fee2e2; color: #b91c1c; }
/* Статус-бар с прогрессом (станция упаковки): зелёная заливка на долю
   --progress поверх фона любого состояния, при 100% полоса целиком зелёная. */
.status-banner--progress {
    position: relative; overflow: hidden; display: flex; align-items: center; gap: 12px;
}
.status-banner--progress::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0;
    width: var(--progress, 0%); background: rgba(34, 197, 94, 0.35); transition: width 0.3s;
}
.status-banner--progress > * { position: relative; }
.status-banner--progress > #status-text { flex: 1; }
.status-banner__count { font-size: 13px; font-weight: 700; white-space: nowrap; opacity: 0.85; }

.card--tap { cursor: pointer; transition: transform 0.1s; }
.card--tap:active { transform: scale(0.98); }
.card--tap.is-done { border-left: 4px solid var(--success); background: #f0fdf4; }
.card--tap.is-pending { border-left: 4px solid var(--warning); }

.progress__bar {
    background: var(--border); border-radius: 10px; height: 8px; overflow: hidden; margin: 8px 0 4px;
}
.progress__fill { background: var(--success); height: 100%; border-radius: 10px; transition: width 0.3s; }
.progress__stats { font-size: 12px; color: #6b7280; }

.list-item {
    background: white; border: 1px solid var(--border); border-radius: 10px;
    padding: 12px; margin-bottom: 8px; display: flex; align-items: center; gap: 12px;
    border-left: 4px solid transparent; min-height: 48px; cursor: pointer;
}
.list-item.is-done { border-left-color: var(--success); background: #f0fdf4; }
.list-item.is-pending { border-left-color: var(--warning); }
.list-item.active-item { outline: 2px solid var(--primary); outline-offset: -1px; }
.list-item__icon { font-size: 20px; flex-shrink: 0; }
.list-item__body { flex: 1; min-width: 0; }
.list-item__name { font-weight: 600; }
.list-item__meta { font-size: 13px; color: #6b7280; }
.qty-cancelled { color: #dc2626; font-weight: 600; }
.list-item__count { font-size: 18px; font-weight: 700; flex-shrink: 0; white-space: nowrap; }
.list-item__meta--place { color: #3730a3; font-weight: 500; }

.bottom-bar {
    position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px;
    background: white; border-top: 1px solid var(--border); z-index: 20;
}

/* ---------- Станция упаковки: блоки заказов волны ---------- */

.order-block {
    border: 1px solid var(--border); border-radius: 10px; margin-bottom: 14px; overflow: hidden;
}
.order-block.is-active { border: 2px solid var(--primary); }
.order-block.is-done { opacity: 0.7; }
.order-block__header {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    background: #f9fafb; border-bottom: 1px solid var(--border); font-weight: 600;
}
.order-block__name { flex: 1; min-width: 0; }
.order-block__body { padding: 8px 8px 0; }
.order-block__attention {
    padding: 8px 12px; background: #fef3c7; color: #9a6a00; font-size: 13px; font-weight: 500;
    border-bottom: 1px solid var(--border);
}
.order-block__body .list-item { cursor: default; }
.order-badge {
    font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.order-badge--done { background: #dcfce7; color: #15803d; }
.order-badge--deferred { background: #fef3c7; color: #9a6a00; }
.order-badge--error { background: #fee2e2; color: #b91c1c; }
.order-badge--places { background: #e0e7ff; color: #3730a3; }
/* Отгрузка: заказ, чьё проведение МойСклад отклонил. Коробку отдавать
   нельзя, поэтому карточка кричит цветом, а не подписью мелким шрифтом. */
.order-block.is-failed { border: 2px solid #dc2626; }
.order-block__attention--error { background: #fee2e2; color: #b91c1c; }
.retry-ship-btn {
    display: block; margin-top: 8px; font-size: 13px; padding: 6px 12px;
    border: 1px solid #b91c1c; color: #b91c1c; border-radius: 8px; background: white; cursor: pointer;
}
.mark-manual-btn {
    flex-shrink: 0; font-size: 12px; padding: 6px 10px; margin-left: 8px;
    border: 1px solid var(--border); border-radius: 8px; background: white; cursor: pointer;
}
.defer-order-btn {
    flex-shrink: 0; font-size: 12px; padding: 4px 10px;
    border: 1px solid var(--warning); color: #9a6a00; border-radius: 8px; background: white; cursor: pointer;
}
.reprint-order-kiz-btn, .reprint-order-sticker-btn {
    flex-shrink: 0; font-size: 12px; padding: 4px 10px; margin-left: 4px;
    border: 1px solid var(--border); border-radius: 8px; background: white; cursor: pointer;
}

/* ---------- Инвентаризация: клейм стеллажа (Раздел 18) ---------- */

.shelf-status {
    font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #e5e7eb; white-space: nowrap;
}
.shelf-status.mine { background: #dbeafe; color: var(--primary); }
.shelf-status.other { background: #fef3c7; color: var(--warning); }
.shelf-status.done { background: #dcfce7; color: var(--success); }

.qty-input {
    display: flex; align-items: center; gap: 8px; margin-top: 6px;
}

.inv-actions {
    display: flex; gap: 8px; margin-top: 6px;
}
.inv-actions button {
    padding: 8px 14px; font-size: 16px; line-height: 1;
}
.qty-input input[type="number"] {
    width: 80px; margin-bottom: 0; text-align: center; padding: 8px;
}
.qty-input button {
    padding: 8px 14px; font-size: 18px; line-height: 1;
}

.modal-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
    display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px;
}
.modal-overlay .card { max-width: 400px; margin-bottom: 0; text-align: center; }

/* ---------- Живой камера-скан (BarcodeDetector/server-декодинг) ---------- */

.cam-overlay {
    position: fixed; inset: 0; background: #000; z-index: 50;
    display: flex; align-items: center; justify-content: center;
}
.cam-overlay video {
    position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.cam-overlay__frame {
    position: relative; width: 70vw; max-width: 320px; aspect-ratio: 1;
    border: 3px solid rgba(255, 255, 255, 0.8); border-radius: 16px;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.cam-overlay__frame.is-hit { border-color: var(--success); box-shadow: 0 0 0 999px rgba(22, 163, 74, 0.25); }
.cam-overlay__hint {
    position: absolute; top: calc(env(safe-area-inset-top) + 16px); left: 0; right: 0;
    text-align: center; color: white; font-size: 14px; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.cam-overlay__bar {
    position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 16px);
    display: flex; justify-content: center; gap: 12px; padding: 0 16px;
}
.cam-overlay__bar button { background: rgba(255, 255, 255, 0.15); color: white; }

/* ---------- ТСД: узкая мобильная вкладочная навигация ---------- */

.tsd-tabs {
    display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding: 8px 12px; background: white; border-bottom: 1px solid var(--border);
}
.tsd-tabs__item {
    flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; font-size: 13px;
    font-weight: 600; color: #6b7280; text-decoration: none; white-space: nowrap;
}
.tsd-tabs__item.active { background: var(--primary); color: white; }

/* ---------- Сегмент-контрол (напр. качество товара при возврате) ---------- */

.segmented { display: flex; gap: 4px; background: #f3f4f6; border-radius: 8px; padding: 4px; }
.segmented__item {
    flex: 1; background: transparent; color: #6b7280; padding: 10px; font-size: 14px;
}
.segmented__item.active { background: white; color: var(--primary); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); }
