:root {
  --slate: #1E293B; 
  --slate-deep: #131B29; 
  --slate-900: #0E1520;
  --cyan: #06B6D4; 
  --cyan-soft: rgba(6,182,212,0.14);
  --amber: #F59E0B; 
  --amber-soft: rgba(245,158,11,0.16);
  --red: #F43F5E;
  --red-soft: rgba(244,63,94,0.14);
  --green: #10B981;
  --yellow: #F59E0B;
  --cloud: #F8FAFC; 
  --ink-soft: #94A3B8; 
  --ink-soft-2: #CBD5E1;
  --line: rgba(148,163,184,0.16);
  --surface-tint: rgba(255,255,255,0.04);
  --display: 'Space Grotesk', 'Inter', sans-serif;
  --body: 'Inter', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overscroll-behavior-y: none; }
body {
  font-family: var(--body); background: var(--slate-900); color: var(--cloud);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column; align-items: center;
}

button, select, input { font-family: var(--body); }

/* Contenedor principal para emular app nativa */
.app-container {
  width: 100%; max-width: 500px; height: 100vh;
  display: flex; flex-direction: column; position: relative;
  background: var(--slate-900);
}

/* ---------------- HEADER ---------------- */
.app-header { display: flex; align-items: center; gap: 10px; padding: 20px 20px 14px; flex-shrink: 0; }
.app-brand-mark { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
.app-header .titles { flex: 1; min-width: 0; }
.app-header .tenant { font-family: var(--display); font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .user { font-size: 12px; color: var(--ink-soft); font-family: var(--mono); }
.app-avatar {
  width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--cyan), var(--amber));
  display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 700; font-size: 14px;
  color: #0E1520; flex-shrink: 0; cursor: pointer;
}

/* ---------------- ALERTAS GLOBALES ---------------- */
.app-alert {
  position: fixed; top: 16px; left: 16px; right: 16px; z-index: 9999;
  background: linear-gradient(90deg, #B91C3C, #F43F5E); color: #fff; border-radius: 12px;
  padding: 14px 16px; font-size: 14px; font-weight: 600; display: none; align-items: center; gap: 10px;
  box-shadow: 0 10px 22px -10px rgba(244,63,94,0.6);
}
.app-alert.show { display: flex; animation: alertPulse 1.4s ease-in-out infinite; }
.app-alert svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2; flex-shrink: 0; }
@keyframes alertPulse { 0%,100%{transform:scale(1);} 50%{transform:scale(1.02);} }

/* ---------------- MAIN CONTENT ---------------- */
.app-main { flex: 1; overflow-y: auto; padding: 10px 16px 24px; display: flex; flex-direction: column; gap: 16px; }

/* Tarjetas */
.card { background: var(--slate-deep); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.card-top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-icon { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.card-icon.amber { background: var(--amber-soft); } .card-icon.amber svg { stroke: var(--amber); }
.card-icon.cyan { background: var(--cyan-soft); } .card-icon.cyan svg { stroke: var(--cyan); }
.card-icon.red { background: var(--red-soft); } .card-icon.red svg { stroke: var(--red); }
.card-icon svg { width: 22px; height: 22px; fill: none; stroke-width: 1.8; }
.card-title { font-size: 16px; font-weight: 700; }
.card-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }

/* Widget de mapa (ubicación) */
.map-container { width: 100%; height: 220px; border-radius: 12px; overflow: hidden; background: var(--surface-tint); }
.map-container .leaflet-control-attribution { font-size: 9px; }

/* Botones Gigantes */
.big-btn {
  width: 100%; padding: 18px; border-radius: 14px; border: none; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer;
  transition: transform .12s cubic-bezier(0.4, 0, 0.2, 1), background .15s ease, box-shadow .15s ease;
  user-select: none;
}
.big-btn.amber { background: var(--amber); color: #0E1520; box-shadow: 0 10px 24px -10px rgba(245,158,11,0.55); }
.big-btn.amber:active, .big-btn.amber.active { transform: scale(0.96); background: #d97706; }
.big-btn.success { background: var(--cyan); color: #0E1520; box-shadow: 0 10px 24px -10px rgba(6,182,212,0.55); }
.big-btn.red { background: var(--red); color: #FFF; box-shadow: 0 10px 24px -10px rgba(244,63,94,0.55); }
.big-btn.red:active, .big-btn.red.active { transform: scale(0.96); background: #be123c; }

.big-btn:disabled { opacity: 0.7; pointer-events: none; }
.card-sub.success { color: var(--cyan); }
.card-sub.red { color: var(--red); }
.big-btn .spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(14,21,32,0.3); border-top-color: #0E1520; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login Form */
.login-form { display: flex; flex-direction: column; gap: 16px; padding: 20px 0; }
.form-field { display: flex; flex-direction: column; gap: 8px; }
.form-field label { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.form-field input, .form-field select {
  background: var(--surface-tint); border: 1px solid var(--line); color: var(--cloud);
  padding: 14px 16px; border-radius: 12px; font-size: 16px; outline: none;
}
.form-field input:focus, .form-field select:focus { border-color: var(--cyan); }

/* Switch Toggle */
.row-between { display: flex; align-items: center; justify-content: space-between; }
.switch { width: 54px; height: 30px; border-radius: 15px; background: rgba(148,163,184,0.22); position: relative; border: none; cursor: pointer; flex-shrink: 0; }
.switch.on { background: var(--cyan); }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #FFFFFF; transition: transform .22s cubic-bezier(.4,0,.2,1); box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.switch.on .thumb { transform: translateX(24px); }
.switch-label { font-size: 14px; font-weight: 600; color: var(--ink-soft-2); }

/* GPS Readouts */
.gps-readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.gps-stat { background: var(--surface-tint); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.gps-stat .lbl { font-family: var(--mono); font-size: 10.5px; color: var(--ink-soft); text-transform: uppercase; }
.gps-stat .val { font-family: var(--mono); font-weight: 700; font-size: 18px; margin-top: 4px; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft-2); margin-top: 14px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-soft); flex-shrink: 0; }
.status-dot.on { background: var(--cyan); box-shadow: 0 0 0 4px var(--cyan-soft); }

/* Alarm Status */
.alarm-status { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--cyan); }
.alarm-status.active { color: var(--red); }

/* Activity Log */
.activity-title { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 8px 0 4px; }
.activity-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.activity-item:last-child { border-bottom: none; }
.activity-time { font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft); flex-shrink: 0; width: 46px; }
.activity-text { color: var(--ink-soft-2); }

/* Loading State */
.loading-state { display: flex; align-items: center; justify-content: center; height: 200px; }
.loading-state .spinner { width: 40px; height: 40px; border: 3px solid var(--line); border-top-color: var(--cyan); border-radius: 50%; animation: spin 1s linear infinite; }

/* Technician Flow */
.type-opt {
  display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface-tint); cursor: pointer; margin-bottom: 12px;
}
.type-opt:active { transform: scale(0.98); }
.type-opt .to-icon { width: 42px; height: 42px; border-radius: 12px; background: var(--cyan-soft); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.type-opt .to-icon svg { width: 20px; height: 20px; stroke: var(--cyan); fill: none; stroke-width: 1.8; }
.type-opt .to-text b { display: block; font-size: 15px; margin-bottom: 2px; }
.type-opt .to-text span { font-size: 12.5px; color: var(--ink-soft); }

/* Utilitarios */
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }

/* --- Widgets Constructor App v2 (paridad con NativeWidgets.tsx) --- */
.wc-canvas { width: 100%; height: 90px; }

.gauge-wrap { position: relative; display: flex; flex-direction: column; align-items: center; padding-top: 8px; }
.gauge-dial { width: 140px; height: 140px; border-radius: 50%; display: flex; align-items: center; justify-content: center; position: relative; }
.gauge-hole { width: 104px; height: 104px; border-radius: 50%; background: var(--slate-deep); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge-num { font-family: var(--display); font-weight: 700; font-size: 24px; }
.gauge-unit { font-size: 11px; color: var(--ink-soft); }
.gauge-needle { position: absolute; top: 50%; left: 50%; width: 3px; height: 40px; background: var(--cloud); border-radius: 2px; transform-origin: top center; }
.gauge-pivot { position: absolute; top: 50%; left: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--cloud); }

.led-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0; }
.led-dot { width: 34px; height: 34px; border-radius: 50%; transition: background .2s, box-shadow .2s; }
.led-status { font-size: 12.5px; font-weight: 600; }

.bar-wrap { display: flex; align-items: center; gap: 16px; }
.bar-track { width: 28px; height: 120px; border-radius: 14px; background: var(--surface-tint); position: relative; overflow: hidden; flex-shrink: 0; }
.bar-mask { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(180deg, var(--cyan), var(--amber)); border-radius: 14px; transition: height .3s; }
.bar-info { display: flex; flex-direction: column; justify-content: space-between; height: 120px; }

.ring-wrap { display: flex; align-items: center; gap: 16px; }
.ring { width: 92px; height: 92px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ring-hole { width: 68px; height: 68px; border-radius: 50%; background: var(--slate-deep); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-pct { font-weight: 700; font-size: 15px; }

.num-value { font-family: var(--display); font-weight: 700; font-size: 32px; }
.num-unit { font-size: 13px; color: var(--ink-soft); margin-left: 4px; }

.knob-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 0; }
.knob { width: 90px; height: 90px; border-radius: 50%; background: var(--surface-tint); border: 2px solid var(--line); position: relative; touch-action: none; cursor: grab; }
.knob-notch { position: absolute; top: 8px; left: 50%; width: 4px; height: 22px; margin-left: -2px; border-radius: 2px; background: var(--amber); transform-origin: 2px 37px; }
.knob-val { font-size: 13px; color: var(--ink-soft); }

.seg-track { display: flex; background: var(--surface-tint); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-opt { flex: 1; padding: 8px 10px; border: none; background: transparent; color: var(--ink-soft); border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.seg-opt.active { background: var(--cyan); color: #04222B; }

.step-controls { display: flex; align-items: center; justify-content: center; gap: 18px; }
.step-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-tint); color: var(--cloud); font-size: 22px; line-height: 1; cursor: pointer; }
.step-btn:active { transform: scale(0.94); }
.step-value { font-family: var(--display); font-weight: 700; font-size: 20px; min-width: 90px; text-align: center; }

.camera-frame, .stream-frame { width: 100%; aspect-ratio: 4/3; background: #000; border-radius: 10px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.camera-frame img, .stream-frame img { width: 100%; height: 100%; object-fit: contain; }
.camera-frame .placeholder, .stream-frame .placeholder { color: var(--ink-soft); font-size: 12.5px; }
.text-center { text-align: center; }

/* .btn/.btn-sm: usados por los widgets de cámara (foto/stream) y por el
   escáner QR — no tenían ninguna regla propia, así que salían como el botón
   nativo del navegador sin ningún estilo. */
.btn {
  border: none; border-radius: 8px; cursor: pointer; font-weight: 600;
  font-family: var(--body); transition: transform .12s ease, background .15s ease, color .15s ease;
  user-select: none;
}
.btn-sm {
  padding: 7px 14px; font-size: 12.5px;
  background: var(--cyan-soft); color: var(--cyan); border: 1px solid rgba(6,182,212,0.35);
}
.btn-sm:hover { background: var(--cyan); color: #0E1520; }
.btn-sm:active { transform: scale(0.95); }
.btn-sm:disabled { opacity: 0.6; pointer-events: none; transform: none; }

.stream-frame.stream-frame-preview {
  flex-direction: column; gap: 8px; cursor: pointer;
  border: 1px dashed var(--line); background: #0a0f16;
}
.stream-frame-preview:active { transform: scale(0.98); }
.stream-frame-preview svg { width: 34px; height: 34px; stroke: var(--ink-soft); fill: none; stroke-width: 1.6; }
.stream-frame-preview .placeholder { text-align: center; padding: 0 20px; }
