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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #f1f5f9;
    color: #0f172a;
}

/* ===== Auth (login / register) ===== */

.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
}

.auth-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 2rem;
    width: 100%;
    max-width: 360px;
}

.auth-card h1 {
    font-size: 1.4rem;
    margin-bottom: 1.25rem;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ===== Layout: grid base ===== */

body {
    display: grid;
    grid-template-areas: "header header" "aside main" "footer footer";
    grid-template-columns: 240px 1fr;
    grid-template-rows: 50px 1fr 50px;
    min-height: 100vh;
    transition: grid-template-columns 0.25s ease;
}

.app-header {
    grid-area: header;
    height: 50px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
}

.app-main {
    grid-area: main;
    overflow-y: auto;
    padding: 1.5rem;
}

.app-footer {
    grid-area: footer;
    height: 50px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    font-size: 0.85rem;
    color: #64748b;
}

/* ===== Header ===== */

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: #2563eb;
}

.header-username {
    font-size: 0.9rem;
    font-weight: 500;
    color: #334155;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #334155;
    cursor: pointer;
    text-decoration: none;
}

.icon-btn:hover {
    background: #e2e8f0;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

/* ===== Aside ===== */

.app-aside {
    grid-area: aside;
    background: #1e293b;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    padding: 1rem 0.75rem;
    gap: 1rem;
    overflow: hidden;
}

.profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.25rem 0.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.avatar {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar::after {
    content: attr(data-initial);
    font-size: 1.4rem;
    font-weight: 700;
}

.profile-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.profile-info strong {
    color: #fff;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-info small {
    color: #94a3b8;
    font-size: 0.8rem;
}

/* ===== Menú ===== */

.menu {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

.menu-label {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #64748b;
    padding: 0 0.75rem;
    margin-bottom: 0.25rem;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: none;
    border-radius: 8px;
    background: none;
    color: #cbd5e1;
    font-size: 0.95rem;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.menu-item svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.menu-item .arrow {
    width: 14px;
    height: 14px;
    margin-left: auto;
    transition: transform 0.2s ease;
}

.has-submenu > .menu-item .arrow {
    transform: rotate(0deg);
}

.has-submenu.open > .menu-item .arrow {
    transform: rotate(90deg);
}

.submenu {
    list-style: none;
    display: none;
    flex-direction: column;
    gap: 0.15rem;
    margin: 0.15rem 0 0.25rem;
    padding-left: 1.5rem;
}

.has-submenu.open .submenu {
    display: flex;
}

.submenu a {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    color: #94a3b8;
    font-size: 0.9rem;
    text-decoration: none;
}

.submenu a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.menu-logout {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0;
    padding-top: 0.85rem;
}

.menu-logout:hover {
    color: #f87171;
}

/* ===== Aside colapsado ===== */

body.aside-collapsed {
    grid-template-columns: 72px 1fr;
}

body.aside-collapsed .profile {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

body.aside-collapsed .profile-info,
body.aside-collapsed .menu-label,
body.aside-collapsed .menu-text,
body.aside-collapsed .menu-item .arrow,
body.aside-collapsed .submenu {
    display: none;
}

body.aside-collapsed .menu-item {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

/* ===== Contenido ===== */

.welcome h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.stat-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.stat-label {
    font-size: 0.8rem;
    color: #64748b;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #0f172a;
}

/* ===== Formularios auth ===== */

label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    font-weight: 500;
}

input {
    padding: 0.6rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}

input:focus {
    outline: 2px solid #2563eb;
    border-color: transparent;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    max-width: 100%;
}

textarea {
    padding: 0.6rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    min-height: 70px;
}

button,
.button {
    padding: 0.6rem 1rem;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    display: inline-block;
}

button:hover,
.button:hover {
    background: #1d4ed8;
}

.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.muted {
    color: #475569;
    font-size: 0.9rem;
}

.muted a,
.auth-card .muted a {
    color: #2563eb;
}

.auth-card .muted {
    margin-top: 1.25rem;
}

/* ===== Contenido / páginas ===== */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.page-head h1 {
    font-size: 1.4rem;
}

.table-wrap {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 0.7rem 1rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

.table thead th {
    background: #f8fafc;
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background: #f8fafc;
}

.table-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
}

.inline-form {
    display: inline;
}

.badge {
    display: inline-block;
    background: #e0e7ff;
    color: #3730a3;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    margin-right: 0.25rem;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-warning {
    background: #ffedd5;
    color: #9a3412;
}

.badge-caution {
    background: #fef9c3;
    color: #854d0e;
}

.badge-neutral {
    background: #f1f5f9;
    color: #334155;
}

.tree-branch {
    color: #94a3b8;
    margin-right: 0.25rem;
}

.small {
    font-size: 0.8rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-grid > * {
    min-width: 0;
}

@media (max-width: 640px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

.calc-preview {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.calc-preview .calc-value {
    font-size: 1.1rem;
    font-weight: 700;
}

.calc-preview .calc-label {
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-card-wide {
    max-width: 1120px;
}

.row-inactive td {
    opacity: 0.55;
}

.card-grid {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 1rem;
    align-items: start;
}

.card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem 1.25rem;
}

.card-title {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #1e3a5f;
    margin: 0 0 0.75rem;
}

.month-bar {
    background: #e2e8f0;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
    width: 100%;
}

.month-bar-fill {
    background: #1e3a5f;
    height: 100%;
    border-radius: 4px;
}

@media (max-width: 900px) {
    .card-grid {
        grid-template-columns: 1fr;
    }
}

.epp-item-row {
    display: grid;
    grid-template-columns: minmax(0, 2.2fr) 70px auto minmax(120px, 160px) minmax(0, 1.4fr) 32px;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.epp-item-row input,
.epp-item-row select {
    padding: 0.4rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    width: 100%;
    min-width: 0;
}

@media (max-width: 900px) {
    .epp-item-row {
        grid-template-columns: 1fr 1fr;
    }
}

.plan-activity-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem 1.1rem;
    margin-bottom: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.plan-activity-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.plan-activity-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #1e3a5f;
}

.plan-activity-card .pa-remove {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.filter-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.filter-form select {
    padding: 0.35rem 0.6rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.2;
    height: 36px;
    background: #fff;
    min-width: 0;
    flex: 1 1 180px;
}

.filter-form button {
    padding: 0.4rem 1.1rem;
    font-size: 0.85rem;
    height: 36px;
}

.nowrap {
    white-space: nowrap;
}

.empty-cell {
    text-align: center;
    color: #64748b;
    padding: 2rem !important;
}

.empty {
    background: #fff;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    color: #64748b;
    padding: 2rem;
    text-align: center;
}

.form-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 560px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-card label > input:not([type="checkbox"]):not([type="radio"]),
.form-card label > select,
.form-card label > textarea {
    width: 100%;
}

.form-card fieldset {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem 1rem 1rem;
}

.perm-group {
    margin-bottom: 0.75rem;
}

.perm-group:last-child {
    margin-bottom: 0;
}

.perm-group-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    margin: 0.25rem 0 0.15rem;
}

.form-card legend {
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    padding: 0 0.35rem;
}

.check {
    flex-direction: row;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.35rem 0;
    font-weight: 400;
    cursor: pointer;
}

.check input {
    margin-top: 0.2rem;
    accent-color: #2563eb;
}

.check code {
    margin-left: 0.4rem;
    font-size: 0.75rem;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn {
    display: inline-block;
    padding: 0.45rem 0.85rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
}

.btn-secondary {
    background: #fff;
    border-color: #cbd5e1;
    color: #334155;
}

.btn-secondary:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.btn-danger {
    background: #fff;
    border-color: #fecaca;
    color: #b91c1c;
}

.btn-danger:hover {
    background: #fef2f2;
}

.success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* ===== Responsive (móvil) ===== */

@media (max-width: 768px) {
    body,
    body.aside-collapsed {
        grid-template-areas: "header" "main" "footer";
        grid-template-columns: 1fr;
    }

    .app-aside {
        position: fixed;
        top: 50px;
        bottom: 0;
        left: 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 100;
    }

    body.aside-open .app-aside {
        transform: translateX(0);
    }

    .aside-backdrop {
        position: fixed;
        inset: 50px 0 0 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
    }

    .header-username {
        display: none;
    }

    .app-footer {
        font-size: 0.75rem;
        gap: 0.5rem;
    }

    .stat-grid {
        grid-template-columns: 1fr;
    }
}

.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

.chart-card {
    min-width: 0;
}

.chart-wide {
    grid-column: 1 / -1;
}

.chart-canvas {
    position: relative;
    height: 240px;
}

.quick-links {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 0.5rem;
}

.quick-links a {
    display: block;
    text-align: center;
    padding: 0.65rem 0.5rem;
    border: 1px solid #dbe3ee;
    border-radius: 8px;
    text-decoration: none;
    color: #1e3a5f;
    background: #f8fafc;
    font-size: 0.88rem;
    font-weight: 600;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.quick-links a:hover {
    background: #e8eef7;
    border-color: #1e3a5f;
}

@media (max-width: 900px) {
    .chart-grid {
        grid-template-columns: 1fr;
    }
}
