/* Система учёта металлоконструкций — mobile-first */

:root {
  --blue: #1a56db;
  --blue-dark: #14409f;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --green: #16a34a;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
}

/* Шапка */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: var(--blue); color: #fff;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
#topbar h1 { margin: 0; font-size: 18px; flex: 1; text-align: center; }
#topbar .back, #topbar .refresh {
  background: rgba(255,255,255,.15); border: 0; color: #fff;
  font-size: 20px; width: 40px; height: 40px; border-radius: 10px;
  cursor: pointer; flex-shrink: 0;
}
/* офлайн-индикатор в шапке: 📴 — нет связи, ⏳ N — очередь на отправку */
#topbar .offbtn {
  background: #f59e0b; border: 0; color: #fff;
  font-size: 13px; font-weight: 600; height: 40px; padding: 0 12px;
  border-radius: 10px; cursor: pointer; flex-shrink: 0;
}
#topbar .offbtn.offline { background: #dc2626; }

/* Основная область */
#view { max-width: 720px; margin: 0 auto; padding: 12px 12px 80px; }

/* Карточки */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card .muted { color: var(--muted); font-size: 14px; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; cursor: pointer;
  font-size: 15px; font-weight: 600; padding: 12px 16px;
  min-height: 44px; text-decoration: none; color: #fff;
  background: var(--blue);
}
.btn:active { background: var(--blue-dark); }
.btn.gray { background: #475569; }
.btn.red { background: var(--danger); }
.btn.green { background: var(--green); }
.btn.ghost { background: #e8eef7; color: var(--blue); }
.btn.block { display: flex; width: 100%; }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 14px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 90px; }

/* Прогресс-бар */
.progress { background: #e2e8f0; border-radius: 8px; height: 10px; overflow: hidden; margin: 8px 0 4px; }
.progress > div { background: var(--green); height: 100%; border-radius: 8px; transition: width .3s; }

/* Список заказов */
.order-card { display: block; text-decoration: none; color: inherit; cursor: pointer; }
.order-card .num { font-weight: 700; font-size: 17px; }
.order-card .stat { font-size: 14px; color: var(--muted); }

/* Позиции */
.item-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: #f8fafc;
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
}
.item-row .info { flex: 1; min-width: 0; cursor: pointer; }
.item-row .marka { font-weight: 700; font-size: 16px; }
.item-row .sub { font-size: 13px; color: var(--muted); }

.status-badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap;
}
.st-in_work  { background: #64748b; }
.st-assembly { background: #d97706; }
.st-welding  { background: #dc2626; }
.st-welded   { background: #c2410c; }
.st-cleaning { background: #7c3aed; }
.st-cleaned  { background: #0d9488; }
.st-shipped  { background: #16a34a; }

.status-group h4 {
  margin: 14px 0 8px; font-size: 14px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .3px;
  display: flex; align-items: center; gap: 8px;
}
.status-group .dot { width: 10px; height: 10px; border-radius: 50%; }

/* Кнопка «дальше» */
.next-btn {
  flex-shrink: 0; min-width: 44px; min-height: 44px;
  border-radius: 10px; border: 0; cursor: pointer;
  font-size: 20px; font-weight: 700; color: #fff; background: var(--blue);
  display: flex; align-items: center; justify-content: center; padding: 0 12px;
}
.next-btn:active { background: var(--blue-dark); }
.next-btn.done { background: var(--green); }

/* Статусные кнопки позиции */
.status-btns { display: flex; flex-direction: column; gap: 8px; }
.status-btn {
  display: flex; align-items: center; justify-content: space-between;
  border: 2px solid var(--border); border-radius: 10px;
  background: #fff; padding: 12px 14px; font-size: 16px; font-weight: 600;
  cursor: pointer; color: var(--text); min-height: 48px;
}
.status-btn .arrow { font-size: 20px; color: var(--muted); }
.status-btn.current { border-color: var(--blue); background: #e8eef7; }
.status-btn.shipped { border-color: var(--green); background: #e8f7ee; }

/* Фото */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photos img, .photo-add {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--border);
}
.photo-add {
  display: flex; align-items: center; justify-content: center;
  background: #e8eef7; font-size: 30px; color: var(--blue); cursor: pointer;
}

/* История */
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border); font-size: 14px;
}
.history .time { color: var(--muted); white-space: nowrap; font-size: 13px; }
.history .who { color: var(--muted); font-size: 13px; }

/* Файлы заказа */
.file-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.file-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.file-row a, .file-row button { flex-shrink: 0; }

/* Сводка */
.ready-box {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: #fff; border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.ready-box .v { font-size: 30px; font-weight: 800; }
.ready-box .l { font-size: 14px; opacity: .95; }
.badge-part {
  display: inline-block; background: #fef3c7; color: #92400e;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  margin-left: 4px;
}
.btn:disabled { opacity: .45; pointer-events: none; }

/* Сроки */
.due-badge {
  display: inline-block; background: #e8eef7; color: var(--blue);
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  margin-left: 4px; white-space: nowrap;
}
.due-badge.today { background: #fef3c7; color: #92400e; }
.due-badge.overdue { background: #fee2e2; color: #b91c1c; }

/* Возраст позиции на стадии */
.age-tag {
  display: inline-block; background: #f1f5f9; color: #475569;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  margin-left: 4px; white-space: nowrap;
}
.age-tag.old { background: #fee2e2; color: #b91c1c; }

/* Таблица по маркам */
.marka-table .marka-row {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
  gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 13px; text-align: right;
}
.marka-table .marka-row span:first-child { text-align: left; font-weight: 600; }
.marka-table .marka-row.head {
  color: var(--muted); font-size: 11px; text-transform: uppercase;
  font-weight: 700; letter-spacing: .3px;
}
.marka-table .marka-row:last-child { border-bottom: 0; }

/* Готово к отгрузке (в списке заказов) */
.ready-badge {
  display: inline-block; background: #dcfce7; color: #15803d;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  margin-left: 4px; white-space: nowrap;
}

/* Фильтры-чипы */
.filter-chip { border: 0; cursor: pointer; font-family: inherit; }
.filter-chip.on { background: var(--blue); color: #fff; }

/* Сворачиваемые группы статусов */
.grp-head { cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.grp-head > span:first-child { display: flex; align-items: center; gap: 8px; }
.grp-arrow { color: var(--muted); font-size: 16px; }
.grp-body { display: none; }
.grp-body.open { display: block; }

/* Строки результатов импорта */
.imp-row { font-size: 14px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.imp-row.err { color: var(--danger); }
.imp-row.warn { color: #92400e; }

/* Доска объявлений */
.board-note { background: #fefce8; border: 1px solid #fde68a; cursor: pointer; }
.board-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-weight: 700; }
.board-text { white-space: pre-wrap; font-size: 15px; }

/* Прогноз готовности */
.forecast-badge {
  display: inline-block; background: #ede9fe; color: #6d28d9;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  margin-left: 4px; white-space: nowrap;
}

/* Сборка отгрузки */
.item-row .sel-chk { width: 24px; height: 24px; flex-shrink: 0; accent-color: var(--blue); }
.item-row .sel-qty {
  width: 84px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px; font-size: 15px; font-family: inherit; background: #fff; text-align: center;
}
.item-row .sel-qty:disabled { opacity: .4; }
.ship-bar {
  position: fixed; left: 8px; right: 8px; bottom: calc(60px + var(--safe-bottom)); z-index: 18;
  max-width: 704px; margin: 0 auto; background: #fff; border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px; box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.ship-bar-info { font-size: 15px; }
.ship-print.off { pointer-events: none; opacity: .45; }

/* Время по стадиям */
.stage-time { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.stage-time:last-child { border-bottom: 0; }
.stage-time .st-time { font-weight: 700; font-size: 15px; }

/* Недельный график */
.week-chart { display: flex; justify-content: space-between; gap: 6px; }
.wc-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.wc-v { font-size: 11px; font-weight: 700; color: var(--green); min-height: 14px; }
.wc-bar { width: 100%; max-width: 26px; height: 80px; background: #e2e8f0; border-radius: 6px; display: flex; align-items: flex-end; overflow: hidden; }
.wc-bar > div { width: 100%; background: var(--green); border-radius: 6px; min-height: 2px; }
.wc-d { font-size: 11px; color: var(--muted); }

/* Сменное задание */
.naryad-select {
  flex: 1; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; font-size: 15px; font-family: inherit; background: #fff;
}

/* Прогресс по стадиям на странице позиции */
.part-line { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.part-line .pl-label { font-size: 14px; font-weight: 600; min-width: 86px; }
.part-line .bar { flex: 1; background: #e2e8f0; height: 12px; border-radius: 6px; overflow: hidden; }
.part-line .bar > div { height: 100%; border-radius: 6px; }
.part-line .pl-n { font-size: 13px; color: var(--muted); min-width: 48px; text-align: right; white-space: nowrap; }

/* Селект в формах */
.field select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-size: 16px; font-family: inherit; background: #f8fafc;
}
.field select:focus { outline: 2px solid var(--blue); background: #fff; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-box { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stat-box .v { font-size: 24px; font-weight: 800; }
.stat-box .l { font-size: 13px; color: var(--muted); }

.dash-status-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.dash-status-row .bar { flex: 1; background: #e2e8f0; height: 14px; border-radius: 7px; overflow: hidden; }
.dash-status-row .bar > div { height: 100%; }
.dash-status-row .n { min-width: 44px; text-align: right; font-weight: 700; }

/* Нижняя навигация */
#bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  max-width: 720px; margin: 0 auto;
}
#bottomnav a {
  flex: 1; text-align: center; padding: 12px 2px; text-decoration: none;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
#bottomnav a.active { color: var(--blue); }

/* Модальное окно */
#modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
.modal-box {
  background: #fff; width: 100%; max-width: 720px;
  border-radius: 16px 16px 0 0; padding: 18px; padding-bottom: calc(18px + var(--safe-bottom));
  max-height: 90vh; overflow-y: auto;
}
.modal-box h2 { margin: 0 0 14px; font-size: 18px; }

/* Формы */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-size: 16px; font-family: inherit; background: #f8fafc;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--blue); background: #fff; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

/* Просмотр фото на весь экран */
#photoViewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; flex-direction: column; }
#photoViewer[hidden] { display: none; }
#photoViewer img { flex: 1; object-fit: contain; min-height: 0; }
#photoViewer .pv-bar { display: flex; gap: 10px; padding: 12px; justify-content: center; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 10px 18px;
  border-radius: 10px; font-size: 14px; z-index: 70; max-width: 90vw;
}
#toast[hidden] { display: none; }

/* Поиск */
.search-wrap { margin-bottom: 12px; }
.search-wrap input {
  width: 100%; padding: 13px 14px; border: 1px solid var(--border);
  border-radius: 12px; font-size: 16px; background: #fff; font-family: inherit;
}
.search-wrap input:focus { outline: 2px solid var(--blue); }

/* Исполнители */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #e8eef7; border-radius: 999px;
  padding: 6px 8px 6px 12px; font-size: 14px; font-weight: 600;
}
.chip-x {
  border: 0; background: #94a3b8; color: #fff;
  width: 20px; height: 20px; border-radius: 50%;
  cursor: pointer; font-size: 12px; line-height: 1;
}
.assign-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.assign-row {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--border); border-radius: 10px;
  background: #f8fafc; padding: 12px 14px; font-size: 15px;
  cursor: pointer; color: var(--text); text-align: left;
}

/* FAB */
.fab {
  position: fixed; right: 16px; bottom: calc(76px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--blue); color: #fff; font-size: 28px; font-weight: 700;
  box-shadow: 0 4px 10px rgba(0,0,0,.3); cursor: pointer; z-index: 15;
}
.fab:active { background: var(--blue-dark); }

.section-title { margin: 18px 0 8px; font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 15px; }

@media (min-width: 720px) {
  .photos { grid-template-columns: repeat(4, 1fr); }
}
