/* MES PWA — цеховой интерфейс. Только системные шрифты, никаких внешних ресурсов. */
:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f242e;
  --surface-3: #272d39;
  --border: #2f3644;
  --text: #e8ecf2;
  --muted: #9aa5b5;
  --accent: #3b9ae1;
  --accent-ink: #06263c;
  --ok: #2fa46a;
  --warn: #d9a326;
  --danger: #e05252;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --r: 14px;
  --tap: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="light"] {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --surface-3: #e7ebf1;
  --border: #cfd6e0;
  --text: #12161c;
  --muted: #5c6675;
  --accent: #1668a8;
  --accent-ink: #ffffff;
  --shadow: 0 4px 18px rgba(20, 30, 45, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Классы ниже задают display, а он перебивает атрибут hidden — возвращаем ему силу. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; }

/* ------------------------------ Вход ------------------------------ */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px calc(24px + var(--safe-b)); }
.login__card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); }
.login__logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 16px;
  display: grid; place-items: center; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(150deg, var(--accent), #1b5f96); color: #fff; font-size: 22px; }
.login__title { text-align: center; font-size: 20px; margin-bottom: 22px; }
.login__error { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; font-size: 14px;
  background: rgba(224, 82, 82, .14); border: 1px solid rgba(224, 82, 82, .4); color: #ffb4b4; }
:root[data-theme="light"] .login__error { color: #a11; }
.login__hint { margin: 16px 0 0; color: var(--muted); font-size: 13px; text-align: center; }

.field { display: block; margin-bottom: 16px; }
.field__label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field__input, .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 12px 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.field textarea { min-height: 110px; resize: vertical; }
.field__input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 20px; color: var(--muted); font-size: 14px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ------------------------------ Каркас ------------------------------ */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar__titles { flex: 1; min-width: 0; }
.topbar__title { font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__actions { display: flex; align-items: center; gap: 4px; }
.topbar__icon { min-width: 42px; height: 42px; display: grid; place-items: center; font-size: 20px;
  background: transparent; border: 0; border-radius: 12px; }
.topbar__icon:active { background: var(--surface-3); }

.view { flex: 1; padding: 12px 12px 96px; max-width: 900px; width: 100%; margin: 0 auto; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: var(--safe-b); }
.tab { flex: 1; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: transparent; border: 0; color: var(--muted); font-size: 11px; position: relative; }
.tab__icon { font-size: 20px; line-height: 1; }
.tab.is-active { color: var(--accent); }
.tab.is-active::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px;
  border-radius: 0 0 3px 3px; background: var(--accent); }
.tab__dot { position: absolute; top: 8px; left: 50%; transform: translateX(6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger);
  color: #fff; font-size: 11px; line-height: 18px; font-weight: 700; }

/* ------------------------------ Карточки ------------------------------ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 14px; margin-bottom: 12px; }
.card--flag { border-left: 4px solid var(--accent); }
.card--work { border-left: 4px solid var(--ok); }
.card--hold { border-left: 4px solid var(--warn); }
.card__head { display: flex; align-items: flex-start; gap: 10px; }
.card__title { flex: 1; font-weight: 650; font-size: 17px; word-break: break-word; }
.card__sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card__rows { margin-top: 10px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.card__rows dt { color: var(--muted); }
.card__rows dd { margin: 0; word-break: break-word; }
.card__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.qty { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; white-space: nowrap; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--muted); }
.badge--ok { background: rgba(47, 164, 106, .18); color: #56d295; }
.badge--warn { background: rgba(217, 163, 38, .18); color: #ecc35f; }
.badge--danger { background: rgba(224, 82, 82, .18); color: #ff9b9b; }
.badge--accent { background: rgba(59, 154, 225, .18); color: #7cc3f2; }
:root[data-theme="light"] .badge--ok { color: #1a7a4a; }
:root[data-theme="light"] .badge--warn { color: #8a6410; }
:root[data-theme="light"] .badge--danger { color: #a92c2c; }
:root[data-theme="light"] .badge--accent { color: #12608f; }

/* ------------------------------ Кнопки ------------------------------ */
.btn { min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 600; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--ok { background: var(--ok); border-color: var(--ok); color: #04220f; }
.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--ghost { background: transparent; }
.btn--lg { width: 100%; min-height: 58px; font-size: 17px; }
.btn--sm { min-height: 42px; padding: 0 12px; font-size: 14px; }
.btn--grow { flex: 1; }

/* ------------------------------ Списки, состояния ------------------------------ */
.section-title { margin: 18px 2px 8px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty__icon { font-size: 44px; opacity: .5; }
.empty__text { margin-top: 10px; }
.skeleton { height: 96px; border-radius: var(--r); margin-bottom: 12px;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-3) 50%, var(--surface) 70%);
  background-size: 300% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { from { background-position: 100% 0 } to { background-position: -100% 0 } }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 14px; display: inline-flex; align-items: center; }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.search { width: 100%; min-height: 46px; margin-bottom: 10px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); }

/* ------------------------------ Модальные окна ------------------------------ */
.modal-root, .drawer-root { position: fixed; inset: 0; z-index: 60; display: grid; }
.modal-root { place-items: center; padding: 16px; background: rgba(0, 0, 0, .55); }
.modal { width: 100%; max-width: 460px; max-height: 88vh; overflow: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }
.modal__title { font-size: 18px; margin-bottom: 6px; }
.modal__sub { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.modal__actions { display: flex; gap: 10px; margin-top: 18px; }
.drawer-root { background: rgba(0, 0, 0, .55); align-items: end; }
.drawer { background: var(--surface); border-top: 1px solid var(--border); border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + var(--safe-b)); max-height: 86vh; overflow: auto; }
.drawer__handle { width: 44px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 14px; }
.menu-item { width: 100%; min-height: var(--tap); display: flex; align-items: center; gap: 12px;
  padding: 0 6px; background: transparent; border: 0; border-bottom: 1px solid var(--border); text-align: left; }
.menu-item:last-child { border-bottom: 0; }

.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 56px; height: 56px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 26px; }
.stepper input { flex: 1; min-height: 56px; text-align: center; font-size: 24px; font-weight: 700;
  border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2);
  font-variant-numeric: tabular-nums; }

/* ------------------------------ Тосты, блокер ------------------------------ */
.toasts { position: fixed; left: 12px; right: 12px; bottom: calc(76px + var(--safe-b)); z-index: 90;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { padding: 13px 15px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 15px; animation: up .18s ease-out; }
.toast--ok { border-color: var(--ok); }
.toast--err { border-color: var(--danger); }
@keyframes up { from { opacity: 0; transform: translateY(8px) } }
.blocker { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(0, 0, 0, .4); }
.blocker__spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--surface-3);
  border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }

/* ------------------------------ Прочее ------------------------------ */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.msg { border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface-2);
  border: 1px solid var(--border); }
.msg--mine { background: rgba(59, 154, 225, .12); border-color: rgba(59, 154, 225, .35); }
.msg__meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.filelist { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.filelist__item { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; font-size: 13px;
  border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.viewer { position: fixed; inset: 0; z-index: 80; background: #000; display: flex; flex-direction: column; }
.viewer__bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #111; color: #eee; font-size: 14px; }
.viewer__body { flex: 1; overflow: auto; display: grid; place-items: center; }
.viewer__body img { max-width: 100%; }
.viewer__body iframe, .viewer__body object { width: 100%; height: 100%; border: 0; background: #fff; }
@media (min-width: 720px) {
  .view { padding: 16px 16px 96px; }
  .card__title { font-size: 18px; }
}
