/* --- MI CONVERSOR CSS --- */
:root {
    --primary: #8462EA;
    --secondary: #1976d2;
    --tertiary: #5c34ba;
    --text: #fff;
    --muted: #888;
    --surface: rgba(21, 21, 25, 0.7);
    --surface-solid: #17171c;
    --bg: #0b0b0e;
    --border: rgb(41, 41, 50);
    --border-secondary: #ccc;
    --hover: rgba(124, 58, 237, 0.2);
    --red: #E64C4C;
    --blue: #30ABE8;
    --holiday: #02a756;
    --gradient-primary: linear-gradient(135deg, #4830c4, #8462EA);
}

.light-mode {
    --secondary: #B39DDB;
    --tertiary: #4f35e0; /* Limpiado el error previo */
    --text: #22222A;
    --muted: #6D6D78;
    --surface: #fff;
    --surface-solid: #fff;
    --bg: #f0f0f0;
    --border: #e0d7f2;
    --blue: #228EC3;
}


/* --- 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; }
/* Fuente extendida solo para el logo: material-icons.woff2 no incluye 'convert_to_text'. Alternativas con el mismo glifo (contorno): icons2.woff2 / icons_light.woff2 */
@font-face { font-family: 'Material Icons Ext'; src: url('./fonts/icons.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 5rem 0; font-size: 1rem; font-family: "Roboto", sans-serif; background: var(--bg); color: var(--text); }
.container { width: 100%; max-width: 940px; margin: 0 auto; padding: 0 15px; }

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


/* --- CABECERA --- */
.nav-grid { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 1.25rem; font-weight: 500; }
.icon-logo { font-family: 'Material Icons Ext', 'Material Icons'; color: var(--primary); font-size: 28px; }
.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; }

/* --- 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(--primary);
    font-family: 'Roboto Mono', monospace;
}
.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); }


/* =====================================================================
   CONVERSOR  (portado de Mi TV v71; colores adaptados a las variables de esta app)
   ===================================================================== */

/* Ancho cómodo para un formulario (pestañas + tarjeta) */
.converter-page { max-width: 560px; margin-left: auto; margin-right: auto; }  /* centrado (la plantilla fija .sub-nav-bar a margin 1.5rem 0) */

.converter-box {
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 28px;
}

/* --- Pestañas Codificar / Decodificar --- */
.tabs-header { display: flex; width: 100%; border-bottom: 1px solid var(--border); }
.tab-btn {
    flex: 1;
    display: flex; justify-content: center; align-items: center;
    padding: 12px 5px;
    background: none; border: none; border-bottom: 3px solid transparent;
    color: var(--muted); font: inherit; font-size: 0.95rem; font-weight: 700;
    cursor: pointer; transition: all 0.2s ease;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, transparent);
}

/* --- Selector de formato (radio MD3) --- */
.format-selector {
    display: flex; gap: 2px;
    margin-bottom: 20px; padding: 4px;
    background: color-mix(in srgb, var(--text) 4%, transparent);
    border-radius: 16px;
}
.radio-item {
    flex: 1; position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; padding: 8px 2px;
    cursor: pointer;
}
.radio-item input { display: none; }
.radio-circle {
    position: relative; flex-shrink: 0;
    width: 22px; height: 22px;
    border: 2px solid var(--muted); border-radius: 50%;
    transition: border-color 0.3s ease;
}
.radio-circle::after {
    content: "";
    position: absolute; top: 50%; left: 50%;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--primary);
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.radio-item input:checked + .radio-circle { border-color: var(--primary); }
.radio-item input:checked + .radio-circle::after { transform: translate(-50%, -50%) scale(1); }
.radio-item span {
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
    color: var(--muted); transition: color 0.3s ease;
}
.radio-item input:checked ~ span { color: var(--primary); }

/* --- Stack (grid de 2 filas: switch + contenido) --- */
.tab-stack {
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: minmax(0, 1fr);   /* minmax(0,…): evita que un Base64 largo ensanche la columna */
    gap: 8px;
    min-height: 250px;
}

/* Interruptor "Campo de texto" */
#box-mode-toggle {
    grid-row: 1; grid-column: 1;
    display: flex; align-items: center; justify-content: center;
    gap: 15px; margin-bottom: 15px;
    width: 100%;
    transition: none !important;
}
.toggle-label { font-size: 0.9rem; font-weight: 500; color: var(--text); }
.switch { position: relative; display: inline-block; 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.4s;
}
.slider:before {
    content: "";
    position: absolute; left: 3px; bottom: 3px;
    width: 18px; height: 18px; border-radius: 50%;
    background-color: #fff; transition: 0.4s;
}
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(21px); }

/* Grupos de entrada / salida */
.group-input, .group-output {
    display: flex; flex-direction: column; gap: 8px;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}
#box-kid-key, #box-text-area, #box-output {
    grid-row: 2; grid-column: 1;
    display: flex; flex-direction: column;
}
/* Estado elástico: ocupa las dos filas del grid.
   :not(.hidden) evita que display:flex !important gane a .hidden y deje visible una caja oculta
   (era lo que superponía la leyenda "Resultado" con la de la entrada) */
.full-height { grid-row: 1 / 3 !important; }
.full-height:not(.hidden) {
    display: flex !important;
    flex-direction: column;
}

.input-label {
    display: block; min-height: 1.2rem; margin-left: 12px;
    font-size: 0.8rem; color: var(--primary);
}
.label-spacing { margin-top: 10px; }

.md3-input-full, .md3-textarea-auto {
    width: 100%;
    padding: 12px; border-radius: 12px;
    background: var(--bg); color: var(--text);
    border: 2px solid transparent; outline: none;
    font-family: 'Roboto Mono', monospace; font-size: 1rem;
}
.md3-input-full { margin: 10px 0; padding: 10px; }
.md3-textarea-auto {
    flex: 1;
    max-width: 100%;
    field-sizing: content;     /* navegadores modernos */
    margin: 8px 0;
    resize: none;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.md3-input-full:focus, .md3-textarea-auto:focus { border-color: var(--primary); }

/* --- Botones --- */
.action-buttons { display: flex; gap: 8px; width: 100%; margin-top: 15px; }
.md3-btn-primary, .md3-btn-secondary {
    flex: 1;
    padding: 12px 5px;
    border: none; border-radius: 20px;
    font: inherit; font-size: 0.85rem; 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-primary:focus-visible, .md3-btn-secondary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* "Procesar" deshabilitado hasta que los datos sean válidos */
.action-buttons button:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(1); pointer-events: none; }

/* --- Globito de estado (tooltip anclado) --- */
.dynamic-tooltip {
    position: absolute; z-index: 5000;
    margin-bottom: 12px; padding: 6px 12px;
    background-color: var(--primary); color: #fff;
    border-radius: 12px;
    font-size: 0.85rem; font-weight: 700;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    animation: tooltip-pop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.dynamic-tooltip::after {
    content: "";
    position: absolute; top: 100%; left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--primary);
}
@keyframes tooltip-pop {
    from { opacity: 0; transform: translateY(10px) scale(0.8); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.dynamic-tooltip.error-tooltip {
    background-color: var(--red);
    box-shadow: 0 4px 15px color-mix(in srgb, var(--red) 40%, transparent);
    animation: tooltip-shake 0.3s ease-in-out;
}
.dynamic-tooltip.error-tooltip::after { border-top-color: var(--red); }
@keyframes tooltip-shake {
    0%, 100% { transform: translateY(0) scale(1); }
    25% { transform: translateY(0) translateX(-4px); }
    75% { transform: translateY(0) translateX(4px); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .md3-btn-primary, .md3-btn-secondary { font-size: 0.75rem; }
}
@media (min-width: 400px) {
    .radio-item { flex-direction: row; gap: 8px; }
    .radio-item span { font-size: 0.85rem; }
}
