/* ── Variables Premium Dark Theme ── */
:root {
    --brand-dark:   #0b0f1a;
    --brand-navy:   #0d1b3e;
    --brand-blue:   #1a3566;
    --brand-gold:   #c9982a;
    --brand-gold-l: #f0c050;
    --text-primary: #e8eaf0;
    --text-muted:   #8b93a8;
    --card-bg:      rgba(255,255,255,0.03);
    --card-border:  rgba(255,255,255,0.08);
    --input-bg:     rgba(255,255,255,0.08);
    --hover-bg:     rgba(255,255,255,0.06);
}

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

body {
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    background: var(--brand-dark);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* ── Background ── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 15% 0%, rgba(26,53,102,0.5) 0%, transparent 65%),
        radial-gradient(ellipse 50% 60% at 90% 100%, rgba(201,152,42,0.12) 0%, transparent 65%);
    pointer-events: none;
    z-index: 0;
}

/* ── Topbar (De menu.html) ── */
.topbar {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 40px;
    border-bottom: 1px solid var(--card-border);
    background: rgba(13,27,62,0.4);
    backdrop-filter: blur(16px);
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}
.topbar-brand img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(201,152,42,0.35);
}
.topbar-brand span {
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--brand-gold), var(--brand-gold-l));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: 16px;
}
.user-info {
    text-align: right;
}
.user-info .user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}
.user-info .user-rol {
    font-size: 0.70rem;
    color: var(--brand-gold);
    font-weight: 500;
}
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-blue), var(--brand-navy));
    border: 2px solid rgba(201,152,42,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--brand-gold-l);
}
.btn-logout {
    padding: 7px 16px;
    border-radius: 6px;
    border: 1px solid var(--card-border);
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    text-transform: uppercase;
}
.btn-logout:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(201,152,42,0.4);
    color: var(--text-primary);
}

/* ── Contenedor Principal ── */
.main {
    position: relative;
    z-index: 1;
    max-width: 1300px;
    margin: 40px auto;
    padding: 32px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.05);
    backdrop-filter: blur(20px);
}
.form-container h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 24px;
    color: #fff;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 16px;
}

/* ── Cabecera Formulario ── */
.seccion-cabecera {
    margin-bottom: 32px;
}
.cabecera-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px 32px;
}
.field-group {
    display: flex;
    flex-direction: column;
}
.field-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.field-group label span.required {
    color: var(--brand-gold);
}

/* Inputs y Selects */
input[type="text"],
input[type="number"],
input[type="url"],
input[type="date"],
input[type="month"],
select {
    width: 100%;
    padding: 10px 14px;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.2s;
}
input:focus, select:focus {
    outline: none;
    border-color: rgba(201,152,42,0.5);
    box-shadow: 0 0 0 3px rgba(201,152,42,0.1);
}
input[readonly], select[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    background: rgba(255,255,255,0.02);
}
select option {
    background: #ffffff;
    color: #000000;
    font-size: 14px;
}

/* Input Money en la cabecera */
.input-money {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s;
    height: 38px;
}
.input-money:focus-within {
    border-color: rgba(201,152,42,0.5);
    box-shadow: 0 0 0 3px rgba(201,152,42,0.1);
}
.money-prefix {
    padding: 0 12px;
    font-size: 0.85rem;
    color: var(--brand-gold-l);
    background: rgba(201,152,42,0.1);
    border-right: 1px solid var(--card-border);
    height: 100%;
    display: flex;
    align-items: center;
}
.input-money input[type="text"] {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 14px !important;
    height: 100% !important;
}

/* ── TABLA MATRIZ ── */
.lineas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 40px;
    margin-bottom: 16px;
    border-top: 1px solid var(--card-border);
    padding-top: 24px;
}
.lineas-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}
.tabla-wrapper {
    overflow-x: auto;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    background: rgba(0,0,0,0.2);
}
.tabla-wrapper::-webkit-scrollbar {
    height: 10px;
}
.tabla-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
}

.tabla-lineas {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    min-width: 1200px;
}
.tabla-lineas th {
    background: rgba(255,255,255,0.03);
    padding: 14px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--brand-gold-l);
    border-bottom: 1px solid var(--card-border);
    white-space: nowrap;
}
.tabla-lineas td {
    padding: 10px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    vertical-align: middle;
}
.tabla-lineas tr.fila-linea:nth-child(4n - 3) td {
    background: rgba(26,53,102,0.15);
}
.tabla-lineas tr.fila-sublinea td {
    background: rgba(201,152,42,0.05); /* Ligeramente dorado para sublineas */
}

/* Evitando inputs muy pesados en la tabla pero manteniéndolos visibles */
.tabla-lineas select,
.tabla-lineas input[type="text"],
.tabla-lineas input[type="number"],
.tabla-lineas input[type="url"] {
    padding: 8px 10px;
    font-size: 0.75rem;
    height: 32px;
    width: 100%;
    min-width: 110px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 6px;
}
.tabla-lineas .input-money {
    height: 32px;
    width: 100%;
    min-width: 130px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
}
.tabla-lineas .money-prefix {
    padding: 0 8px;
    background: rgba(0, 0, 0, 0.2);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.col-num {
    text-align: center;
    color: var(--brand-gold);
    font-weight: 700;
    width: 30px;
}

/* Anchos fijos específicos heredados */
.col-kpi {
    width: 100px;
    min-width: 100px;
}
.col-cpo,
.col-restante {
    min-width: 100px;
}
.col-inversion {
    width: 130px;
    min-width: 130px;
}

/* Indicadores de Restante y Porcentaje */
.col-restante, .col-porcentaje, .col-cpo {
    text-align: right;
    font-weight: 600;
    white-space: nowrap;
    padding-right: 16px !important;
}
.restante-disponible { color: #64b5f6; }
.restante-ok         { color: #81c784; }
.restante-excedido   { color: #e57373; }
.cpo-calculado       { color: #fff; font-weight: 700; }

/* ── BOTONES ── */
.btn-agregar, .btn-eliminar, .btn-eliminar-sublinea {
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}
.btn-agregar {
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--brand-gold), #b8860b);
    color: #fff;
    border: none;
    font-size: 0.85rem;
    box-shadow: 0 4px 12px rgba(201,152,42,0.25);
}
.btn-agregar:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(201,152,42,0.4);
}
.btn-eliminar, .btn-eliminar-sublinea {
    padding: 6px 10px;
    background: rgba(229,115,115,0.1);
    color: #e57373;
    border: 1px solid rgba(229,115,115,0.2);
    font-size: 0.75rem;
}
.btn-eliminar:hover, .btn-eliminar-sublinea:hover {
    background: rgba(229,115,115,0.2);
    color: #ef9a9a;
}

/* Form Footer & Avisos */
.form-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 24px;
    gap: 16px;
}
.form-footer button[type="submit"] {
    background: #1e8e3e;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: 0 4px 12px rgba(30,142,62,0.2);
}
.form-footer button[type="submit"]:hover {
    transform: translateY(-1px);
    background: #23a047;
}
.aviso-error {
    background: rgba(229,115,115,0.1);
    color: #e57373;
    border: 1px solid rgba(229,115,115,0.3);
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 500;
}
/* Especiales Checkbox Varias Audiencias */
.tabla-lineas label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 0.70rem;
    color: var(--brand-gold-l);
    cursor: pointer;
}
.tabla-lineas label input[type="checkbox"] {
    accent-color: var(--brand-gold);
}

/* ── Button Volver (Unified Design) ── */
.page-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    background: none;
    border: none;
    padding: 8px 12px;
    transition: color 0.2s;
    cursor: pointer;
    margin-bottom: 16px;
    font-family: inherit;
    font-weight: 600;
}
.page-back:hover {
    color: var(--brand-gold-l);
}