:root {
  --bg: #0f1419;
  --card: #1a2332;
  --card2: #243044;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --ok: #22c55e;
  --warn: #eab308;
  --bad: #ef4444;
  --ign: #6b7280;
  --accent: #3b82f6;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --nav-h: 56px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
}
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; height: auto; display: block; }

.app-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15,20,25,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid #2a3548;
  padding: calc(10px + var(--safe-t)) 14px 10px;
}
.app-header .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand span { color: var(--ok); }
.spacer { flex: 1; }
.nav-links { display: flex; gap: 8px; flex-wrap: wrap; }
.nav-links a, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 12px; border-radius: 10px; border: 1px solid #2a3548;
  background: var(--card); color: var(--text); font-size: .9rem; cursor: pointer;
  min-height: 40px; touch-action: manipulation;
}
.btn:active, .nav-links a:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.btn-danger { background: #7f1d1d; border-color: #991b1b; }
.btn-ok { background: #14532d; border-color: #166534; }
.btn-ghost { background: transparent; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.wrap { padding: 12px 14px calc(24px + var(--safe-b)); max-width: 1400px; margin: 0 auto; }

.summary {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px;
}
@media (min-width: 600px) { .summary { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 900px) { .summary { grid-template-columns: repeat(6, 1fr); } }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 12px;
  border: 1px solid #2a3548;
}
.stat .n { font-size: 1.4rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .8rem; }
.stat.ok .n { color: var(--ok); }
.stat.bad .n { color: var(--bad); }
.stat.warn .n { color: var(--warn); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center;
}
.toolbar input, .toolbar select {
  background: var(--card); color: var(--text); border: 1px solid #2a3548;
  border-radius: 10px; padding: 10px 12px; font-size: 1rem; min-height: 42px;
  flex: 1 1 140px;
}
.progress-box {
  background: var(--card); border: 1px solid #2a3548; border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px; display: none;
}
.progress-box.on { display: block; }
.bar { height: 8px; background: #2a3548; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0%; transition: width .3s; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 480px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(6, 1fr); } }
@media (min-width: 1280px) { .grid { grid-template-columns: repeat(8, 1fr); } }

.cam {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  border: 2px solid #2a3548; text-decoration: none; color: inherit;
  display: flex; flex-direction: column;
}
.cam.OK { border-color: var(--ok); }
.cam.BORROSA, .cam.OSCURA, .cam.TAPADA, .cam.SOSPECHOSA { border-color: var(--warn); }
.cam.SIN_SENAL { border-color: var(--bad); }
.cam.ignored { border-color: var(--ign); opacity: .75; }
.cam .thumb {
  aspect-ratio: 16/10; background: #0a0e14; position: relative; overflow: hidden;
}
.cam .thumb img { width: 100%; height: 100%; object-fit: cover; }
.cam .thumb .ph {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--bad); font-size: .75rem; font-weight: 600;
}
.cam .meta { padding: 8px; font-size: .75rem; }
.cam .meta .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam .meta .sub { color: var(--muted); display: flex; justify-content: space-between; gap: 4px; }
.badge {
  display: inline-block; padding: 2px 6px; border-radius: 6px; font-size: .65rem; font-weight: 700;
}
.badge.OK { background: #14532d; color: #86efac; }
.badge.BORROSA, .badge.OSCURA, .badge.TAPADA, .badge.SOSPECHOSA { background: #713f12; color: #fde68a; }
.badge.SIN_SENAL { background: #7f1d1d; color: #fecaca; }
.badge.IGNORED { background: #374151; color: #d1d5db; }

.detail-hero {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  border: 1px solid #2a3548; margin-bottom: 12px;
}
.detail-hero img { width: 100%; max-height: 70vh; object-fit: contain; background: #000; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  border: 1px solid #2a3548; margin-bottom: 12px;
}
.card h2, .card h3 { margin: 0 0 10px; font-size: 1.05rem; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: .9rem; }
.kv div { background: var(--card2); padding: 8px 10px; border-radius: 8px; }
.kv .k { color: var(--muted); font-size: .75rem; }
.hist { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.hist a { background: #0a0e14; border-radius: 8px; overflow: hidden; border: 1px solid #2a3548; }
.hist img { width: 100%; aspect-ratio: 16/10; object-fit: cover; }
.hist .t { font-size: .65rem; padding: 4px 6px; color: var(--muted); }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; padding-top: calc(20px + var(--safe-t));
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 16px;
  padding: 24px; border: 1px solid #2a3548;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.35rem; }
.login-card p { color: var(--muted); margin: 0 0 18px; }
.login-card label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
.login-card input {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #2a3548;
  background: var(--bg); color: var(--text); font-size: 1rem; min-height: 46px;
}
.login-card .btn { width: 100%; margin-top: 16px; min-height: 48px; }
.error { background: #7f1d1d; color: #fecaca; padding: 10px; border-radius: 8px; margin-bottom: 10px; font-size: .9rem; }
.flash { background: #14532d; color: #86efac; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }

.form-grid { display: grid; gap: 10px; }
@media (min-width: 700px) { .form-grid.cols2 { grid-template-columns: 1fr 1fr; } }
.form-grid label { font-size: .85rem; color: var(--muted); display: block; margin-bottom: 4px; }
.form-grid input, .form-grid select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #2a3548;
  background: var(--bg); color: var(--text); font-size: 1rem; min-height: 42px;
}
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.check input { width: 20px; height: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 10px 16px; border-radius: 99px;
  font-size: .9rem; z-index: 100; display: none; max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.on { display: block; }

@media print {
  .app-header, .toolbar, .btn, .nav-links { display: none !important; }
  body { background: #fff; color: #000; }
  .cam { break-inside: avoid; border-color: #000; }
}
