/* USTOZ PRO — конфигуратор мебели. Тёмная премиальная тема: тёплый графит,
   древесный подтон, латунно-карамельный акцент, сериф в цифрах сметы. */

:root {
  --bg: #141110;
  --bg-2: #181412;
  --panel: #1c1714;
  --panel-2: #241d18;
  --panel-3: #2b231c;
  --line: #362c23;
  --line-soft: #292119;
  --text: #f1e9dd;
  --muted: #a3937f;
  --faint: #7a6c5b;
  --accent: #d9a45b;
  --accent-strong: #eec488;
  --accent-dim: #8a6a3f;
  --danger: #c9705a;
  --serif: 'Playfair Display', 'Georgia', serif;
  --sans: 'Manrope', 'Segoe UI', sans-serif;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app {
  display: grid;
  height: 100vh;
  grid-template-columns: 304px minmax(0, 1fr) 330px;
  grid-template-rows: 58px minmax(0, 1fr) auto;
  grid-template-areas:
    "top       top       top"
    "library   stage     inspector"
    "estimate  stage     inspector";
}

/* ---------- верхняя панель ---------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 18px 0 16px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 11px; margin-right: auto; }
.brand-mark { color: var(--accent); width: 34px; height: 34px; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.brand-text span { font-size: 11px; color: var(--muted); letter-spacing: 0.14em; text-transform: uppercase; }

.views {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.views button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 6px 14px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.views button:hover { color: var(--text); }
.views button.on { background: var(--panel-3); color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--line); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-ghost:hover { border-color: var(--accent-dim); color: var(--accent-strong); background: var(--panel-2); }

/* ---------- библиотека ---------- */
.library {
  grid-area: library;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 4;
}

.lib-tabs {
  display: flex;
  gap: 2px;
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--line-soft);
}
.lib-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 4px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.lib-tab:hover { color: var(--text); }
.lib-tab.on { color: var(--accent-strong); background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--line); }

.lib-cards {
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s, background 0.15s, box-shadow 0.15s;
}
.card:hover {
  border-color: var(--accent-dim);
  background: var(--panel-3);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
}
.card:active { transform: translateY(0); }

.card-icon {
  width: 42px; height: 42px;
  flex: none;
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  display: grid;
  place-items: center;
}
.card-icon svg { width: 30px; height: 30px; }

.card-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.card-name { font-weight: 600; font-size: 13.5px; }
.card-dims { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-cost { font-size: 12px; color: var(--accent-strong); font-variant-numeric: tabular-nums; margin-top: 2px; }

.card-add {
  margin-left: auto;
  color: var(--faint);
  font-size: 20px;
  font-weight: 300;
  line-height: 1;
  transition: color 0.15s;
}
.card:hover .card-add { color: var(--accent); }

/* ---------- сцена ---------- */
.stage {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: radial-gradient(120% 90% at 50% 10%, #1a1613 0%, var(--bg) 70%);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.stage canvas:active { cursor: grabbing; }

.empty-hint {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20, 16, 13, 0.82);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 22px;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  backdrop-filter: blur(4px);
  box-shadow: var(--shadow);
}

.webgl-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 30px;
  background: var(--bg);
}
.webgl-fallback b { font-size: 17px; color: var(--accent-strong); }
.webgl-fallback span { color: var(--muted); max-width: 420px; }

/* ---------- инспектор ---------- */
.inspector {
  grid-area: inspector;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
  z-index: 4;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.insp-empty { padding: 26px 20px; color: var(--faint); font-size: 13px; }
.insp-empty p { margin: 0; border: 1px dashed var(--line); border-radius: 12px; padding: 18px 16px; }

.insp-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.insp-head { display: flex; align-items: baseline; gap: 8px; }
.insp-head b { font-size: 16px; font-weight: 700; }
.insp-id { color: var(--faint); font-size: 12px; }

.insp-dims { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.insp-dims label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 11px; color: var(--muted); letter-spacing: 0.02em;
}
.insp-dims input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 9px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.insp-dims input:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(217, 164, 91, 0.14);
}

.insp-steps { display: flex; flex-direction: column; gap: 6px; }
.step-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--muted);
}
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  transition: border-color 0.15s, color 0.15s;
}
.stepper button:hover:not(:disabled) { border-color: var(--accent-dim); color: var(--accent-strong); }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper b { min-width: 18px; text-align: center; color: var(--text); font-variant-numeric: tabular-nums; }

.insp-cost-row {
  display: flex; align-items: baseline; justify-content: space-between;
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
  font-size: 12.5px; color: var(--muted);
}
.insp-cost-row b { font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; }

.decor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.decor-head span { font-size: 12.5px; color: var(--muted); }
.btn-link {
  border: 0; background: transparent; color: var(--accent);
  font-size: 12px; font-weight: 600; padding: 2px 0;
}
.btn-link:hover { color: var(--accent-strong); text-decoration: underline; }

.decor-strip { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch {
  width: 27px; height: 27px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  overflow: hidden;
  transition: transform 0.12s, box-shadow 0.12s;
}
.swatch span { display: block; width: 100%; height: 100%; }
.swatch:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4); }
.swatch.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }

.btn-danger {
  border: 1px solid rgba(201, 112, 90, 0.4);
  background: transparent;
  color: var(--danger);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.btn-danger:hover { background: rgba(201, 112, 90, 0.12); border-color: var(--danger); }

/* ---------- смета ---------- */
.estimate {
  grid-area: estimate;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 14px 16px 13px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.est-rows { display: flex; flex-direction: column; gap: 4px; }
.est-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; color: var(--muted); }
.est-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; font-size: 13.5px; }

.est-coeff label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12.5px; color: var(--muted); margin-bottom: 5px;
}
.est-coeff b { color: var(--accent-strong); font-variant-numeric: tabular-nums; }
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 22px;
  margin: 0;
  cursor: pointer;
}

.est-sale {
  display: flex; justify-content: space-between; align-items: baseline;
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
}
.est-sale span { font-size: 12px; color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; }
.est-sale b {
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.est-formula { margin: 0; font-size: 11px; color: var(--faint); }

/* ---------- тост ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 16px);
  background: var(--panel-3);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: var(--shadow);
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- скроллбары (webkit) ---------- */
.lib-cards::-webkit-scrollbar, .inspector::-webkit-scrollbar { width: 8px; }
.lib-cards::-webkit-scrollbar-thumb, .inspector::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 4px;
}

/* ---------- адаптив ---------- */
@media (max-width: 1250px) {
  #app { grid-template-columns: 264px minmax(0, 1fr) 296px; }
}

@media (max-width: 920px) {
  #app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }
  .topbar { position: sticky; top: 0; padding: 8px 12px; gap: 10px; flex-wrap: wrap; }
  .brand-text span { display: none; }
  .stage { height: 48vh; min-height: 300px; order: 1; }
  .estimate { order: 2; border-right: 0; }
  .est-sale b { font-size: 24px; }
  .library { order: 3; border-right: 0; border-top: 1px solid var(--line); }
  .inspector { order: 4; border-left: 0; border-top: 1px solid var(--line); }
  .lib-cards {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .card { flex: none; width: 230px; }
  .insp-empty { padding: 16px; }
}
