:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #111827;
  --accent: #2563eb;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
.app-shell { min-height: 100dvh; padding-bottom: 86px; }
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(17,24,39,.97); color: white; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; box-shadow: 0 2px 14px rgba(0,0,0,.16); }
.topbar-row { max-width: 900px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.context-pill { max-width: 68%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; background: rgba(255,255,255,.12); padding: 7px 10px; border-radius: 999px; color: #e5e7eb; }
.main { max-width: 900px; margin: 0 auto; padding: 16px; }
.section { margin-bottom: 18px; }
.section-title { margin: 0 0 10px; font-size: 18px; }
.section-subtitle { margin: -5px 0 12px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card + .card { margin-top: 12px; }
.card-title { font-weight: 800; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 10px; }
.stat-value { font-size: 23px; font-weight: 900; letter-spacing: -.04em; }
.stat-label { color: var(--muted); font-size: 11px; margin-top: 3px; }
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-btn { min-height: 86px; border: 0; border-radius: 16px; padding: 14px; text-align: left; background: var(--primary); color: white; box-shadow: var(--shadow); font-weight: 800; }
.quick-btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.quick-btn.danger { background: #991b1b; }
.quick-btn span { display: block; color: #d1d5db; font-size: 12px; font-weight: 500; margin-top: 5px; line-height: 1.35; }
.quick-btn.secondary span { color: var(--muted); }
.quick-btn.missing-start { width: 100%; min-height: 112px; text-align: center; font-size: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.input, .select { width: 100%; border: 1px solid #d1d5db; background: white; color: var(--text); border-radius: 12px; padding: 11px 12px; min-height: 44px; outline: none; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.no-wrap { flex-wrap: nowrap; }
.btn { border: 0; border-radius: 12px; padding: 11px 14px; min-height: 44px; font-weight: 800; background: var(--primary); color: white; }
.btn.secondary { background: white; color: var(--text); border: 1px solid var(--line); }
.btn.success { background: var(--success); }
.btn.danger { background: var(--danger); }
.btn.warning { background: var(--warning); }
.btn.small-btn { min-height: 36px; padding: 7px 10px; font-size: 12px; }
.btn.full { width: 100%; }
.text-btn, .link-btn { border: 0; background: transparent; padding: 4px; color: var(--accent); font-weight: 800; font-size: 12px; }
.danger-text { color: var(--danger); }
.problem-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.problem-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 13px; padding: 12px 10px; text-align: left; min-height: 54px; font-weight: 800; }
.problem-btn.active { border-color: var(--accent); background: #eff6ff; color: #1d4ed8; box-shadow: inset 0 0 0 1px var(--accent); }
.scale-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; }
.scale-btn { min-height: 64px; border-radius: 13px; border: 1px solid var(--line); background: white; padding: 8px 4px; font-size: 16px; font-weight: 900; position: relative; }
.scale-btn .worker { display: block; margin-top: 4px; font-size: 9px; color: var(--muted); font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 8px; font-size: 11px; font-weight: 800; background: #f3f4f6; color: #374151; white-space: nowrap; }
.badge.success { background: #dcfce7; color: #166534; }
.badge.warning { background: #ffedd5; color: #9a3412; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.list { display: grid; gap: 8px; }
.list-item { background: white; border: 1px solid var(--line); border-radius: 13px; padding: 10px 12px; }
.list-main { font-weight: 800; }
.list-meta { color: var(--muted); font-size: 11px; margin-top: 4px; line-height: 1.4; }
.rank-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border-bottom: 0; }
.rank-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.rank-value { font-weight: 900; }
.catalog-row { display: flex; gap: 8px; margin-bottom: 8px; }
.catalog-row .input { flex: 1; }
.catalog-list { display: flex; gap: 6px; flex-wrap: wrap; }
.catalog-chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); background: white; padding: 7px 9px; border-radius: 999px; font-size: 12px; }
.catalog-chip button { border: 0; background: transparent; color: var(--danger); font-weight: 900; padding: 0; }
.scale-config { display: grid; gap: 8px; }
.scale-config-row { display: grid; grid-template-columns: 56px 50px 1fr; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.scale-config-row:last-child { border-bottom: 0; }
.scale-number { font-weight: 900; }
.toggle { display: inline-flex; align-items: center; justify-content: center; }
.toggle input { width: 20px; height: 20px; }
.empty { text-align: center; color: var(--muted); padding: 20px 10px; font-size: 13px; }
.divider { height: 1px; background: var(--line); margin: 12px 0; }
.sticky-actions { position: sticky; bottom: 78px; z-index: 10; padding-top: 10px; }
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(255,255,255,.97); border-top: 1px solid var(--line); padding: 7px 8px calc(7px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(5,1fr); box-shadow: 0 -4px 16px rgba(17,24,39,.08); }
.nav-btn { border: 0; background: transparent; color: var(--muted); padding: 6px 2px; font-size: 10px; font-weight: 700; border-radius: 10px; }
.nav-btn.active { color: var(--text); background: #f3f4f6; }
.nav-icon { display: block; font-size: 18px; line-height: 1; margin-bottom: 4px; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translate(-50%,20px); z-index: 100; background: #111827; color: white; padding: 11px 14px; border-radius: 12px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; max-width: calc(100vw - 32px); font-size: 13px; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(17,24,39,.55); display: flex; align-items: flex-end; }
.modal { width: 100%; max-height: 90dvh; overflow: auto; background: white; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.modal-handle { width: 44px; height: 5px; background: #d1d5db; border-radius: 999px; margin: 0 auto 14px; }
.production-list { display: grid; gap: 10px; }
.production-card { border-left: 4px solid transparent; }
.production-card.selected { border-left-color: var(--accent); background: #f8fbff; }
.production-card-main { min-width: 0; }
.production-actions { display: flex; gap: 12px; margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); }
.production-tabs { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.production-tabs.compact { grid-template-columns: repeat(2,minmax(0,1fr)); }
.production-chip { border: 1px solid var(--line); border-radius: 13px; background: white; padding: 10px; text-align: left; min-width: 0; }
.production-chip strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.production-chip span { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.production-chip.active { border-color: var(--accent); background: #eff6ff; color: #1d4ed8; box-shadow: inset 0 0 0 1px var(--accent); }
.shortcut-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.recent-btn { border: 1px solid var(--line); border-radius: 12px; background: #f9fafb; padding: 10px; text-align: left; }
.recent-btn strong, .recent-btn span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.recent-btn span { font-size: 10px; color: var(--muted); margin-top: 3px; }
.alert-card { border-color: #fed7aa; background: #fffaf5; }
.counter-scale-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; }
.counter-scale { position: relative; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: white; }
.counter-scale.seen { border-color: #86efac; background: #f0fdf4; }
.counter-main { width: 100%; min-height: 78px; border: 0; background: transparent; padding: 8px 24px 8px 6px; color: var(--text); }
.counter-number { display: block; font-size: 16px; font-weight: 900; }
.counter-worker { display: block; font-size: 8px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.counter-value { display: block; font-size: 20px; margin-top: 3px; color: var(--success); }
.counter-minus { position: absolute; top: 4px; right: 4px; width: 25px; height: 25px; border: 0; border-radius: 8px; background: #f3f4f6; color: var(--danger); font-weight: 900; }
.candidate-list { display: grid; gap: 8px; margin-top: 10px; }
.candidate-row { border: 1px solid var(--line); border-radius: 13px; padding: 10px; background: #fff; }
.candidate-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.candidate-actions { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: end; margin-top: 8px; }
.mini-field { font-size: 10px; color: var(--muted); font-weight: 700; }
.mini-field input { display: block; width: 100%; max-width: 120px; min-height: 36px; border: 1px solid #d1d5db; border-radius: 9px; padding: 6px 8px; margin-top: 3px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.switch { position: relative; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d1d5db; border-radius: 999px; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,.25); transition: .2s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(20px); }
.backup-status { padding: 9px 10px; border-radius: 10px; background: #f9fafb; border: 1px solid var(--line); margin: 10px 0; font-size: 12px; }
.history-filters { display: grid; gap: 8px; grid-template-columns: 1fr; }

@media (min-width: 620px) {
  .form-grid { grid-template-columns: repeat(3,1fr); }
  .form-grid.two-cols { grid-template-columns: repeat(2,1fr); }
  .problem-grid { grid-template-columns: repeat(4,1fr); }
  .scale-grid { grid-template-columns: repeat(8,1fr); }
  .counter-scale-grid { grid-template-columns: repeat(8,1fr); }
  .quick-grid { grid-template-columns: repeat(4,1fr); }
  .production-tabs, .production-tabs.compact { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .shortcut-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .history-filters { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; }
  .bottom-nav { left: 50%; transform: translateX(-50%); max-width: 900px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .modal { max-width: 900px; margin: 0 auto; }
}
