/* --- VARIABLES & TEMA --- */
:root {
    color-scheme: dark;
    --bg-color: #1c1c1e;
    /* Fondo con gradientes sutiles para que el cristal tenga algo que desenfocar */
    --bg-gradient: radial-gradient(circle at 10% 20%, rgba(0, 122, 255, 0.15) 0%, transparent 40%),
                   radial-gradient(circle at 90% 80%, rgba(255, 69, 58, 0.1) 0%, transparent 40%),
                   #1c1c1e;
    --text-color: #ffffff;
    --text-secondary: #8e8e93;
    --accent-color: #007AFF;
    
    /* Variables de cristal ajustadas */
    --glass-bg: rgba(44, 44, 46, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
    --input-bg: rgba(255, 255, 255, 0.05);
    
    --danger-color: #ff453a;
    --success-color: #32d74b;
    --card-bg: rgba(37, 37, 39, 0.5); /* Tarjeta translúcida */
    --nav-height: 65px;
    --header-height: 75px;
}

@media (prefers-color-scheme: light) {
    :root {
        color-scheme: light;
        --bg-color: #f2f2f7;
        --bg-gradient: radial-gradient(circle at 10% 20%, rgba(0, 122, 255, 0.08) 0%, transparent 40%),
                       radial-gradient(circle at 90% 80%, rgba(255, 69, 58, 0.05) 0%, transparent 40%),
                       #f2f2f7;
        --text-color: #000000;
        --text-secondary: #3c3c4399;
        
        --glass-bg: rgba(255, 255, 255, 0.7);
        --glass-border: rgba(255, 255, 255, 0.4);
        --input-bg: rgba(118, 118, 128, 0.08);
        --card-bg: rgba(255, 255, 255, 0.55);
    }
}

/* RESET & FUENTES NATIVAS */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--bg-gradient);
    background-color: var(--bg-color);
    background-attachment: fixed; /* Mantiene el fondo estático al hacer scroll */
    color: var(--text-color);
    padding-top: calc(var(--header-height) + 15px);
    /* Ajustado para el Navbar Flotante y el Safe Area de iOS */
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 40px);
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

/* --- UTILIDADES --- */
.hidden { display: none !important; }
.centered-title { text-align: center; width: 100%; font-size: 1.1rem; font-weight: 600; margin: 0; line-height: 1.2; }

/* --- GLASS HEADER & BADGE --- */
.glass-header {
    background: var(--glass-bg); 
    backdrop-filter: blur(25px); 
    -webkit-backdrop-filter: blur(25px);
    border-bottom: 0.5px solid var(--glass-border);
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    height: var(--header-height);
    display: flex; align-items: center; justify-content: center;
    padding: 0 15px;
}
.header-content { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; }
.glass-header .icon-btn { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); }

.header-badge {
    background-color: var(--accent-color);
    color: white; font-size: 11px; font-weight: 600;
    padding: 2px 10px; border-radius: 12px; margin-top: 4px;
    box-shadow: 0 2px 6px rgba(0, 122, 255, 0.3);
}

.glass-panel { 
    background: var(--glass-bg); 
    backdrop-filter: blur(25px); 
    -webkit-backdrop-filter: blur(25px); 
    border: 1px solid var(--glass-border); 
    border-radius: 18px; 
    padding: 20px; 
    box-shadow: 0 8px 32px rgba(0,0,0,0.1); 
}

/* --- INPUTS --- */
.glass-input { 
    width: 100%; display: block; appearance: none; 
    background: var(--input-bg); 
    border: 1px solid var(--glass-border); 
    border-radius: 12px; padding: 14px; 
    color: var(--text-color); font-size: 16px; 
    margin-bottom: 16px; outline: none; 
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s; 
}
.glass-input:focus { 
    border-color: var(--accent-color); 
    background: var(--glass-bg);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}
.glass-input.big-input { font-size: 18px; font-weight: 600; text-align: center; }
.input-label { display: block; margin-bottom: 4px; font-size: 0.8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 10px; }

/* --- API SEARCH BOX --- */
.api-search-container { display: flex; align-items: stretch; margin-bottom: 5px; }
.btn-api-search {
    background: var(--accent-color); color: white; border: none;
    border-radius: 0 12px 12px 0; padding: 0 15px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.btn-api-search:active { opacity: 0.8; }

/* --- BUTTONS --- */
.btn-primary { width: 100%; background: var(--accent-color); color: white; border: none; padding: 16px; border-radius: 12px; font-size: 17px; font-weight: 600; cursor: pointer; box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3); margin-bottom: 10px; }
.btn-secondary { display: block; width: 100%; background: var(--input-bg); color: var(--text-color); padding: 14px; border-radius: 12px; text-align: center; cursor: pointer; border: 1px solid var(--glass-border); font-size: 16px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.btn-text { background: none; border: none; color: var(--danger-color); font-size: 15px; margin-top: 5px; cursor: pointer; width: 100%; }
.icon-btn { background: none; border: none; color: var(--accent-color); padding: 5px; cursor: pointer; }

/* --- SEARCH --- */
.relative-wrapper { position: relative; width: 100%; margin-bottom: 10px; }
.search-icon-left { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); pointer-events: none; }
.search-input-padded { padding-left: 38px !important; padding-right: 38px !important; margin-bottom: 0 !important; }
.btn-clear { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text-secondary); padding: 8px; cursor: pointer; display: flex; align-items: center; }

/* --- FILTROS --- */
.filter-scroll { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 15px; scrollbar-width: none; -ms-overflow-style: none; }
.filter-scroll::-webkit-scrollbar { display: none; }
.filter-chip { background: var(--glass-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); color: var(--text-secondary); border: 1px solid var(--glass-border); border-radius: 20px; padding: 8px 16px; font-size: 14px; white-space: nowrap; cursor: pointer; transition: all 0.2s; }
.filter-chip.active { background: var(--accent-color); color: white; border-color: var(--accent-color); font-weight: 500; }

/* --- VISTAS --- */
.view-section { display: none; padding: 15px; opacity: 0; transition: opacity 0.2s ease-in; }
.view-section.active { display: block; opacity: 1; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* --- BOOK CARDS --- */
.book-card-container { 
    margin-bottom: 16px; 
    position: relative; 
    border-radius: 16px; 
    overflow: hidden; /* Mantiene los botones fuera si no se desliza */
    box-shadow: 0 4px 15px rgba(0,0,0,0.05); 
}

/* Swipe Actions (Reveal - FIX: Positioned Outside) */
.swipe-actions {
    position: absolute; top: 0; bottom: 0;
    left: 100%; /* FIX: Físicamente fuera de la tarjeta por la derecha */
    display: flex; align-items: stretch;
    /* FIX: Un z-index más alto que el book-card para quedar encima cuando aparezca */
    z-index: 3; 
}
.swipe-btn {
    border: none; color: white; font-weight: 600; font-size: 14px;
    padding: 0 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: filter 0.2s;
}
.swipe-btn:active { filter: brightness(0.8); }
.swipe-btn-edit { background: var(--accent-color); }
.swipe-btn-delete { background: var(--danger-color); }

.book-card { 
    background: var(--card-bg); 
    backdrop-filter: blur(15px); 
    -webkit-backdrop-filter: blur(15px);
    padding: 18px; 
    border-radius: 16px; 
    position: relative; 
    z-index: 2; /* Inferior al z-index de swipe-actions */
    transition: transform 0.1s linear; 
    border: 1px solid var(--glass-border); 
}

.book-header { display: flex; justify-content: space-between; align-items: flex-start; }
.book-title { font-size: 17px; font-weight: 600; color: var(--text-color); margin-bottom: 4px; }
.book-author { color: var(--text-secondary); font-size: 14px; }
.book-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 11px; padding: 4px 8px; background: var(--input-bg); border-radius: 6px; color: var(--text-secondary); border: 1px solid var(--glass-border); }

.progress-wrapper { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.progress-bg { flex: 1; height: 6px; background: var(--input-bg); border-radius: 10px; overflow: hidden; border: 1px solid var(--glass-border); }
.progress-fill { height: 100%; background: var(--accent-color); border-radius: 10px; transition: width 0.3s; }
.progress-text { font-size: 13px; font-weight: 500; color: var(--text-color); min-width: 60px; text-align: right; }

.notes-box { margin-top: 12px; padding: 12px; background: var(--input-bg); border-radius: 8px; font-size: 14px; line-height: 1.4; color: var(--text-secondary); display: none; font-style: italic; border: 1px solid var(--glass-border); }
.notes-box.show { display: block; }

/* --- NAV (BARRA INFERIOR FLOTANTE) --- */
.bottom-nav { 
    top: auto; 
    /* Margen dinámico para no pisar el Home Indicator de iOS */
    bottom: calc(env(safe-area-inset-bottom, 0px) + 15px); 
    left: 50%;
    right: auto;
    transform: translateX(-50%); /* Centrado perfecto */
    width: 92%;
    max-width: 400px;
    border: 1px solid var(--glass-border) !important; /* Forza un borde en todo el contorno */
    border-radius: 35px; /* Efecto Píldora */
    height: var(--nav-height); 
    justify-content: space-around; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.25); /* Sombra flotante */
}

.nav-btn { background: none; border: none; color: var(--text-secondary); display: flex; flex-direction: column; align-items: center; font-size: 10px; gap: 4px; cursor: pointer; padding: 5px 20px; transition: color 0.2s ease;}
.nav-btn.active { color: var(--accent-color); }

/* --- MODAL --- */
.modal-overlay { 
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; 
    background: rgba(0,0,0,0.4); z-index: 3000;
    display: flex; align-items: center; justify-content: center; 
    backdrop-filter: blur(8px); 
    -webkit-backdrop-filter: blur(8px);
}
.modal-content { width: 90%; max-width: 320px; position: relative; }
.modal-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.separator { height: 1px; background: var(--glass-border); margin: 5px 0; }
