/* --- MI EDITOR CSS --- */
:root {
    --primary: #3cc4cf;                 /* acento para textos/iconos (sobre fondo oscuro) */
    --primary-solid: #0e7c86;           /* color de marca */
    --text: #e8eef0;
    --muted: #8a9aa2;
    --surface: rgba(20, 27, 31, 0.82);
    --surface-solid: #141b1f;
    --bg: #0c1114;
    --border: #243038;
    --hover: rgba(60, 196, 207, 0.14);
    --red: #ee6b6b;
    --gradient-primary: linear-gradient(135deg, #0e7c86, #13939e);
}

.light-mode {
    --primary: #0e7c86;
    --text: #172025;
    --muted: #5b6d74;
    --surface: rgba(255, 255, 255, 0.86);
    --surface-solid: #fff;
    --bg: #f2f7f8;
    --border: #d5e3e6;
    --hover: rgba(14, 124, 134, 0.1);
    --red: #c93c3c;
}


/* --- LOCAL FONTS --- */
@font-face { font-family: 'Roboto'; src: url('./fonts/roboto-regular.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Roboto'; src: url('./fonts/roboto-medium.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Roboto'; src: url('./fonts/roboto-bold.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Roboto Mono'; src: url('./fonts/roboto-mono.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Material Icons'; src: url('./fonts/material-icons.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: block; }
@font-face { font-family: 'Material Icons Outlined'; src: url('./fonts/material-icons-outlined.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: block; }

/* --- ICONOS --- */
.material-icons, .material-icons-outlined { font-weight: normal; font-style: normal; font-size: 24px; line-height: 1; display: inline-block; text-transform: none; direction: ltr; -webkit-font-smoothing: antialiased; }
.material-icons { font-family: 'Material Icons'; }
.material-icons-outlined { font-family: 'Material Icons Outlined'; }

/* --- LAYOUT --- */
* { box-sizing: border-box; }
.hidden { display: none !important; }
body { margin: 0 0 6rem 0; font-size: 1rem; font-family: "Roboto", sans-serif; background: var(--bg); color: var(--text); }
.container { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 15px; }

/* --- NAV BARS --- */
.top-app-bar { position: sticky; top: 0; z-index: 100; padding: 10px 0 0; border-bottom: 1px solid var(--border); background: var(--surface); backdrop-filter: blur(12px); }

/* --- CABECERA --- */
.nav-grid { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; cursor: default; }
.brand h1 { margin: 0; font-size: 1.25rem; font-weight: 500; letter-spacing: -0.2px; }
.brand-logo { display: block; width: 32px; height: 32px; border-radius: 9px; }
.nav-actions { display: flex; align-items: center; }

.icon-button {
    display: grid; place-items: center;
    width: 42px; height: 42px;
    background: none; border: none; border-radius: 50%;
    color: var(--text); cursor: pointer;
    transition: background 0.2s ease;
}
.icon-button:hover, .icon-button:popover-open { background: var(--hover); }
.icon-button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* --- BUSCADOR + CATEGORÍAS --- */
.toolbar { padding-top: 8px; padding-bottom: 10px; }
.search-box {
    display: flex; align-items: center; gap: 10px;
    padding: 0 14px; height: 44px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 22px;
    transition: border-color 0.2s;
}
.search-box:focus-within { border-color: var(--primary); }
.search-box .material-icons { font-size: 20px; color: var(--muted); }
.search-box input {
    flex: 1; min-width: 0; height: 100%;
    background: none; border: none; outline: none;
    color: var(--text); font: inherit; font-size: 0.95rem;
}
.search-box input::placeholder { color: var(--muted); }

.chips {
    display: flex; gap: 8px; margin-top: 10px; padding-bottom: 2px;
    overflow-x: auto; scrollbar-width: none;
    scroll-snap-type: x proximity;
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
    flex: none; display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 8px 7px 14px;
    background: transparent; color: var(--text);
    border: 1px solid var(--border); border-radius: 999px;
    font: inherit; font-size: 0.82rem; font-weight: 500; white-space: nowrap;
    cursor: pointer; scroll-snap-align: start;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.chip b {
    min-width: 22px; padding: 1px 7px; border-radius: 999px;
    background: color-mix(in srgb, var(--text) 9%, transparent);
    font-size: 0.72rem; font-weight: 700; text-align: center; color: var(--muted);
}
.chip:hover { background: var(--hover); }
.chip.dim { color: var(--muted); }
.chip.active { background: var(--gradient-primary); border-color: transparent; color: #fff; }
.chip.active b { background: rgba(255, 255, 255, 0.22); color: #fff; }
.chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* --- MENÚ POPOVER --- */
#btn-menu { anchor-name: --menu-anchor; }

.menu-popup {
    /* Posición de respaldo (navegadores sin anchor positioning): esquina superior derecha */
    inset: 58px 12px auto auto;
    margin: 0;
    min-width: 230px;
    padding: 8px;
    background: var(--surface-solid);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}
@supports (position-area: bottom) {
    .menu-popup {
        inset: auto;
        position-anchor: --menu-anchor;
        position-area: bottom span-left;
        margin-top: 6px;
    }
}
.menu-popup:popover-open { display: block; animation: fadeSlide 0.2s ease; }
@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.menu-content { display: flex; flex-direction: column; gap: 2px; }
.menu-info-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 16px;
    font-size: 11px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.8px;
}
.version-tag {
    padding: 2px 8px; border-radius: 6px;
    background: color-mix(in srgb, var(--primary) 14%, transparent);
    color: var(--text);
    font-family: 'Roboto Mono', monospace;
}
/* Items de solo texto (ej. Versión): cursor normal; los .menu-item con :hover conservan el pointer */
.menu-info-item,
.menu-info-item > .menu-label,
.menu-info-item > .menu-label + .version-tag { cursor: default; }
.menu-divider, #pwa-install-section hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.menu-section-label {
    padding: 8px 16px 4px; opacity: 0.8;
    font-size: 0.7rem; font-weight: 700; color: var(--primary);
    text-transform: uppercase; letter-spacing: 1px;
}

.menu-item {
    width: 100%;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    background: transparent; border: none; border-radius: 12px;
    color: var(--text); font: inherit; font-size: 0.95rem; text-align: left;
    cursor: pointer; transition: background 0.2s;
}
.menu-item:hover { background: var(--hover); }
.menu-item .material-icons, .menu-item .material-icons-outlined { font-size: 20px; color: var(--primary); }
.menu-item.is-selected { background: color-mix(in srgb, var(--primary) 12%, transparent); font-weight: 700; }

.ios-prompt {
    display: flex; flex-direction: column; gap: 8px;
    margin: 8px; padding: 12px;
    background: var(--bg); border-left: 4px solid var(--primary); border-radius: 8px;
    font-size: 0.8rem;
}
.ios-prompt p { margin: 0; line-height: 1.4; }
.ios-prompt strong { color: var(--primary); }




/* =====================================================================
   LISTA DE ITEMS
   ===================================================================== */
.list-info { margin: 16px 4px 8px; font-size: 0.78rem; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }

.row {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 8px 10px 10px;
    background: var(--surface-solid);
    border: 1px solid var(--border); border-radius: 18px;
    transition: border-color 0.2s, background 0.2s;
    animation: fadeIn 0.25s ease;
}
.row:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.row-main { flex: 1; min-width: 0; }
.row-name { font-size: 0.98rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-name.auto { color: var(--muted); font-style: italic; font-weight: 400; }
.row-sub { margin-top: 2px; font-family: 'Roboto Mono', monospace; font-size: 0.74rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub.bad { color: var(--red); font-family: inherit; font-size: 0.78rem; font-weight: 500; }
.row-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px 2px 6px; border-radius: 999px;
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    color: var(--primary); font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
}
.badge .material-icons { font-size: 13px; }

.thumb {
    position: relative; flex: none; display: grid; place-items: center;
    width: 48px; height: 48px; overflow: hidden;
    background: var(--bg); border: 1px solid var(--border); border-radius: 14px;
}
.thumb .ph { font-size: 22px; color: var(--muted); }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; padding: 5px; object-fit: contain; }
.thumb-lg { width: 52px; height: 52px; }

.edit-btn { flex: none; color: var(--primary); }
.edit-btn:hover { background: var(--hover); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 56px 0; color: var(--muted); }
.empty .material-icons { font-size: 44px; opacity: 0.6; }
.empty p { margin: 0; font-size: 0.95rem; }

/* --- Botón flotante --- */
.fab {
    position: fixed; right: max(16px, calc((100vw - 760px) / 2 + 15px)); bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 90; display: inline-flex; align-items: center; gap: 8px;
    height: 54px; padding: 0 22px 0 16px;
    background: var(--gradient-primary); color: #fff;
    border: none; border-radius: 27px;
    font: inherit; font-size: 0.95rem; font-weight: 700;
    box-shadow: 0 6px 20px color-mix(in srgb, var(--primary-solid) 45%, transparent);
    cursor: pointer; transition: transform 0.15s ease, filter 0.2s;
}
.fab:hover { filter: brightness(1.1); }
.fab:active { transform: scale(0.96); }
.fab:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }

/* --- Toast (popover: queda por encima de los diálogos) --- */
.toast {
    position: fixed; inset: auto; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); top: auto; right: auto;
    margin: 0; border: none;
    max-width: calc(100vw - 32px); padding: 10px 18px;
    background: var(--text); color: var(--bg);
    border-radius: 14px; font-size: 0.88rem; font-weight: 500; text-align: center;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    transform: translateX(-50%);
}
.toast.error { background: var(--red); color: #fff; }
.toast:popover-open { animation: toastIn 0.2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Botones --- */
.md3-btn-primary, .md3-btn-secondary, .md3-btn-danger {
    padding: 12px 20px;
    border: none; border-radius: 20px;
    font: inherit; font-size: 0.88rem; font-weight: 700;
    text-align: center; white-space: nowrap;
    cursor: pointer; transition: all 0.2s ease;
}
.md3-btn-primary { background: var(--gradient-primary); color: #fff; }
.md3-btn-primary:hover { filter: brightness(1.1); }
.md3-btn-secondary {
    background: color-mix(in srgb, var(--text) 6%, transparent);
    color: var(--text);
    border: 1px solid var(--border);
}
.md3-btn-secondary:hover { background: var(--hover); border-color: var(--primary); }
.md3-btn-danger { background: transparent; color: var(--red); padding-left: 14px; padding-right: 14px; }
.md3-btn-danger:hover { background: color-mix(in srgb, var(--red) 12%, transparent); }
.md3-btn-danger.confirm { background: var(--red); color: #fff; }
.md3-btn-primary:focus-visible, .md3-btn-secondary:focus-visible, .md3-btn-danger:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* --- Formulario del editor --- */
.modal-content.modal-wide { width: 520px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label { margin-left: 4px; font-size: 0.82rem; font-weight: 500; color: var(--primary); }
.field code, .field > label code {
    margin-left: 4px; padding: 1px 6px; border-radius: 6px;
    background: var(--bg); color: var(--muted);
    font-family: 'Roboto Mono', monospace; font-size: 0.72rem; font-weight: 400;
}
.field .muted { color: var(--muted); font-weight: 400; }
.field .req { margin-left: 4px; font-size: 0.7rem; font-weight: 700; color: var(--red); text-transform: uppercase; letter-spacing: 0.5px; }
.hint { margin-left: 4px; font-size: 0.75rem; color: var(--muted); }
.hint:empty, .err:empty { display: none; }
.err { margin-left: 4px; font-size: 0.78rem; font-weight: 500; color: var(--red); }

.md3-input {
    width: 100%; padding: 11px 14px; border-radius: 14px;
    background: var(--bg); color: var(--text);
    border: 2px solid transparent; outline: none;
    font: inherit; font-size: 0.95rem;
    transition: border-color 0.2s;
}
.md3-input.mono { font-family: 'Roboto Mono', monospace; font-size: 0.85rem; }
textarea.md3-input { resize: vertical; min-height: 56px; }
select.md3-input { appearance: none; padding-right: 38px; cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%;
    background-size: 6px 6px; background-repeat: no-repeat; }
.md3-input:focus { border-color: var(--primary); }
.md3-input::placeholder { color: var(--muted); opacity: 0.8; }
.field:has(.err:not(:empty)) .md3-input { border-color: var(--red); }

.pair { display: flex; flex-direction: column; gap: 8px; }
.icon-line { display: flex; align-items: center; gap: 12px; }
.icon-line .md3-input { flex: 1; min-width: 0; }

.field-switch { flex-direction: row; align-items: center; justify-content: space-between; padding: 4px 4px 4px 4px; }
.field-switch .toggle-label { font-size: 0.92rem; font-weight: 500; color: var(--text); cursor: pointer; }
.switch { position: relative; display: inline-block; flex: none; width: 45px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; inset: 0;
    background-color: var(--muted);
    border-radius: 24px; cursor: pointer; transition: 0.3s;
}
.slider:before {
    content: "";
    position: absolute; left: 3px; bottom: 3px;
    width: 18px; height: 18px; border-radius: 50%;
    background-color: #fff; transition: 0.3s;
}
input:checked + .slider { background-color: var(--primary-solid); }
input:checked + .slider:before { transform: translateX(21px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary); outline-offset: 2px; }

.adv { margin: 4px 0 8px; border: 1px solid var(--border); border-radius: 16px; }
.adv > summary {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; font-size: 0.9rem; font-weight: 500; list-style: none; cursor: pointer;
}
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::after {
    content: ""; width: 8px; height: 8px;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
    transform: rotate(45deg); transition: transform 0.2s ease;
}
.adv[open] > summary { color: var(--primary); }
.adv[open] > summary::after { transform: rotate(-135deg); border-color: var(--primary); }
.adv > .field { padding: 0 16px; }
.adv > .field:last-child { margin-bottom: 16px; }
.adv > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 12px; }

.modal-footer { display: flex; align-items: center; gap: 8px; flex-shrink: 0; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.modal-footer .spacer { flex: 1; }

/* =====================================================================
   AYUDA (diálogo) — clases sugeridas: modal-content / modal-header / icon-btn / help-item
   ===================================================================== */
dialog {
    padding: 0; border: none;
    background: transparent; color: var(--text);
    overflow: visible;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); }
dialog[open] .modal-content { animation: fadeIn 0.2s ease; }
body:has(dialog[open]) { overflow: hidden; }   /* no se desplaza la página de fondo */

.modal-content {
    display: flex; flex-direction: column;
    width: 400px; max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 32px);
    padding: 24px;
    background: var(--surface-solid);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 28px;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0; margin-bottom: 20px;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; font-weight: 500; }

.icon-btn {
    display: flex; padding: 10px;
    background: transparent; border: none; border-radius: 50%;
    color: var(--text); cursor: pointer;
    transition: background 0.3s ease;
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 10%, transparent); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

#modal-help hr { margin: 15px 0; border: none; border-top: 1px solid var(--border); }

/* El contenido se desplaza dentro del cuadro; la cabecera queda fija */
.modal-body {
    flex: 1; min-height: 0;
    margin-right: -8px; padding-right: 8px;
    overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

.help-intro { margin: 0 0 16px; font-size: 0.9rem; line-height: 1.5; color: var(--muted); }
.help-intro strong { color: var(--text); }

/* Pasos numerados */
.help-steps { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; counter-reset: step; }
.help-steps li { display: flex; align-items: flex-start; gap: 12px; font-size: 0.9rem; line-height: 1.45; counter-increment: step; }
.help-steps li::before {
    content: counter(step);
    display: grid; place-items: center; flex: 0 0 24px; height: 24px;
    border-radius: 50%; background: var(--primary); color: #fff;
    font-size: 0.8rem; font-weight: 700;
}

/* Secciones desplegables */
.help-item { border-bottom: 1px solid var(--border); }
.help-item:last-child { border-bottom: none; }
.help-item summary {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 0;
    font-size: 0.95rem; font-weight: 500;
    list-style: none; cursor: pointer;
}
.help-item summary::-webkit-details-marker { display: none; }
.help-item summary::after {                       /* flecha */
    content: ""; flex-shrink: 0;
    width: 8px; height: 8px; margin-right: 4px;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
    transform: rotate(45deg); transition: transform 0.2s ease;
}
.help-item[open] > summary { color: var(--primary); }
.help-item[open] > summary::after { transform: rotate(-135deg); border-color: var(--primary); }
.help-item summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 8px; }

.help-body { padding-bottom: 14px; font-size: 0.88rem; line-height: 1.55; }
.help-body p { margin: 0 0 10px; }
.help-body p:last-child { margin-bottom: 0; }
.help-body ul { display: flex; flex-direction: column; gap: 8px; margin: 0; padding-left: 18px; }
.help-body li::marker { color: var(--primary); }
.help-body code {
    padding: 1px 6px; border-radius: 6px;
    background: var(--bg); color: var(--text);
    font-family: 'Roboto Mono', monospace; font-size: 0.85em;
    overflow-wrap: anywhere;
}
.help-ico { font-size: 1.1em; vertical-align: -4px; color: var(--primary); }


/* --- Estado de botones (guardando / error) --- */
.btn-spinner {
    display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
    border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.md3-btn-secondary .btn-spinner, .md3-btn-danger .btn-spinner { border-color: color-mix(in srgb, currentColor 30%, transparent); border-top-color: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }
.md3-btn-primary:disabled, .md3-btn-danger:disabled { cursor: progress; }
.md3-btn-primary.is-saving { filter: saturate(0.7); }
.md3-btn-primary.is-error { background: var(--red); }

/* --- Candado de edición --- */
#btn-lock { color: var(--muted); }
#btn-lock.unlocked { color: var(--primary); }
#btn-lock .material-icons { font-size: 22px; }

/* --- Editor de listas globales --- */
.lbox { display: flex; flex-direction: column; gap: 8px; }
.lrow { display: flex; align-items: center; gap: 8px; }
.lrow .md3-input { flex: 1; min-width: 0; padding-top: 9px; padding-bottom: 9px; }
.lrow .icon-btn { flex: none; color: var(--red); padding: 8px; }
.lnum { flex: none; width: 24px; text-align: right; font-family: 'Roboto Mono', monospace; font-size: 0.78rem; color: var(--muted); }
.btn-small { align-self: flex-start; padding: 8px 16px; font-size: 0.8rem; }
.adv > summary code { margin-left: 8px; padding: 1px 6px; border-radius: 6px; background: var(--bg); color: var(--muted); font-family: 'Roboto Mono', monospace; font-size: 0.72rem; font-weight: 400; }

/* --- Responsive --- */
@media (max-width: 480px) {
    .fab-text { display: none; }
    .fab { width: 56px; height: 56px; padding: 0; justify-content: center; border-radius: 28px; }
    .modal-content { padding: 18px; }
    .modal-footer .md3-btn-primary, .modal-footer .md3-btn-secondary { padding-left: 14px; padding-right: 14px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
