:root {
  --bg: #faf6f7;
  --surface: #ffffff;
  --surface-2: #fcf8f9;
  --ink: #2b2233;
  --ink-soft: #5d5663;
  --line: #eee2e6;
  --brand: #d92d5f;       /* botones y acentos: texto blanco legible (4,7:1) */
  --brand-ink: #ffffff;
  --brand-soft: #ffe1e7;
  --brand-text: #c21e50;  /* texto en color de marca sobre fondos claros y rosa */
  --logo-pink: #ff4f79;
  --focus: #2563eb;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(42, 37, 48, .06), 0 4px 16px rgba(42, 37, 48, .06);
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Fraunces', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1820; --surface: #24202a; --surface-2: #2b2632; --ink: #f1edf4; --ink-soft: #b7afbf;
    --line: #3a3442; --brand: #ff86a1; --brand-ink: #2b2233; --brand-soft: #3a2430; --brand-text: #ff9db3; --logo-pink: #ff86a1; --focus: #93c5fd;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 38px; height: 38px; display: block; }
.brand-link { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-name { font-family: 'Fredoka', var(--font); font-weight: 700; font-size: 23px; letter-spacing: -.02em; color: var(--ink); }
.brand-name b { color: var(--logo-pink); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-soft); }
.pill.ok { color: var(--ok); border-color: currentColor; }
.pill.warn { color: var(--warn); border-color: currentColor; }
.pill.soon { color: var(--brand-text); border-color: currentColor; background: var(--brand-soft); }
.ai-btn:disabled { opacity: 1; cursor: not-allowed; color: var(--ink-soft); background: var(--surface-2); border-style: dashed; }
.soon-badge { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--brand-soft); color: var(--brand-text); vertical-align: 1px; }

button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 7px 13px; background: none; }
button.primary { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.secondary { background: var(--surface); border-color: var(--line); font-weight: 500; }
button.secondary:hover, button.ghost:hover { background: var(--surface-2); }
button.ghost { color: var(--ink-soft); }
button.link { color: var(--ink-soft); text-decoration: underline; padding: 7px 4px; }
button:disabled { opacity: .55; cursor: progress; }

/* Distribución */
.layout { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border-radius: 0; padding: 12px 8px; color: var(--ink-soft); font-weight: 500; border-bottom: 2px solid transparent; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }
.tabpanel { padding: 16px; display: flex; flex-direction: column; gap: 10px; }

.field-label { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); margin: 4px 0 2px; }
.hint { font-size: 13px; color: var(--ink-soft); margin: 0; }
textarea, input[type="text"], input[type="password"], input[type="url"], select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2);
}
textarea { resize: vertical; min-height: 80px; }
#rawText { min-height: 300px; font-size: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.settings summary { cursor: pointer; color: var(--ink-soft); font-size: 14px; }
.settings[open] { display: flex; flex-direction: column; gap: 6px; }

/* Campos del panel de opciones */
.img-field { display: flex; flex-direction: column; gap: 6px; }
.img-thumb { max-width: 100%; max-height: 110px; border-radius: 6px; border: 1px solid var(--line); align-self: flex-start; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0/12px 12px; }
.warn-note { font-size: 12px; color: var(--warn); margin: 0; }
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input { flex: 1; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }

/* Colores */
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.preset { border: 1px solid var(--line); background: var(--surface); padding: 8px; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.preset[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.swatches { display: flex; height: 22px; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.swatches span { flex: 1; }
.preset small { font-size: 12px; color: var(--ink-soft); }
.preset-wrap { position: relative; display: flex; }
.preset-wrap .preset { flex: 1; }
.preset-del { position: absolute; top: 2px; right: 2px; padding: 2px 6px; font-size: 12px; color: var(--ink-soft); }
.preset-del:hover { color: var(--ink); background: var(--surface-2); }
.creator { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); margin-top: 6px; }
.creator-title { font-family: var(--display); font-size: 17px; margin: 0; }
.roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 420px) { .roles { grid-template-columns: 1fr; } }
.role { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; cursor: pointer; }
.role input[type="color"] { width: 100%; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }
.role span { display: flex; flex-direction: column; line-height: 1.25; }
.role b { font-size: 13px; }
.role small { font-size: 11px; color: var(--ink-soft); }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); padding: 7px 13px; background: var(--surface); font-weight: 500; }
.file-btn:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.extracted { display: flex; flex-direction: column; gap: 8px; }
.apply-to { align-self: flex-start; }
.ex-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.ex-swatches button { width: 38px; height: 38px; padding: 0; border-radius: 8px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.ex-swatches button:hover { box-shadow: 0 0 0 2px var(--brand); }
.warnings { margin: 0; padding: 8px 10px 8px 26px; border-radius: 8px; background: #fff7ed; color: #9a3412; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
@media (prefers-color-scheme: dark) { .warnings { background: #3a2a20; color: #fdba74; } }
.save-row input { flex: 1; min-width: 140px; }
.color-grid { margin-top: 8px; display: grid; grid-template-columns: 1fr; gap: 6px; }
.color-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.color-row input[type="color"] { width: 40px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; flex: none; }

/* Email editable */
.preview-wrap { min-width: 0; }
.preview-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border-radius: 0; padding: 5px 12px; font-size: 13px; color: var(--ink-soft); }
.seg button[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }

.stage { position: relative; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--surface); padding-bottom: 8px; min-height: 480px; }
.canvas { margin: 0 auto; max-width: 100%; transition: max-width .2s; }
.stage.mobile .canvas { max-width: 375px; }
/* El email trae sus propios estilos en línea: neutralizamos los del editor dentro */
.canvas, .canvas * { box-sizing: content-box; }
.canvas { font: 15px/1.5 Arial, sans-serif; color: #222; }
.canvas img { max-width: 100%; }
.canvas tr[data-bid] { cursor: pointer; }
.canvas tr[data-bid]:hover > td { box-shadow: inset 0 0 0 2px rgba(217, 45, 95, .35); }
.canvas tr[data-bid].sel > td { box-shadow: inset 0 0 0 2px #d92d5f; }
.canvas [data-field] { cursor: text; border-radius: 3px; min-width: 2em; }
.canvas tr.sel [data-field]:hover { outline: 1px dashed rgba(217, 45, 95, .6); outline-offset: 2px; }
.canvas [data-field]:empty::before { content: attr(data-ph); opacity: .45; font-weight: normal; font-style: italic; }
.canvas div[data-field]:empty { min-height: 1.3em; }
.canvas a[data-field]:empty, .canvas span[data-field]:empty { display: inline-block; min-width: 6em; }
.canvas [contenteditable] { outline: 2px solid #2563eb !important; outline-offset: 3px; white-space: pre-wrap; cursor: text; }
.canvas [data-pick] { cursor: pointer; }
.canvas tr.sel [data-pick]:hover { outline: 2px dashed #2563eb; outline-offset: 2px; }
.canvas-empty { font-family: var(--font); color: var(--ink-soft); text-align: center; padding: 72px 24px; }

.toolbar { position: absolute; z-index: 5; display: flex; flex-wrap: wrap; max-width: calc(100% - 12px); align-items: center; gap: 2px; padding: 3px; background: var(--ink); color: var(--bg); border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, .2); font-size: 13px; }
.toolbar button { color: inherit; padding: 5px 8px; border-radius: 6px; font-size: 14px; line-height: 1; }
.toolbar button:hover:not(:disabled) { background: rgba(255, 255, 255, .16); }
.toolbar button:disabled { opacity: .35; cursor: default; }
.toolbar .tb-type { padding: 0 8px 0 6px; font-weight: 600; opacity: .85; }
.toolbar .tb-sep { width: 1px; align-self: stretch; background: rgba(255, 255, 255, .2); margin: 2px 3px; }
.toolbar select { background: transparent; color: inherit; border: 1px solid rgba(255, 255, 255, .3); border-radius: 6px; padding: 3px 6px; font-size: 13px; width: auto; }
.toolbar select option { color: #222; }
.toolbar .tb-drag { cursor: grab; touch-action: none; }
.toolbar .tb-size { font-weight: 700; font-size: 13px; }
.toolbar .tb-fmt { font-family: Georgia, serif; font-size: 15px; min-width: 28px; }
.toolbar .tb-pct { font-size: 12px; min-width: 3.4em; opacity: .85; font-variant-numeric: tabular-nums; padding: 5px 2px; }
.fmtbar { position: absolute; z-index: 8; display: flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, .15); }
.fmtbar button { width: 32px; height: 30px; padding: 0; border-radius: 6px; font-size: 15px; color: var(--ink); font-family: Georgia, serif; }
.fmtbar button:hover { background: var(--brand-soft); color: var(--brand-text); }
.link-pop { z-index: 9; }
.insert-after { position: absolute; z-index: 5; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: var(--brand); color: var(--brand-ink); font-size: 16px; line-height: 1; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.drop-line { position: absolute; z-index: 6; height: 3px; background: #2563eb; border-radius: 2px; pointer-events: none; }

.popover { position: absolute; z-index: 7; width: min(320px, calc(100% - 24px)); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); padding: 14px; display: flex; flex-direction: column; gap: 8px; font-family: var(--font); }
.popover h3 { margin: 0; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.insert-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: min(300px, calc(100% - 24px)); }
.insert-menu button { border: 1px solid var(--line); background: var(--surface); text-align: left; padding: 8px 10px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.insert-menu button:hover { border-color: var(--brand); color: var(--brand-text); }
.insert-menu .ico { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--brand-soft); color: var(--brand-text); font-weight: 700; font-size: 13px; }
.add-end { display: flex; justify-content: center; padding: 8px 0 4px; }

/* Documento abierto (barra superior) */
.doc { display: flex; align-items: center; gap: 8px; flex: 1 1 300px; min-width: 0; }
.topbar button { white-space: nowrap; }
.icon-only { font-size: 18px; padding: 4px 10px; }
.title-input { flex: 1; min-width: 120px; max-width: 360px; border: 1px solid transparent !important; background: transparent !important; font-weight: 600; font-size: 15px; padding: 6px 8px !important; }
.title-input:hover { border-color: var(--line) !important; }
.title-input:focus { border-color: var(--line) !important; background: var(--surface-2) !important; }
.save-status { font-size: 12px; color: var(--ink-soft); white-space: nowrap; flex: none; }

/* Ventanas (Mis emails, Historial) */
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 18px; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.dlg::backdrop { background: rgba(20, 16, 24, .45); }
.dlg-wide { width: min(1100px, calc(100vw - 32px)); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.dlg-head h2 { font-family: var(--display); font-size: 22px; margin: 0; }
.dlg .row input { flex: 1; min-width: 160px; }
.email-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.email-item { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.email-item.current { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.email-main { min-width: 0; flex: 1 1 260px; }
.email-main h3 { margin: 0; font-size: 15px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.email-preview { margin: 4px 0 0; font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-date { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }
.email-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-soft); }
.chip-sent { color: var(--ok); border-color: currentColor; }
.chip-open { color: var(--brand-text); border-color: currentColor; }
.history-body { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 14px; margin-top: 12px; min-height: 0; }
@media (max-width: 760px) { .history-body { grid-template-columns: 1fr; } }
.version-list { display: flex; flex-direction: column; gap: 6px; max-height: 62vh; overflow: auto; }
.version-item { display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.version-item.active { border-color: var(--brand); background: var(--brand-soft); }
.version-label { color: var(--ink-soft); font-size: 13px; }
.version-preview { border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 62vh; overflow: auto; background: var(--surface-2); min-width: 0; }
.preview-mini { zoom: .8; pointer-events: none; }
.preview-mini, .preview-mini * { box-sizing: content-box; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 760px) { .compare { grid-template-columns: 1fr; } }
.compare h4 { margin: 0 0 6px; font-size: 13px; }
.compare pre { white-space: pre-wrap; word-break: break-word; font: 13px/1.5 var(--font); margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

/* Acceso obligatorio: mientras no hay sesión, el editor queda oculto tras la bienvenida */
body.locked .layout, body.locked .doc, body.locked .actions { visibility: hidden; }
#loginDlg.gate::backdrop { background: radial-gradient(900px 500px at 80% -10%, #ffe1e7, transparent 70%), var(--bg); }
.gate-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 4px; }
.gate-brand .brand-name { font-size: 28px; }
#loginDlg.gate h2#loginTitle { font-family: var(--display); font-size: 21px; margin: 0; text-align: center; }
#loginDlg.gate > .hint:first-of-type { text-align: center; }
.dlg a { color: var(--brand-text); }
.back-home { font-size: 13px; color: var(--ink-soft); text-align: center; margin-top: 2px; }

/* Cuentas */
button.primary-soft { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
button.primary-soft:hover { filter: brightness(.97); }
.account-btn { display: inline-flex; align-items: center; gap: 6px; }
.avatar { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); font-size: 12px; font-weight: 700; }
.dlg-narrow { width: min(440px, calc(100vw - 32px)); }
.dlg-narrow[open] { display: flex; flex-direction: column; gap: 8px; }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; font-weight: 600; }
.google-btn span { font-weight: 800; color: #4285f4; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); font-size: 12px; margin: 6px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.login-form { display: flex; flex-direction: column; gap: 4px; }
.login-form .row { margin-top: 8px; }
.login-links { justify-content: space-between; }
.login-links .link { font-size: 13px; padding: 4px 0; }
.login-msg { margin: 0; font-size: 13px; color: #b42318; min-height: 1em; }
.login-msg.ok { color: var(--ok); }
.acc { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 4px 0 8px; font-size: 14px; }
.acc dt { color: var(--ink-soft); }
.acc dd { margin: 0; }
.acc-actions { display: flex; flex-direction: column; gap: 8px; }
button.danger { color: #b42318; border: 1px solid #f3c1bd; background: var(--surface); }
button.danger:hover { background: #fdecea; }

.toast { position: fixed; inset: auto auto 20px 50%; margin: 0; border: 0; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: calc(100% - 32px); z-index: 50; font-size: 14px; }

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