/* --- 0. Video de Fondo --- */
#background-video-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -2;
    overflow: hidden;
}
#background-video {
    width: 100vw; height: 100vh;
    object-fit: cover;
}

/* Superposición oscura para legibilidad */
body::before {
    content: '';
    position: fixed; inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: -1;
}

/* --- 1. General Styles & Typography --- */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap');

:root {
    /* Paleta refinada (manteniendo nombres de variables) */
    --accent-color: #5AA7FF;       /* azul más profesional */
    --success-color: #22C55E;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;

    --background-primary: transparent;
    --background-secondary: #161B22;
    --container-bg: rgba(22, 27, 34, 0.70);
    --text-primary: #E7ECF3;
    --border-color: #2B3440;

    --bg: #0B1220; --surface: #121a2b; --text: #E7ECF3; --muted: #9BA6B2;
    --primary: #7DF9FF; --secondary: #B08CFF;

    --success:#34D399; --warning:#F59E0B; --error:#F87171;
    --radius: 16px; --shadow: 0 10px 30px rgba(0,0,0,.35);
    --space-1:8px; --space-2:12px; --space-3:16px; --space-4:24px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--background-primary);
    color: var(--text-primary);
    margin: 0;
    padding: 20px;
    line-height: 1.45; /* mejor legibilidad */
}

/* --- 2. Header & Navigation (MEJORADO) --- */
header {
    max-width: 1250px;
    margin: 0 auto 30px auto;
    padding: 18px 24px;
    border-radius: 20px;
    background: rgba(10, 20, 40, 0.65);
    backdrop-filter: blur(14px);
    box-shadow: inset 0 0 18px rgba(90,167,255,0.25),
                0 4px 24px rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.08);
    animation: fadeIn 0.8s ease-in-out;
    text-align: center;
}

h1 {
    margin-bottom: 12px;
    font-size: 2.3em;
    font-weight: 700;
    color: var(--accent-color);
    text-shadow: 0 0 14px rgba(90,167,255,0.45);
    letter-spacing: .3px;
}

.main-nav {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    padding: 8px 18px;
    border-radius: 999px;
    background: rgba(255,255,255,0.03);
    box-shadow: inset 0 0 12px rgba(90,167,255,0.15);
}

.main-nav a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 1rem;
    padding: 8px 14px;
    border-radius: 8px;
    transition: all 0.3s ease;
}
.main-nav a:hover {
    color: #fff;
    background: rgba(90,167,255,.25);
    box-shadow: 0 0 10px rgba(90,167,255,.25);
}

/* Botón de cierre de sesión actualizado */
.logout-button {
    background: linear-gradient(135deg, #EF4444, #b71c1c);
    color: #fff;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    margin-left: 10px;
    cursor: pointer;
    transition: all .25s ease;
    box-shadow: 0 4px 14px rgba(239,68,68,0.35);
}
.logout-button:hover {
    filter: brightness(1.15);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(239,68,68,0.45);
}

/* --- 3. Containers & Forms --- */
h2 {
    font-weight: 600;
    font-size: 1.35em;
    border-left: 4px solid var(--accent-color);
    padding-left: 14px;
    margin-bottom: 16px;
    line-height: 1.2;
}

.form-container, .table-container, .cotizador-container {
    background-color: var(--container-bg);
    padding: 24px 26px;
    margin: 18px auto;
    border-radius: 16px;
    box-shadow: var(--shadow);
    max-width: 1200px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    animation: slideUp 0.6s ease-out;
}

.form-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 18px;
}
.form-container h2 { grid-column: 1 / -1; }

/* ====== Controles uniformes ====== */
input, select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-family: 'Poppins', sans-serif;
    font-size: 0.98rem;
    background-color: var(--background-secondary);
    color: var(--text-primary);
    transition: all 0.25s ease;
    height: 44px;
    min-height: 44px;
    line-height: 20px;
}
input[type="date"] { padding: 10px 12px; height: 44px; min-height: 44px; }
select { height: 44px; }

input:focus, select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 6px rgba(90,167,255, 0.15);
}

input::placeholder { color: #cfd8e3b3; }
label { font-weight: 500; margin-bottom: -8px; }

#cantidad, #periodo { max-width: 340px; }
@media (min-width: 900px) {
    #cantidad, #periodo { justify-self: start; }
}

button#saveButton, button, #addItemButton, #addCategoriaButton, #addConceptoButton, #generatePdfButton {
    background: linear-gradient(135deg, #0d4bb5, #0a2c6b);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 14px 18px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform .15s ease, filter .2s ease, box-shadow .2s ease;
    box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
button#saveButton, #addCategoriaButton, #addConceptoButton { grid-column: 1 / -1; }
button:hover, #addItemButton:hover, #addCategoriaButton:hover, #addConceptoButton:hover, #generatePdfButton:hover { 
    transform: translateY(-1px); 
    filter: brightness(1.04);
}
button:disabled { background: #566; cursor: not-allowed; filter: grayscale(.2); }

/* --- 4. Tables --- */
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
th, td { padding: 14px 12px; text-align: left; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
thead th { font-weight: 600; color: var(--text-primary); background-color: rgba(90,167,255, 0.15); }
tbody tr { transition: background-color .15s ease; }
tbody tr:hover { background-color: rgba(255, 255, 255, 0.05); }

.actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}
.actions-cell.actions-wide button,
.actions-cell.actions-wide a { min-width: 140px; }

.actions-cell button, .actions-cell a {
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.25s ease;
    color: white;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(0,0,0,.30);
}
.actions-cell button:hover, .actions-cell a:hover { 
    transform: translateY(-1px); 
    filter: brightness(1.05);
}

.actions-cell .edit { background-color: var(--accent-color); }
.actions-cell .edit:hover { background-color: #3f8cf0; }

.actions-cell .status-toggle { background-color: #c07a0a; }
.actions-cell .status-toggle:hover { background-color: #a56809; }

.actions-cell .delete { background-color: #C63232; }
.actions-cell .delete:hover { background-color: #a32929; }

.actions-cell .whatsapp-btn { background-color: #25D366; }
.actions-cell .whatsapp-btn:hover { background-color: #1fb85a; }

.actions-cell .register-payment { 
    background: linear-gradient(135deg, #D4AF37, #A67C00);
    color: #111;
}
.actions-cell .register-payment:hover { filter: brightness(1.06); }

.actions-cell .view-history { background: #3A4756; }
.actions-cell .view-history:hover { background: #2f3a46; }

.status-indicator { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; }
.status-indicator.activo { background-color: var(--success-color); }
.status-indicator.inactivo { background-color: var(--danger-color); }

#totalPago { grid-column: 1 / -1; font-weight: 600; font-size: 1.1em; color: var(--success-color); }

.cotizador-form { 
    display: grid; 
    grid-template-columns: 2fr 2fr 3fr 1fr 1fr; 
    gap: 15px; 
    align-items: center; 
    margin-bottom: 20px; 
}
.radio-group { display: flex; gap: 14px; align-items: center; }

#pago-section {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 16px;
    align-items: center;
    margin-top: 8px;
}
#pago-section h2 { grid-column: 1 / -1; margin-bottom: 6px; }

#pago-section .radio-group {
    grid-column: 1 / 2;
    background: rgba(255,255,255,.03);
    border: 1px solid rgba(255,255,255,.06);
    border-radius: 12px;
    padding: 8px 10px;
}
#pago-section .radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    cursor: pointer;
    border: 1px dashed transparent;
    transition: background-color .2s ease, border-color .2s ease;
    font-weight: 600;
    line-height: 1;
}
#pago-section .radio-group input[type="radio"] { accent-color: var(--accent-color); }
#pago-section .radio-group input[type="radio"]:checked + span,
#pago-section .radio-group label:has(input[type="radio"]:checked) {
    background: rgba(90,167,255,.18);
    border-color: rgba(90,167,255,.35);
}

#pago-section label[for="inst"] { grid-column: 2 / 3; align-self: center; }
#pago-section #inst { grid-column: 2 / 3; }
#pago-section #instP { grid-column: 3 / 4; }
#pago-section #inst, #pago-section #instP { height: 44px; min-height: 44px; }

#pago-section #anualHint {
    grid-column: 4 / 5;
    justify-self: start;
    max-width: 240px;
    font-size: 0.86rem;
    line-height: 1.25;
    opacity: .85;
}

@media (max-width: 1024px) {
    #pago-section { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
    #pago-section #anualHint { grid-column: 1 / -1; }
}

@media (max-width: 768px) {
    body { padding: 10px; }
    h1 { font-size: 1.9em; }
    h2 { font-size: 1.25em; }
    
    th, td {
        padding: 10px 6px;
        font-size: 0.92em;
    }

    .form-container { grid-template-columns: 1fr; }
    .cotizador-form { grid-template-columns: 1fr; gap: 10px; }

    #pago-section { grid-template-columns: 1fr; }
    #pago-section .radio-group,
    #pago-section #inst,
    #pago-section #instP,
    #pago-section #anualHint { grid-column: 1 / -1; }

    .actions-cell {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .actions-cell button, .actions-cell a {
        text-align: center;
        width: 100%;
    }
}

/* --- 8. Estilos del Modal (Genéricos) --- */
.modal-hidden { display: none; }
.modal {
    position: fixed; z-index: 100;
    left: 0; top: 0; width: 100%; height: 100%;
    overflow: auto; background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
}
.modal-content {
    background-color: var(--background-secondary);
    margin: 10% auto; padding: 26px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 80%; max-width: 700px;
    position: relative;
    animation: slideUp 0.5s;
}
.close-button {
    color: #aeb7c4;
    float: right;
    font-size: 26px;
    font-weight: bold;
    position: absolute; top: 14px; right: 22px;
}
.close-button:hover, .close-button:focus { color: white; cursor: pointer; }

#assignedMaterialsList ul { list-style: none; padding: 0; margin-top: 10px; }
#assignedMaterialsList li {
    background-color: #2a2f36;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex; justify-content: space-between; align-items: center;
}

.modal-header {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;
}
.modal-header h2 { margin-bottom: 0; border-left: none; padding-left: 0; }
.print-button {
    background: #506079;
    color: white; border: none; border-radius: 10px;
    padding: 10px 15px; font-size: 0.92em; font-weight: 600;
    cursor: pointer; transition: filter 0.2s ease;
}
.print-button:hover { filter: brightness(1.06); }
#historyContent table { width: 100%; margin-top: 16px; border-collapse: collapse; }
#historyContent th, #historyContent td { border: 1px solid var(--border-color); padding: 8px; text-align: left; }
#historyContent th { background-color: rgba(90,167,255, 0.15); }

.login-container {
    text-align: center;
    max-width: 450px;
    margin: 10vh auto;
    padding: 38px;
    background-color: var(--container-bg);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.login-container h2 { border-left: none; padding-left: 0; text-align: center; }
.error-text { color: var(--danger-color); margin-top: 15px; min-height: 20px; }

.logout-button {
    background: var(--danger-color);
    padding: 8px 15px !important;
    font-size: 0.9em !important;
    border-radius: 8px !important;
    margin-left: 20px;
}
.logout-button:hover { background-color: #c0392b; }

.table-header {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 18px; margin-bottom: 10px;
}
#searchInput { padding: 10px 15px; max-width: 300px; }
.pagination-controls {
    display: flex; justify-content: center; gap: 8px; margin-top: 18px;
}
.page-btn {
    background: var(--background-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.25s ease;
}
.page-btn:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
}
.page-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    font-weight: bold;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

#servicesTable {
  border-collapse: separate;
  border-spacing: 0 20px;
}

#servicesTable tbody tr {
  background: rgba(20, 25, 40, 0.7);
  border-radius: 16px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.3s ease;
}
#servicesTable tbody tr:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

#servicesTable td:first-child {
  width: 30%;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 20px;
  color: #E7ECF3;
}
#servicesTable td:first-child small {
  display: block;
  margin-top: 6px;
  color: #9BA6B2;
  font-weight: 400;
}

#servicesTable td:nth-child(2) {
  width: 50%;
  vertical-align: top;
  padding: 16px 10px 16px 0;
}
#servicesTable td:nth-child(2) ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#servicesTable td:nth-child(2) li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid rgba(125, 249, 255, 0.08);
  color: #E7ECF3;
  font-size: 0.9rem;
}

#servicesTable td:nth-child(2) li button {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}
#servicesTable td:nth-child(2) li button:hover {
  filter: brightness(1.2);
  transform: translateY(-1px);
}

#servicesTable td:last-child {
  width: 20%;
  text-align: right;
  padding-right: 20px;
  vertical-align: middle;
}
#servicesTable td:last-child button {
  background: linear-gradient(135deg, #0d4bb5, #0a2c6b);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
#servicesTable td:last-child button:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

@media (max-width: 900px) {
  #servicesTable, #servicesTable tbody, #servicesTable tr, #servicesTable td {
    display: block;
    width: 100%;
  }
  #servicesTable tr {
    margin-bottom: 18px;
  }
  #servicesTable td {
    text-align: left !important;
    padding: 12px 16px;
  }
  #servicesTable td:nth-child(2) li {
    flex-wrap: wrap;
    gap: 6px;
  }
  #servicesTable td:last-child {
    text-align: left;
    padding-top: 6px;
  }
}

#serviceSearchInput {
  display: block;
  margin: 0 auto 12px auto;
  max-width: 400px;
  width: 90%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: all 0.2s ease;
  text-align: center;
}
#serviceSearchInput:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 4px rgba(90,167,255,0.18);
  outline: none;
}

.password-field { position: relative; }

.password-field input[type="password"],
.password-field input[type="text"] {
  padding-right: 44px;
}

#togglePassword {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  box-shadow: none !important;
  border-radius: 8px !important;
  color: var(--text-primary);
  opacity: .85;
}
#togglePassword:hover { opacity: 1; }
#togglePassword:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; border-radius: 8px; }
#togglePassword svg { width: 20px; height: 20px; display:block; }
