/* SPIRITS LAB 3D — UI premium: grafito oscuro + champagne dorado */
:root {
  --bg: #0d0e11;
  --panel: #15161a;
  --panel-2: #1b1c21;
  --line: #26272e;
  --line-soft: #1f2026;
  --gold: #c9a030;
  --gold-hi: #e6c878;
  --cream: #efeadd;
  --text: #d6d3ca;
  --text-dim: #8b8a83;
  --ok: #6fae62;
  --warn: #d8a93f;
  --bad: #cf6a55;
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

/* ── Loader ─────────────────────────────────────────── */
#loader {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  transition: opacity .6s ease, visibility .6s;
}
#loader.hide { opacity: 0; visibility: hidden; }
.loader-mark, .brand {
  font-family: var(--serif);
  letter-spacing: 6px;
  color: var(--cream);
}
.loader-mark { font-size: 34px; }
.loader-mark b, .brand b { color: var(--gold); font-weight: 600; }
.loader-mark span, .brand span { color: var(--text-dim); font-size: .6em; vertical-align: super; }
.loader-sub { font-size: 10px; letter-spacing: 5px; color: var(--text-dim); }

/* ── Barra superior ─────────────────────────────────── */
#topbar {
  height: 56px; flex: 0 0 56px;
  display: flex; align-items: center; gap: 16px;
  padding: 0 18px;
  background: linear-gradient(180deg, #16171c, #121317);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 17px; white-space: nowrap; }
#projectName {
  flex: 0 1 340px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--cream);
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: 1px;
  padding: 7px 12px;
}
#projectName:focus { outline: none; border-color: var(--gold); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 13px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  user-select: none;
}
.btn:hover { border-color: var(--gold); color: var(--cream); }
.btn-gold {
  background: linear-gradient(180deg, #d8b34a, #b08a25);
  border-color: #d8b34a;
  color: #1a1407;
  font-weight: 600;
}
.btn-gold:hover { background: linear-gradient(180deg, #e6c463, #c09a30); color: #1a1407; }
.btn-small { padding: 4px 10px; font-size: 11.5px; }

#exportMenu { position: relative; }
#exportMenu summary { list-style: none; display: inline-block; }
#exportMenu summary::-webkit-details-marker { display: none; }
#exportMenu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 230px;
  padding: 6px;
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
}
#exportMenu .menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  padding: 8px 10px; border-radius: 5px; font-size: 12.5px; cursor: pointer;
}
#exportMenu .menu button:hover { background: #25262d; color: var(--gold-hi); }

/* ── Layout principal ───────────────────────────────── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 84px 308px 1fr 272px;
  min-height: 0;
}

/* Rail de pestañas */
#rail {
  background: #101116;
  border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column;
  padding: 10px 8px; gap: 4px;
  overflow-y: auto;
}
.rail-btn {
  background: none; border: 1px solid transparent; border-radius: 8px;
  color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px; font-size: 9.5px; letter-spacing: .4px;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.rail-ico { font-size: 17px; line-height: 1; }
.rail-btn:hover { color: var(--cream); }
.rail-btn.active {
  color: var(--gold-hi);
  background: var(--panel-2);
  border-color: var(--line);
}

/* Panel de controles */
#panel {
  background: var(--panel);
  border-right: 1px solid var(--line-soft);
  overflow-y: auto;
  padding: 14px;
}
.panel-tab { display: none; }
.panel-tab.active { display: block; }

.ctl { margin-bottom: 12px; }
.ctl-header {
  font-family: var(--serif);
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-tab .ctl-header:first-child { margin-top: 2px; }
.ctl-note { color: var(--text-dim); font-size: 11.5px; line-height: 1.5; margin: 8px 0 12px; }
.ctl-label { display: block; color: var(--text-dim); font-size: 11.5px; margin-bottom: 4px; }
.ctl-toggle { display: flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.ctl-row { display: flex; align-items: center; gap: 8px; }
.ctl-val { min-width: 52px; text-align: right; font-size: 11px; color: var(--gold-hi); font-variant-numeric: tabular-nums; }

input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 3px; border-radius: 3px;
  background: #2c2d35;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--gold);
  border: 2px solid #0d0e11;
  transition: transform .1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); background: var(--gold-hi); }

select, input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 9px;
  font-size: 12.5px;
  font-family: var(--sans);
}
select:focus, input[type="text"]:focus, input[type="password"]:focus, textarea:focus { outline: none; border-color: var(--gold); }

/* Puerta de acceso (contraseña única, grande y centrada) */
#gate {
  position: fixed; inset: 0; z-index: 95;
  background: radial-gradient(120% 90% at 50% 30%, #17140f 0%, var(--bg) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
}
#gate[hidden] { display: none; }
.gate-brand {
  font-family: var(--serif); letter-spacing: 10px; color: var(--cream);
  font-size: clamp(34px, 6vw, 58px);
}
.gate-brand b { color: var(--gold); font-weight: 600; }
.gate-brand span { color: var(--text-dim); font-size: .55em; vertical-align: super; }
.gate-sub { font-size: clamp(10px, 1.4vw, 13px); letter-spacing: 6px; color: var(--text-dim); margin-bottom: 28px; }
.gate-box { display: flex; flex-direction: column; gap: 12px; width: min(360px, 82vw); }
.gate-box input {
  text-align: center; font-size: 17px; padding: 15px;
  letter-spacing: 1px; border-radius: 10px;
}
.gate-box input#gatePw { letter-spacing: 4px; }
.gate-box .btn-gold { padding: 14px; font-size: 15px; letter-spacing: 2px; border-radius: 10px; }
.gate-msg { color: var(--bad); font-size: 13px; min-height: 16px; text-align: center; }
input[type="color"] {
  width: 100%; height: 30px;
  background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px;
  cursor: pointer; padding: 2px;
}
input[type="checkbox"] { accent-color: var(--gold); width: 15px; height: 15px; }
input[type="file"] { width: 100%; color: var(--text-dim); font-size: 11px; margin: 4px 0 10px; }
input[type="file"]::file-selector-button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px;
  padding: 5px 10px; margin-right: 8px; cursor: pointer; font-size: 11.5px;
}

/* Biblioteca */
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text-dim); border-radius: 20px;
  padding: 4px 11px; font-size: 11px; cursor: pointer;
}
.chip:hover { color: var(--cream); }
.chip.active { color: #1a1407; background: var(--gold); border-color: var(--gold); font-weight: 600; }
.lib-grid { display: flex; flex-direction: column; gap: 8px; }
.lib-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.lib-card:hover { border-color: var(--gold); transform: translateX(2px); }
.lib-cat { color: var(--gold); font-size: 9.5px; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 3px; }
.lib-name { font-family: var(--serif); color: var(--cream); font-size: 14px; margin-bottom: 3px; }
.lib-desc { color: var(--text-dim); font-size: 11px; line-height: 1.45; margin-bottom: 6px; }

/* IA */
.ai-prompt { resize: vertical; margin-bottom: 10px; line-height: 1.5; }
.ai-results { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }

/* Viewport 3D */
#viewport { position: relative; min-width: 0; background: var(--bg); }
#viewport canvas { display: block; width: 100% !important; height: 100% !important; }
#refOverlay {
  display: none;
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  max-height: 86%; max-width: 70%;
  opacity: .45;
  pointer-events: none;
  z-index: 5;
}
#viewportHud {
  position: absolute; left: 50%; bottom: 14px;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  z-index: 6;
}
.pills {
  display: flex; gap: 4px;
  background: rgba(16, 17, 22, .82);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 4px;
  backdrop-filter: blur(8px);
}
.pill {
  background: none; border: none;
  color: var(--text-dim);
  border-radius: 16px;
  padding: 5px 12px; font-size: 11px;
  cursor: pointer;
}
.pill:hover { color: var(--cream); }
.pill.active { background: var(--gold); color: #1a1407; font-weight: 600; }

/* Panel de especificaciones */
#specs {
  background: var(--panel);
  border-left: 1px solid var(--line-soft);
  overflow-y: auto;
  padding: 16px 14px;
}
#specs h3 {
  font-family: var(--serif);
  color: var(--gold);
  font-size: 12px; letter-spacing: 2.5px; text-transform: uppercase;
  margin: 4px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}
#specs h3 + #specsVia, #specsBody { margin-bottom: 20px; }
.spec-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 0;
  border-bottom: 1px dotted var(--line-soft);
  font-size: 11.5px;
}
.spec-row span { color: var(--text-dim); }
.spec-row b { color: var(--cream); font-weight: 500; text-align: right; }

.via-badges, #specsVia { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.via-pill {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 4px 11px; font-size: 11px; color: var(--text-dim);
}
.via-pill b { color: var(--gold-hi); }
.via-item {
  width: 100%;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 11px; line-height: 1.45;
  margin-bottom: 5px;
  border: 1px solid var(--line);
}
.via-item.ok { border-left: 3px solid var(--ok); color: var(--text); }
.via-item.warn { border-left: 3px solid var(--warn); color: var(--text); background: rgba(216, 169, 63, .06); }
.via-item.bad { border-left: 3px solid var(--bad); color: var(--text); background: rgba(207, 106, 85, .08); }

/* Modal de versiones */
#versionsModal, #planoModal {
  margin: auto;
  width: min(880px, 92vw);
  max-height: 84vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 0;
  overflow: hidden;
}
#planoModal { width: min(560px, 92vw); }
#versionsModal::backdrop, #planoModal::backdrop { background: rgba(5, 5, 8, .7); backdrop-filter: blur(3px); }
#versionsModal header, #planoModal header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-family: var(--serif);
  letter-spacing: 2px; text-transform: uppercase; font-size: 13px;
  color: var(--gold);
}
#closeVersions, #closePlano {
  background: none; border: none; color: var(--text-dim);
  font-size: 22px; cursor: pointer; line-height: 1;
}
#closeVersions:hover, #closePlano:hover { color: var(--cream); }
#versionsGrid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  overflow-y: auto;
  max-height: calc(84vh - 54px);
}
.ver-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.ver-card img {
  width: 100%; aspect-ratio: 4/3; object-fit: cover;
  border-radius: 6px; background: #0a0a0c;
  margin-bottom: 8px;
}
.ver-name { font-family: var(--serif); color: var(--cream); font-size: 13px; margin-bottom: 2px; }
.ver-author { color: var(--gold); font-size: 10px; letter-spacing: .3px; margin-bottom: 5px; }
.ver-meta { color: var(--text-dim); font-size: 10.5px; line-height: 1.5; margin-bottom: 8px; }
.ver-actions { display: flex; gap: 5px; flex-wrap: wrap; }

/* Modal datos del plano */
.plano-fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px;
  padding: 18px;
}
.plano-fields label {
  display: flex; flex-direction: column; gap: 4px;
  color: var(--text-dim); font-size: 11.5px;
}
.plano-fields input { font-size: 13px; }

/* Toast */
.flash {
  position: fixed; left: 50%; bottom: 64px; z-index: 90;
  transform: translateX(-50%) translateY(12px);
  background: var(--panel-2);
  border: 1px solid var(--gold);
  color: var(--gold-hi);
  border-radius: 24px;
  padding: 9px 20px;
  font-size: 12.5px;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Scrollbars */
::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2c2d35; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a3b45; }

/* Responsive mínimo (la app es de escritorio) */
@media (max-width: 1100px) {
  main { grid-template-columns: 70px 280px 1fr; }
  #specs { display: none; }
}
