/* ბეტონის კუბატურა — განლაგება და სტილი */

:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #1e252c;
  --muted: #6d7883;
  --line: #d8dee5;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --danger: #b5432f;
  --radius: 7px;
}

* { box-sizing: border-box; }

/* display-ის მქონე კლასები UA-ს [hidden]-ს ჯაბნიან — ამიტომ !important */
[hidden] { display: none !important; }

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

body {
  font: 14px/1.45 "Segoe UI", "Noto Sans Georgian", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

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

/* ---------- განლაგება ---------- */

.app {
  display: grid;
  grid-template-columns: 348px 1fr;
  height: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  gap: 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.panel h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ---------- ფორმა ---------- */

.form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px 10px;
}

.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field.span2 { grid-column: span 2; }

/* არასავალდებულო ველები — პასუხის ხაზს ქვემოთ, ჩამუქებულად */
.field.extra > span { opacity: 0.75; }
.field.extra input { background: #f5f7f9; }

.field > span {
  font-size: 11.5px;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.field input:focus,
.field select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: -1px;
  background: #fff;
}

.mode {
  grid-column: 1 / -1;
  margin: 0;
  padding: 6px 9px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, #fff);
  font-size: 12px;
}

.preview {
  grid-column: 1 / -1;
  margin: 0;
  min-height: 18px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.preview b { color: var(--ink); }

button.primary {
  grid-column: 1 / -1;
  padding: 9px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.primary:disabled { background: #b9c2c9; cursor: not-allowed; }

/* ---------- სია ---------- */

.list {
  flex: 1 1 auto;
  min-height: 60px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.list li {
  display: grid;
  grid-template-columns: 12px 1fr auto 22px 22px;
  align-items: center;
  gap: 7px;
  padding: 8px 2px;
  border-bottom: 1px solid #eef1f4;
  cursor: pointer;
}
.list li:hover { background: #f6f8fa; }
.list li.is-sel { background: color-mix(in srgb, var(--accent) 10%, #fff); }

.swatch { width: 12px; height: 12px; border-radius: 3px; }

.li-main { min-width: 0; }
.li-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.li-dims { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.li-vol {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.li-act {
  width: 22px; height: 22px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.li-dup:hover { background: #dde6ec; color: var(--ink); }
.li-del:hover { background: #f2d9d4; color: var(--danger); }

.empty {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  margin: 0;
  padding: 22px 8px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ---------- ჯამები ---------- */

.totals {
  padding: 11px 12px;
  border-radius: var(--radius);
  background: #f4f6f8;
  border: 1px solid var(--line);
}

.trow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.trow b { color: var(--ink); font-size: 14px; }

.trow.big {
  margin-top: 5px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--ink);
}
.trow.big b { font-size: 19px; color: var(--accent); }

.waste { display: inline-flex; align-items: center; gap: 3px; }
.waste input {
  width: 52px;
  padding: 3px 6px;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}
.waste i { font-style: normal; }

/* ---------- ექსპორტი / იმპორტი ---------- */

.io { display: flex; gap: 6px; }
.io button {
  flex: 1;
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 12.5px;
}
.io button:hover { background: #f4f6f8; color: var(--ink); }
.io button.danger:hover { background: #f7e6e2; color: var(--danger); border-color: #e4c4bc; }

/* ---------- ტაბები ---------- */

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.tab {
  padding: 6px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { background: #f2f5f7; }
.tab.is-active {
  background: color-mix(in srgb, var(--accent) 12%, #fff);
  border-color: color-mix(in srgb, var(--accent) 30%, #fff);
  color: var(--accent);
  font-weight: 600;
}

.tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  font-size: 12.5px;
  color: var(--muted);
}
.tools button {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}
.tools button:hover { background: #f4f6f8; color: var(--ink); }

.chk { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); }

/* ---------- ხედები ---------- */

.viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#plan, #scene {
  display: block;
  width: 100%;
  height: 100%;
  background: #f7f9fa;
  touch-action: none;
  user-select: none;
}
#plan { cursor: grab; }
#plan.is-dragging { cursor: grabbing; }

.hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  margin: 0;
  padding: 4px 9px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--muted);
  font-size: 11.5px;
  pointer-events: none;
}

.scalebar {
  position: absolute;
  right: 12px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 4px 9px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.scalebar i {
  display: block;
  height: 6px;
  border: 1px solid var(--muted);
  border-top: 0;
}

.webgl-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 30px;
  text-align: center;
  color: var(--muted);
}

/* ---------- გეგმის ფიგურები ---------- */

.shape { cursor: move; }
.shape rect.body {
  stroke: rgba(0, 0, 0, 0.42);
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
}
.shape.is-kin rect.body { stroke: var(--ink); stroke-width: 2; }
.shape.is-sel rect.body { stroke: var(--ink); stroke-width: 2.5; }

.shape text {
  fill: rgba(0, 0, 0, 0.72);
  text-anchor: middle;
  pointer-events: none;
  font-weight: 600;
}
.shape text.dims { fill: rgba(0, 0, 0, 0.5); font-weight: 400; }

.handle {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.handle.corner { cursor: nwse-resize; }
.handle.rot { cursor: grab; fill: var(--accent); }
.rot-stem {
  stroke: var(--ink);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

/* ---------- ბანერი ---------- */

.banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  max-width: 78vw;
  padding: 9px 16px;
  border-radius: var(--radius);
  background: #2b3238;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}
.banner.is-error { background: var(--danger); }

/* ---------- ვიწრო ეკრანი ---------- */

@media (max-width: 820px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .stage { height: 72vh; }
  .list { max-height: 40vh; }
}
