/* style.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --border:    #334155;
  --text:      #f1f5f9;
  --muted:     #94a3b8;
  --accent:    #2563eb;
  --radius:    6px;
  --topbar-h:  48px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; overflow: hidden; }

/* ── Gallery page ── */
.page { overflow-y: auto; height: 100%; padding: 2rem; }
.page h1 { font-size: 1.5rem; margin-bottom: 1.5rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: border-color .15s; }
.card:hover { border-color: var(--accent); }
.card-thumb { height: 160px; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 4rem; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: .875rem 1rem; }
.card-body h2 { font-size: 1rem; margin-bottom: .25rem; }
.card-body p  { font-size: .8rem; color: var(--muted); margin-bottom: .75rem; }
.btn { display: inline-block; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); padding: .45rem .9rem; font-size: .82rem; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(1.15); }

/* ── Viewer page ── */
#viewer-wrap { display: flex; flex-direction: column; height: 100vh; }

/* Top bar */
#topbar { height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; padding: 0 1rem; flex-shrink: 0; }
#scene-title { font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
#model-count  { font-size: .78rem; color: var(--muted); flex: 1; }
.tb-btn { background: var(--border); border: none; color: var(--text); border-radius: var(--radius); padding: .35rem .75rem; font-size: .78rem; cursor: pointer; white-space: nowrap; }
.tb-btn:hover { filter: brightness(1.3); }
#copy-btn { background: var(--accent); font-weight: 600; }
#menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: .3rem .6rem; cursor: pointer; font-size: 1rem; }
#models-btn { display: none; background: var(--border); border: none; color: var(--text); border-radius: var(--radius); padding: .35rem .65rem; font-size: .8rem; cursor: pointer; }
#mobile-menu { display: none; }
.tb-btn.active { background: var(--accent); color: #fff; }

/* Models panel — vertical drawer at top-left */
#models-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 199; }
#models-backdrop.open { display: block; }
#models-panel {
  display: none; position: fixed;
  top: var(--topbar-h); left: 0;
  width: 280px; max-width: 90vw;
  max-height: calc(100vh - var(--topbar-h) - 12px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) 0;
  box-shadow: 2px 4px 16px rgba(0,0,0,.4);
  z-index: 200; padding: 0;
}
#models-panel.open { display: block; }
#models-panel-header { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: .9rem; }
.close-x { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: .2rem .5rem; }
#models-list { padding: .5rem 0; }
.model-row { display: grid; grid-template-columns: 28px 1fr 28px; align-items: center; gap: .6rem; padding: .55rem 1rem; border-bottom: 1px solid rgba(255,255,255,.04); }
.model-row input[type=color] { width: 26px; height: 22px; border: 1px solid var(--border); border-radius: 3px; padding: 0; background: none; cursor: pointer; }
.model-row .mr-name { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-row .mr-eye  { background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: .2rem; }
.model-row.hidden-model .mr-name { opacity: .45; text-decoration: line-through; }
.model-row .mr-opacity-row { grid-column: 2 / 4; display: flex; align-items: center; gap: .5rem; padding-top: .3rem; }
.model-row .mr-opacity-row input[type=range] { flex: 1; accent-color: var(--accent); }
.model-row .mr-opacity-row span { font-size: .75rem; color: var(--muted); min-width: 28px; text-align: right; }

/* Loading overlay */
#loading-overlay { position: fixed; inset: var(--topbar-h) 0 0 0; display: none; align-items: center; justify-content: center; background: linear-gradient(180deg, rgba(79,175,224,.6) 0%, rgba(200,230,244,.6) 100%); backdrop-filter: blur(2px); z-index: 300; }
#loading-overlay.show { display: flex; }
#loading-card { background: rgba(15,23,42,.92); border: 1px solid var(--border); border-radius: 8px; padding: 1.4rem 1.8rem; min-width: 260px; max-width: 80vw; box-shadow: 0 8px 32px rgba(0,0,0,.4); text-align: center; }
#loading-spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto .8rem; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { font-size: .92rem; font-weight: 600; color: var(--text); margin-bottom: .8rem; }
#loading-bar-wrap { width: 100%; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: .55rem; }
#loading-bar { height: 100%; width: 0%; background: var(--accent); border-radius: 3px; transition: width .15s linear; }
#loading-detail { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Measurement labels (one per finished measurement, positioned each frame) */
.measure-label { position: absolute; background: rgba(15,23,42,.92); color: #facc15; border: 1px solid #facc15; border-radius: 4px; padding: .2rem .5rem; font-size: .8rem; font-weight: 600; pointer-events: none; z-index: 50; backdrop-filter: blur(4px); white-space: nowrap; transform: translate(-50%, -50%); }

/* Views dropdown */
#views-wrap { position: relative; }
#views-menu { display: none; position: absolute; top: calc(100% + 4px); right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 120px; z-index: 100; }
#views-menu.open { display: block; }
#views-menu button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: .5rem .75rem; font-size: .82rem; cursor: pointer; }
#views-menu button:hover { background: var(--border); }

/* 3D canvas */
#canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
  background: linear-gradient(180deg, #4FAFE0 0%, #8AC9E7 45%, #C8E6F4 100%);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#canvas-wrap canvas { touch-action: none; }
#canvas-wrap canvas { display: block; }

/* Chips overlay */
#chips-area { position: absolute; bottom: 0; left: 0; right: 0; padding: .6rem .75rem; background: linear-gradient(transparent, rgba(15,23,42,.85)); }
#chips-row { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.chip { display: flex; align-items: center; gap: .35rem; background: rgba(15,23,42,.85); border: 1px solid var(--border); border-radius: 20px; padding: .3rem .65rem; font-size: .78rem; cursor: pointer; backdrop-filter: blur(6px); transition: border-color .15s, opacity .15s; }
.chip.hidden-model { opacity: .45; }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chip-name { color: var(--text); }
.chip-eye { color: var(--muted); margin-left: .2rem; font-size: .9rem; }

/* Model control panel (inline, below chips) */
#ctrl-panel { display: none; background: rgba(30,41,59,.95); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .875rem; margin-top: .4rem; backdrop-filter: blur(6px); }
#ctrl-panel.open { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
#ctrl-panel label { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: .4rem; }
#ctrl-color { width: 28px; height: 22px; border: 1px solid var(--border); border-radius: 3px; cursor: pointer; padding: 0; background: none; }
#ctrl-opacity { width: 100px; accent-color: var(--accent); }
#ctrl-opacity-val { font-size: .78rem; color: var(--muted); min-width: 28px; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .gallery { grid-template-columns: 1fr; }
  #tb-desktop { display: none; }
  #menu-btn { display: block; }
  #mobile-menu { display: none; position: fixed; top: var(--topbar-h); right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 0 var(--radius); z-index: 200; padding: .5rem 0; min-width: 160px; max-width: 80vw; max-height: calc(100vh - var(--topbar-h) - 12px); overflow-y: auto; overscroll-behavior: contain; }
  #mobile-menu.open { display: block; }
  #mobile-menu button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: .55rem 1rem; font-size: .85rem; cursor: pointer; }
  #mobile-menu button:hover { background: var(--border); }
  #ctrl-panel.open { position: fixed; bottom: 0; left: 0; right: 0; border-radius: var(--radius) var(--radius) 0 0; padding: 1rem; z-index: 100; }
  #chips-area { display: none; }     /* en mobile usamos el panel desplegable */
  #models-btn { display: inline-block; order: -1; margin-right: .5rem; }
  #scene-title { order: 0; max-width: 140px; }
  #model-count { display: none; }
  #menu-btn    { order: 2; }
}
