/* GrBox Constructor — app.css
 * Дизайн-система: тёмная тема, золотой акцент.
 * Структура: appbar сверху → экраны → tabbar снизу.
 * Все цели ≥ 44px, safe-area учтены.
 */
:root {
  --bg: #111215;
  --panel: rgba(17, 18, 21, .94);
  --panel2: #191a1d;
  --card: #1c1d21;
  --line: #3a352c;
  --txt: #eee6d8;
  --dim: #aaa69e;
  --acc: #c5a46c;
  --acc2: #e3d7c2;
  --danger: #d99;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --appbar-h: calc(56px + var(--sat));
  --tabbar-h: calc(58px + var(--sab));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; width: 100%; height: 100%;
  background: var(--bg); color: var(--txt);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }

/* ================= верхняя панель ================= */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: var(--appbar-h); padding: var(--sat) 14px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(17, 18, 21, .92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 30px; height: 30px; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand-txt b { font-size: 15px; letter-spacing: .02em; color: var(--acc2); }
.brand-txt span { font-size: 11px; color: var(--dim); letter-spacing: .06em; text-transform: uppercase; }
.appbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel2);
  font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(197, 164, 108, .18); }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--acc); color: #17140e;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800;
}
.avatar.big { width: 62px; height: 62px; font-size: 26px; }

/* ================= экраны ================= */
#screens {
  position: fixed; top: var(--appbar-h); bottom: var(--tabbar-h);
  left: 0; right: 0; overflow: hidden;
}
.screen {
  position: absolute; inset: 0;
  display: none; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.screen.active { display: block; }
#screen-build { overflow: hidden; }

.pad { padding: 16px 16px 28px; }
.sec-title {
  margin: 22px 0 10px; font-size: 12px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; color: var(--acc);
}
.sec-title:first-child { margin-top: 4px; }
.about { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }

/* ================= canvas-экран ================= */
canvas#cv {
  position: absolute; inset: 0;
  display: block; width: 100%; height: 100%;
  touch-action: none; cursor: grab;
}
canvas#cv:active { cursor: grabbing; }

.top {
  position: absolute; top: 10px; left: 12px; right: 12px; z-index: 6;
  display: flex; justify-content: space-between; gap: 8px; pointer-events: none;
}
.pill {
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  padding: 8px 13px; font-size: 12px; letter-spacing: .03em;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); white-space: nowrap;
}
.pill b { color: var(--acc); }

.quickbar {
  position: absolute; right: 12px; top: 60px; z-index: 7;
  display: flex; flex-direction: column; gap: 8px;
}
.quickbar button {
  width: 46px; height: 46px; border-radius: 13px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--acc2);
  font-size: 21px; line-height: 1; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.quickbar button:disabled { opacity: .35; }

#measures { position: absolute; inset: 0; z-index: 5; pointer-events: none; display: none; }
#measures .chip {
  position: absolute; transform: translate(-50%, -50%);
  background: rgba(17, 18, 21, .92); border: 1px solid var(--acc); border-radius: 9px;
  padding: 5px 9px; font-size: 11px; font-weight: 650; color: var(--acc2);
  white-space: nowrap;
}

#loader {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--bg); color: var(--dim); font-size: 13px; letter-spacing: .06em;
  transition: opacity .3s;
}
#loader.done { opacity: 0; pointer-events: none; }
.spin {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--acc);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= оверлеи / модалки ================= */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(10, 10, 12, .88);
}
.overlay.open { display: flex; }
.overlay .card {
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; width: min(420px, 100%);
  display: flex; flex-direction: column; gap: 12px;
}
.overlay h2 { margin: 0; font-size: 17px; color: var(--acc2); }
.overlay p { margin: 0; color: var(--dim); font-size: 14px; line-height: 1.5; }

/* ================= нижняя шторка (сборка) ================= */
.sheet {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--kb, 0px));
  z-index: 8;
  max-height: 52%; overflow-y: auto;
  background: var(--panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 6px 16px 16px;
  -webkit-overflow-scrolling: touch;
  transition: transform .25s ease;
}
.sheet-grip {
  display: block; width: 100%; height: 44px; margin: -6px 0 0;
  padding: 0; border: 0; background: transparent; cursor: pointer;
  position: relative;
}
.sheet-grip span {
  display: block; width: 42px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 12px auto 0;
}
.sheet-grip::after {
  content: '▾ панель'; position: absolute; left: 0; right: 0; top: 22px;
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim);
}
.sheet.collapsed { transform: translateY(calc(100% - 44px)); overflow: hidden; }
.sheet.collapsed .sheet-grip::after { content: '▴ панель'; }

details { border-bottom: 1px solid rgba(58, 53, 44, .5); padding: 6px 0; }
details:last-child { border-bottom: 0; }
summary {
  list-style: none; cursor: pointer;
  min-height: 44px; display: flex; align-items: center;
  font-size: 13px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  color: var(--acc2);
}
summary::-webkit-details-marker { display: none; }
summary::after { content: '▾'; margin-left: auto; color: var(--dim); transition: transform .2s; }
details[open] summary::after { transform: rotate(180deg); }

/* ================= элементы управления ================= */
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding-bottom: 10px; }
.dim { display: flex; flex-direction: column; gap: 6px; }
.dim.wide { padding: 6px 0 12px; }
.dim span { font-size: 11px; color: var(--dim); letter-spacing: .05em; }
.dim input[type=number] {
  width: 100%; min-height: 44px; text-align: center;
  background: var(--panel2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 10px; font-size: 16px; font-weight: 650;
}
.dim input[type=number]:focus { outline: none; border-color: var(--acc); }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 34px; background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--line);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; margin-top: -11px;
  border-radius: 50%; background: var(--acc); border: 2px solid var(--bg);
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--acc); border: 2px solid var(--bg);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 10px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; }
.chip span {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 11px;
  background: linear-gradient(180deg, rgba(38, 34, 27, .8), rgba(21, 20, 23, .8));
  color: var(--dim); font-size: 13px; font-weight: 600;
}
.chip input:checked + span {
  color: #17140e; background: var(--acc); border-color: var(--acc);
}

.btnrow { display: flex; gap: 10px; padding: 4px 0 12px; }
.btn {
  flex: 1; min-height: 44px; border-radius: 11px; border: 1px solid var(--acc);
  background: var(--acc); color: #17140e; font-size: 13px; font-weight: 700;
  letter-spacing: .05em; cursor: pointer; padding: 0 14px;
}
.btn.ghost { background: transparent; color: var(--acc); }
.btn.active { background: var(--acc); color: #17140e; border-color: var(--acc); }
.btn.danger { border-color: #7a4a44; color: var(--danger); }
.btn.danger:active { background: #7a4a44; color: #fff; }
.btnrow.rot-row { align-items: center; }

.rot-input {
  flex: 0 0 84px; min-height: 44px; text-align: center;
  background: var(--panel2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 11px; font-size: 15px; font-weight: 650;
}

.hint { margin: 0 0 8px; color: var(--dim); font-size: 12px; line-height: 1.5; }
.hint b { color: var(--acc2); }

.insp-name { font-size: 14px; font-weight: 700; color: var(--acc2); padding: 2px 0 10px; }

.parts { list-style: none; margin: 0; padding: 0 0 8px; }
.parts li {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 0 10px;
  border-radius: 10px; color: var(--txt); font-size: 13px; cursor: pointer;
}
.parts li:active, .parts li.sel { background: rgba(197, 164, 108, .16); }
.parts .dot {
  width: 12px; height: 12px; border-radius: 4px; flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, .35);
}

/* ================= карточки (каталог/проекты/кабинет) ================= */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.card-ico {
  width: 42px; height: 42px; border-radius: 11px; flex: 0 0 auto;
  background: var(--panel2); display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.card-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-body b { font-size: 14px; color: var(--acc2); }
.card-body span { font-size: 12px; color: var(--dim); }

.proj-card { flex-direction: column; align-items: stretch; gap: 12px; }
.proj-top { display: flex; gap: 12px; align-items: center; }
.proj-thumb {
  width: 92px; height: 64px; border-radius: 10px; flex: 0 0 auto;
  background: var(--panel2) center/cover no-repeat; border: 1px solid var(--line);
}
.proj-meta { flex: 1; min-width: 0; }
.proj-meta b { display: block; font-size: 14px; color: var(--acc2); }
.proj-meta span { font-size: 11px; color: var(--dim); }

.mini-select {
  min-height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--txt); padding: 0 10px; font-size: 13px;
}

/* профиль */
.profile-head {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.name-input {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  min-height: 44px; padding: 0 12px; font-size: 16px; font-weight: 650; color: var(--txt);
  width: 100%;
}
.name-input:focus { outline: none; border-color: var(--acc); }
.name-input.wide { width: 100%; }

/* ================= tabbar ================= */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: var(--tabbar-h); padding-bottom: var(--sab);
  display: flex;
  background: rgba(17, 18, 21, .96);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: 0; background: transparent; cursor: pointer;
  color: var(--dim); font-size: 10px; letter-spacing: .04em; font-weight: 650;
  min-height: 54px;
}
.tab .tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--acc); }
.tab.active .tab-ico { transform: translateY(-1px); }

/* ================= тост ================= */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: var(--acc); color: #17140e;
  padding: 11px 20px; border-radius: 12px;
  font-size: 13px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: all .3s ease; z-index: 80;
  max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================= ландшафт: шторка справа ================= */
@media (orientation: landscape) and (min-width: 700px) {
  .sheet {
    left: auto; top: 0; right: 0;
    width: min(380px, 42vw); max-height: none;
    border-top: 0; border-left: 1px solid var(--line);
    border-radius: 0;
  }
  .sheet.collapsed { transform: translateX(calc(100% - 44px)); }
  .sheet.collapsed .sheet-grip::after { content: '▴'; top: 8px; }
  .quickbar { right: calc(min(380px, 42vw) + 12px); }
}
