/* ══════════════════════════════════════════════════════════════════════
   MORFI CONTROL — sistema visual (tema claro, identidad Morfi)
   Blanco cálido + naranja #e8711a. Misma familia que la app pública.
   ══════════════════════════════════════════════════════════════════════ */
:root {
  --bg:        #f6f7f9;   /* fondo general, gris muy claro */
  --bg-2:      #ffffff;   /* tarjetas / paneles */
  --bg-3:      #f0f2f5;   /* zonas sutiles */
  --line:      #e4e8ee;   /* bordes */
  --ink:       #1a2129;   /* texto principal */
  --ink-2:     #556070;   /* secundario */
  --ink-3:     #8a96a4;   /* terciario / muted */
  --brand:     #e8711a;   /* naranja Morfi */
  --brand-ink: #ffffff;   /* texto sobre naranja */
  --brand-soft:#fdf0e6;   /* naranja muy claro para fondos */
  /* estados de ciudad */
  --asleep:    #8a96a4;
  --low:       #3b82f6;
  --normal:    #16a34a;
  --peak:      #e8711a;
  /* semánticos */
  --ok:        #16a34a;
  --warn:      #e8711a;
  --danger:    #e11d48;
  --shadow:    0 1px 2px rgba(16,24,40,.04), 0 4px 12px -2px rgba(16,24,40,.07);
  --shadow-lg: 0 2px 4px rgba(16,24,40,.04), 0 12px 28px -8px rgba(16,24,40,.14);
  --radius:    14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.num, .kpi-val, td.n, .tabular { font-variant-numeric: tabular-nums; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), var(--bg) 60%); }
.login-card { width: 100%; max-width: 370px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 34px 30px; box-shadow: var(--shadow); }
.login-card .logo { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.login-card .logo b { color: var(--brand); }
.login-card .logo svg { width: 26px; height: 26px; flex: none; }
.login-card .sub { color: var(--ink-3); font-size: 12.5px; margin-bottom: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11.5px; color: var(--ink-2); margin-bottom: 6px; font-weight: 500; }
.field input { width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 14px; outline: none; transition: border-color .15s; }
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn { width: 100%; background: var(--brand); color: var(--brand-ink); font-weight: 650;
  border-radius: var(--radius-sm); padding: 12px; font-size: 14px; transition: filter .15s; }
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); font-weight: 500; }
.login-err { color: var(--danger); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* ── Layout principal ──────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px; }
.side .brand { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 800; letter-spacing: -0.02em; padding: 4px 8px 18px; }
.side .brand b { color: var(--brand); }
.side .brand svg { width: 22px; height: 22px; flex: none; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-size: 13.5px; font-weight: 500; margin-bottom: 2px; transition: background .12s; }
.nav-item:hover { background: var(--bg-3); color: var(--ink); }
.nav-item.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; flex: none; opacity: .9; font-size: 15px; }
.side .spacer { flex: 1; }
.side .me { padding: 11px 12px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line); margin-top: 8px; }
.side .me b { color: var(--ink); display: block; font-size: 12.5px; }

.main { padding: 24px 28px; overflow-y: auto; max-height: 100vh; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.page-head h1 { font-size: 20px; font-weight: 750; letter-spacing: -0.01em; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.conn.live .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(22,163,74,.16); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* ── KPIs ──────────────────────────────────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); transition: transform .14s, box-shadow .14s; }
.kpi:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.kpi .label { font-size: 11.5px; color: var(--ink-3); margin-bottom: 8px; font-weight: 500; }
.kpi .kpi-val { font-size: 27px; font-weight: 780; letter-spacing: -0.02em; }
.kpi .kpi-val small { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.kpi .hint { font-size: 11.5px; color: var(--ink-3); margin-top: 5px; }
.kpi.hero { background: linear-gradient(135deg, #fff 40%, var(--brand-soft)); border-color: #f3d4b8;
  box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.kpi.hero::after { content:''; position: absolute; top: -40%; right: -10%; width: 140px; height: 140px;
  background: radial-gradient(circle, rgba(232,113,26,.14), transparent 70%); border-radius: 50%; }
.kpi.hero .label { color: #b06a2c; }
.kpi.hero .kpi-val { color: var(--brand); position: relative; }

/* ── Tarjetas / tablas ─────────────────────────────────────────────────── */
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card h2 { font-size: 13px; font-weight: 650; color: var(--ink-2); margin-bottom: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--ink-3); font-weight: 500; font-size: 11.5px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--bg-3); }
tr:last-child td { border-bottom: none; }
td.n, th.n { text-align: right; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 99px; }
.badge .d { width: 6px; height: 6px; border-radius: 50%; }
.badge.asleep { color: var(--asleep); background: #eef0f3; } .badge.asleep .d { background: var(--asleep); }
.badge.low    { color: var(--low);    background: #eaf1fe; } .badge.low .d    { background: var(--low); }
.badge.normal { color: var(--normal); background: #e7f6ec; } .badge.normal .d { background: var(--normal); }
.badge.peak   { color: var(--peak);   background: var(--brand-soft); } .badge.peak .d { background: var(--peak); }
.badge.ok     { color: var(--ok);     background: #e7f6ec; }
.badge.warn   { color: var(--warn);   background: var(--brand-soft); }
.badge.danger { color: var(--danger); background: #fde7ec; }

/* ── Ciudades ──────────────────────────────────────────────────────────── */
.cities-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.city-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); transition: transform .14s, box-shadow .14s; }
.city-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.city-card.peak { border-color: #f3d4b8; background: linear-gradient(170deg, #fff, var(--brand-soft) 220%); }
.city-card .name { font-size: 14px; font-weight: 650; margin-bottom: 11px; display: flex; justify-content: space-between; align-items: center; }
.city-card .stat { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); padding: 3px 0; }
.city-card .stat b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ── Agentes ───────────────────────────────────────────────────────────── */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.agent-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.agent-card .top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.agent-card .av { font-size: 26px; }
.agent-card .nm { font-weight: 650; font-size: 14px; }
.agent-card .ml { font-size: 11px; color: var(--ink-3); }
.state-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.state-asleep { background: var(--asleep); } .state-working { background: var(--ok); }
.state-waiting { background: var(--low); } .state-paused { background: var(--ink-3); }
.state-alert { background: var(--danger); }

/* ── Switch / apagado ──────────────────────────────────────────────────── */
.switch { position: relative; width: 40px; height: 23px; border-radius: 99px; background: #d4dae2; transition: background .15s; flex: none; cursor: pointer; }
.switch.on { background: var(--ok); }
.switch::after { content:''; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch.on::after { transform: translateX(17px); }
.kill { background: var(--danger); color: #fff; font-weight: 650; padding: 10px 18px; border-radius: var(--radius-sm); }

/* ══ VISTA EN VIVO — mockups de dispositivos realistas ═════════════════ */
.live-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.live-tab { padding: 8px 16px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg-2);
  font-size: 13px; font-weight: 550; color: var(--ink-2); box-shadow: var(--shadow); transition: all .14s; }
.live-tab:hover { border-color: #d7c3b3; }
.live-tab.on { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 4px 12px rgba(232,113,26,.3); }
.live-stage { display: flex; justify-content: center; gap: 48px; align-items: center; flex-wrap: wrap;
  padding: 32px 16px 36px; background: radial-gradient(900px 400px at 50% 0%, #eef1f5, transparent 70%); border-radius: var(--radius); }

/* ── Marco de CELULAR (iPhone 14/15, titanio, Dynamic Island) ──────────── */
/* Medidas proporcionales a un iPhone real: ratio ~1:2.05, bisel fino uniforme. */
.device-phone { width: 232px; flex: none; }
.phone-frame { position: relative; background: linear-gradient(135deg, #43474d 0%, #2a2d33 30%, #1c1e22 70%, #343840 100%);
  border-radius: 40px; padding: 7px;
  box-shadow:
    0 1px 3px rgba(0,0,0,.35),
    0 18px 40px -14px rgba(16,24,40,.4),
    inset 0 0 0 1.5px rgba(255,255,255,.08),
    inset 0 0 2px 1px rgba(0,0,0,.45); }
/* botón de power (derecha, largo) */
.phone-frame::after { content:''; position: absolute; right: -2px; top: 108px; width: 2.5px; height: 54px;
  background: linear-gradient(#4a4e55, #26292f); border-radius: 0 2px 2px 0; }
/* botones de la izquierda: silencio (corto) + 2 de volumen */
.phone-btns { position: absolute; left: -2px; top: 74px; z-index: 3; }
.phone-btns i { display: block; width: 2.5px; background: linear-gradient(#4a4e55, #26292f); border-radius: 2px 0 0 2px; margin-bottom: 11px; }
.phone-btns i:nth-child(1) { height: 18px; } .phone-btns i:nth-child(2) { height: 34px; } .phone-btns i:nth-child(3) { height: 34px; }
.phone-screen { position: relative; border-radius: 33px; overflow: hidden; background: #000; aspect-ratio: 1 / 2.05;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.4); }
/* Dynamic Island: más chica y pegada arriba, para no pisar el contenido de la app */
.phone-screen::before { content:''; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: 62px; height: 18px; background: #000; border-radius: 99px; z-index: 4; }
/* reflejo diagonal muy sutil del vidrio */
.phone-screen::after { content:''; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: linear-gradient(130deg, rgba(255,255,255,.08) 0%, transparent 18%); }
/* La app se RENDERIZA a ancho de celular real (390px) y se ESCALA para caber en el marco.
   Así se ve idéntica a un celular (no comprimida). El wrapper recorta lo que sobra. */
.phone-viewport { position: absolute; inset: 0; z-index: 1; overflow: hidden; background: #fff; }
.phone-screen.with-status .phone-viewport { top: 34px; }
.phone-viewport iframe { position: absolute; top: 0; left: 0; border: none; display: block; background: #fff;
  width: 390px;                      /* ancho real de celular */
  height: 820px;                     /* alto generoso de celular */
  transform-origin: top left;
  /* el scale lo pone app.js según el ancho real del marco (ancho_marco / 390) */ }
/* franja de status bar: deja respirar la Dynamic Island arriba de la app */
.phone-statusbar { position: absolute; top: 0; left: 0; right: 0; height: 34px; background: #000; z-index: 2;
  display: flex; align-items: flex-end; justify-content: space-between; padding: 0 20px 6px; }
.phone-statusbar .hora { color: #fff; font-size: 11px; font-weight: 600; }
.phone-statusbar .icons { color: #fff; font-size: 9px; letter-spacing: 1px; opacity: .9; }
.device-caption { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 16px; font-weight: 500; letter-spacing: .01em; }
.device-caption b { color: var(--ink-2); font-weight: 600; }

/* ── Marco de LAPTOP (tapa + barra de navegador + base con bisagra) ─────── */
.device-pc { flex: 1 1 620px; min-width: 460px; max-width: 820px; }
.pc-lid { background: linear-gradient(155deg, #2b2f36, #16191e); border-radius: 16px 16px 0 0; padding: 12px 12px 0;
  box-shadow: 0 24px 48px -16px rgba(16,24,40,.4), inset 0 0 0 1px rgba(255,255,255,.05); }
.pc-browser { background: #fff; border-radius: 9px 9px 0 0; overflow: hidden; box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.pc-bar { display: flex; align-items: center; gap: 7px; padding: 9px 12px; background: #eef0f3; border-bottom: 1px solid #e0e3e8; }
.pc-bar .dot { width: 11px; height: 11px; border-radius: 50%; box-shadow: inset 0 0 0 .5px rgba(0,0,0,.08); }
.pc-bar .r { background: #ff5f57; } .pc-bar .y { background: #febc2e; } .pc-bar .g { background: #28c840; }
.pc-bar .reload { margin-left: 8px; color: #9aa4b0; font-size: 13px; }
.pc-bar .url { margin-left: 4px; flex: 1; display: flex; align-items: center; gap: 6px; background: #fff; color: #4a5562;
  font-size: 11.5px; padding: 5px 12px; border-radius: 99px; font-family: ui-monospace, monospace;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border: 1px solid #e4e7ec; }
.pc-bar .url .lock { color: #16a34a; font-size: 10px; }
/* La app de negocios se renderiza a ancho de escritorio real (1280px) y se escala
   para caber: así se ve como en una PC, no apretada. */
.pc-screen { position: relative; background: #fff; overflow: hidden; aspect-ratio: 16 / 10; }
.pc-viewport { position: absolute; inset: 0; overflow: hidden; }
.pc-viewport iframe { position: absolute; top: 0; left: 0; border: none; display: block; background: #fff;
  width: 1280px; height: 800px; transform-origin: top left; /* scale lo pone app.js */ }
/* base del laptop con bisagra y muesca del trackpad */
.pc-base { position: relative; height: 15px; margin: 0 auto; width: 102%; max-width: none; margin-left: -1%;
  background: linear-gradient(#d7dce2, #b9c0c9 55%, #9aa2ac);
  border-radius: 0 0 12px 12px; box-shadow: 0 10px 20px -8px rgba(16,24,40,.35); }
.pc-base::before { content:''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 90px; height: 7px; background: #aab2bc; border-radius: 0 0 8px 8px; }

.empty { color: var(--ink-3); font-size: 13px; padding: 26px; text-align: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--ink-3); }
.mono { font-family: ui-monospace, 'SF Mono', monospace; font-size: 12px; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 8px; }
  .side .brand, .side .spacer, .side .me { display: none; }
  .nav-item { flex-direction: column; gap: 3px; font-size: 10px; padding: 7px 11px; white-space: nowrap; }
  .nav-item .ico { font-size: 16px; }
  .main { padding: 16px; max-height: none; }
  .live-stage { gap: 24px; }
  .device-pc { min-width: 0; flex-basis: 100%; }
  .device-phone { width: 280px; }
}
