:root {
  --azul: #1f3a5f; --azul2: #2c5282; --fondo: #f4f6f9; --borde: #dde3ea; --texto: #1d2733;
  --muted: #6b7785; --rojo: #dc2626; --naranja: #ea580c; --amarillo: #ca8a04; --verde: #16a34a;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--texto); background: var(--fondo); font-size: 14px; }
.hidden { display: none !important; }
a { color: var(--azul2); }
h2 { margin: 0 0 12px; font-size: 20px; }
h3 { margin: 18px 0 8px; font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .error { color: var(--rojo); }
.spacer { flex: 1; }

/* login */
.login { position: fixed; inset: 0; display: grid; grid-template-columns: 1.35fr 1fr; background: #0c1726; }
.login-foto { position: relative; overflow: hidden; }
.login-foto-img { position: absolute; inset: -4%; background: url("/static/img/login.jpg") center/cover no-repeat;
  animation: kenburns 28s ease-in-out infinite alternate; }
.login-foto-velo { position: absolute; inset: 0;
  background: linear-gradient(105deg, rgba(10,22,40,.92) 0%, rgba(10,22,40,.70) 38%, rgba(10,22,40,.15) 75%, rgba(10,22,40,.45) 100%); }
.login-fibras { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.fibra { fill: none; stroke-linecap: round; stroke-width: 2.2; stroke-dasharray: 90 900; animation: luz 6s linear infinite;
  filter: drop-shadow(0 0 6px currentColor); }
.f1 { stroke: #38bdf8; color: #38bdf8; }
.f2 { stroke: #facc15; color: #facc15; animation-delay: -2s; animation-duration: 7.5s; }
.f3 { stroke: #22d3ee; color: #22d3ee; animation-delay: -4s; animation-duration: 9s; opacity: .7; }
.login-foto-texto { position: absolute; left: 7%; top: 50%; transform: translateY(-50%); max-width: 470px; color: #fff;
  animation: subir .9s ease-out both .2s; }
.login-marca { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: #7dd3fc; border: 1px solid rgba(125,211,252,.45); padding: 5px 12px; border-radius: 20px; margin-bottom: 18px;
  background: rgba(14,165,233,.08); backdrop-filter: blur(4px); }
.login-foto-texto h2 { font-size: 38px; line-height: 1.1; margin: 0 0 14px; font-weight: 750; letter-spacing: -.01em; }
.login-foto-texto p { font-size: 16px; line-height: 1.5; color: #cbd5e1; margin: 0 0 22px; }
.login-puntos { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.login-puntos li { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #e2e8f0; opacity: 0; animation: subir .6s ease-out forwards; }
.login-puntos li:nth-child(1) { animation-delay: .7s; } .login-puntos li:nth-child(2) { animation-delay: .9s; } .login-puntos li:nth-child(3) { animation-delay: 1.1s; }
.login-puntos span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: rgba(255,255,255,.1); }
.login-panel { display: grid; place-items: center; background: linear-gradient(160deg, #f8fafc, #e8eef5); padding: 24px; overflow-y: auto; min-height: 0; }
.login-box { margin: auto; }
.login-box { background: #fff; padding: 36px 34px; border-radius: 14px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 50px rgba(15,31,51,.14), 0 2px 6px rgba(15,31,51,.06); animation: subir .7s ease-out both; }
.login-logo { width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; margin-bottom: 4px;
  background: linear-gradient(135deg, #1f3a5f, #0ea5e9); box-shadow: 0 8px 20px rgba(14,165,233,.35); }
.login-logo span { color: #fff; font-weight: 800; font-size: 17px; letter-spacing: .04em; }
.login-box h1 { margin: 0; font-size: 24px; color: var(--azul); }
.login-box .btn.primary { padding: 10px; font-weight: 600; background: linear-gradient(135deg, #2c5282, #0e7fbf); border: 0; transition: transform .15s, box-shadow .15s; }
.login-box .btn.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(14,127,191,.35); }
.login-box input { padding: 9px 10px; transition: border-color .15s, box-shadow .15s; }
.login-box input:focus { outline: none; border-color: #0ea5e9; box-shadow: 0 0 0 3px rgba(14,165,233,.18); }
.empresa-login { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--azul2); }
@keyframes kenburns { from { transform: scale(1) translate(0,0); } to { transform: scale(1.08) translate(-1.5%, -1%); } }
@keyframes luz { from { stroke-dashoffset: 990; } to { stroke-dashoffset: 0; } }
@keyframes subir { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.login-foto-texto { animation-name: subirCentro; }
@keyframes subirCentro { from { opacity: 0; transform: translateY(calc(-50% + 14px)); } to { opacity: 1; transform: translateY(-50%); } }
@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; grid-template-rows: 120px minmax(0, 1fr); }
  .login-foto-texto { left: 6%; right: 6%; }
  .login-foto-texto h2 { font-size: 24px; } .login-foto-texto p, .login-puntos { display: none; }
}
@media (prefers-reduced-motion: reduce) { .login *, .login { animation: none !important; } .login-puntos li { opacity: 1; } }

/* layout */
.layout { display: flex; height: 100vh; }
.sidebar { width: 210px; background: var(--azul); color: #fff; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { padding: 18px 16px; font-weight: 700; font-size: 17px; line-height: 1.2; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand .empresa { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #9fc6ef; margin-bottom: 6px; line-height: 1.3; }
nav a { display: block; color: #dbe6f3; text-decoration: none; padding: 10px 16px; }
nav a:hover { background: rgba(255,255,255,.07); }
nav a.activo { background: rgba(255,255,255,.15); color: #fff; font-weight: 600; }
.user { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.user a { color: #9fb6d1; }
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; gap: 16px; align-items: center; padding: 10px 18px; background: #fff; border-bottom: 1px solid var(--borde); }
.topbar label { display: flex; flex-direction: row; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
#vista { flex: 1; overflow: auto; padding: 18px; position: relative; }
#vista.full { padding: 0; overflow: hidden; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--borde); border-radius: 6px; background: #fff; }
textarea { min-height: 60px; }
.btn { font: inherit; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--borde); background: #fff; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #eef2f7; }
.btn.primary { background: var(--azul2); border-color: var(--azul2); color: #fff; }
.btn.primary:hover { background: var(--azul); }
.btn.peligro { color: var(--rojo); }
.btn.chico { padding: 3px 8px; font-size: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 14px; }
.fila { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card { background: #fff; border: 1px solid var(--borde); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.check { flex-direction: row; align-items: center; gap: 6px; }

/* tablas */
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: middle; }
th { background: #eef2f7; font-weight: 600; font-size: 12px; position: sticky; top: 0; }
tr.click:hover { background: #f7fafc; cursor: pointer; }
td input, td select { width: 100%; min-width: 50px; padding: 4px; }
#t-ocup td:first-child select { min-width: 170px; }
td.num, th.num { text-align: right; }
.tabla-scroll { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--borde); border-radius: 8px; }

/* etiquetas */
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; color: #fff; background: var(--muted); margin: 1px; }
.tag.critica { background: var(--rojo); } .tag.mayor { background: var(--naranja); } .tag.menor { background: var(--amarillo); }
.tag.abierta { background: #64748b; } .tag.notificada { background: #2563eb; } .tag.corregida { background: var(--verde); } .tag.descartada { background: #9ca3af; }
.punto { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--borde); border-radius: 8px; padding: 14px; }
.kpi .v { font-size: 24px; font-weight: 700; color: var(--azul); }
.kpi .l { font-size: 12px; color: var(--muted); }

/* mapa */
#mapa { position: absolute; inset: 0; }
.panel-mapa { position: absolute; top: 12px; right: 12px; z-index: 1000; width: 300px; max-height: calc(100% - 24px); overflow: auto; }
.leyenda { position: absolute; bottom: 20px; left: 12px; z-index: 1000; background: #fff; padding: 8px 10px; border-radius: 6px; font-size: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.2); }

/* fotos */
.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.foto { border: 1px solid var(--borde); border-radius: 6px; overflow: hidden; background: #fff; }
.foto img { width: 100%; height: 110px; object-fit: cover; display: block; cursor: pointer; }
.foto .pie { padding: 5px 6px; display: flex; gap: 4px; flex-wrap: wrap; align-items: center; font-size: 12px; }

/* medición */
.medicion { display: flex; height: calc(100vh - 56px); }
.medicion .lienzo { flex: 1; position: relative; background: #222; overflow: hidden; cursor: crosshair; }
.medicion canvas { position: absolute; left: 0; top: 0; }
.medicion .herramientas { width: 300px; background: #fff; border-left: 1px solid var(--borde); padding: 14px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modo { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.modo .btn.activo { background: var(--azul2); color: #fff; border-color: var(--azul2); }
.puntos-lista { font-size: 12px; }
.puntos-lista div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--borde); gap: 6px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 5000; display: grid; place-items: center; }
.modal-box { background: #fff; border-radius: 10px; padding: 20px; width: min(900px, 95vw); max-height: 92vh; overflow: auto; position: relative; }
.modal-cerrar { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 18px; cursor: pointer; }
#visor360 { width: 100%; height: 70vh; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--azul); color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 6000; }
.toast.error { background: var(--rojo); }
