/* PromptForge web — estética de sidios.cl (estilo Apple) */
:root {
  --bg: #ffffff;
  --bg-alt: #f5f5f7;
  --tile: #f5f5f7;
  --field: #ffffff;
  --pop: #ffffff;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --link: #0066cc;
  --button: #0071e3;
  --button-hover: #0077ed;
  --rule: #d2d2d7;
  --nav-bg: rgba(255, 255, 255, 0.72);
  --nav-rule: rgba(0, 0, 0, 0.12);
  --seg-track: rgba(0, 0, 0, 0.06);
  --seg-on: #ffffff;
  --seg-on-ring: rgba(0, 0, 0, 0.08);
  --hover: rgba(0, 0, 0, 0.04);
  --active: rgba(0, 113, 227, 0.1);
  --focus: rgba(0, 113, 227, 0.6);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --nav-h: 48px;
  --gutter: 22px;
  --max: 1180px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-alt: #161617;
    --tile: #1d1d1f;
    --field: #1d1d1f;
    --pop: #2c2c2e;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #86868b;
    --link: #2997ff;
    --rule: #424245;
    --nav-bg: rgba(22, 22, 23, 0.72);
    --nav-rule: rgba(255, 255, 255, 0.12);
    --seg-track: rgba(255, 255, 255, 0.08);
    --seg-on: #636366;
    --seg-on-ring: rgba(255, 255, 255, 0.04);
    --hover: rgba(255, 255, 255, 0.06);
    --active: rgba(41, 151, 255, 0.16);
    --focus: rgba(41, 151, 255, 0.7);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.1);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: var(--nav-h); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -0.022em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-synthesis: none;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
::selection { background: rgba(0, 113, 227, 0.22); }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: calc(var(--max) + var(--gutter) * 2); margin: 0 auto; padding: 0 var(--gutter); }

/* ===================== NAV ===================== */
.nav {
  position: fixed; inset: 0 0 auto 0; height: var(--nav-h); z-index: 50;
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--nav-rule);
}
.nav-inner { height: 100%; display: flex; align-items: center; gap: 20px; }
.nav-brand { color: var(--text); font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.nav-app { color: var(--text-2); font-size: 14px; letter-spacing: -0.016em; }
.nav-brand:hover, .nav-app:hover { text-decoration: none; }
.nav-links { display: flex; gap: 28px; margin-left: auto; }
.nav-btn {
  appearance: none; background: none; border: 0; padding: 0; cursor: pointer;
  font-size: 12px; letter-spacing: -0.01em; color: var(--text); opacity: 0.8;
  line-height: var(--nav-h); white-space: nowrap; transition: opacity .15s ease;
}
.nav-btn:hover { opacity: 1; }

/* ===================== HERO ===================== */
.hero { padding-top: calc(var(--nav-h) + 72px); padding-bottom: 56px; }
.hero-kicker { font-size: 21px; line-height: 1.38; font-weight: 600; letter-spacing: 0.011em; color: var(--text-2); margin-bottom: 8px; }
.hero-name { font-size: 80px; line-height: 1.05; font-weight: 600; letter-spacing: -0.015em; }
.hero-tagline { font-size: 28px; line-height: 1.14; font-weight: 400; letter-spacing: 0.007em; margin-top: 16px; }
.hero-sub { font-size: 21px; line-height: 1.38; letter-spacing: 0.011em; color: var(--text-2); margin-top: 16px; max-width: 34ch; }

/* ===================== LAYOUT ===================== */
.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) minmax(320px, 400px);
  gap: 40px;
  padding-top: 40px; padding-bottom: 120px;
  align-items: start;
}

.panel-label, .field-label { font-size: 21px; line-height: 1.19; font-weight: 600; letter-spacing: 0.011em; color: var(--text); }
.stack-label { font-size: 14px; line-height: 1.43; font-weight: 600; letter-spacing: -0.016em; color: var(--text-2); margin-bottom: 12px; }

/* ===================== HISTORIAL ===================== */
.history { position: sticky; top: calc(var(--nav-h) + 24px); max-height: calc(100vh - var(--nav-h) - 48px); display: flex; flex-direction: column; }
.history .panel-label { margin-bottom: 16px; }
.search {
  width: 100%; font: inherit; font-size: 14px; letter-spacing: -0.016em;
  padding: 7px 12px; border: 0; border-radius: 9px; background: var(--seg-track); color: var(--text); outline: none;
}
.search::placeholder { color: var(--text-3); }
.search:focus { box-shadow: 0 0 0 3px var(--focus); }
.history-list { overflow-y: auto; margin-top: 16px; flex: 1; min-height: 0; padding: 0 2px; }
.hgroup { font-size: 12px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-2); margin: 20px 8px 6px; }
.hgroup:first-child { margin-top: 0; }
.hitem {
  position: relative; display: block; width: 100%; text-align: left; cursor: default;
  padding: 8px 56px 8px 10px; border-radius: 10px; transition: background-color .15s ease;
}
.hitem:hover { background: var(--hover); }
.hitem.active { background: var(--active); }
.hitem-title { font-size: 14px; font-weight: 600; letter-spacing: -0.016em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hitem-sub { display: flex; gap: 6px; font-size: 12px; letter-spacing: -0.01em; color: var(--text-2); white-space: nowrap; overflow: hidden; margin-top: 1px; }
.hitem-sub .d { flex: 0 0 auto; font-variant-numeric: tabular-nums; color: var(--text); opacity: .7; }
.hitem-sub .p { overflow: hidden; text-overflow: ellipsis; }
.hitem-actions { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.hitem:hover .hitem-actions, .hitem:focus-within .hitem-actions, .hitem.active .hitem-actions { opacity: 1; }
.icon-btn {
  width: 24px; height: 24px; display: grid; place-items: center; cursor: pointer;
  background: none; border: 0; border-radius: 6px; font-size: 14px; color: var(--text-2);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.history-empty { font-size: 14px; color: var(--text-2); padding: 8px; }
.history-close { margin-top: 16px; }
.scrim { display: none; }

/* ===================== FORMULARIO ===================== */
.select-wrap { position: relative; display: inline-block; max-width: 100%; }
.select-wrap::after {
  content: ""; position: absolute; right: 13px; top: 50%; width: 7px; height: 7px; pointer-events: none;
  border-right: 1.5px solid var(--text-2); border-bottom: 1.5px solid var(--text-2);
  transform: translateY(-70%) rotate(45deg);
}
select {
  appearance: none; -webkit-appearance: none; max-width: 100%;
  font: inherit; font-size: 17px; letter-spacing: -0.022em; color: var(--text);
  background: var(--field); border: 1px solid var(--rule); border-radius: 12px;
  padding: 10px 40px 10px 14px; cursor: pointer; outline: none;
}
select:focus { border-color: var(--button); box-shadow: 0 0 0 3px var(--focus); }
.select-wrap.small select { font-size: 14px; padding: 6px 34px 6px 12px; border-radius: 8px; }

.domain { padding-bottom: 32px; border-bottom: 1px solid var(--rule); }
.domain .field-label { display: block; margin-bottom: 12px; }
.field-help { margin-top: 10px; font-size: 14px; line-height: 1.43; letter-spacing: -0.016em; color: var(--text-2); }

.field { padding: 32px 0; border-bottom: 1px solid var(--rule); }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.field-title { font-size: 28px; line-height: 1.14; font-weight: 600; letter-spacing: 0.007em; }
.field .field-help { margin: 6px 0 16px; }

.menu-anchor { position: relative; flex: 0 0 auto; }
.menu-btn {
  appearance: none; background: none; border: 0; padding: 0; cursor: pointer;
  font-size: 17px; color: var(--link);
}
.menu-btn::after {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 7px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: translateY(-3px) rotate(45deg); transition: transform .15s ease;
}
.menu-btn[aria-expanded="true"]::after { transform: translateY(0) rotate(-135deg); }
.menu-btn:hover { text-decoration: underline; }

.input-wrap { position: relative; }
textarea {
  display: block; width: 100%; resize: none; overflow-y: hidden;
  font: inherit; font-size: 17px; line-height: 1.47; letter-spacing: -0.022em; color: var(--text);
  background: var(--field); border: 1px solid var(--rule); border-radius: 12px;
  padding: 14px 16px; outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
textarea::placeholder { color: var(--text-3); }
textarea:focus { border-color: var(--button); box-shadow: 0 0 0 3px var(--focus); }

/* Listas flotantes (autocompletado y menú de sugerencias) */
.pop {
  position: absolute; z-index: 30; background: var(--pop); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; max-height: 360px; overflow-y: auto;
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.pop.complete { left: 0; right: 0; top: calc(100% + 6px); }
.pop.menu { right: 0; top: calc(100% + 8px); width: min(380px, calc(100vw - 44px)); }
.pop-group { font-size: 12px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-2); padding: 10px 10px 4px; }
.pop-item {
  display: block; width: 100%; text-align: left; background: none; border: 0; cursor: default;
  padding: 7px 10px; border-radius: 7px; font-size: 15px; letter-spacing: -0.016em; color: var(--text);
}
.pop-item:hover, .pop-item.hl, .pop-item:focus-visible { background: var(--button); color: #fff; outline: none; }
.pop details { border-top: 1px solid var(--rule); margin-top: 6px; padding-top: 2px; }
.pop details > summary { list-style: none; cursor: default; padding: 8px 10px; border-radius: 7px; font-size: 15px; letter-spacing: -0.016em; }
.pop details > summary:hover { background: var(--hover); }
.pop details > summary::-webkit-details-marker { display: none; }
.pop details > summary::after {
  content: ""; float: right; width: 6px; height: 6px; margin-top: 7px;
  border-right: 1.5px solid var(--text-2); border-bottom: 1.5px solid var(--text-2); transform: rotate(-45deg);
}
.pop details[open] > summary::after { transform: rotate(45deg); }
.pop details details { border: 0; margin: 0; padding-left: 10px; }

/* Chips (reglas comunes) */
.rules { margin-top: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 14px; letter-spacing: -0.016em; color: var(--text); cursor: pointer; text-align: left;
  background: var(--tile); border: 0; border-radius: 980px; padding: 7px 14px;
  transition: background-color .15s ease, color .15s ease;
}
.chip:hover { background: var(--seg-track); }
.chip[aria-pressed="true"] { background: var(--button); color: #fff; }

.form-actions { padding-top: 24px; }
.link-btn { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; font-size: 17px; color: var(--link); }
.link-btn:hover { text-decoration: underline; }

/* ===================== VISTA PREVIA ===================== */
.preview { position: sticky; top: calc(var(--nav-h) + 24px); }
.preview-inner {
  background: var(--tile); border-radius: 28px; overflow: hidden;
  display: flex; flex-direction: column; max-height: calc(100vh - var(--nav-h) - 48px);
}
.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 28px 28px 16px; }

.seg { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--seg-track); }
.seg button {
  appearance: none; border: 0; margin: 0; height: 28px; padding: 0 12px; border-radius: 7px; cursor: default;
  background: transparent; color: var(--text); font-size: 13px; letter-spacing: -0.01em; transition: background-color .15s ease;
}
.seg button[aria-checked="true"] { background: var(--seg-on); font-weight: 600; box-shadow: 0 0 0 0.5px var(--seg-on-ring), 0 1px 2px rgba(0,0,0,.06); }

.preview-body { flex: 1; min-height: 220px; overflow: auto; margin: 0 16px; background: var(--bg); border-radius: 16px; }
.output { margin: 0; padding: 18px; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 13px; line-height: 1.6; letter-spacing: 0; color: var(--text); }
.empty { padding: 32px 22px; }
.empty-title { font-size: 21px; line-height: 1.19; font-weight: 600; letter-spacing: 0.011em; margin-bottom: 8px; }
.empty p { margin: 0 0 16px; color: var(--text-2); font-size: 17px; }

.preview-actions { display: flex; gap: 10px; padding: 20px 28px 8px; flex-wrap: wrap; align-items: center; }
.btn {
  appearance: none; border: 0; cursor: pointer; border-radius: 980px; padding: 9px 18px;
  font-size: 15px; line-height: 1.2; letter-spacing: -0.016em;
  background: transparent; color: var(--link); transition: background-color .15s ease, opacity .15s ease;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn.primary { background: var(--button); color: #fff; padding: 9px 20px; }
.btn.primary:hover:not(:disabled) { background: var(--button-hover); }
.btn:disabled { opacity: .35; cursor: default; }

.progress { padding: 16px 28px 28px; }
.progress-row { display: flex; justify-content: space-between; font-size: 14px; letter-spacing: -0.016em; color: var(--text-2); margin-bottom: 10px; }
#progress-text { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.rail { position: relative; height: 4px; border-radius: 4px; background: var(--seg-track); overflow: hidden; }
.fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--button); width: 0; border-radius: 4px; transition: width .3s ease; }
.stats { margin-top: 12px; font-size: 12px; letter-spacing: -0.01em; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ===================== FOOTER ===================== */
footer { background: var(--bg-alt); color: var(--text-2); font-size: 12px; line-height: 1.33; letter-spacing: -0.01em; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; padding-top: 16px; padding-bottom: 24px; }
.footer-inner a { color: var(--text-2); }

/* ===================== DIALOG / TOAST ===================== */
.dialog {
  border: 0; border-radius: 20px; padding: 0; box-shadow: var(--shadow);
  width: min(480px, calc(100vw - 32px)); background: var(--pop); color: var(--text);
}
.dialog::backdrop { background: rgba(0,0,0,0.3); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.dialog-inner { padding: 28px; }
.dialog-title { font-size: 28px; line-height: 1.14; font-weight: 600; letter-spacing: 0.007em; margin-bottom: 20px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding-top: 14px; border-top: 1px solid var(--rule); }
.row > span:first-child { font-size: 17px; }
.row.check input { width: 20px; height: 20px; accent-color: var(--button); }
.dialog .field-help { margin: 6px 0 16px; font-size: 13px; }
.shortcuts { border-top: 1px solid var(--rule); padding-top: 16px; font-size: 14px; color: var(--text-2); display: grid; gap: 8px; }
.shortcuts .stack-label { margin-bottom: 4px; }
kbd { font-family: var(--font); font-size: 12px; border-radius: 5px; padding: 1px 6px; color: var(--text); background: var(--seg-track); }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 24px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: var(--pop); color: var(--text); box-shadow: var(--shadow);
  padding: 12px 20px; border-radius: 980px; font-size: 14px; letter-spacing: -0.016em;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 80;
  display: flex; gap: 16px; align-items: center; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; color: var(--link); font-size: 14px; }

.only-narrow { display: none; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 1180px) {
  .app { grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: 40px; }
  .only-narrow { display: inline-block; }
  .history {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); max-height: none;
    background: var(--bg); border-right: 1px solid var(--nav-rule); padding: calc(var(--nav-h) + 24px) 16px 20px;
    z-index: 60; transform: translateX(-102%); transition: transform .3s ease;
  }
  .history.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.25); z-index: 55; }
  .history-close { align-self: flex-start; }
}

@media (max-width: 1068px) {
  .hero-name { font-size: 64px; }
}

@media (max-width: 834px) {
  .app { grid-template-columns: minmax(0, 1fr); padding-top: 24px; padding-bottom: 80px; gap: 40px; }
  .preview { position: static; }
  .preview-inner { max-height: none; }
}

@media (max-width: 734px) {
  .nav-inner { gap: 14px; }
  .nav-links { gap: 18px; }
  .hero { padding-top: calc(var(--nav-h) + 48px); padding-bottom: 32px; }
  .hero-kicker { font-size: 17px; line-height: 1.47; }
  .hero-name { font-size: 48px; line-height: 1.08; }
  .hero-tagline { font-size: 21px; line-height: 1.38; margin-top: 8px; }
  .hero-sub { font-size: 17px; line-height: 1.47; }
  .field-title { font-size: 24px; line-height: 1.17; }
  .preview-inner { border-radius: 20px; }
  .preview-head { padding: 22px 20px 14px; }
  .preview-body { margin: 0 12px; }
  .preview-actions { padding: 16px 20px 6px; }
  .progress { padding: 14px 20px 22px; }
}

@media (max-width: 420px) {
  .nav-app { display: none; }
  #btn-example { display: none; }
}

/* ===================== MÓVIL: BARRA INFERIOR ===================== */
.mbar { display: none; }
.preview { scroll-margin-top: calc(var(--nav-h) + 16px); }

@media (max-width: 834px) {
  .mbar {
    display: flex; align-items: center; gap: 8px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
    background: var(--nav-bg);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--nav-rule);
    transition: transform .25s ease;
  }
  .mbar.away { transform: translateY(110%); }
  .mbar-info { margin-right: auto; font-size: 14px; letter-spacing: -0.016em; color: var(--text-2); }
  .mbar-info strong { color: var(--text); font-variant-numeric: tabular-nums; }
  footer { padding-bottom: 72px; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ===================== MÓVIL: TÁCTIL Y TAMAÑOS ===================== */
@media (max-width: 734px) {
  /* iOS hace zoom al enfocar campos con letra < 16 px */
  .search, .select-wrap.small select { font-size: 16px; }
  .hero-name { font-size: clamp(38px, 12.5vw, 48px); }
  .history-close { font-size: 17px; }
}

@media (hover: none) {
  .hitem { padding-right: 76px; }
  .hitem-actions { opacity: 1; gap: 4px; }
  .icon-btn { width: 32px; height: 32px; font-size: 16px; }
  .hide-touch { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* Crédito */
.hero-credit { margin-top: 20px; font-size: 17px; color: var(--text-2); }
.hero-credit a { color: var(--link); }

/* Aviso de cookies (Google Analytics) */
.consent {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 90;
  width: min(560px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 20px; border-radius: 18px; background: var(--pop); color: var(--text); box-shadow: var(--shadow);
  font-size: 14px; line-height: 1.43; letter-spacing: -0.016em;
}
.consent p { flex: 1 1 260px; margin: 0; color: var(--text-2); }
.consent-actions { display: flex; gap: 8px; margin-left: auto; }
@media (max-width: 834px) {
  .consent { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
