:root {
  --bg: #0f0f0f;
  --panel: #181818;
  --panel2: #161616;
  --card: #1c1c1c;
  --field: #1f1f1f;
  --line: #2a2a2a;
  --line2: #3a3a3a;
  --text: #ececec;
  --muted: #a8a8a8;
  --accent: #5b9dff;
  --accent-fill: #1f5fbf;
  --accent-soft: #1d2633;
  --reject: #a64d12;
  --reject-line: #e07a35;
  --warn: #f0b183;
  --sans: 'IBM Plex Sans', -apple-system, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; -webkit-text-size-adjust: 100%; }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
h1, h2 { margin: 0; font-weight: 600; }
.mono { font-family: var(--mono); }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.err { color: var(--warn); margin: 0; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: none; padding: var(--st) var(--sr) var(--sb) var(--sl); }
.screen.active { display: flex; }

/* ---------- Botones ---------- */
.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 0; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; }
.btn.primary { background: var(--accent-fill); color: #fff; font-weight: 600; }
.btn.light { background: var(--text); color: #121212; font-weight: 600; }
.btn.outline { background: transparent; border: 1px solid var(--line2); color: var(--text); }
.btn.danger { background: #2a1d15; border: 1px solid #5a3a26; color: var(--warn); }
.btn.reject { background: var(--reject); color: #fff; font-weight: 600; }
.btn.recover { background: var(--accent-fill); color: #fff; font-weight: 600; }
.btn.tall { min-height: 56px; border-radius: 12px; }
.btn.big { height: 56px; border-radius: 14px; font-size: 17px; }
.btn.wide { min-width: 260px; }
.btn.stack { flex-direction: column; gap: 2px; }
.btn.stack .small { font-weight: 400; color: #444; }
.small-btn { min-height: 38px; padding: 0 14px; border-radius: 19px; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; color: var(--text); }
.icon-btn.outline { border: 1px solid var(--line2); }
.icon-btn.big { width: 56px; height: 56px; border-radius: 12px; }
.linkbtn { background: none; border: 0; padding: 8px 0; color: var(--muted); text-align: left; text-decoration: underline; min-height: 44px; }

/* ---------- Acceso ---------- */
#login { align-items: center; justify-content: center; }
.login-card { width: min(380px, 90vw); display: flex; flex-direction: column; gap: 14px; padding: 32px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.login-card h1 { font-size: 30px; }
.login-card p { margin: 0 0 6px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.login-card label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); }
.login-card input[type=checkbox] { width: 22px; height: 22px; }
input[type=text], input[type=password], input:not([type]), input[type=number], input[type=search] {
  height: 46px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line2); background: var(--field); color: var(--text); font: inherit; font-size: 16px; outline: none;
}
input:focus { border-color: var(--accent); }

/* ---------- Carpetas ---------- */
.side { width: 220px; flex-shrink: 0; padding: 24px 16px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.brand { font-size: 20px; font-weight: 600; padding: 0 10px 18px; }
.nav { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 10px; border-radius: 10px; color: #c9c9c9; text-decoration: none; }
.nav.active { background: #26303f; color: #fff; font-weight: 500; }
.nav.disabled { color: #777; }
.cachebox { margin-top: auto; padding: 12px 10px; border-radius: 10px; background: #1f1f1f; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.cachebox .strong { color: var(--text); }
.cachebox .btn { margin-top: 4px; }

.browse { flex: 1; min-width: 0; padding: 24px 28px; display: flex; flex-direction: column; gap: 18px; overflow: hidden; }
.browse-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.browse-titles { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.browse-titles h1 { font-size: 26px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; font-family: var(--mono); font-size: 13px; color: var(--muted); }
.crumbs button { background: none; border: 0; padding: 4px 4px; color: var(--muted); min-height: 32px; font-family: var(--mono); font-size: 13px; }
.crumbs button:last-child { color: var(--text); }
.search { display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 12px; border-radius: 10px; background: var(--field); border: 1px solid #2f2f2f; width: 240px; color: var(--muted); flex-shrink: 0; }
.search input { border: 0; background: transparent; height: 40px; padding: 0; width: 100%; }
.cards { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-content: start; padding-bottom: 24px; }
.card { text-align: left; display: flex; align-items: center; gap: 12px; padding: 16px; min-height: 64px; border-radius: 14px; background: var(--card); border: 1px solid #2c2c2c; color: var(--text); }
.card svg { color: var(--muted); }
.card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.sel { border-color: #3f4f66; }
.empty { color: var(--muted); padding: 24px 4px; grid-column: 1 / -1; line-height: 1.5; }

.panel { width: 320px; flex-shrink: 0; padding: 24px 22px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.panel h2 { font-size: 19px; line-height: 1.3; word-break: break-word; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; font-size: 13px; }
.fact { padding: 10px; border-radius: 10px; background: #202020; display: flex; flex-direction: column; gap: 2px; }
.fact span:first-child { color: var(--muted); }
.fact span:last-child { font-size: 17px; font-weight: 600; }
.progress { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 12px; background: #202020; }
.progress .row { display: flex; justify-content: space-between; font-size: 14px; }
.bar { height: 8px; border-radius: 4px; background: #333; overflow: hidden; }
.bar div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.note { font-size: 13px; color: var(--muted); line-height: 1.5; }

/* ---------- Selección ---------- */
#select { flex-direction: column; }
.topbar { height: 68px; flex-shrink: 0; padding: 0 20px; display: flex; align-items: center; gap: 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.titles { display: flex; flex-direction: column; min-width: 0; max-width: 260px; }
.seg { display: flex; padding: 4px; border-radius: 12px; background: #222; gap: 2px; flex-shrink: 0; }
.seg button { min-height: 40px; padding: 0 14px; border-radius: 9px; border: 0; background: transparent; color: #c9c9c9; white-space: nowrap; }
.seg button b { font-weight: 500; font-family: var(--mono); }
.seg button.on { background: var(--line2); color: #fff; font-weight: 500; }
.spacer { flex: 1; }

.sel-body { flex: 1; min-height: 0; display: flex; }
.viewer { flex: 1; min-width: 0; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.stage { flex: 1; min-height: 0; position: relative; border-radius: 6px; overflow: hidden; background: #1a1a1a; touch-action: none; }
.track { position: absolute; inset: 0; will-change: transform; }
.track img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; will-change: transform; -webkit-user-drag: none; backface-visibility: hidden; }
.track img:not([src]) { visibility: hidden; }
.stage-msg, .full-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 20px; pointer-events: none; }
.badge { position: absolute; top: 14px; left: 14px; padding: 6px 12px; border-radius: 8px; background: rgba(0,0,0,.65); font-size: 13px; }
.badge.rej { background: var(--reject); color: #fff; }
.actions { display: flex; align-items: center; justify-content: center; gap: 14px; }
.hint { text-align: center; font-size: 13px; color: var(--muted); }

.sel-panel { width: 270px; padding: 20px 18px; background: var(--panel2); }
.kept { display: flex; flex-direction: column; gap: 2px; }
.big-num { font-size: 52px; font-weight: 600; line-height: 1.05; }
.goal { font-size: 14px; color: var(--warn); min-height: 20px; }
.goal.ok { color: #8fd18f; }
.goal.low { color: #7fb2ff; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.row input { width: 90px; text-align: right; font-family: var(--mono); }
.goalbar { position: relative; height: 10px; border-radius: 5px; background: #333; }
#goalFill { height: 10px; border-radius: 5px; background: var(--accent); width: 0; transition: width .2s; }
#goalMark { position: absolute; top: -5px; width: 2px; height: 20px; background: #fff; }
.goalscale { display: flex; justify-content: space-between; margin-top: 6px; }
.stats { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.stats div { display: flex; justify-content: space-between; }
.sel-panel #btnCreate { margin-top: auto; }

.strip { height: 104px; flex-shrink: 0; padding: 12px 20px; background: var(--panel2); border-top: 1px solid var(--line); display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.th { width: 104px; flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; border-radius: 6px; padding: 2px; border: 2px solid transparent; background: none; }
.th img, .th .ph { width: 100%; height: 62px; border-radius: 4px; object-fit: cover; background: #2a2a2a; display: block; }
.th i { height: 4px; border-radius: 2px; background: transparent; display: block; }
.th.cur { border-color: #fff; }
.th.rej { opacity: .4; }
.th.rej i { background: var(--reject-line); }

/* ---------- Pantalla completa ---------- */
#full { background: #000; padding: 0; touch-action: none; overflow: hidden; z-index: 5; }
.full-top { position: absolute; top: calc(16px + var(--st)); left: calc(16px + var(--sl)); right: calc(16px + var(--sr)); display: flex; align-items: center; gap: 12px; pointer-events: none; }
.full-top > * { pointer-events: auto; }
.pill-btn { width: 44px; height: 44px; border-radius: 22px; border: 0; background: rgba(0,0,0,.6); color: #fff; display: flex; align-items: center; justify-content: center; }
.pill { height: 44px; padding: 0 14px; border-radius: 22px; background: rgba(0,0,0,.6); display: flex; align-items: center; font-size: 14px; }
.counter { margin: 0 auto; height: 48px; padding: 0 20px; background: rgba(0,0,0,.72); gap: 14px; }
.counter .n { font-size: 22px; font-weight: 600; font-family: var(--mono); }
.counter .sep { width: 1px; height: 22px; background: #555; }
.counter .w { color: var(--warn); }
.counter .ok { color: #8fd18f; }
.counter .low { color: #7fb2ff; }
.full-hint { position: absolute; left: 50%; bottom: calc(96px + var(--sb)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; color: rgba(255,255,255,.75); font-size: 13px; text-align: center; transition: opacity .6s; pointer-events: none; }
.full-hint.gone { opacity: 0; }

/* ---------- Aviso y diálogo ---------- */
.toast { position: fixed; left: 50%; bottom: calc(28px + var(--sb)); transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 14px; height: 52px; padding: 0 8px 0 18px; border-radius: 26px; background: rgba(20,20,20,.92); border: 1px solid var(--line2); white-space: nowrap; }
.toast .dot { width: 10px; height: 10px; border-radius: 5px; background: var(--reject-line); }
dialog { border: 1px solid var(--line2); border-radius: 16px; background: var(--panel); color: var(--text); padding: 24px; width: min(440px, 90vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { font-size: 20px; margin-bottom: 8px; }
dialog p { color: #c9c9c9; line-height: 1.5; margin: 0 0 20px; white-space: pre-line; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; }


/* ---------- Galería de JPG ---------- */
#gallery, #edit { flex-direction: column; }
.gal-grid { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; align-content: start; }
.gcard { display: flex; flex-direction: column; gap: 8px; padding: 8px; border-radius: 12px; background: var(--card); border: 1px solid #2c2c2c; color: var(--text); text-align: left; position: relative; }
.gcard img, .gcard .ph { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; background: #2a2a2a; display: block; }
.gcard img.pano { object-fit: fill; }
.gcard .nm { font-size: 13px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gcard .done { position: absolute; top: 14px; left: 14px; padding: 4px 10px; border-radius: 8px; background: var(--accent-fill); color: #fff; font-size: 12px; font-weight: 600; }

/* ---------- Editor ---------- */
.ed-body { flex: 1; min-height: 0; display: flex; }
.ed-tools { width: 84px; flex-shrink: 0; padding: 14px 0; background: var(--panel2); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.tool { width: 70px; min-height: 60px; border-radius: 12px; border: 0; background: transparent; color: #c9c9c9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 11px; }
.tool.on { background: #26303f; color: #fff; }
.tool.alt { color: var(--warn); }
.ed-center { flex: 1; min-width: 0; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.ed-stage { flex: 1; min-height: 0; position: relative; overflow: hidden; border-radius: 6px; background: #1a1a1a; touch-action: none; }
.ed-wrap { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.ed-wrap canvas { position: absolute; left: 0; top: 0; display: block; }
#edOverlay { opacity: .45; pointer-events: none; }
#edOverlay.layer { filter: hue-rotate(190deg); }
.ed-cursor { position: absolute; border: 1.5px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.6); pointer-events: none; transform: translate(-50%, -50%); }
.ed-drop { position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: 12px; background: rgba(31,95,191,.25); display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 600; pointer-events: none; }
.ed-bottom { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding: 0 4px; }
.ctl { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #c9c9c9; }
.ctl input[type=range] { width: 160px; }
.ctl.chk input { width: 20px; height: 20px; }
.small-seg button { min-width: 44px; min-height: 36px; padding: 0 10px; }
.ed-panel { width: 330px; padding: 18px 16px; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line2); background: transparent; color: #c9c9c9; font-size: 14px; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: #fff; }
.staging { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.staging label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
select { height: 40px; border-radius: 10px; border: 1px solid var(--line2); background: var(--field); color: var(--text); font: inherit; font-size: 14px; padding: 0 8px; }
#edPrompt { width: 100%; resize: vertical; min-height: 110px; padding: 10px; border-radius: 10px; border: 1px solid #333; background: var(--field); color: var(--text); font-family: var(--mono); font-size: 12px; line-height: 1.5; }
.steps { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 12px; background: #202020; }
.steps .btn { justify-content: flex-start; gap: 12px; }
.num { width: 24px; height: 24px; border-radius: 12px; background: #fff; color: var(--accent-fill); font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.num.alt { background: var(--accent); color: #0f0f0f; }
.steps .linkbtn { text-align: center; }
.layers { display: flex; flex-direction: column; gap: 6px; }
.lay { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; background: #1f1f1f; border: 1px solid #2c2c2c; }
.lay.on { border-color: var(--accent); background: var(--accent-soft); }
.lay .pick { flex: 1; min-width: 0; min-height: 40px; background: none; border: 0; text-align: left; display: flex; flex-direction: column; justify-content: center; }
.lay .pick span:last-child { font-size: 12px; color: var(--muted); }
.lay .icon-btn { width: 40px; height: 40px; }
.adjust { display: flex; flex-direction: column; gap: 8px; }
.adj-row { display: flex; flex-wrap: wrap; gap: 6px; }
.adj-row .icon-btn { width: 44px; height: 44px; font-size: 20px; }
.busy { position: absolute; inset: 0; z-index: 10; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.busy-box { width: 320px; padding: 22px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line2); display: flex; flex-direction: column; gap: 12px; }
.show-narrow { display: none; }
.ed-pano { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.ed-edit, .pano-panel { display: flex; flex-direction: column; gap: 12px; }
.ed-edit[hidden], .pano-panel[hidden] { display: none; }
.pano-views { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.pano-views .btn { padding: 0 6px; font-size: 14px; }
#edit.pano-mode .ed-tools, #edit.pano-mode .ed-bottom, #edit.pano-mode #edModes, #edit.pano-mode #edUndo, #edit.pano-mode #edRedo { display: none; }
#edit { position: fixed; }

.side .mini-cache { display: none; margin: auto auto 0; }

/* ---------- iPad en vertical ---------- */
@media (max-width: 1000px) {
  .side { width: 76px; padding: 20px 10px; }
  .side .brand { font-size: 15px; padding: 0 0 14px; text-align: center; }
  .nav span, .cachebox { display: none; }
  .nav { justify-content: center; }
  .side .mini-cache { display: flex; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .panel { width: 280px; }
  .search { width: 180px; }
  .hide-narrow { display: none; }
  .titles { max-width: 160px; }
  .btn.wide { min-width: 180px; }
  .sel-panel { width: 220px; }
  .ed-panel { width: 270px; }
  .ed-tools { width: 70px; }
  .tool { width: 60px; }
  .ctl input[type=range] { width: 110px; }
  .show-narrow { display: inline; }
}
