:root {
  --bg1: #f4efe7;
  --bg2: #dcd5cb;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --ink: #2a2723;
  --ink2: #6f675d;
  --line: rgba(60, 50, 40, 0.12);
  --accent: #3d7bfd;
  --accent-soft: rgba(61, 123, 253, 0.12);
  --danger: #e5484d;
  --ok: #2f9e6b;
  --r: 18px;
  --shadow: 0 10px 30px rgba(40, 30, 20, 0.16), 0 2px 6px rgba(40, 30, 20, 0.08);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(120% 90% at 50% 20%, var(--bg1), var(--bg2));
  user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
#app { position: fixed; inset: 0; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* ---- верхняя панель ---- */
.topbar {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(10px + var(--safe-t)) 12px 0;
  display: flex; gap: 8px; align-items: center; justify-content: space-between;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.chip, .seg, .icon, .fab, .status {
  background: var(--glass); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  box-shadow: var(--shadow); border-radius: 999px;
}
.chip { height: 40px; padding: 0 14px; display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; flex: 0 1 auto; }
.chip span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; box-shadow: 0 0 0 3px rgba(47,158,107,.18); }
.chip.bad .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(229,72,77,.18); }
.seg { display: flex; padding: 3px; height: 40px; flex: none; }
.seg button { padding: 0 11px; border-radius: 999px; font-weight: 600; color: var(--ink2); transition: .2s; }
.seg button.on { background: var(--ink); color: #fff; }
.icon { width: 40px; height: 40px; display: grid; place-items: center; font-size: 20px; font-weight: 700; flex: none; }
.icon.ghost { background: rgba(0,0,0,.05); box-shadow: none; backdrop-filter: none; width: 34px; height: 34px; font-size: 15px; }

.status {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(60px + var(--safe-t));
  padding: 7px 14px; font-size: 13px; font-weight: 600; white-space: nowrap; color: var(--danger);
}
.hint {
  position: absolute; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%);
  background: rgba(42,39,35,.78); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 13px; text-align: center;
  transition: opacity .6s; pointer-events: none; width: max-content; max-width: calc(100% - 32px);
}
.hidden { display: none !important; }

/* ---- нижние листы ---- */
.fab {
  position: absolute; right: 16px; bottom: calc(18px + var(--safe-b));
  height: 52px; padding: 0 22px; font-weight: 700; font-size: 16px;
  background: var(--ink); color: #fff;
}
.fab:active { transform: scale(.97); }
.sheet {
  position: absolute; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b));
  background: var(--glass-strong); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-radius: 22px; box-shadow: var(--shadow); padding: 14px 14px 12px;
  animation: up .25s cubic-bezier(.2,.9,.3,1.2);
  max-width: 560px; margin: 0 auto;
}
.sheet.big { max-height: 72vh; display: flex; flex-direction: column; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.grab { width: 40px; height: 4px; border-radius: 4px; background: rgba(0,0,0,.15); margin: -4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 18px; }

.card-head { display: flex; justify-content: space-between; gap: 8px; }
.card-title { font-weight: 700; font-size: 17px; }
.card-sub { color: var(--ink2); font-size: 13px; margin-top: 2px; }
.card-warn { font-size: 13px; margin: 8px 0 2px; color: var(--ok); font-weight: 600; }
.card-warn.bad { color: var(--danger); }
.actions { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.actions::-webkit-scrollbar { display: none; }
.actions button {
  flex: 1 0 auto; min-width: 60px; padding: 8px 8px 7px; border-radius: 14px; background: rgba(0,0,0,.05);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 600;
}
.actions button b { font-size: 18px; line-height: 1; }
.actions button:active { background: var(--accent-soft); }
.actions button.danger { color: var(--danger); }
.actions button.on { background: var(--accent-soft); color: var(--accent); }

.dims { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 10px; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink2); font-weight: 600; }
label.f input, label.f select {
  font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); width: 100%;
}

.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; flex: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { padding: 7px 13px; border-radius: 999px; background: rgba(0,0,0,.05); font-weight: 600; font-size: 14px; white-space: nowrap; }
.tabs button.on { background: var(--ink); color: #fff; }
.cards { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; padding-bottom: 4px; }
.pcard {
  text-align: left; background: #fff; border-radius: 16px; padding: 10px; border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; transition: transform .12s;
}
.pcard:active { transform: scale(.97); }
.pcard svg { width: 100%; height: 64px; }
.pcard .n { font-weight: 700; font-size: 14px; }
.pcard .s { color: var(--ink2); font-size: 12px; }
.pcard .row { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.pcard .price { font-weight: 700; }
.pcard .badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: rgba(47,158,107,.12); color: var(--ok); font-weight: 700; }
.pcard .badge.no { background: rgba(229,72,77,.12); color: var(--danger); }

.form { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.form .grp { background: #fff; border-radius: 16px; padding: 10px; border: 1px solid var(--line); }
.form .grp h3 { margin: 0 0 8px; font-size: 14px; }
.form .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.form textarea { width: 100%; min-height: 160px; font: 12px/1.4 ui-monospace, monospace; border-radius: 10px; border: 1px solid var(--line); padding: 8px; }
.btn { padding: 10px 14px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 700; }
.btn.light { background: rgba(0,0,0,.06); color: var(--ink); }
.small { font-size: 12px; color: var(--ink2); margin: 10px 2px 0; }

.menu-list { display: flex; flex-direction: column; gap: 6px; }
.menu-list button { text-align: left; padding: 12px 14px; border-radius: 14px; background: rgba(0,0,0,.04); font-weight: 600; }
.menu-list button.danger { color: var(--danger); }

/* ---- подписи в 3D ---- */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
  background: #fff; color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.lbl.tight { background: #fff3d6; color: #a66300; }
.lbl.zero { background: var(--danger); color: #fff; }
.lbl.name { background: rgba(42,39,35,.72); color: #fff; font-weight: 600; font-size: 11px; }

.toast {
  position: absolute; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; transition: .25s; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  .sheet { left: auto; right: 16px; bottom: 16px; width: 420px; margin: 0; }
  .sheet.big { max-height: calc(100vh - 100px); }
  .fab { bottom: 24px; right: 24px; }
  body.sheet-open .fab { display: none; }
}
