:root {
    --primary: #1d5f3f;
    --primary-light: #e8f3ee;
    --danger: #c0392b;
    --warning: #d68910;
    --ok: #1e8449;
    --bg: #f4f5f3;
    --card: #ffffff;
    --text: #222;
    --muted: #6b7280;
    --border: #e2e4e0;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    padding-bottom: 78px;
}

.topbar {
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-obra {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 15px;
}
.cambiar-link {
    color: #cfe8db;
    font-size: 13px;
    font-weight: 400;
    text-decoration: underline;
}
.topbar-usuario {
    font-size: 12px;
    color: #cfe8db;
    margin-top: 4px;
}

.content {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
}

.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 6px 0 max(6px, env(safe-area-inset-bottom));
    z-index: 20;
}
.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--muted);
    text-decoration: none;
    font-size: 10px;
    padding: 4px 2px;
    flex: 1;
    min-width: 0;
}
.bottom-nav a span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.bottom-nav a.active { color: var(--primary); font-weight: 600; }
.bottom-nav .icon { font-size: 19px; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

h1 { font-size: 20px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }

.kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}
.kpi {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    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; }
