/* --- Variables de Tema y Estilos Globales --- */
:root {
    --bg-color-dark: #121212;
    --surface-color-dark: #1e1e1e;
    --primary-color-dark: #bb86fc;
    --text-color-dark: #e0e0e0;
    --border-color-dark: #333;

    --bg-color-light: #f5f5ff;
    --surface-color-light: #ffffff;
    --primary-color-light: #007bff;
    --text-color-light: #212529;
    --border-color-light: #dee2e6;
    
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --border-radius: 8px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-color: var(--bg-color-dark);
    --surface-color: var(--surface-color-dark);
    --primary-color: var(--primary-color-dark);
    --text-color: var(--text-color-dark);
    --border-color: var(--border-color-dark);
}

[data-theme="light"] {
    --bg-color: var(--bg-color-light);
    --surface-color: var(--surface-color-light);
    --primary-color: var(--primary-color-light);
    --text-color: var(--text-color-light);
    --border-color: var(--border-color-light);
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- Cabecera y Logo --- */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--box-shadow);
}
.logo { max-height: 50px; }
h1 { font-size: 1.5rem; margin: 0; color: var(--primary-color); text-align: center; }
.theme-button { background: none; border: none; color: var(--text-color); font-size: 1.5rem; cursor: pointer; }

/* --- Contenedor Principal y Tarjetas --- */
.main-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    padding: 2rem;
}

.error-hidden { display: none; }
.error-message { display: block; background-color: #dc3545; color: white; padding: 1rem; border-radius: var(--border-radius); margin-top: 1rem; text-align: center; }

footer { text-align: center; padding: 1rem; background-color: var(--surface-color); border-top: 1px solid var(--border-color); width: 100%; margin-top: auto; }

/* --- ESTILOS PARA LAYOUT Y EL HISTORIAL --- */
.tool-layout {
    display: flex;
    flex-wrap: wrap; 
    align-items: flex-start; 
    gap: 2rem;
    width: 100%;
    max-width: 1100px; 
    justify-content: center;
}

.generator-card {
    flex: 2; 
    min-width: 450px;
    background-color: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    border: 1px solid var(--border-color);
}

.history-card {
    flex: 1; 
    min-width: 300px;
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    border: 1px solid var(--border-color);
    align-self: stretch; 
}

/* --- ESTILOS ESPECÍFICOS DEL GENERADOR --- */
.password-display-container {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 1.25rem;
    word-break: break-all;
    font-family: 'Courier New', Courier, monospace;
}
.copy-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-size: 1.5rem;
}
.copy-btn.copied { color: #28a745; }

.strength-meter-container { margin-bottom: 1.5rem; }
.strength-bar { height: 10px; width: 0%; background-color: #ccc; border-radius: 5px; transition: width 0.3s ease-in-out, background-color 0.3s ease-in-out; }
.strength-text { display: block; text-align: right; font-size: 0.9rem; margin-top: 0.25rem; font-weight: bold; transition: color 0.3s ease-in-out; }
.strength-bar.weak { width: 25%; background-color: #dc3545; }
.strength-bar.medium { width: 50%; background-color: #fd7e14; }
.strength-bar.strong { width: 75%; background-color: #ffc107; }
.strength-bar.very-strong { width: 100%; background-color: #28a745; }
.strength-text.weak { color: #dc3545; }
.strength-text.medium { color: #fd7e14; }
.strength-text.strong { color: #ffc107; }
.strength-text.very-strong { color: #28a745; }

.form-group { margin-bottom: 1.5rem; }
label { display: block; margin-bottom: 0.5rem; font-weight: bold; }

.length-slider-container .slider-wrapper { display: flex; align-items: center; gap: 1rem; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 8px; background: var(--border-color); border-radius: 5px; outline: none; opacity: 0.7; transition: opacity .2s; }
input[type="range"]:hover { opacity: 1; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 24px; height: 24px; background: var(--primary-color); cursor: pointer; border-radius: 50%; }
input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; background: var(--primary-color); cursor: pointer; border-radius: 50%; }
#length-value { font-size: 1.2rem; font-weight: bold; color: var(--primary-color); min-width: 25px; text-align: center; }

.options { 
    display: grid;
    grid-template-columns: repeat(2, 1fr); 
    gap: 1rem; 
    margin-bottom: 2rem; 
}
.option { display: flex; align-items: center; gap: 0.75rem; }
.option-full-width { grid-column: 1 / -1; }
input[type="checkbox"] { width: 1.3em; height: 1.3em; accent-color: var(--primary-color); }

.generate-button { width: 100%; padding: 0.8rem; font-size: 1.2rem; font-weight: bold; color: #fff; background-color: var(--primary-color); border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.2s; }
.generate-button:hover { opacity: 0.9; }

/* --- ESTILOS DEL HISTORIAL --- */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}
.history-header h2 { margin: 0; font-size: 1.2rem; color: var(--primary-color); }
#clear-history-button { background: transparent; border: 1px solid var(--border-color); color: var(--text-color); padding: 0.3rem 0.8rem; border-radius: 4px; cursor: pointer; font-size: 0.9rem; transition: all 0.2s ease; }
#clear-history-button:hover { background-color: #dc3545; color: white; border-color: #dc3545; }
#history-list { list-style: none; padding: 0; margin: 0; max-height: 400px; overflow-y: auto; }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 0.5rem; border-bottom: 1px solid var(--border-color); font-family: 'Courier New', Courier, monospace; word-break: break-all; }
.history-item:last-child { border-bottom: none; }
.history-password { margin-right: 1rem; }
.history-copy-btn { background: none; border: none; color: var(--text-color); cursor: pointer; font-size: 1.2rem; opacity: 0.7; transition: opacity 0.2s, color 0.2s; }
.history-copy-btn:hover { opacity: 1; color: var(--primary-color); }

/* --- ###################################################### --- */
/* --- SECCIÓN DE RESPONSIVIDAD MÓVIL (REVISADA Y CORREGIDA) --- */
/* --- ###################################################### --- */

/* Primero, la regla general para tablets o pantallas medianas */
@media (max-width: 900px) {
    .tool-layout { 
        flex-direction: column; 
        align-items: center; 
    }
    .generator-card, .history-card { 
        width: 100%; 
        max-width: 500px; 
        flex: none; 
        min-width: initial;
    }
}

/* Luego, los ajustes específicos y corregidos para celulares */
@media (max-width: 550px) {
    .main-container {
        padding: 1rem; /* Menos espacio en los bordes */
    }

    /* --- CORRECCIÓN DE LA CABECERA USANDO CSS GRID --- */
    header {
        display: grid;
        grid-template-columns: auto 1fr auto; /* Columna para el logo, columna flexible para el título, columna para el botón */
        align-items: center;
        padding: 0.75rem 1rem;
        gap: 1rem;
    }

    .logo {
        grid-column: 1 / 2; /* Logo en la primera columna */
        justify-self: start; /* Asegura que se alinee a la izquierda */
        max-height: 40px; /* Hacemos el logo un poco más pequeño */
    }

    h1 {
        grid-column: 2 / 3; /* Título en la columna central */
        font-size: 1.15rem; /* Tamaño de fuente ajustado */
        text-align: center;  /* Texto centrado dentro de su columna */
        margin: 0;
        padding: 0;
    }

    .theme-button {
        grid-column: 3 / 4; /* Botón en la tercera columna */
        justify-self: end; /* Asegura que se alinee a la derecha */
        font-size: 1.4rem;
    }
    
    .generator-card, .history-card {
        padding: 1.5rem;
    }

    .options {
        grid-template-columns: 1fr; /* Opciones en una sola columna */
    }

    .password-display-container {
        font-size: 1rem; /* Contraseña generada un poco más pequeña para que no se corte */
        flex-wrap: wrap; /* Permitir que el botón de copiar pase abajo si no hay espacio */
    }
}