/* ============================================================
   MT4 Monitor — Tema oscuro minimalista
   ============================================================ */

:root {
  --bg: #0b0f14;          /* fondo general */
  --card: #151b23;        /* tarjetas y paneles */
  --card2: #1c242e;       /* campos y botones secundarios */
  --text: #e8edf2;
  --muted: #8a96a3;
  --green: #2ecc71;
  --red: #ff5252;
  --orange: #ffa726;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", system-ui, Segoe UI, Roboto, sans-serif;
  min-height: 100%;
  overscroll-behavior-y: none;
}

.view { padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 24px); max-width: 640px; margin: 0 auto; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.center { text-align: center; padding: 24px 0; }
.green { color: var(--green); }
.red { color: var(--red); }
.orange { color: var(--orange); }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0 14px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 85%, transparent);
}
.topbar h2 { font-size: 1.15rem; }
.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 1.3rem; width: 40px; height: 36px; cursor: pointer;
}
.btn-back { font-size: 1.9rem; line-height: 1; color: var(--green); }
.conn { font-size: 0.72rem; color: var(--muted); display: flex; align-items: center; gap: 5px; width: 40px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }

/* ---------- Login ---------- */
#view-login:not([hidden]) { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-box .logo { font-size: 3.2rem; }
.login-box h1 { margin: 8px 0 2px; }
.login-box form { margin-top: 26px; display: grid; gap: 12px; text-align: left; }
input, button { font-size: 1rem; font-family: inherit; }
input {
  width: 100%; padding: 14px; border-radius: var(--radius);
  border: 1px solid #232c37; background: var(--card); color: var(--text);
}
input:focus { outline: 2px solid var(--green); border-color: transparent; }
details summary { color: var(--muted); font-size: 0.85rem; cursor: pointer; padding: 4px 0; }
details input { margin-top: 10px; }
button[type="submit"], .primary {
  background: var(--green); color: #06130b; font-weight: 700;
  padding: 14px; border: none; border-radius: var(--radius); cursor: pointer;
}
button:disabled { opacity: 0.5; }
.error { color: var(--red); font-size: 0.85rem; }

/* ---------- Resumen ---------- */
.summary { display: flex; gap: 10px; margin-bottom: 14px; }
.metric {
  flex: 1; background: var(--card); border-radius: var(--radius);
  padding: 12px 8px; text-align: center;
}
.metric .label { display: block; font-size: 0.72rem; color: var(--muted); margin-bottom: 4px; }
.metric .value { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.02rem; }
.metric.big .value { font-size: 1.35rem; }

/* ---------- Controles ---------- */
.controls { display: grid; gap: 10px; margin-bottom: 14px; }
.segmented { display: flex; background: var(--card); border-radius: 10px; padding: 3px; }
.segmented button {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 8px 4px; border-radius: 8px; font-size: 0.85rem; cursor: pointer;
}
.segmented button.active { background: var(--card2); color: var(--text); font-weight: 600; }

/* ---------- Lista de cuentas ---------- */
.cards { list-style: none; display: grid; gap: 8px; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 13px 14px; display: flex; justify-content: space-between; align-items: center;
  cursor: pointer;
}
.card:active { background: var(--card2); }
.card.stale { opacity: 0.5; }
.card .l1 { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.card .l2 { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.card .r { text-align: right; }
.card .r .f { font-weight: 700; font-variant-numeric: tabular-nums; }
.card .r .t { font-size: 0.76rem; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- Paneles / detalle ---------- */
.panel { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.panel-title { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 10px; }
.panel .segmented { margin-bottom: 12px; }
canvas { width: 100%; display: block; }
dl div { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid #1f2830; }
dl div:last-child { border-bottom: none; }
dt { color: var(--muted); }
dd { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Ajustes ---------- */
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.field-row input { width: 140px; text-align: right; }
.secondary {
  width: 100%; background: var(--card2); color: var(--text); border: none;
  padding: 12px; border-radius: 10px; cursor: pointer; margin-bottom: 8px;
}
.danger { width: 100%; background: #3a1518; color: var(--red); border: none; padding: 12px; border-radius: 10px; cursor: pointer; }
.row-btn {
  width: 100%; background: none; border: none; color: var(--text);
  padding: 13px 2px; text-align: left; font-size: 1rem; cursor: pointer;
  display: flex; justify-content: space-between; border-bottom: 1px solid #1f2830;
}
.row-btn:last-child { border-bottom: none; }
.chev { color: var(--muted); }

/* ---------- Dispositivos / auditoría ---------- */
.device, .audit-item { background: var(--card); border-radius: var(--radius); padding: 13px 14px; margin-bottom: 8px; }
.device .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.device .name { font-weight: 600; }
.device .meta { font-size: 0.76rem; color: var(--muted); margin-top: 3px; }
.badge { font-size: 0.7rem; padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
.badge.ok { background: #123320; color: var(--green); }
.badge.pending { background: #33260e; color: var(--orange); }
.badge.revoked { background: #331214; color: var(--red); }
.device .actions { margin-top: 10px; display: flex; gap: 8px; }
.device .actions button { flex: 1; padding: 9px; border-radius: 9px; border: none; cursor: pointer; }
.approve { background: var(--green); color: #06130b; font-weight: 600; }
.revoke { background: #3a1518; color: var(--red); }
.audit-item .head { display: flex; justify-content: space-between; font-size: 0.82rem; }
.audit-item .ev { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.audit-item .detail { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }
.section-label { color: var(--muted); font-size: 0.8rem; margin: 14px 2px 8px; text-transform: uppercase; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 16px; right: 16px; top: calc(var(--safe-top) + 12px);
  background: #22150a; border: 1px solid #5a3d16; color: var(--text);
  border-radius: var(--radius); padding: 13px 15px; z-index: 50;
  display: grid; gap: 3px; font-size: 0.9rem;
  animation: slide-in 0.25s ease;
}
#toast strong { color: var(--orange); }
#toast[hidden] { display: none; }
.view[hidden] { display: none; }
@keyframes slide-in { from { transform: translateY(-20px); opacity: 0; } }
