/* ── Ampergy Presupuestos — Estilos principales ── */

:root {
    --navy:      #0a1c3a;
    --navy-light:#1a2d4d;
    --gold:      #efb328;
    --gold-dark: #d49e20;
    --blue:      #4f8cff;
    --blue-dim:  #3865b0;
    --blue-table:#1c3a63;
    --blue-row:  #17243f;
    --green:     #17c964;
    --green-dark:#0fa651;
    --orange:    #ff8a3d;
    --yellow:    #ffd600;
    --red:       #f0554d;
    /* Fondo/superficies: azul-noche muy oscuro (no negro puro), a tono con el azul
       de marca de Ampergy en vez de un gris genérico. */
    --bg:        #0a1220;
    --bg-elevated:#0d1a2e;
    --surface:   #111f36;
    --surface-2: #16283f;
    --border:    #243453;
    --text:      #e7ecf5;
    --text-muted:#8b9ab3;
    --radius:    8px;
    --shadow:    0 4px 16px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.3);
    --sidenav-w: 232px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(1100px 620px at 18% -8%, rgba(79,140,255,.16), transparent 60%),
        radial-gradient(700px 500px at 100% 0%, rgba(239,179,40,.07), transparent 55%);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
}

/* ── LAYOUT ── */
.app-header {
    background: var(--navy);
    color: #fff;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.app-header img { height: 36px; }
.app-header h1 {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: .02em;
}

.app-nav {
    margin-left: auto;
    display: flex;
    gap: 4px;
}

.app-nav button {
    background: transparent;
    color: rgba(255,255,255,.7);
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .9rem;
    font-weight: 500;
    transition: all .15s;
}
.app-nav button:hover { background: rgba(255,255,255,.1); color: #fff; }
.app-nav button.active { background: var(--gold); color: var(--navy); font-weight: 600; }

.app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ── SHELL: sidebar izquierdo de submenú + contenido ── */
.app-shell {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - 56px);
}
.app-sidebar {
    width: 210px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-height: calc(100vh - 56px);
    position: sticky;
    top: 56px;
}
.app-sidebar button {
    text-align: left;
    background: transparent;
    border: none;
    padding: 10px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .9rem;
    font-weight: 500;
    color: var(--text);
    transition: all .15s;
}
.app-sidebar button:hover { background: var(--surface-2); }
.app-sidebar button.active { background: var(--blue); color: #fff; font-weight: 600; }
.app-shell .app-main { flex: 1; margin: 0; max-width: none; }

/* ══════════════════ MENÚ LATERAL ÚNICO (escritorio) ══════════════════
   Construido por sidenav.js con el árbol completo (CRM/Presupuestos/
   Contabilidad/Usuarios + sus sub-vistas), a partir de las imágenes de
   referencia que pidió Alex. Sustituye visualmente, solo en escritorio, a la
   antigua cabecera (.app-nav) + submenú por página (.app-sidebar) -- esos dos
   se mantienen ocultos pero presentes en el DOM porque auth-guard.js y
   mobile.js siguen dependiendo de ellos (permisos / barra inferior móvil). */
body.has-sidenav:not(.view-mobile) .app-header,
body.has-sidenav:not(.view-mobile) .app-sidebar { display: none; }
body.has-sidenav:not(.view-mobile) .app-shell { min-height: 100vh; margin-left: var(--sidenav-w); }
/* Páginas sin .app-shell (p.ej. usuarios.html, .app-main suelto): el margen va
   directo en .app-main; dentro de .app-shell ya lo lleva el propio shell, así
   que ahí se resetea a 0 para no sumar el margen dos veces. */
body.has-sidenav:not(.view-mobile) .app-main { margin-left: var(--sidenav-w); max-width: none; }
body.has-sidenav:not(.view-mobile) .app-shell .app-main { margin-left: 0; }

.sidenav {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidenav-w);
    background: linear-gradient(185deg, var(--bg-elevated), #0a1526 88%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 120;
}
/* En móvil se sigue usando el patrón antiguo (bottom-nav + .app-sidebar en
   fila, ver mobile.js y las reglas body.view-mobile de más abajo). */
body.view-mobile .sidenav { display: none; }
.sidenav-brand {
    padding: 18px 18px 14px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}
.sidenav-brand img { height: 26px; display: block; }
.sidenav-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 10px 10px 6px;
}
.sidenav-scroll::-webkit-scrollbar { width: 6px; }
.sidenav-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }

.sidenav-group { margin-bottom: 4px; }
.sidenav-group-title {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px 6px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.sidenav-group-title .sn-icon { width: 13px; height: 13px; opacity: .7; }
.sidenav-group-actual .sidenav-group-title { color: var(--gold); }
.sidenav-group-actual .sidenav-group-title .sn-icon { opacity: 1; color: var(--gold); }

.sidenav-items { display: flex; flex-direction: column; gap: 1px; }
.sidenav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    border-radius: 7px;
    padding: 7px 10px 7px 14px;
    margin-left: 6px;
    color: var(--text-muted);
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .12s, color .12s;
    position: relative;
}
.sidenav-item .sn-icon { width: 15px; height: 15px; flex-shrink: 0; opacity: .85; }
.sidenav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidenav-item:hover { background: rgba(255,255,255,.05); color: var(--text); }
.sidenav-item.active {
    background: linear-gradient(90deg, rgba(79,140,255,.22), rgba(79,140,255,.07));
    color: #fff;
    font-weight: 600;
}
.sidenav-item.active::before {
    content: '';
    position: absolute;
    left: -6px; top: 4px; bottom: 4px;
    width: 3px;
    border-radius: 3px;
    background: var(--gold);
}
.sidenav-item-top {
    margin-left: 0;
    padding-left: 10px;
    font-weight: 600;
    color: var(--text);
}

.sidenav-foot {
    flex-shrink: 0;
    padding: 12px 16px 16px;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sidenav-user { font-size: .78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidenav-logout {
    background: rgba(240,85,77,.12);
    color: #ff8f88;
    border: 1px solid rgba(240,85,77,.25);
    border-radius: 7px;
    padding: 7px 10px;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}
.sidenav-logout:hover { background: rgba(240,85,77,.2); }

/* ── CARDS / PANELS ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.card-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
}

/* ── BUTTONS ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
}

.btn-primary   { background: var(--gold); color: var(--navy); }
.btn-primary:hover { background: var(--gold-dark); }
.btn-secondary { background: var(--blue); color: #fff; }
.btn-secondary:hover { background: var(--blue-dim); }
.btn-success   { background: var(--green); color: #06341c; }
.btn-success:hover { background: var(--green-dark); }
.btn-danger    { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-ghost     { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm        { padding: 5px 10px; font-size: .8rem; }

/* ── FORMS ── */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: inherit;
    transition: border-color .15s;
    background: var(--surface-2);
    color: var(--text);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(79,140,255,.18);
}
select.form-control option { background: var(--surface-2); color: var(--text); }

select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 60px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
}
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}
table th {
    background: var(--navy);
    color: #fff;
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}
table th:first-child { border-radius: var(--radius) 0 0 0; }
table th:last-child  { border-radius: 0 var(--radius) 0 0; }
/* Cabeceras ordenables (ver ordenarTabla() en api.js): cursor + flechita que aparece
   al pasar el ratón y se fija en la columna activa. */
table th[onclick] { cursor: pointer; user-select: none; }
table th[onclick]:hover { background: var(--navy-light); }
table th[onclick]::after { content: '⇅'; opacity: .45; margin-left: 6px; font-size: .78em; }
table th.th-sorted-asc::after  { content: '↑'; opacity: 1; color: var(--gold); }
table th.th-sorted-desc::after { content: '↓'; opacity: 1; color: var(--gold); }
table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
table tr:nth-child(even) td { background: rgba(255,255,255,.02); }
table tr:hover td { background: rgba(79,140,255,.08); }

.td-actions { white-space: nowrap; text-align: right; }

/* ── SEARCH BAR ── */
.search-bar {
    display: flex;
    gap: 10px;
    align-items: center;
}
.search-bar .form-control { max-width: 320px; }

/* ── MODAL ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(3,8,18,.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn .15s;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,.45);
    width: 560px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp .2s;
}
.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 1.05rem; color: var(--text); }
.modal-body { padding: 20px 24px; }
.modal-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }

/* ── BADGE / TAG ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-fv     { background: rgba(79,140,255,.16); color: #8ab4ff; }
.badge-comp   { background: rgba(167,139,250,.16); color: #c4b5fd; }
.badge-prot   { background: rgba(240,85,77,.16); color: #ff9d97; }
.badge-cab    { background: rgba(244,114,182,.16); color: #f6a8cf; }
.badge-canal  { background: rgba(56,189,248,.16); color: #7dd3fc; }
.badge-cajas  { background: rgba(163,230,53,.14); color: #bef264; }
.badge-mat    { background: rgba(250,204,21,.16); color: #fde68a; }
.badge-ferr   { background: rgba(148,163,184,.16); color: #cbd5e1; }
.badge-clima  { background: rgba(34,211,238,.16); color: #a5f3fc; }
.badge-herr   { background: rgba(244,63,94,.14); color: #fda4af; }
.badge-mo     { background: rgba(23,201,100,.16); color: #6ee7ab; }
.badge-otros  { background: rgba(139,154,179,.14); color: var(--text-muted); }
.badge-eventos{ background: rgba(217,70,239,.16); color: #f0abfc; }

/* ── TOAST ── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--navy);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
    font-size: .88rem;
    animation: slideUp .2s;
    max-width: 360px;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green-dark); }

/* ── INGRESOS / PAGOS FUTUROS: caja de "añadir" a la izquierda, lista a la derecha ── */
.futuros-row { display: flex; gap: 20px; align-items: flex-start; max-width: 800px; }
.futuros-form-box { width: 230px; flex-shrink: 0; }
.futuros-form-box .form-group { margin-bottom: 10px; }
.futuros-list-box { flex: 1; min-width: 0; align-self: stretch; border-left: 1px solid var(--border); padding-left: 20px; }
.futuros-lista { display: flex; flex-direction: column; gap: 6px; }
.futuros-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    cursor: pointer;
    transition: border-color .15s;
}
.futuros-item:hover { border-color: var(--blue); }
.futuros-item .fi-importe { font-weight: 700; white-space: nowrap; }
.futuros-item .fi-concepto { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.futuros-item .fi-fecha { font-size: .78rem; color: var(--text-muted); white-space: nowrap; }
.futuros-item .fi-aviso { font-size: .9rem; }
/* Tick "no contar en la previsión" a la derecha de la fila -- excluida se ve apagada
   (misma idea que las filas inactivas de Gastos fijos) pero sigue en la lista, nunca
   se oculta: hay que poder volver a marcarla sin tener que buscarla en otro sitio. */
.futuros-item.fi-excluida { opacity: .55; }
.futuros-item .fi-check { display: flex; flex-direction: column; align-items: center; gap: 2px; flex-shrink: 0; }
.futuros-item .fi-check-label { font-size: .62rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
.futuros-item .fi-check input { width: 17px; height: 17px; cursor: pointer; }

/* ── OBRAS: divisor entre días en la tabla de Horas, con las tareas de ese día
   (mismo dato que la tabla de Diario de obra, de abajo -- clic aquí abre/precarga
   ese mismo formulario, no es una segunda forma de editarlo). ── */
/* max-width:0 es el truco para que esta celda NO participe en el cálculo del ancho de
   la tabla: sin él, el texto del diario (que puede ser largo) estiraba la tabla entera
   y había que irse a la barra horizontal para leerlo. Con esto, la celda se queda con
   el ancho que marcan las filas de datos y el texto envuelve dentro. */
.dia-divisor-row td { padding: 0 !important; border: none !important; max-width: 0; }
.dia-divisor {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px;
    padding: 6px 10px; margin: 8px 0 4px;
    background: var(--surface-2); border-top: 2px solid var(--gold); border-radius: 4px;
    font-size: .82rem;
}
.dia-divisor-fecha { font-weight: 700; color: var(--text); text-transform: capitalize; white-space: nowrap; }
/* El texto del diario envuelve en varias líneas y se adapta al ancho, igual que en la
   tabla de "Diario de obra" -- antes iba en una sola línea (nowrap + ellipsis), que
   dentro de una celda de tabla no recorta nada: ensancha la tabla. */
.dia-divisor-tareas {
    flex: 1 1 240px; min-width: 0;
    color: var(--text-muted); cursor: pointer; font-style: italic; text-align: left;
    white-space: pre-wrap; overflow-wrap: anywhere;
}
.dia-divisor-tareas:hover { color: var(--gold); text-decoration: underline; }
.dia-divisor-tareas.dia-divisor-tareas-vacio { color: var(--blue); font-style: normal; }
/* Mientras se escribe, la fila pasa de "fecha | tareas en una línea" a fecha arriba
   y la caja de texto ocupando todo el ancho debajo -- si no, un textarea no cabría
   a la derecha del todo. */
.dia-divisor.dia-divisor-editando { flex-direction: column; align-items: stretch; gap: 6px; }
.dia-divisor-editor { display: flex; gap: 8px; align-items: flex-start; }
.dia-divisor-editor textarea {
    flex: 1; min-height: 44px; resize: vertical; font-family: inherit; font-size: .82rem;
    padding: 6px 8px; border-radius: 4px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text);
}
.dia-divisor-editor-botones { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

/* ── Resumen de "Horas de {trabajador}" (modal-th-detalle): total pagado / pendiente /
   general de un vistazo, en vez de tener que sumar las filas de las dos tablas a mano. ── */
.th-resumen { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.th-resumen-tile {
    flex: 1; min-width: 140px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px 14px; border-top: 3px solid var(--border);
}
.th-resumen-tile.pagado { border-top-color: var(--green); }
.th-resumen-tile.pendiente { border-top-color: var(--gold); }
.th-resumen-tile .th-resumen-lbl { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 3px; }
.th-resumen-tile .th-resumen-eur { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.th-resumen-tile.pagado .th-resumen-eur { color: var(--green); }
.th-resumen-tile.pendiente .th-resumen-eur { color: var(--gold); }
.th-resumen-tile .th-resumen-horas { font-size: .78rem; color: var(--text-muted); margin-top: 1px; }

/* ── EMPTY STATE ── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: .95rem; }

/* ── HIDDEN VIEWS ── */
.view { display: none; }
.view.active { display: block; }

/* ── CRM: KANBAN ── */
.kanban-board {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding-bottom: 10px;
    align-items: flex-start;
}
.crm-columna {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 230px;
    max-width: 230px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 160px);
}
.crm-columna-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 10px 8px;
    font-weight: 600;
    color: var(--text);
    font-size: .85rem;
}
.crm-columna-header .crm-col-nombre { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-columna-header .crm-col-count {
    background: rgba(255,255,255,.08);
    border-radius: 10px;
    padding: 1px 8px;
    font-size: .72rem;
    font-weight: 600;
}
.crm-columna-header button { background: transparent; border: none; cursor: pointer; font-size: .8rem; opacity: .6; padding: 2px; }
.crm-columna-header button:hover { opacity: 1; }
.crm-columna-cards {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 50px;
}
.crm-columna-cards.crm-drag-over { background: rgba(239,179,40,.15); border-radius: var(--radius); }
.crm-add-lead-btn {
    margin: 0 8px 10px;
    background: transparent;
    border: none;
    text-align: left;
    color: var(--text-muted);
    font-size: .82rem;
    padding: 6px 4px;
    cursor: pointer;
    border-radius: var(--radius);
}
.crm-add-lead-btn:hover { background: rgba(255,255,255,.06); color: var(--text); }
.crm-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    box-shadow: var(--shadow);
    cursor: grab;
}
.crm-card:active { cursor: grabbing; }
.crm-card.crm-dragging { opacity: .4; }
.crm-card-nombre { font-weight: 600; font-size: .88rem; color: var(--text); margin-bottom: 5px; display: flex; align-items: center; gap: 6px; }
.crm-card-meta { font-size: .76rem; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.crm-card-pendiente {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: .74rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.crm-card-pendiente.crm-card-pendiente-rojo { color: var(--red); }
.crm-card-pendiente.crm-card-pendiente-verde { color: var(--green); }
.crm-semaforo {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.crm-semaforo-ampergy { background: var(--red); }
.crm-semaforo-cliente { background: var(--green-dark); }

.crm-pendiente-btn {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    font-size: .82rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all .15s;
}
.crm-pendiente-btn:hover { border-color: var(--gold); }
.crm-pendiente-btn-rojo.crm-activo { background: rgba(240,85,77,.16); border-color: var(--red); color: #ff9d97; font-weight: 600; }
.crm-pendiente-btn-verde.crm-activo { background: rgba(23,201,100,.16); border-color: var(--green-dark); color: #6ee7ab; font-weight: 600; }

.crm-nueva-columna-wrap { min-width: 220px; max-width: 220px; flex-shrink: 0; }
.crm-nueva-columna-btn {
    width: 100%;
    background: transparent;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 14px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: .85rem;
}
.crm-nueva-columna-btn:hover { border-color: var(--gold); color: var(--text); }

.crm-en-marcha-grupo h3 { color: var(--text); margin: 18px 0 8px; font-size: 1rem; }
.crm-en-marcha-grupo:first-child h3 { margin-top: 0; }
.crm-horas-tabla-wrap { max-height: 240px; overflow-y: auto; }

/* ══════════════════ VISTA MÓVIL ══════════════════
   Todo se activa vía la clase body.view-mobile (nunca @media directamente), que
   pone mobile.js: por autodetección de ancho de pantalla o por el botón flotante
   que fuerza el modo manualmente. Así el toggle manual y la autodetección usan
   exactamente el mismo camino. */

/* ── Botón flotante de alternar PC/Móvil (siempre visible, en las 5 páginas) ── */
.mobile-toggle-btn {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 190; /* por debajo del modal-overlay (200), por encima de bottom-nav (150) */
    background: var(--navy);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 10px 16px;
    font-size: .8rem;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0,0,0,.28);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}
.mobile-toggle-btn:hover { background: var(--navy-light); }
body.view-mobile .mobile-toggle-btn { bottom: 76px; } /* deja sitio a la bottom-nav */

/* ── Barra de navegación inferior (sustituye a .app-nav en modo móvil) ──
   Se crea siempre que hay .app-nav (ver mobile.js), pero solo se muestra bajo
   body.view-mobile -- en modo escritorio se queda oculta en el DOM. */
.bottom-nav { display: none; }
body.view-mobile .bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: var(--navy);
    display: flex;
    z-index: 150;
    box-shadow: 0 -2px 10px rgba(0,0,0,.18);
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav button {
    flex: 1;
    background: transparent;
    border: none;
    color: rgba(255,255,255,.65);
    padding: 8px 4px 10px;
    min-height: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: .68rem;
    font-weight: 600;
    cursor: pointer;
}
.bottom-nav button .bottom-nav-icon { font-size: 1.3rem; line-height: 1; }
.bottom-nav button.active { color: var(--gold); }

/* ── Reflujo general de layout en modo móvil ── */
body.view-mobile .app-header .app-nav { display: none; }
body.view-mobile .app-shell { flex-direction: column; }
body.view-mobile .app-sidebar {
    width: auto;
    flex-direction: row;
    overflow-x: auto;
    min-height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    gap: 8px;
}
body.view-mobile .app-sidebar button { flex-shrink: 0; white-space: nowrap; }
body.view-mobile .app-main {
    max-width: none;
    padding: 14px 14px calc(84px + env(safe-area-inset-bottom, 0));
}
body.view-mobile .card { padding: 16px; }
body.view-mobile .card-header,
body.view-mobile .search-bar { flex-wrap: wrap; }
body.view-mobile .search-bar .form-control { max-width: none; flex: 1 1 160px; }
body.view-mobile .form-row,
body.view-mobile .form-row-3 { grid-template-columns: 1fr; }

/* Objetivos táctiles más grandes (~44px) */
body.view-mobile .btn { min-height: 42px; padding: 9px 16px; }
body.view-mobile .btn-sm { min-height: 38px; padding: 8px 12px; }
body.view-mobile .td-actions .btn-sm,
body.view-mobile .crm-columna-header button { min-height: 34px; min-width: 34px; }

body.view-mobile .toast-container { bottom: 76px; }
body.view-mobile .modal-header,
body.view-mobile .modal-body,
body.view-mobile .modal-footer { padding-left: 16px; padding-right: 16px; }

/* ── Tablas → tarjetas (patrón data-label) ──
   Cada <td> de las tablas de listado debe llevar data-label="Columna" (añadido en
   las funciones de render de app.js/contabilidad.js/crm.js/usuarios.js); esta regla
   los convierte en pares etiqueta+valor apilados dentro de una tarjeta por fila. */
body.view-mobile .table-wrap table,
body.view-mobile .table-wrap tbody,
body.view-mobile .table-wrap tr,
body.view-mobile .table-wrap td { display: block; width: 100%; }
body.view-mobile .table-wrap thead { display: none; }
body.view-mobile .table-wrap tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 4px 14px;
    box-shadow: var(--shadow);
}
body.view-mobile .table-wrap tr:nth-child(even) td,
body.view-mobile .table-wrap tr:hover td { background: transparent; }
/* En móvil las celdas pasan a bloque con width:100%, así que hay que soltar el
   max-width:0 que el divisor de día usa en escritorio para no estirar la tabla: si no,
   gana al width y la celda se queda en 0 de ancho, con el texto en una columna de
   letra por línea. Aquí no hace falta, porque ya no hay columnas que estirar. */
body.view-mobile .dia-divisor-row td { max-width: none; }
body.view-mobile .table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
}
body.view-mobile .table-wrap td:last-child { border-bottom: none; }
body.view-mobile .table-wrap td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    text-align: left;
    margin-right: 10px;
    flex-shrink: 0;
}
body.view-mobile .table-wrap td.td-actions {
    justify-content: flex-end;
    padding-top: 10px;
}
body.view-mobile .table-wrap td.td-actions::before { content: none; }

/* ── CRM Kanban en móvil: una columna a la vez, con scroll-snap táctil ──
   El drag-and-drop nativo no se toca (no funciona en touch); mover un lead entre
   columnas en móvil se hace desde el select "Mover a columna" del modal de lead. */
body.view-mobile .kanban-board {
    scroll-snap-type: x mandatory;
    gap: 12px;
}
body.view-mobile .crm-columna {
    min-width: 85vw;
    max-width: 85vw;
    scroll-snap-align: start;
}

/* Campo de hora en cuartos (ver horaCuartosMontar en obras.js): dos desplegables
   metidos dentro de una sola caja para que se vea igual que el input de hora que
   había antes, pero con los minutos limitados a 00/15/30/45. */
.hora-cuartos {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    max-width: 110px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    transition: border-color .15s;
}
.hora-cuartos:focus-within {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(79, 140, 255, .18);
}
.hora-cuartos .hc-sel {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: .9rem;
    padding: 2px 1px;
    text-align: center;
    cursor: pointer;
}
.hora-cuartos .hc-sel:focus { outline: none; }
.hora-cuartos .hc-sel option { background: var(--surface-2); color: var(--text); }
.hora-cuartos .hc-sep { color: var(--text-muted); font-size: .9rem; }

/* Facturar una obra de precio cerrado (ver obrasFijaAbrir en obras.js): resumen de
   cuánto se ha certificado ya, barra de avance y lista de extras pendientes. */
.off-tiles { display: flex; gap: 10px; flex-wrap: wrap; }
.off-tile {
    flex: 1 1 130px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-top: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}
.off-tile.pagado { border-top-color: var(--green); }
.off-tile.pendiente { border-top-color: var(--gold); }
.off-tile .off-lbl {
    display: block;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.off-tile strong { font-size: 1rem; }
.off-barra {
    height: 6px;
    border-radius: 3px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    margin-top: 8px;
    overflow: hidden;
}
.off-barra-relleno { height: 100%; background: var(--green); }
.off-nota { font-size: .75rem; color: var(--text-muted); margin: 6px 0 0; }
.off-aviso {
    font-size: .78rem;
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--gold);
    background: rgba(230, 178, 60, .12);
    color: var(--text);
}
.off-extra {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    margin-bottom: 5px;
    font-size: .85rem;
    cursor: pointer;
}
.off-extra .off-extra-imp { margin-left: auto; font-weight: 600; }
