:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }
.center { text-align: center; }

/* ---------- вход ---------- */
.login-box {
  margin: 12vh auto 0; max-width: 360px; background: var(--card);
  padding: 24px; border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.08);
}
.login-box h1 { font-size: 22px; margin: 0 0 4px; }
.login-box label { display: block; margin: 16px 0 0; font-size: 14px; color: var(--muted); }
.login-box input {
  width: 100%; margin-top: 6px; padding: 14px; font-size: 17px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}

/* ---------- шапка ---------- */
header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  background: #1f2937; color: #fff;
}
header .name { font-weight: 600; font-size: 15px; }
header .muted { color: #9ca3af; }

/* ---------- кнопки ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 14px 18px; font-size: 17px;
  background: #e5e7eb; color: var(--text); font-weight: 600;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.warn { background: var(--warn); color: #fff; }
.btn.ghost { background: rgba(255,255,255,.14); color: #fff; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 9px; }
.btn.wide { width: 100%; margin-top: 20px; }
.btn:disabled { opacity: .5; }

/* ---------- табы ---------- */
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs .tab {
  flex: 1; border: 0; background: none; padding: 14px 4px 16px;
  font-size: 13px; color: var(--muted); font-weight: 600;
}
#tabs .tab.active { color: var(--accent); }

main { padding: 12px 12px 88px; max-width: 720px; margin: 0 auto; }

/* ---------- карточки ---------- */
.card {
  background: var(--card); border-radius: 14px; padding: 14px;
  margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card.click { active: none; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.title { font-weight: 700; font-size: 16px; }
.sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: #eef2ff; color: #3730a3;
}
.badge.idle { background: #eef1f4; color: #374151; }
.badge.soldering { background: #fff4cc; color: #92400e; }
.badge.molding { background: #e6efff; color: #1e40af; }
.badge.packing { background: #fbe7f6; color: #9d174d; }
.badge.awaiting { background: #cffafe; color: #155e75; }
.badge.received { background: #dcfce7; color: #166534; }

.big-qty { font-size: 28px; font-weight: 800; }
.stage-buttons { display: grid; gap: 8px; margin-top: 14px; }
.stage-buttons .btn { width: 100%; }
.field { margin-top: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px; font-size: 16px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--text);
}
.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }

.events { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.event { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.event:last-child { border-bottom: 0; }
.event .when { color: var(--muted); font-size: 12px; }

/* ---------- скан ---------- */
#scanner { width: 100%; border-radius: 14px; background: #000; overflow: hidden; }
#scanner video { width: 100%; display: block; }

/* ---------- журнал ---------- */
.jrow { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.jrow:last-child { border-bottom: 0; }
.jtime { font-size: 12px; color: var(--muted); white-space: nowrap; }
.jbody { flex: 1; font-size: 14px; }

/* ---------- панель снизу ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: rgba(15,23,42,.45);
  display: flex; align-items: flex-end;
}
.sheet-body {
  width: 100%; max-height: 88vh; overflow: auto; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 16px 16px 24px;
}
.sheet h3 { margin: 4px 0 12px; font-size: 18px; }

/* ---------- обновление «потянуть вниз» ---------- */
.ptr {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: 56px; display: flex; align-items: center; justify-content: center;
  background: #1f2937; color: #fff; font-size: 14px; font-weight: 600;
  transform: translateY(-100%); opacity: 0;
  transition: transform .18s ease, opacity .18s ease;
  pointer-events: none;
}
.ptr.active { transition: none; }

header .hbtns { display: flex; gap: 8px; align-items: center; }
header .btn.ghost.small { padding: 8px 12px; }

.loader { text-align: center; color: var(--muted); padding: 24px; }
