:root {
    --brand-green: #8ac37f;
    --brand-green-soft: #eaf5e6;
    --brand-teal: #2b9bb3;
    --brand-teal-soft: #e7f6f9;
    --brand-dark: #1f3b3a;
    --brand-dark-soft: #335857;
    --text-main: #243433;
    --text-soft: #5d6c6b;
    --border-soft: #dbe7e5;
    --bg-main: #f4f7f7;
    --bg-card: #ffffff;
    --danger: #991b1b;
    --danger-bg: #fee2e2;
    --success: #166534;
    --success-bg: #dcfce7;
    --shadow-soft: 0 10px 30px rgba(31, 59, 58, 0.08);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 10px;

    --header-height: 92px;
    --header-height-mobile: 76px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: Arial, sans-serif;
    background: linear-gradient(180deg, var(--bg-main) 0%, #eef5f4 100%);
    color: var(--text-main);
    overflow-x: hidden;
}

body {
    min-height: 100vh;
}

.page-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.topbar {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    border-bottom: 1px solid var(--border-soft);
    background: rgba(255, 255, 255, 0.85);
    color: var(--brand-dark-soft);
    backdrop-filter: blur(6px);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.topbar-logo {
    width: 52px;
    height: 52px;
    object-fit: contain;
    flex-shrink: 0;
}

.topbar-brand {
    font-size: 22px;
    font-weight: 700;
    color: var(--brand-dark);
    line-height: 1.1;
}

.topbar-subbrand {
    font-size: 14px;
    color: var(--brand-dark-soft);
    margin-top: 4px;
}

/* ── Layout con sidebar ─────────────────────────────────────────── */
.layout-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
}

.sidebar {
    width: 200px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-soft);
    background: rgba(255,255,255,0.7);
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-soft);
    padding: 0 18px 10px;
}

.day-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 10px;
}

.day-nav-empty {
    font-size: 13px;
    color: var(--text-soft);
    padding: 8px;
    line-height: 1.5;
}

.day-link {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-main);
    transition: background 0.15s, color 0.15s;
    position: relative;
}

.day-link:hover {
    background: var(--brand-teal-soft);
    text-decoration: none;
}

.day-link--active,
.day-link--today {
    background: var(--brand-teal-soft);
    color: var(--brand-dark);
}

.day-link--active {
    border-left: 3px solid var(--brand-teal);
    padding-left: 9px;
}

.day-link-label {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    text-transform: capitalize;
}

.day-link-date {
    font-size: 12px;
    color: var(--text-soft);
    margin-top: 2px;
}

.day-badge-today {
    font-size: 10px;
    font-weight: 700;
    background: var(--brand-teal);
    color: #fff;
    border-radius: 999px;
    padding: 1px 7px;
    margin-top: 4px;
    align-self: flex-start;
}

/* ── Contenido principal ────────────────────────────────────────── */
.main-container {
    flex: 1;
    min-width: 0;
    padding: 24px 16px 40px;
}

.hero-card {
    background: linear-gradient(135deg, rgba(43, 155, 179, 0.08) 0%, rgba(138, 195, 127, 0.10) 100%);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 30px;
    margin-bottom: 24px;
    width: 100%;
}

.hero-card h1 {
    margin: 0 0 12px;
    font-size: 34px;
    color: var(--brand-dark);
}

.hero-card p {
    margin: 0;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-soft);
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 24px;
}

.form-card,
.table-card {
    overflow: hidden;
    width: 100%;
}

.empty-message {
    padding: 24px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--brand-dark-soft);
    background: var(--brand-teal-soft);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    margin-bottom: 18px;
}

.hidden {
    display: none;
}

.form-grid {
    display: grid;
    gap: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 700;
    color: var(--brand-dark);
}

textarea,
.file-input,
input[type="text"],
input[type="file"] {
    width: 100%;
    font-size: 15px;
}

textarea,
input[type="text"] {
    border: 1px solid #cfe0dd;
    background: #fff;
    color: var(--text-main);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    outline: none;
    transition: 0.2s ease;
}

textarea {
    min-height: 360px;
    resize: vertical;
    font-family: Arial, sans-serif;
    line-height: 1.5;
}

textarea:focus,
input[type="text"]:focus {
    border-color: var(--brand-teal);
    box-shadow: 0 0 0 4px rgba(43, 155, 179, 0.12);
}

.file-input {
    border: 1px dashed #bdd7d3;
    background: #fbfdfd;
    border-radius: var(--radius-sm);
    padding: 14px;
}

.button-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.top-actions {
    margin: 0 0 18px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 12px 18px;
    border: none;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(90deg, var(--brand-teal) 0%, var(--brand-green) 100%);
    color: #fff;
    box-shadow: 0 8px 18px rgba(43, 155, 179, 0.18);
}

.btn-secondary {
    background: #fff;
    color: var(--brand-dark);
    border: 1px solid var(--border-soft);
}

.alert {
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 18px;
    font-weight: 700;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-info {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-soft);
    padding: 20px;
}

.stat-filter {
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    transition: 0.2s ease;
}

.stat-filter:hover {
    transform: translateY(-2px);
    border-color: var(--brand-teal);
}

.stat-filter.active {
    border-color: var(--brand-teal);
    box-shadow: 0 10px 28px rgba(43, 155, 179, 0.18);
}

.stat-label {
    display: block;
    color: var(--brand-dark-soft);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.stat-value {
    display: block;
    font-size: 34px;
    font-weight: 700;
    color: var(--brand-dark);
    line-height: 1;
}

/* ── Tabla ──────────────────────────────────────────────────────── */
.table-wrap {
    width: 100%;
    overflow-x: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

thead th {
    background: #f9fbfb;
    color: var(--brand-dark);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

th, td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid #e8efee;
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

tbody tr:hover {
    background: #fcfefe;
}

/* Anchos de columna: Ref 8% | Expediente 11% | Presupuesto 10% | Asignado 12% | Resumen resto | Estado 10% */
table th:nth-child(1), table td:nth-child(1) { width: 8%; }
table th:nth-child(2), table td:nth-child(2) { width: 11%; }
table th:nth-child(3), table td:nth-child(3) { width: 10%; text-align: right; }
table th:nth-child(4), table td:nth-child(4) { width: 12%; }
table th:nth-child(5), table td:nth-child(5) { width: auto; }
table th:nth-child(6), table td:nth-child(6) { width: 10%; }

.cell-presupuesto {
    text-align: right;
    white-space: normal;
    word-wrap: break-word;
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
}

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.badge.ok {
    background: var(--success-bg);
    color: var(--success);
}

.badge.no {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-asignado {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.asignado-1 { background: #dbeafe; color: #1e40af; }   /* Manuel Torres  - azul oscuro */
.asignado-2 { background: #fce7f3; color: #9d174d; }   /* Victoria Durán - rosa        */
.asignado-3 { background: #ececec; color: #576c79; }   /* Fernando Romero - azul claro */
.asignado-4 { background: #fef3c7; color: #92400e; }   /* Antonio Merino  - amarillo   */

/* ── Footer ─────────────────────────────────────────────────────── */
.app-footer {
    margin-top: auto;
    padding: 18px 20px;
    text-align: center;
    border-top: 1px solid var(--border-soft);
    background: rgba(255, 255, 255, 0.85);
    color: var(--brand-dark-soft);
    font-size: 14px;
    backdrop-filter: blur(6px);
}

.app-footer p {
    margin: 0;
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 992px) {
    .main-container {
        padding: 20px 16px 32px;
    }

    .hero-card h1 {
        font-size: 28px;
    }

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

@media (max-width: 768px) {
    .layout-body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-soft);
        padding: 12px 0;
    }

    .day-nav {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0 12px;
        gap: 6px;
    }

    .day-link {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
    }

    .day-link--active {
        border-left: none;
        border-bottom: 2px solid var(--brand-teal);
        padding-left: 12px;
    }

    table th:nth-child(2), table td:nth-child(2) { display: none; }
    table th:nth-child(6), table td:nth-child(6) { display: none; }
}

@media (max-width: 640px) {
    .topbar {
        height: var(--header-height-mobile);
        padding: 0 16px;
    }

    .topbar-logo {
        width: 42px;
        height: 42px;
    }

    .topbar-brand {
        font-size: 18px;
    }

    .topbar-subbrand {
        font-size: 12px;
    }

    .main-container {
        padding: 16px 12px 24px;
    }

    .hero-card,
    .card,
    .stat-card {
        padding: 16px;
    }

    .hero-card h1 {
        font-size: 24px;
    }

    .hero-card p {
        font-size: 14px;
    }

    .btn {
        width: 100%;
    }

    textarea {
        min-height: 220px;
    }

    .app-footer {
        font-size: 13px;
        padding: 16px 12px;
    }
}


/* ── Enlaces dentro de la tabla ── */
table a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: rgba(0,0,0,.35);
    font-weight: 500;
}
table a:hover {
    text-decoration-color: currentColor;
    opacity: .8;
}

/* ── Filtro por asignado ─────────────────────────────────────────── */
.asignado-filter-bar {
    display: none;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: var(--brand-teal-soft);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
}

.asignado-filter-bar.visible {
    display: flex;
}

.asignado-filter-bar label {
    font-size: 13px;
    font-weight: 700;
    color: var(--brand-dark);
    white-space: nowrap;
}

.asignado-filter-bar select {
    font-size: 13px;
    font-family: inherit;
    color: var(--text-main);
    background: #fff;
    border: 1px solid #cfe0dd;
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.asignado-filter-bar select:focus {
    border-color: var(--brand-teal);
    box-shadow: 0 0 0 3px rgba(43,155,179,0.12);
}
