@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;700;800&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --ink: #2C3E63;            /* azul marino: títulos, énfasis, texto del sidebar */
    --ink-soft: #3D5480;
    --paper: #F6F9FC;          /* fondo general, celeste muy suave */
    --card: #FFFFFF;
    --border: #DCE6F2;
    --copper: #EAC23D;         /* ámbar/amarillo: acento secundario de marca (usa texto oscuro, no blanco) */
    --copper-soft: #FBF1D9;
    --copper-text: #2C3E63;    /* texto sobre fondos ámbar (reutiliza el navy para buen contraste) */
    --teal: #2C68A0;           /* azul de marca: acción primaria */
    --teal-soft: #DCEBF9;
    --success: #1D8049;        /* verde: éxito / OK — independiente de la marca */
    --success-soft: #DFF3E7;
    --success-text: #1C6B3E;
    --text: #28324A;
    --text-muted: #647290;
    --danger: #C94848;         /* rojo: error — independiente de la marca */
    --danger-soft: #FBE4E4;
    --danger-text: #A83A3A;
    --radius: 8px;
    --sidebar-bg: #E3EDF9;     /* celeste pastel */
    --sidebar-active-bg: #CFE1F5;
    --sidebar-hover-bg: #F0F5FC;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--text);
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px;
}

h1, h2, h3, h4, .brand, .nav-section-title {
    font-family: 'Manrope', sans-serif;
}

.mono, table td.num, table th.num, .amount {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    padding: 22px 0;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    border-right: 1px solid var(--border);
}

.brand {
    font-weight: 800;
    font-size: 17px;
    color: var(--ink);
    padding: 0 22px 18px 22px;
    border-bottom: 1px solid rgba(44,62,99,0.12);
    margin-bottom: 14px;
    letter-spacing: 0.2px;
}
.brand small { display:block; font-family:'Inter'; font-weight:400; font-size:11px; color: #8A6614; margin-top:3px; }

.nav-section-title {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(44,62,99,0.45);
    padding: 14px 22px 6px 22px;
    font-weight: 700;
}

.modulo-tabs-bar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    display: flex;
    gap: 4px;
}
.modulo-tab {
    font-size: 20px;
    font-weight: 700;
    padding: 12px 4px;
    margin-right: 22px;
    color: var(--text-muted);
    border-bottom: 4px solid transparent;
}
.modulo-tab:hover { color: var(--ink); text-decoration: none; }
.modulo-tab.active { color: var(--ink); font-weight: 800; border-bottom-color: var(--copper); }

.modulo-tab-grupo {
    display: flex;
    align-items: center;
    margin-right: 18px;
}
.modulo-tab-grupo .modulo-tab { margin-right: 0; }
.modulo-tab-nueva-ventana {
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.55;
    padding: 3px 5px;
    margin-left: 2px;
    border-radius: 5px;
    line-height: 1;
}
.modulo-tab-nueva-ventana:hover {
    opacity: 1;
    color: var(--copper);
    background: var(--sidebar-hover-bg);
    text-decoration: none;
}

/* Pestañas secundarias reutilizables (dentro de una página: proyecto,
   ficha del trabajador, etc.) — activa resalta con fondo ámbar suave y
   subrayado grueso, para diferenciarse claramente de las inactivas. */
.subtabs-bar {
    display: flex;
    gap: 6px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}
.subtab {
    font-size: 13px;
    font-weight: 700;
    padding: 10px 16px 9px 16px;
    color: var(--text-muted);
    border-bottom: 4px solid transparent;
    margin-bottom: -2px;
    border-radius: 6px 6px 0 0;
    background: none;
    border-left: none; border-right: none; border-top: none;
    cursor: pointer;
    font-family: inherit;
}
.subtab:hover { color: var(--ink); text-decoration: none; background: var(--sidebar-hover-bg); }
.subtab.active {
    color: var(--ink);
    background: var(--copper-soft);
    border-bottom-color: var(--copper);
}

.tab-alert-badge {
    display: inline-block;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
    vertical-align: 2px;
}

.sidebar-footer {
    font-size: 10.5px;
    color: rgba(44,62,99,0.45);
    line-height: 1.5;
    padding: 16px 22px 4px 22px;
}
.sidebar-footer b { color: rgba(44,62,99,0.65); font-weight: 700; }

.nav-link {
    display: block;
    padding: 8px 22px;
    color: rgba(44,62,99,0.78);
    font-size: 13.5px;
    border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--sidebar-hover-bg); text-decoration:none; color: var(--ink); }
.nav-link.active {
    background: var(--sidebar-active-bg);
    border-left-color: var(--copper);
    color: var(--ink);
    font-weight: 700;
}
.nav-link-sub {
    padding-left: 34px;
    font-size: 12.5px;
    color: rgba(44,62,99,0.68);
}
.nav-link-sub:before { content: "› "; color: var(--copper); }
.brand:hover { opacity: 0.85; }

.modulo-icon-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    margin: 0 10px 2px 10px;
    border-radius: 10px;
    color: rgba(44,62,99,0.78);
    font-size: 13px;
}
.modulo-icon-row:hover { background: var(--sidebar-hover-bg); text-decoration:none; color: var(--ink); }
.modulo-icon-row.active { background: var(--sidebar-active-bg); color: var(--ink); font-weight: 700; }
.modulo-icon-row .icon-badge {
    width: 27px; height: 27px; border-radius: 8px; flex-shrink: 0;
    background: var(--card); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; color: var(--ink);
}
.modulo-icon-row.active .icon-badge { background: var(--copper); border-color: var(--copper); color: var(--copper-text); }
.modulo-icon-row .tab-alert-badge { margin-left: auto; position: static; }

.rama-conectada {
    margin: 4px 10px 12px 34px;
    padding-left: 12px;
    border-left: 2px solid var(--copper);
}
.rama-conectada .nav-link, .rama-conectada .nav-link-sub {
    padding: 6px 10px;
    border-left: none;
    border-radius: 6px;
}
.rama-conectada .nav-link.active { border-left: none; }
.rama-conectada .nav-section-title { padding: 10px 10px 4px 10px; }

.main {
    margin-left: 250px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 14px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 800; color: var(--ink); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.oculto { display: none !important; }

/* Galería de fotos de avance */
.galeria-avance {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.foto-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.foto-card img { width: 100%; height: 160px; object-fit: cover; display: block; }
.foto-info { padding: 10px 12px; }
.foto-fecha { font-size: 12px; font-weight: 700; color: var(--ink); }
.foto-desc { font-size: 12.5px; color: var(--text); margin-top: 3px; }
.foto-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.foto-info form { margin-top: 8px; }
.topbar .meta { font-size: 12.5px; color: var(--text-muted); }

.content { padding: 28px 32px 60px 32px; }

/* ============================================================= MÓVIL */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--ink);
    padding: 4px 8px;
    margin-right: 6px;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 26, 46, 0.45);
    z-index: 90;
}

@media (max-width: 860px) {
    body { overflow-x: hidden; }
    .menu-toggle { display: inline-flex; align-items: center; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        z-index: 100;
        width: 78vw;
        max-width: 300px;
        box-shadow: 4px 0 24px rgba(0,0,0,0.18);
    }
    .sidebar.abierto { transform: translateX(0); }
    .sidebar-overlay.visible { display: block; }

    .main { margin-left: 0; }

    .modulo-tabs-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 12px;
        gap: 2px;
    }
    .modulo-tab { white-space: nowrap; margin-right: 14px; padding: 12px 2px; font-size: 16px; }
    .modulo-tab-grupo { margin-right: 12px; flex-shrink: 0; }

    .topbar { padding: 10px 14px; flex-wrap: wrap; row-gap: 8px; min-width: 0; }
    .topbar > div:first-child { min-width: 0; overflow: hidden; }
    .topbar h1 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .topbar-actions { gap: 8px; flex-wrap: wrap; min-width: 0; }
    .topbar .meta { font-size: 11px; white-space: normal; }
    .main, .app-shell, .content { min-width: 0; }

    .content { padding: 14px; }

    .card { padding: 14px !important; }

    .field-row { grid-template-columns: 1fr; gap: 10px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

    table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

    .galeria-avance { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
    .foto-card img { height: 120px; }

    .subtabs-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
    .subtab { white-space: nowrap; }

    .btn, .btn-sm { min-height: 38px; }
}

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

/* ---------- Cards / componentes ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 20px;
}
.card-header-row { display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; }
.card-header-row h2 { font-size: 15.5px; margin: 0; font-weight: 800; color: var(--ink); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi {
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--teal);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.kpi.copper { border-left-color: var(--copper); }
.kpi.success { border-left-color: var(--success); }
.kpi.danger { border-left-color: var(--danger); }
.kpi .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); font-weight:600; }
.kpi .value { font-family: 'JetBrains Mono', monospace; font-size: 22px; font-weight: 600; margin-top: 6px; color: var(--ink); }

/* ---------- Tablas ---------- */
table { width: 100%; border-collapse: collapse; }
table th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 700;
    padding: 9px 12px;
    border-bottom: 2px solid var(--border);
}
table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
}
table tbody tr:hover { background: #F4F8FD; }
table td.num, table th.num { text-align: right; }
table tfoot td { font-weight: 700; border-top: 2px solid var(--ink); }

.table-scroll { overflow-x: auto; }

/* ---------- Formularios ---------- */
label { display:block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #3D5480; }
input[type=text], input[type=password], input[type=date], input[type=number],
input[type=email], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13.5px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--teal-soft);
}
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; }
.help-text { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

.label-with-action { display: flex; justify-content: space-between; align-items: center; }
.label-with-action label { margin-bottom: 5px; }
.link-inline-new { font-size: 11.5px; font-weight: 600; white-space: nowrap; }

/* ---------- Botones ---------- */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    font-family: 'Inter', sans-serif;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: #234F79; }
.btn-copper { background: var(--copper); color: var(--copper-text); }
.btn-copper:hover { background: #DCB233; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #166339; }
.btn-outline { background: var(--teal-soft); border-color: var(--ink); color: var(--ink); }
.btn-outline:hover { background: #C9E0F5; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #A83A3A; }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ---------- Badges / estados ---------- */
.badge { display:inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-ok { background: var(--success-soft); color: var(--success-text); }
.badge-warn { background: var(--copper-soft); color: #8A5A11; }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-muted { background: #EAEFF6; color: var(--text-muted); }

/* ---------- Alertas ---------- */
.alert { padding: 11px 16px; border-radius: 6px; font-size: 13.5px; margin-bottom: 16px; border: 1px solid; }
.alert-ok { background: var(--success-soft); border-color: #BEE3CD; color: var(--success-text); }
.alert-error { background: var(--danger-soft); border-color: #F0C9C9; color: var(--danger-text); }

/* ---------- Login ---------- */
.login-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #CFE1F5 0%, #EAF2FB 55%, #FAFAF0 100%);
}
.login-card {
    background: var(--card);
    border-radius: 12px;
    padding: 40px 38px;
    width: 380px;
    box-shadow: 0 20px 60px rgba(44,62,99,0.18);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px 0; color: var(--ink); }
.login-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-footer { margin-top: 22px; font-size: 12px; color: var(--ink-soft); text-align: center; }
.login-footer b { color: var(--ink); }

/* ---------- utilidades ---------- */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.flex-between { display:flex; justify-content:space-between; align-items:center; }
.tag-tree-0 { font-weight: 800; color: var(--ink); }
.tag-tree-1 { padding-left: 18px; font-weight: 600; color: var(--text-muted); }
.tag-tree-2 { padding-left: 36px; }
