:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e2e4e9;
    --accent: #36368e;
    --danger: #dc2626;
    --ok: #16a34a;
    --sin-datos: #9ca3af;
    --amber: #b45309;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .brand { display: flex; align-items: center; text-decoration: none; color: var(--text); font-size: 1.05rem; }
.topbar nav a { margin-left: 0.9rem; color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.topbar nav a:hover { color: var(--accent); }
.brand-logo { height: 26px; width: auto; display: block; }
.login-logo { display: block; height: 52px; width: auto; margin: 0 auto 1rem; }

main {
    max-width: 480px;
    margin: 0 auto;
    padding: 1rem;
}

h1 { font-size: 1.25rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.05rem; margin-top: 1.5rem; }

/* Tarjetas de sensor — apiladas, no tabla ancha */
.tarjeta {
    display: block;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.85rem;
    text-decoration: none;
    color: inherit;
}
.tarjeta-titulo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.tarjeta-nombre { font-weight: 600; font-size: 1.05rem; }
.tarjeta-fecha { color: var(--muted); font-size: 0.8rem; margin-top: 0.5rem; }

.nivel-wrap { display: flex; align-items: center; gap: 0.6rem; }
.nivel-barra {
    position: relative;
    flex: 1;
    height: 18px;
    background: #eef0f3;
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.nivel-barra-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); }
.nivel-texto { font-size: 0.95rem; font-weight: 600; white-space: nowrap; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
}
.badge-ok { background: var(--ok); }
.badge-alerta { background: var(--danger); }
.badge-sin-datos { background: var(--sin-datos); }

.tabla { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-size: 0.85rem; }
.tabla th, .tabla td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; }
.tabla th { background: #fafafa; color: var(--muted); font-weight: 600; }
.tabla tr:last-child td { border-bottom: none; }
.tabla-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

form.form-stack label { display: block; margin-bottom: 1rem; font-size: 0.9rem; color: var(--muted); }
input, select, button {
    display: block;
    width: 100%;
    margin-top: 0.3rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    min-height: 44px;
}
button {
    background: var(--accent);
    color: #fff;
    border: none;
    font-weight: 600;
    cursor: pointer;
}

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); padding: 1rem; }
.login-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; width: 100%; max-width: 360px; }
.login-box label { display: block; margin-bottom: 1rem; font-size: 0.9rem; color: var(--muted); }
.login-box button { margin-top: 0.5rem; }

.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: 0.7rem 0.9rem; border-radius: 8px; }
.ok { background: #eefbf1; color: #166534; border: 1px solid #bbf7d0; padding: 0.7rem 0.9rem; border-radius: 8px; }
.muted { color: var(--muted); font-size: 0.85rem; }

.tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.tab { padding: 0.5rem 0.9rem; text-decoration: none; color: var(--muted); font-size: 0.9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab-activa { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.form-inline-btn { margin-bottom: 0.85rem; }
.form-inline-btn label { font-size: 0.85rem; color: var(--muted); display: inline-block; margin-right: 1rem; vertical-align: top; }
.form-inline-btn select { width: auto; min-width: 140px; display: inline-block; }

.grafico-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; margin-bottom: 0.75rem; }
.grafico-svg { width: 100%; height: auto; }
.grafico-eje { stroke: var(--border); stroke-width: 1; }
.grafico-grid { stroke: var(--border); stroke-width: 1; opacity: 0.6; }
.grafico-umbral { stroke: var(--danger); stroke-width: 1; stroke-dasharray: 4 3; }
.grafico-linea { fill: none; stroke: var(--accent); stroke-width: 2; }
.grafico-label { fill: var(--muted); font-size: 10px; }
.grafico-punto-alto, .grafico-punto-bajo { stroke: var(--panel); stroke-width: 1.5; }
.grafico-punto-alto { fill: var(--danger); }
.grafico-punto-bajo { fill: var(--amber); }

.tasas-wrap { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.75rem; }
.tasa-card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.8rem; flex: 1 1 130px; min-width: 130px; }
.tasa-etiqueta { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.tasa-valor { font-size: 18px; font-weight: 700; margin-top: 2px; color: var(--text); }
.tasa-valor.tasa-sindatos { font-size: 13px; font-weight: 400; color: var(--muted); }
.tasa-sub { font-size: 11px; color: var(--muted); }
.tasa-proy { font-size: 11px; color: var(--muted); margin-top: 4px; }
.tasa-proy-atencion { font-size: 11px; color: var(--amber); margin-top: 4px; font-weight: 600; }
.tasa-proy-urgente { font-size: 11px; color: var(--danger); margin-top: 4px; font-weight: 600; }
.tasa-nota { font-size: 11px; color: var(--muted); font-style: italic; margin: -0.3rem 0 0.75rem; }

.estanque-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; display: flex; justify-content: center; margin-bottom: 0.75rem; }
.estanque-svg { width: 200px; height: auto; }

.alerta-pendiente { background: #fef2f2; border: 1px solid var(--danger); border-radius: 8px; padding: 0.85rem; margin-bottom: 0.75rem; }
.alerta-pendiente p { margin: 0 0 0.6rem; font-size: 0.9rem; }
.alerta-pendiente button { background: var(--danger); }
