:root {
    --primary: #672178;
    --accent: #3498db;
    --bg: #f8f9fa;
    --card: #ffffff;
    --text: #2d3436;
    --text-light: #636e72;
    --border: #dfe6e9;
    --danger: #d63031;
    --success: #00b894;
    --shadow: 0 4px 20px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
    --bg: #121212;
    --card: #1e1e1e;
    --text: #f5f6fa;
    --text-light: #a4b0be;
    --border: #2f3542;
    --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; font-family: 'Nunito', sans-serif; }

body { margin: 0; background: var(--bg); color: var(--text); transition: background 0.3s; overflow-x: hidden; overscroll-behavior-y: none; }
body[data-text-size="small"] { --text-scale: 0.85; }
body[data-text-size="normal"] { --text-scale: 1; }
body[data-text-size="large"] { --text-scale: 1.2; }

/* --- Entry --- */
#entry-screen { position: fixed; inset: 0; background: var(--primary); z-index: 9999; display: flex; align-items: center; justify-content: center; text-align: center; }
.logo-text { color: white; font-size: 2.8rem; font-weight: 800; margin-bottom: 30px; }
.logo-text span { font-weight: 400; opacity: 0.7; }
#enter-app-btn { background: white; color: var(--primary); border: none; padding: 16px 40px; border-radius: 40px; font-weight: 800; font-size: 1.1rem; cursor: pointer; box-shadow: 0 10px 25px rgba(0,0,0,0.2); }

/* --- Header --- */
header { position: fixed; top: 0; left: 0; right: 0; height: 65px; background: var(--card); display: flex; align-items: center; padding: 0 15px; z-index: 1000; box-shadow: var(--shadow); }
.header-title { flex: 1; text-align: center; font-weight: 800; color: var(--primary); font-size: 1.1rem; }
.header-icon { background: none; border: none; font-size: 1.6rem; color: var(--text); cursor: pointer; width: 45px; }

/* --- Sidebar --- */
#side-menu { position: fixed; top: 0; left: 0; width: 300px; height: 100%; background: var(--card); z-index: 2001; transform: translateX(-100%); transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1); display: flex; flex-direction: column; }
#side-menu.open { transform: translateX(0); }
#menu-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 2000; display: none; backdrop-filter: blur(2px); }
#menu-overlay.show { display: block; }

.menu-header { padding: 40px 20px 20px; border-bottom: 1px solid var(--border); }
.menu-content { padding: 15px; flex: 1; overflow-y: auto; }
.menu-btn { width: 100%; padding: 14px; border: none; background: none; text-align: left; font-size: calc(1rem * var(--text-scale, 1)); color: var(--text); display: flex; align-items: center; gap: 12px; border-radius: 12px; cursor: pointer; font-weight: 600; margin-bottom: 5px;}
.menu-btn:active { background: var(--bg); }
.undo-highlight { background: rgba(0, 184, 148, 0.1); color: var(--success); border: 1px solid var(--success); margin-bottom: 15px; }

.accordion { margin-top: 5px; }
.accordion-header { width: 100%; padding: 14px; border: none; background: none; display: flex; justify-content: space-between; align-items: center; cursor: pointer; font-weight: 700; color: var(--text); font-size: 1rem; }
.accordion-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out; background: var(--bg); border-radius: 12px; }
.accordion-body.show { max-height: 300px; padding: 5px 0; }
.sub-item { padding-left: 30px; font-size: 0.9rem; }

/* --- Layout & Search --- */
.app-container { max-width: 650px; margin: 0 auto; padding: 85px 15px 100px; }
.search-wrapper { position: relative; margin-bottom: 20px; }
.search-wrapper input { width: 100%; padding: 14px 15px 14px 45px; border-radius: 15px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 1rem; outline: none; box-shadow: var(--shadow); }
.search-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); opacity: 0.5; }

/* --- Tabs --- */
.tabs-container { display: flex; overflow-x: auto; gap: 10px; padding-bottom: 15px; scrollbar-width: none; -ms-overflow-style: none; }
.tabs-container::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; padding: 10px 20px; background: var(--card); border-radius: 25px; border: 1px solid var(--border); font-weight: 700; font-size: calc(0.85rem * var(--text-scale, 1)); color: var(--text-light); transition: 0.3s; cursor: pointer; }
.tab.active { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 5px 15px rgba(103, 33, 120, 0.3); }

/* --- Contact Cards --- */
.contact-list { list-style: none; padding: 0; margin: 0; }
.contact-card { background: var(--card); border-radius: 18px; padding: 15px; margin-bottom: 12px; display: flex; flex-direction: column; align-items: flex-start; box-shadow: var(--shadow); border: 2px solid transparent; transition: 0.2s; position: relative; cursor: pointer;}
.contact-card.selected { border-color: var(--accent); background: rgba(52, 152, 219, 0.05); }
.contact-card.dragging { opacity: 0.5; transform: scale(0.98); }

.contact-card-header { display: flex; align-items: center; width: 100%; }
.drag-handle { color: var(--text-light); font-size: 1.2rem; margin-right: 10px; opacity: 0.5; display: none; cursor: grab;}
.contact-card.draggable .drag-handle { display: block; }

.contact-avatar { width: 45px; height: 45px; border-radius: 50%; background: var(--accent); color: white; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.1rem; margin-right: 15px; flex-shrink: 0; }
.contact-info { flex: 1; min-width: 0; width: calc(100% - 60px); }
.contact-name { font-weight: 800; font-size: calc(1.05rem * var(--text-scale, 1)); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-sub { font-size: calc(0.8rem * var(--text-scale, 1)); color: var(--text-light); margin-top: 3px; line-height: 1.3; }

.card-actions { display: flex; gap: 10px; width: 100%; justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px;}

/* Configuración de tamaño de texto */
.text-size-wrapper { padding: 5px 15px 15px 42px; }
.text-size-controls { display: flex; gap: 5px; background: var(--bg); padding: 5px; border-radius: 10px; border: 1px solid var(--border); }
.btn-text-size { flex: 1; border: none; background: transparent; color: var(--text); padding: 8px; border-radius: 8px; font-weight: 700; cursor: pointer; transition: 0.2s; font-family: 'Nunito', sans-serif;}
.btn-text-size.active { background: var(--primary); color: white; box-shadow: 0 2px 5px rgba(0,0,0,0.2);}
.btn-round { background: var(--bg); border: none; width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-light); font-size: 1.1rem; transition: 0.2s; z-index: 2;}
.btn-round.fav.active { color: #f1c40f; }

/* --- Selection Bar --- */
#selection-bar { position: fixed; bottom: 25px; left: 15px; right: 15px; background: #2d3436; color: white; padding: 15px; border-radius: 20px; display: none; flex-direction: column; gap: 12px; z-index: 1500; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.selection-info { display: flex; justify-content: space-between; align-items: center; font-weight: bold;}
.selection-actions { display: flex; gap: 10px; }
#btn-select-all { background: none; border: 1px solid white; color: white; padding: 5px 12px; border-radius: 15px; font-size: 0.8rem; cursor: pointer;}
.btn-action-primary { background: var(--accent); border: none; color: white; padding: 12px; border-radius: 12px; flex: 1; font-weight: 700; cursor: pointer;}
.btn-danger-outline { background: transparent; border: 1px solid var(--danger); color: #ff7675; padding: 12px; border-radius: 12px; flex: 1; font-weight: 700; cursor: pointer;}
.btn-cancel { background: #636e72; border: none; color: white; padding: 12px 18px; border-radius: 12px; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center;}

/* --- Modals & Forms --- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: none; align-items: center; justify-content: center; z-index: 3000; padding: 20px; backdrop-filter: blur(5px); }
.modal.active { display: flex; }
.modal-content { background: var(--card); width: 100%; max-width: 450px; border-radius: 24px; padding: 30px; position: relative; animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); max-height: 90vh; overflow-y: auto;}
@keyframes modalPop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.85rem; color: var(--text-light); }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 12px 15px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1rem; }

/* Dynamic Phones */
.btn-sm-add { background: var(--success); color: white; border: none; padding: 5px 12px; border-radius: 10px; font-size: 0.8rem; font-weight: bold; cursor: pointer; box-shadow: 0 2px 5px rgba(0,184,148,0.3);}
.phone-row { display: flex; gap: 8px; margin-bottom: 8px; }
.phone-row input { flex: 1; margin: 0; }
.btn-remove-phone { background: var(--danger); color: white; border: none; border-radius: 12px; width: 45px; font-weight: bold; font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center;}

.modal-buttons { display: flex; gap: 12px; margin-top: 25px; }
.btn-primary { background: var(--primary); color: white; border: none; padding: 14px; border-radius: 14px; font-weight: 800; flex: 1; cursor: pointer; }
.btn-ghost { background: var(--border); color: var(--text); border: none; padding: 14px; border-radius: 14px; font-weight: 800; flex: 1; cursor: pointer; }

/* --- Diseño Moderno Cargos Modal --- */
.add-cargo-modern { display: flex; gap: 10px; margin-bottom: 20px; }
.add-cargo-modern input { flex: 1; border: 1px solid var(--border); border-radius: 12px; padding: 12px 15px; background: var(--bg); color: var(--text); font-size: 1rem;}
.add-cargo-modern button { width: 45px; background: var(--primary); color: white; border: none; border-radius: 12px; font-size: 1.5rem; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 10px rgba(103,33,120,0.3);}
.cargos-list-modern { max-height: 250px; overflow-y: auto; padding-right: 5px;}
.cargo-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 15px; background: var(--bg); margin-bottom: 8px; border-radius: 12px; border: 1px solid var(--border); transition: 0.2s;}
.cargo-item span { font-weight: 700; color: var(--text); }
.cargo-item button { color: var(--danger); background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: 5px; border-radius: 50%; display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; transition: 0.2s;}

/* --- FAB --- */
#fab { position: fixed; bottom: 30px; right: 25px; width: 65px; height: 65px; border-radius: 50%; background: var(--primary); color: white; border: none; font-size: 2rem; box-shadow: 0 8px 25px rgba(103, 33, 120, 0.4); z-index: 900; cursor: pointer; transition: 0.2s; }
#fab:active { transform: scale(0.9); }

/* --- Utils --- */
.hidden { display: none !important; }
#toast { position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%); background: #2d3436; color: white; padding: 12px 25px; border-radius: 30px; font-size: 0.9rem; opacity: 0; transition: 0.3s; z-index: 4000; pointer-events: none; }
#toast.show { opacity: 1; }
.badge { background: var(--primary); color: white; padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; margin-left: 5px; vertical-align: middle; }

/* --- Phone Selection Modal --- */
.btn-phone-option {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 12px;
    font-size: calc(1.1rem * var(--text-scale, 1));
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
    text-align: left;
}
.btn-phone-option:active {
    background: var(--border);
}
.btn-phone-option span.tag {
    font-size: 0.75rem;
    background: var(--primary);
    color: white;
    padding: 4px 8px;
    border-radius: 8px;
    font-weight: 800;
}