:root {
    /* Colores RIEGOSA (mismos que el resto de apps: cian de marca #17a9d8) */
    --brand: #17a9d8;              /* cian de marca, para acentos y logo */
    --primary: #0e86ac;           /* cian oscurecido, para fondos con texto blanco */
    --primary-dark: #0b6d8e;
    --primary-light: #e6f5fa;     /* tinte claro para avisos y píldoras activas */
    --danger: #d64545;
    --warning: #d68910;
    --ok: #2e9e6b;
    --bg: #f1f5f8;
    --card: #ffffff;
    --text: #1a2533;
    --muted: #5b6b7a;
    --border: #e0e7ec;
    --radius: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    padding-bottom: 82px;
    overflow-x: hidden;
}

.topbar {
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 10px clamp(14px, 4vw, 32px);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner { max-width: 1360px; margin: 0 auto; }
.topbar-logo {
    display: block;
    height: 30px;
    width: auto;
    background: #fff;
    border-radius: 7px;
    padding: 4px 9px;
    margin-bottom: 8px;
}
.topbar-obra {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 15px;
}
.cambiar-link {
    color: #d6eef7;
    font-size: 13px;
    font-weight: 400;
    text-decoration: underline;
}
.topbar-usuario {
    font-size: 12px;
    color: #d6eef7;
    margin-top: 4px;
}

/* Logo en la pantalla de login */
.login-logo {
    display: block;
    width: 190px;
    max-width: 60%;
    margin: 8px 0 4px;
}

.content {
    max-width: 880px;
    margin: 0 auto;
    padding: clamp(14px, 3.5vw, 30px);
}
/* Páginas con tablas anchas (presupuesto, planning) aprovechan más pantalla */
body.ancho .content { max-width: 1360px; }

.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    padding: 6px 4px max(6px, env(safe-area-inset-bottom));
    z-index: 20;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.bottom-nav::-webkit-scrollbar { display: none; }
.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--muted);
    text-decoration: none;
    font-size: 10.5px;
    line-height: 1.1;
    padding: 4px 3px;
    flex: 1 0 auto;
    min-width: 46px;
    max-width: 130px;
    white-space: nowrap;
}
@media (min-width: 560px) { .bottom-nav a { font-size: 12px; padding: 4px 10px; } }
.bottom-nav a.active { color: var(--brand); font-weight: 600; }
.bottom-nav .icon { font-size: 21px; }

/* Contenedor de tablas anchas: scroll horizontal propio, nunca desborda la página */
.tabla-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: clamp(16px, 3vw, 22px);
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

h1 { font-size: clamp(20px, 4.5vw, 24px); margin: 4px 0 18px; }
h2 { font-size: 17px; margin: 0 0 12px; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.kpi {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi-value.ok { color: var(--ok); }
.kpi-value.warn { color: var(--warning); }
.kpi-value.danger { color: var(--danger); }

.progress-bar {
    background: #e5e7eb;
    border-radius: 6px;
    height: 10px;
    overflow: hidden;
    margin-top: 6px;
}
.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s;
}
.progress-bar-fill.warn { background: var(--warning); }
.progress-bar-fill.danger { background: var(--danger); }

form.stack { display: flex; flex-direction: column; gap: 12px; }
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    background: white;
}
textarea { min-height: 80px; resize: vertical; }
input[type="file"] { padding: 8px 0; border: none; }

.btn {
    display: inline-block;
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    width: 100%;
}
.btn.secondary { background: white; color: var(--primary); border: 1px solid var(--primary); }
.btn.small { width: auto; padding: 8px 14px; font-size: 13px; }
.btn.danger { background: var(--danger); }

.fab-add {
    position: fixed;
    bottom: 88px;
    right: 20px;
    background: var(--primary);
    color: white;
    width: 54px; height: 54px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
    text-decoration: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.25);
    z-index: 15;
}

.list-item {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.list-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}
.list-item-title { font-weight: 600; font-size: 15px; }
.list-item-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list-item-body { font-size: 14px; color: var(--text); margin-top: 6px; white-space: pre-wrap; }
.list-item-photo { width: 100%; border-radius: 8px; margin-top: 8px; max-height: 260px; object-fit: cover; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.badge-abierta, .badge-alta { background: #fdecea; color: var(--danger); }
.badge-en-proceso, .badge-media { background: #fef5e7; color: var(--warning); }
.badge-cerrada, .badge-baja { background: #eafaf1; color: var(--ok); }
.badge-critica { background: var(--danger); color: white; }
.badge-materiales { background: #e8f0fe; color: #1a5fb4; }
.badge-mano-de-obra { background: #f3e8fd; color: #6b21a8; }
.badge-subcontratas { background: #fef5e7; color: #92620a; }
.badge-maquinaria { background: #e6f4f1; color: #0f6b5c; }
.badge-otros { background: #f1f2f4; color: #4b5563; }

.section-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    overflow-x: auto;
}
.section-tabs a {
    padding: 8px 14px;
    border-radius: 20px;
    background: white;
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    white-space: nowrap;
}
.section-tabs a.active { background: var(--primary); color: white; border-color: var(--primary); }

.flash-msg {
    background: var(--primary-light);
    color: var(--primary);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
}

.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; }

.obra-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    text-decoration: none;
    color: var(--text);
    display: block;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.obra-card-nombre { font-weight: 700; font-size: 16px; }
.obra-card-meta { font-size: 13px; color: var(--muted); margin-top: 4px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

table.partidas-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.partidas-table th, table.partidas-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }

/* Buscador y tabla de precios */
.filtros-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filtros-bar input, .filtros-bar select { width: auto; flex: 1 1 160px; }
.filtros-bar .btn { width: auto; flex: 0 0 auto; }
table.precios-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.precios-table th {
    text-align: left; padding: 8px 8px; background: var(--primary-light);
    color: var(--primary-dark); position: sticky; top: 0; white-space: nowrap;
}
table.precios-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.precios-table tr:hover td { background: #fafcfd; }
table.precios-table td.num { text-align: right; white-space: nowrap; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.top-actions .btn { width: auto; }
.pill-nav { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.pill-nav a { padding: 6px 12px; border-radius: 20px; background: white; border: 1px solid var(--border);
    color: var(--text); text-decoration: none; font-size: 13px; }
.pill-nav a.active { background: var(--primary); color: white; border-color: var(--primary); }
