/* ============================================================================
   ROBINN · Configuratore Box Doccia — UI (ispirata a schermata2.png)
   ========================================================================== */
:root {
  --bg: #ffffff;
  --ink: #1a1a1a;
  --muted: #9a9a9a;
  --line: #e4e4e4;
  --line-2: #d8d8d8;
  --accent: #111111;
  --field: #f3f3f3;
  --panel-w-left: 300px;
  --panel-w-right: 320px;
  --topbar-h: 64px;
  --footer-h: 34px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ---------- Top bar ---------- */
#topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 20;
}
.logo { display: flex; align-items: center; }
.logo-img { height: 24px; display: block; }
.logo-text { font-weight: 700; font-size: 26px; letter-spacing: 1px; }
.logo .flip { display: inline-block; transform: scaleX(-1); }
.topnav { display: flex; gap: 34px; }
.topnav a {
  font-size: 12px; letter-spacing: 1.5px; color: #555; cursor: pointer;
  text-decoration: none;
}
.topnav a.active { color: #000; font-weight: 700; }

/* ---------- Header actions (Ambiente / PDF) ---------- */
.header-actions { display: flex; align-items: center; gap: 8px; }
.hdr-wrap { position: relative; }
.hdr-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: #fff; color: #111;
  border: 1px solid var(--line, #ddd); border-radius: 4px;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.hdr-btn:hover { background: #111; color: #fff; border-color: #111; }
.hdr-btn:disabled { opacity: .5; cursor: default; }
.hdr-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 168px; background: #fff;
  border: 1px solid var(--line, #ddd); border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 6px; z-index: 50;
}
.hdr-menu[hidden] { display: none; }
.hdr-menu-title {
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  color: #999; padding: 4px 8px 6px;
}
.hdr-menu button {
  display: block; width: 100%; text-align: left;
  font-size: 13px; color: #222;
  background: none; border: 0; border-radius: 3px;
  padding: 8px 10px; cursor: pointer;
}
.hdr-menu button:hover { background: #f2f2f2; }
.hdr-menu button.active { background: #111; color: #fff; }
body.view-startup .header-actions { display: none; }

/* ---------- Layout ---------- */
#layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--panel-w-left) 1fr var(--panel-w-right);
  min-height: 0;
}

/* ---------- Viewport ---------- */
#viewport {
  position: relative;
  background: linear-gradient(180deg, #d2d1cf 0%, #c3c2c0 100%);
  overflow: hidden;
}
#scene { width: 100%; height: 100%; display: block; }

.hint-orbit {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: #6c6c6c; letter-spacing: .4px;
  background: rgba(255,255,255,.5); padding: 4px 10px; border-radius: 20px;
  pointer-events: none;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(220,219,217,.55); backdrop-filter: blur(2px); z-index: 5;
}
.overlay.show { display: flex; }
.spinner {
  width: 38px; height: 38px; border: 3px solid #fff; border-top-color: #888;
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay .msg {
  max-width: 360px; text-align: center; background: #fff; padding: 22px 26px;
  border-radius: 8px; font-size: 14px; line-height: 1.5;
}
.nomodel-card {
  text-align: center; background: #fff; padding: 26px 30px; border-radius: 8px;
  border: 1px solid var(--line);
}
.nomodel-card .code { font-size: 30px; font-weight: 700; margin-bottom: 8px; }
.nomodel-card p { margin: 0; font-size: 13px; color: #555; line-height: 1.6; }

/* ---------- Pannelli ---------- */
#panel-left, #panel-right {
  background: #fff; overflow-y: auto; font-size: 13px;
}
#panel-left { border-right: 1px solid var(--line); }
#panel-right { border-left: 1px solid var(--line); }

/* scrollbar discreta */
#panel-left::-webkit-scrollbar, #panel-right::-webkit-scrollbar { width: 8px; }
#panel-left::-webkit-scrollbar-thumb, #panel-right::-webkit-scrollbar-thumb {
  background: #e0e0e0; border-radius: 4px;
}

/* ---------- Pannello sinistro ---------- */
.lp-title {
  display: flex; align-items: center; justify-content: space-between;
  background: #111; color: #fff; padding: 13px 16px;
  font-size: 13px; letter-spacing: 1.5px; font-weight: 600;
}
.lp-title .x { cursor: pointer; opacity: .8; }
.hint { color: var(--muted); font-size: 12px; padding: 4px 2px; line-height: 1.5; }

/* ---------- Accordion (entrambi i pannelli) ---------- */
.acc { border-bottom: 1px solid var(--line); }
.acc-head {
  width: 100%; background: none; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 16px; font-size: 12.5px; letter-spacing: 1.2px; font-weight: 700;
  color: #1a1a1a; text-align: left;
}
.acc-head .chev { color: #999; font-weight: 400; font-size: 15px; }
.acc-body { padding: 4px 16px 18px; }

/* ---------- Albero collezioni ---------- */
.col { border-top: 1px solid #f1f1f1; }
.col:first-child { border-top: 0; }
.col-head {
  width: 100%; background: none; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 2px; font-size: 12.5px; letter-spacing: 1px; font-weight: 700;
}
.col-head .chev { color: #aaa; }
.col-list { padding: 2px 0 10px; }
.prod-row {
  width: 100%; background: none; border: 0; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 2px 6px 6px; font-size: 12.5px; color: #444;
}
.prod-row .dot { color: #bbb; font-size: 12px; }
.prod-row .bl { color: #c2c2c2; font-size: 11px; }
.prod-row:hover:not(.disabled) { color: #000; }
.prod-row.active { font-weight: 700; color: #000; }
.prod-row.active .dot { color: #111; }
.prod-row.disabled { color: #c7c7c7; cursor: default; }
.prod-row.disabled .bl { color: #dadada; }

/* ---------- Installazione ---------- */
.inst-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inst-card {
  background: #fff; border: 1px solid var(--line); border-radius: 4px;
  cursor: pointer; padding: 10px 8px 8px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.inst-card:hover { border-color: #bdbdbd; }
.inst-card.active { border-color: #111; box-shadow: inset 0 0 0 1px #111; }
.inst-thumb {
  width: 100%; height: 64px; background: #f4f4f4; border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
}
.inst-name { font-size: 11px; line-height: 1.3; color: #333; }
.inst-name small { color: #aaa; font-size: 10px; }
.inst-card.active .inst-name { font-weight: 700; }

/* ---------- Misure ---------- */
.meas-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.meas {
  background: var(--field); border: 1px solid transparent; border-radius: 3px;
  cursor: pointer; padding: 9px 6px; font-size: 12px; color: #8a8a8a;
}
.meas:hover { color: #333; }
.meas.nominal { color: #444; }
.meas.active {
  background: #fff; border-color: #111; color: #000; font-weight: 700;
}
.meas.disabled { opacity: .35; cursor: default; }
.meas.disabled:hover { color: #8a8a8a; }
.meas-special.disabled { opacity: .4; }
.meas-special.disabled input { cursor: default; background: #f0f0f0; }
.meas-special {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 12px; font-size: 11px; color: #9a9a9a;
}
.meas-special label { display: inline-flex; align-items: center; gap: 4px; }
.meas-special input {
  width: 52px; border: 1px solid var(--line-2); border-radius: 3px;
  padding: 5px 6px; font-size: 12px;
}

/* ---------- Swatches finiture ---------- */
.sw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sw {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-radius: 4px;
  padding: 8px 10px; font-size: 12px; color: #333; text-align: left;
}
.sw:hover { border-color: #bdbdbd; }
.sw.active { border-color: #111; box-shadow: inset 0 0 0 1px #111; font-weight: 600; }
.chip {
  width: 20px; height: 20px; border-radius: 50%; flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,.12);
}
/* profili */
.chip-cromo        { background: linear-gradient(135deg,#f4f6f7,#b9c0c4 60%,#eef1f2); }
.chip-rame         { background: linear-gradient(135deg,#e8a06a,#b87333 60%,#8a4f24); }
.chip-oro_satinato { background: linear-gradient(135deg,#e7cf93,#cfa14e 60%,#9c7a35); }
.chip-nero_opaco   { background: linear-gradient(135deg,#3a3b40,#15161a 60%,#0c0c0e); }
/* vetri */
.chipg-trasparente { background: linear-gradient(135deg,#eef6f8,#cfe0e4); }
.chipg-satinato    { background: linear-gradient(135deg,#f0f2f2,#dadede); }
.chipg-fume        { background: linear-gradient(135deg,#6a6a6e,#37373a); }

/* ---------- Footer ---------- */
#footer {
  height: var(--footer-h); flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; color: #b0b0b0; border-top: 1px solid var(--line);
  padding: 0 20px; text-align: center;
}

/* ---------- Schermata iniziale (tipologia installazione) ---------- */
#startup {
  display: none; flex: 1 1 auto; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px;
}
body.view-startup #startup { display: flex; }
body.view-startup #layout { display: none; }

.st-title {
  font-size: 22px; font-weight: 800; letter-spacing: .5px;
  margin: 0 0 36px; line-height: 1.35;
}
.st-grid { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.st-card {
  width: 168px; height: 224px; background: #fff;
  border: 1px solid var(--line-2); border-radius: 2px; cursor: pointer;
  display: flex; flex-direction: column; padding: 13px; transition: border-color .15s;
}
.st-card:hover:not(.disabled) { border-color: #111; }
.st-thumb {
  flex: 1; background: #ececec; border-radius: 2px;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.st-name { margin-top: 12px; font-weight: 700; font-size: 13px; }
.st-card.disabled { opacity: .45; cursor: default; }
.st-card.disabled .st-name { color: #999; }

/* ---------- Montaggio (reversibile dx/sx) ---------- */
.mount-toggle { display: flex; gap: 8px; margin-top: 8px; }
.mount-btn {
  flex: 1; background: var(--field); border: 1px solid transparent; border-radius: 3px;
  padding: 9px; font-size: 12px; cursor: pointer; color: #666;
}
.mount-btn:hover { color: #222; }
.mount-btn.active { background: #fff; border-color: #111; color: #000; font-weight: 700; }

/* ---------- AR / AR-AI : pulsanti bianco-nero quadrati (stile demo) ---------- */
#ar-btn, #arai-btn {
  position: absolute; right: 16px; z-index: 6;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid #111; border-radius: 2px;
  padding: 11px 16px; font-size: 11px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; cursor: pointer;
}
#ar-btn .btn-ico, #arai-btn .btn-ico { display: block; flex: 0 0 auto; }
#ar-btn { bottom: 62px; background: #fff; color: #111; }     /* bianco */
#ar-btn:hover { background: #111; color: #fff; }
#arai-btn { bottom: 16px; background: #111; color: #fff; }   /* nero */
#arai-btn:hover { background: #fff; color: #111; }
#ar-btn:disabled, #arai-btn:disabled { opacity: .5; cursor: default; }

/* modal AR-AI */
#arai-modal {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center;
  background: rgba(20,20,22,.55); backdrop-filter: blur(3px);
}
#arai-modal.show { display: flex; }
.arai-card {
  position: relative; width: 380px; max-width: 92vw; background: #fff;
  border: 1px solid var(--line); border-radius: 2px;
  padding: 26px 24px 22px; text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.arai-close {
  position: absolute; top: 12px; right: 14px; border: 0; background: none;
  font-size: 16px; color: #999; cursor: pointer;
}
.arai-title { font-size: 13px; font-weight: 800; letter-spacing: 1.5px; margin-bottom: 14px; }
.arai-text { font-size: 13px; color: #444; line-height: 1.5; margin: 0 0 8px; }
.arai-hint { font-size: 11.5px; color: #999; line-height: 1.4; margin: 0 0 16px; }
.arai-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.arai-btn-file, .arai-btn-genera, .arai-btn-dl, .arai-btn-retry {
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  border: 1px solid #111; background: #fff; color: #111; border-radius: 2px;
  padding: 10px 18px; font-size: 11px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; text-decoration: none;
}
.arai-btn-file.primary, .arai-btn-genera, .arai-btn-dl { background: #111; color: #fff; }
.arai-btn-file:hover, .arai-btn-retry:hover { background: #111; color: #fff; }
.arai-btn-file.primary:hover, .arai-btn-genera:hover, .arai-btn-dl:hover { background: #fff; color: #111; }
.arai-preview { margin-top: 16px; }
.arai-img-amb { max-width: 100%; max-height: 240px; border-radius: 2px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.arai-img-res { max-width: 100%; max-height: 460px; border-radius: 2px; box-shadow: 0 2px 12px rgba(0,0,0,.2); }
.arai-ok { color: #111; font-weight: 700; font-size: 13px; margin: 0 0 14px; }
.arai-err-msg { color: #111; font-size: 13px; margin: 0 0 16px; }
.arai-spinner {
  width: 42px; height: 42px; margin: 8px auto 18px; border-radius: 50%;
  border: 4px solid #e6e6e6; border-top-color: #111; animation: spin .9s linear infinite;
}
/* debug AR-AI nascosto (rimuovere questa riga per riattivarlo) */
.arai-debug-link, .arai-debug-prev { display: none !important; }

.arai-debug-link {
  margin-top: 16px; background: none; border: 0; color: #999; font-size: 11px;
  text-decoration: underline; cursor: pointer; letter-spacing: .3px;
}
.arai-debug-link:hover { color: #555; }
.arai-debug-prev { margin-top: 12px; }
.arai-debug-img {
  max-width: 100%; max-height: 240px; border: 1px solid var(--line); border-radius: 2px;
  background: #f3f3f3;
}
.arai-debug-dim { margin: 10px 0 0; font-size: 12px; font-weight: 700; color: #222; }

#ar-modal {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center;
  background: rgba(20,20,22,.55); backdrop-filter: blur(3px);
}
#ar-modal.show { display: flex; }
.ar-card {
  position: relative; width: 320px; max-width: 90vw; background: #fff;
  border-radius: 10px; padding: 26px 26px 22px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.ar-close {
  position: absolute; top: 12px; right: 14px; border: 0; background: none;
  font-size: 16px; color: #999; cursor: pointer;
}
.ar-title { font-size: 13px; font-weight: 800; letter-spacing: 1px; margin-bottom: 10px; }
.ar-text { font-size: 12.5px; color: #555; line-height: 1.5; margin: 0 0 16px; }
.ar-qr { width: 220px; height: 220px; border: 1px solid var(--line); border-radius: 6px; }
.ar-url { margin-top: 12px; font-size: 10.5px; color: #aaa; word-break: break-all; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  :root { --panel-w-left: 240px; --panel-w-right: 260px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  body { height: auto; min-height: 100vh; overflow-y: auto; }

  #topbar { height: 52px; padding: 0 16px; }
  .logo-img { height: 24px; }
  .logo-text { font-size: 20px; }

  /* layout in colonna: viewport sopra, pannelli sotto */
  #layout { display: flex; flex-direction: column; }
  #viewport { order: -1; height: 54vh; min-height: 300px; }
  #panel-left, #panel-right {
    width: 100%; border: 0; border-top: 1px solid var(--line);
    overflow: visible; max-height: none;
  }
  #panel-left { order: 1; }
  #panel-right { order: 2; }

  .hint-orbit { display: none; }
  #ar-btn { bottom: 58px; right: 12px; padding: 9px 15px; font-size: 12px; }
  #arai-btn { bottom: 12px; right: 12px; padding: 9px 15px; font-size: 12px; }
  #footer { height: auto; min-height: 0; padding: 10px 16px; line-height: 1.4; }

  /* schermata iniziale */
  #startup { padding: 18px; }
  .st-title { font-size: 18px; margin-bottom: 22px; }
  .st-grid { gap: 14px; }
  .st-card { width: 42vw; max-width: 170px; height: 190px; padding: 11px; }

  /* configuratore: griglie a piena larghezza più comode al tocco */
  .inst-grid, .sw-grid { grid-template-columns: 1fr 1fr; }
  .meas-grid { grid-template-columns: 1fr 1fr 1fr; }
  .acc-head { padding: 16px; }
  .meas { padding: 12px 6px; }
  .sw, .mount-btn { padding: 11px 10px; }

  /* modal AR a tutto schermo comodo */
  .ar-card { width: 90vw; padding: 22px 18px 18px; }
  .ar-qr { width: 200px; height: 200px; }
}

/* schermo molto stretto */
@media (max-width: 380px) {
  .st-card { width: 80vw; max-width: 220px; height: 200px; }
  .meas-grid { grid-template-columns: 1fr 1fr; }
}
