/* =======================================================
   VARIABLES BASE
======================================================= */
:root {
    --color-bg: #eef1f5;
    --color-text: #1a1a1a;

    --sidebar-bg1: #1d2939;
    --sidebar-bg2: #111a24;

    --primary: #1e88e5;
    --primary-dark: #0d6cd1;

    --table-head: #1e88e5;

    --card-bg: #ffffff;
    --modal-bg: #ffffff;
    --input-bg: #fafafa;

    --smooth: 0.3s ease;
}

/* =======================================================
   DARK MODE
======================================================= */
html.dark {
    --color-bg: #0e1217;
    --color-text: #e5e5e5;

    --sidebar-bg1: #0a0f14;
    --sidebar-bg2: #05080a;

    --primary: #7cb8ff;
    --primary-dark: #5c9de8;

    --table-head: #3d5979;

    --card-bg: #141a22;
    --modal-bg: #1b232e;
    --input-bg: #0f141a;
}

/* =======================================================
   TEMAS EXTRA
======================================================= */
html.theme-rosa   { --primary: #ff4fa3; --primary-dark: #cc2f80; --table-head: #ff4fa3; }
html.theme-dorado { --primary: #e4b34d; --primary-dark: #b4852c; --table-head: #e4b34d; }
html.theme-celeste{ --primary: #11c2ff; --primary-dark: #0096cc; --table-head: #11c2ff; }

/* =======================================================
   BASE GLOBAL
======================================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Inter", sans-serif;
}

body {
    background: var(--color-bg);
    color: var(--color-text);
    transition: background var(--smooth), color var(--smooth);
}

#app { display: flex; height: 100vh; }

/* =======================================================
   BOTÓN FLOTANTE – MÓVIL
======================================================= */
#mobile-menu-btn {
    position: fixed;
    bottom: 25px;
    right: 25px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 16px 18px;
    border-radius: 50%;
    font-size: 24px;
    box-shadow: 0 4px 14px #0006;
    cursor: pointer;
    z-index: 300;
    display: none;
}
#mobile-menu-btn:hover { transform: scale(1.08); }

@media (max-width: 900px) {
    #mobile-menu-btn { display: block; }
}

/* =======================================================
   SIDEBAR MEJORADO 🔥
======================================================= */
.sidebar {
    width: 250px;
    background: linear-gradient(180deg, var(--sidebar-bg1), var(--sidebar-bg2));
    color: white;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 12px #0002;
    border-right: 1px solid #0004;
    transition: left 0.35s ease;
    overflow-y: auto; /* Evita que el menú se salga del fondo en pantallas pequeñas */
}
.sidebar h2 { text-align: center; font-size: 24px; font-weight: 700; margin-bottom: 10px; }

.sidebar ul { 
    list-style: none; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    margin-top: 15px;
    flex-grow: 1; /* Esto es la magia que empuja elementos al fondo */
}

.sidebar li {
    padding: 12px 14px;
    background: #253445d0;
    border-radius: 10px;
    cursor: pointer;
    transition: 0.25s;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
}
.sidebar li:hover { background: var(--primary); transform: translateX(6px) scale(1.04); }

/* Clases para botones especiales del menú */
.menu-btn-crm { background: rgba(46, 204, 113, 0.1) !important; font-weight: bold; border-left: 4px solid #2ecc71; }
.menu-btn-caja { background: rgba(255,255,255,0.1) !important; font-weight: bold; border-left: 4px solid #f1c40f; }
.menu-btn-reporte { font-weight: bold; border-left: 4px solid var(--primary); }
.menu-btn-backup { background: rgba(52, 152, 219, 0.2) !important; font-weight: bold; border-left: 4px solid #3498db; }

/* Botón de cerrar sesión anclado al fondo del marco */
.menu-btn-logout {
    margin-top: auto !important; 
    margin-bottom: 10px;
    background: #e74c3c !important; 
    color: white !important; 
    font-weight: bold !important; 
    border: none !important; 
    box-shadow: 0 4px 10px rgba(231, 76, 60, 0.3);
}
.menu-btn-logout:hover { background: #c0392b !important; }

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: -260px;
        height: 100vh;
        width: 240px;
        padding-top: 40px;
        z-index: 250;
    }
    .sidebar.sidebar-open { left: 0; }
}

/* =======================================================
   CONTENIDO
======================================================= */
.content {
    flex: 1;
    padding: 30px 40px;
    overflow-y: auto;
}
@media (max-width: 900px) { .content { padding: 20px; } }

.section { display: none; }
.section.visible { display: block; }
.section h1 { font-size: 28px; margin-bottom: 18px; font-weight: 700; }

/* =======================================================
   FORMULARIOS
======================================================= */
.form-box {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 14px;
    box-shadow: 0 4px 14px #0001;
    margin-bottom: 30px;
    border: 1px solid #e3e3e3;
}
html.dark .form-box { border-color: #2c3e50; }

.form-row-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}
@media (max-width: 900px) { .form-row-grid { grid-template-columns: 1fr; } }

label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
}

input, select, textarea {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    background: var(--input-bg);
    border: 1px solid #ccc;
    font-size: 14px;
    transition: 0.2s;
}
html.dark input, html.dark select, html.dark textarea { border-color: #334155; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.2); }

/* CLASES NUEVAS PARA IMGBB */
.file-input { padding: 10px; background: #e0f2fe; border: 1px dashed var(--primary); color: var(--primary-dark); cursor: pointer; width: 100%; border-radius: 8px;}
html.dark .file-input { background: #1a2c3f; border-color: var(--primary); color: var(--primary); }

.btn-foto { background: #e0f2fe; color: #0284c7; padding: 6px 12px; border-radius: 8px; text-decoration: none; font-size: 13px; font-weight: bold; border: 1px solid #bae6fd; display: inline-block;}
.btn-foto:hover { background: #bae6fd; }
html.dark .btn-foto { background: #0c4a6e; color: #38bdf8; border-color: #0284c7; }
html.dark .btn-foto:hover { background: #075985; }

/* Botones */
.btn-primary, .btn-secondary {
    padding: 12px 20px;
    border: none;
    min-width: 150px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.25s;
    box-shadow: 0 4px 10px #0003;
}
.btn-primary {
    color: white;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}
.btn-primary:hover { transform: translateY(-2px) scale(1.03); filter: brightness(1.1); }

.btn-secondary { background: #ddd; color: #333; }
.btn-secondary:hover { background: #ccc; }
html.dark .btn-secondary { background: #334155; color: #cbd5e1; }
html.dark .btn-secondary:hover { background: #475569; }

/* =======================================================
   TABLAS
======================================================= */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    margin-top: 15px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px #0002;
}

.data-table thead { background: var(--table-head); color: white; }
.data-table th { padding: 14px 10px; font-size: 14px; font-weight: 600; }
.data-table td {
    padding: 12px 10px;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}
html.dark .data-table td { border-bottom-color: #2c3e50; }
.data-table tr:hover { background: #f1f7ff50; }
html.dark .data-table tr:hover { background: #1e293b; }

/* Botones dentro de tablas */
.data-table button {
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    color: white;
}

.btn-historial { background: #8b5cf6; }
.btn-historial:hover { background: #6d3de9; }

.btn-add { background: #1e88e5; }
.btn-add:hover { background: #0d6cd1; }

.btn-eliminar { background: #e63946; }
.btn-eliminar:hover { background: #c62828; }

.btn-abonar { background: #2ecc71; }
.btn-abonar:hover { background: #27ae60; }

.btn-editar { background: #ff9800; }
.btn-editar:hover { background: #e68900; }

/* =======================================================
   MODALES
======================================================= */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(4px);
    z-index: 90;
}
.modal-overlay.hidden { display: none; }

.modal {
    position: fixed; inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal.hidden { display: none; }

.modal-content {
    background: var(--modal-bg);
    padding: 25px;
    border-radius: 14px;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 6px 18px #0004;
    position: relative;
}

.modal-content.small { max-width: 480px; }
.modal-content.large { max-width: 1000px; }

/* Botón cerrar modal */
.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: #e74c3c;
    color: white;
    border: none;
    width: 34px;
    height: 34px;
    font-size: 20px;
    border-radius: 8px;
    cursor: pointer;
}
.modal-close:hover { background: #c0392b; transform: scale(1.1); }

/* =======================================================
   AUTOCOMPLETAR PACIENTE
======================================================= */
.paciente-sugerencias {
    background: white;
    border: 1px solid #ccc;
    border-radius: 8px;
    max-height: 160px;
    overflow-y: auto;
    padding: 5px;
    margin-top: 4px;
    position: absolute;
    width: calc(100% - 2px);
    z-index: 50;
}
html.dark .paciente-sugerencias { background: var(--input-bg); border-color: #334155; }
.paciente-sugerencias div { padding: 8px; cursor: pointer; }
.paciente-sugerencias div:hover { background: #dce9ff; }
html.dark .paciente-sugerencias div:hover { background: #1e293b; }

.hidden { display: none !important; }

/* =======================================================
   FIX BOTONES OPERA
======================================================= */
#medidas-resumen-tbody button:nth-child(1) { background: #8b5cf6 !important; }
#medidas-resumen-tbody button:nth-child(2) { background: #1e88e5 !important; }
#medidas-resumen-tbody button:nth-child(3) { background: #e63946 !important; }

#modal-medidas-tbody button {
    background: #ff9800 !important;
}
#modal-medidas-tbody button:hover {
    background: #e68900 !important;
}

/* =======================================================
   DASHBOARD
======================================================= */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.card {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 4px 12px #0001;
    border: 1px solid #e3e3e3;
}
html.dark .card { border-color: #2c3e50; }

.entregas-list { list-style: none; margin-top: 10px; padding-left: 0; }

.entregas-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 6px;
    border-bottom: 1px solid #eee;
}
html.dark .entregas-list li { border-bottom-color: #2c3e50; }

.entrega-nombre { flex: 1; font-weight: 600; }
.entrega-fecha { color: #888; margin-left: 10px; }
.entrega-total { font-weight: 600; color: var(--primary-dark); }

/* =======================================================
   REPORTE CLIENTE
======================================================= */
.reporte-cliente-header {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
}

.reporte-cliente-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
}

.data-table.mini th,
.data-table.mini td {
    padding: 6px 8px;
    font-size: 12px;
}

.data-table.mini { border-radius: 10px; }

/* =======================================================
   SELECT DE LUGAR
======================================================= */
.cuenta-lugar-select {
    padding: 6px 10px;
    border-radius: 6px !important;
    border: none !important;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

/* =======================================================
   RESPONSIVE
======================================================= */
@media (max-width: 900px) {
    .content { padding: 15px !important; }
    .form-box { padding: 15px; }

    .data-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }

    #mobile-menu-btn {
        padding: 18px;
        font-size: 26px;
    }

    .sidebar {
        width: 210px !important;
        left: -215px;
    }
}

@media (max-width: 600px) {
    .data-table th, .data-table td {
        padding: 8px 10px;
        font-size: 13px;
    }

    .btn-editar,
    .btn-abonar,
    .btn-eliminar,
    .btn-historial {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
}

/* =======================================================
   HISTORIAL MEDIDAS
======================================================= */

.item-medida {
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    margin-bottom: 18px;
    background: #fff;
}
html.dark .item-medida { background: var(--input-bg); border-color: #334155; }

.tabla-medidas {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    background: #fff;
}
html.dark .tabla-medidas { background: var(--input-bg); }

.tabla-medidas th,
.tabla-medidas td {
    border: 1px solid #ccc;
    padding: 6px;
    text-align: center;
}
html.dark .tabla-medidas th, html.dark .tabla-medidas td { border-color: #334155; }

.label-grupo {
    background: #f2f2f2;
    font-weight: bold;
}
html.dark .label-grupo { background: #1e293b; }

.label-ojo {
    font-weight: bold;
}

.extras p {
    margin: 4px 0;
}

/* =======================================================
   ESTILOS LOGIN
======================================================= */
.login-box {
    background: var(--card-bg);
    width: 100%;
    max-width: 380px;
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    text-align: center;
    border: 1px solid rgba(0,0,0,0.05);
}
html.dark .login-box { border-color: #2c3e50; }

.login-box h2 {
    color: var(--primary);
    font-size: 26px;
    margin-bottom: 20px;
    font-weight: 800;
}

.login-box input {
    width: 100%;
    padding: 14px;
    margin-bottom: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    background: var(--input-bg);
    font-size: 15px;
    transition: 0.3s;
}

.login-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(30, 136, 229, 0.1);
}

.login-box button {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    margin-top: 10px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    font-weight: 700;
    cursor: pointer;
    transition: 0.3s;
}

.login-box button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(30, 136, 229, 0.3);
}

.error-msg {
    background: #fff5f5;
    color: #e53e3e;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 20px;
    border: 1px solid #feb2b2;
    text-align: left;
    display: flex;
    align-items: center;
}
html.dark .error-msg { background: #451a1a; color: #fca5a5; border-color: #7f1d1d; }
.error-msg::before {
    content: "⚠️";
    margin-right: 8px;
}
/* =======================================================
   IMPRESIÓN TÉRMICA (TICKETS Y RECETAS 58mm)
======================================================= */
@media print {
    body.imprimiendo * { visibility: hidden; }
    body.imprimiendo #print-area, body.imprimiendo #print-area * { visibility: visible; }
    body.imprimiendo #print-area {
        position: absolute; left: 0; top: 0;
        width: 58mm; /* Ajustado para ticketeras pequeñas */
        padding: 0; margin: 0;
        font-family: 'Helvetica', 'Arial', sans-serif;
        color: black; background: white; font-size: 11px;
    }
    body.imprimiendo #print-area table.tabla-ticket { width: 100%; border-collapse: collapse; margin-bottom: 5px; }
    body.imprimiendo #print-area table.tabla-ticket th,
    body.imprimiendo #print-area table.tabla-ticket td {
        border: 1px solid black; padding: 2px; text-align: center; font-size: 10px;
    }
}