* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #070A14;
  color: #E8EEF7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column;
}

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: #0A0E1A;
  border-bottom: 1px solid #1F2942;
}
.brand { font-weight: 800; letter-spacing: 2px; display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 28px; height: 28px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #00E5FF, #0091EA);
  color: #001018; font-weight: 900;
}
.brand .sub { font-size: .65rem; color: #8590A6; letter-spacing: 1px; font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-left: 24px; }
.tab {
  background: #131A2E; color: #8590A6; border: 1px solid #1F2942;
  border-radius: 8px; padding: 6px 16px; font-size: .85rem; font-weight: 700;
  cursor: pointer; transition: all .12s;
}
.tab:hover { color: #E8EEF7; }
.tab.active {
  background: linear-gradient(135deg, rgba(0,229,255,0.18), rgba(0,229,255,0.05));
  color: #00E5FF; border-color: rgba(0,229,255,0.4);
}
.controls { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.hidden { display: none !important; }
.locked-hide { display: none !important; }
.wsbtn {
  background: #131A2E; color: #8590A6; border: 1px solid #1F2942;
  border-radius: 8px; padding: 6px 12px; font-size: .8rem; font-weight: 700;
  cursor: pointer; transition: all .12s;
}
.wsbtn:hover { color: #00E5FF; border-color: rgba(0,229,255,0.4); }
select.wsbtn { padding: 5px 8px; max-width: 150px; }
.wsbtn.active {
  background: linear-gradient(135deg, rgba(0,229,255,0.20), rgba(0,229,255,0.06));
  color: #00E5FF; border-color: rgba(0,229,255,0.5);
}
.presets { display: flex; gap: 3px; }
.pbtn {
  background: #131A2E; color: #8590A6; border: 1px solid #1F2942;
  border-radius: 7px; padding: 5px 9px; font-size: .72rem; font-weight: 700;
  letter-spacing: -1px; cursor: pointer; transition: all .12s; min-width: 30px;
}
.pbtn:hover { color: #00E5FF; border-color: rgba(0,229,255,0.4); }

#workspace { flex: 1; padding: 6px; min-height: 0; overflow: auto; }
.grid-stack { background: transparent; }
/* .gpanel es el grid-stack-item-content -> llena el item dragueable */
.gpanel {
  background: #0A0E1A; border: 1px solid #1F2942; border-radius: 10px;
  display: flex; flex-direction: column; overflow: hidden;
}
.grid-stack-item-content { inset: 0; }
.gtitle { cursor: move; }  /* el handle de arrastre */
.gtitle {
  padding: 6px 12px 3px; font-size: .82rem; font-weight: 800; color: #00E5FF;
  display: flex; justify-content: space-between; align-items: baseline;
  text-transform: uppercase; letter-spacing: .3px;
}
.gtitle .gsym { color: #8590A6; font-weight: 700; font-size: .72rem; letter-spacing: 1px; }
.gxr-dte { display: inline-flex; gap: 3px; margin-left: 10px; }
.gxr-dte .dbtn {
  background: #131A2E; color: #8590A6; border: 1px solid #1F2942; border-radius: 5px;
  padding: 2px 7px; font-size: .62rem; font-weight: 700; cursor: pointer; letter-spacing: .3px;
}
.gxr-dte .dbtn:hover { color: #E8EEF7; }
.gxr-dte .dbtn.active { background: rgba(0,229,255,0.15); color: #00E5FF; border-color: rgba(0,229,255,0.45); }
.gsub { padding: 0 12px 5px; font-size: .68rem; font-weight: 600; color: #8590A6;
  border-bottom: 1px solid #1F2942; }
.gpanel canvas { flex: 1; width: 100%; min-height: 0; cursor: crosshair; }
.summary { flex: 1; min-height: 0; overflow: auto; padding: 8px 14px; }
.summary .sreg { text-align: center; font-weight: 800; font-size: 1.05rem; letter-spacing: .5px; margin-top: 4px; }
.summary .sregsub { text-align: center; color: #8590A6; font-size: .72rem; margin-bottom: 10px; }
.summary .srow { display: flex; justify-content: space-between; padding: 5px 2px;
  border-bottom: 1px solid #131A2E; font-size: .82rem; }
.summary .srow span:first-child { color: #8590A6; }
.summary .srow span:last-child { font-weight: 700; }
#asset {
  background: #131A2E; color: #E8EEF7; border: 1px solid #1F2942;
  border-radius: 8px; padding: 6px 10px; font-size: .9rem;
}
.spot { font-weight: 800; font-size: 1.05rem; color: #00E5FF; min-width: 90px; text-align: right; }
.conn { font-size: .72rem; font-weight: 700; }
.conn.on { color: #00FF85; }
.conn.off { color: #FF1F66; }

#layout { flex: 1; display: flex; gap: 10px; padding: 10px; min-height: 0; }
.card {
  background: #0A0E1A; border: 1px solid #1F2942; border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
}
#chart-card { flex: 1; }
#profile-card { width: 220px; }
#oi-card { width: 220px; }
.card-head .oi-legend { margin-left: auto; font-size: .65rem; font-weight: 600; }
#oican { flex: 1; width: 100%; min-height: 0; }
#profile, #oican { cursor: ns-resize; }

/* ---- Login gate (bloquea toda la app) ---- */
.auth-gate {
  position: fixed; inset: 0; z-index: 3000; display: flex;
  align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #0b1426, #05070f);
}
.login-box {
  width: 340px; max-width: 90vw; background: #0C1322; border: 1px solid #243150;
  border-radius: 16px; padding: 28px 26px; box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  display: flex; flex-direction: column;
}
.login-brand { font-weight: 900; letter-spacing: 2px; font-size: 1.15rem; display: flex; align-items: center; gap: 10px; justify-content: center; }
.login-brand .logo { width: 30px; height: 30px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #00E5FF, #0091EA); color: #001018; font-weight: 900; }
.login-sub { text-align: center; color: #8590A6; font-size: .78rem; margin: 4px 0 20px; letter-spacing: 1px; }
.login-input {
  background: #131A2E; color: #E8EEF7; border: 1px solid #2A3A5C; border-radius: 10px;
  padding: 12px 14px; font-size: .95rem; outline: none; margin-bottom: 11px;
}
.login-input:focus { border-color: rgba(0,229,255,0.55); box-shadow: 0 0 0 3px rgba(0,229,255,0.12); }
.login-err { color: #FF1F66; font-size: .78rem; min-height: 16px; margin-bottom: 6px; text-align: center; }
.login-submit {
  background: linear-gradient(135deg, #00E5FF, #0091EA); color: #001018; border: none;
  border-radius: 10px; padding: 12px; font-size: .95rem; font-weight: 800; cursor: pointer; transition: filter .12s;
}
.login-submit:hover { filter: brightness(1.08); }

/* ---- Menú de usuario ---- */
.usermenu { position: relative; }
.user-btn {
  background: #131A2E; color: #E8EEF7; border: 1px solid #1F2942; border-radius: 8px;
  padding: 6px 12px; font-size: .82rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 7px;
}
.user-btn:hover { border-color: rgba(0,229,255,0.4); }
.user-btn .badge { background: linear-gradient(135deg, #00E5FF, #0091EA); color: #001018; font-size: .58rem; font-weight: 800; padding: 1px 6px; border-radius: 5px; letter-spacing: .5px; }
.user-drop {
  position: absolute; right: 0; top: 110%; background: #0C1322; border: 1px solid #243150;
  border-radius: 10px; padding: 6px; min-width: 150px; box-shadow: 0 12px 36px rgba(0,0,0,0.5); z-index: 50;
}
.user-drop button {
  display: block; width: 100%; text-align: left; background: transparent; color: #E8EEF7;
  border: none; border-radius: 7px; padding: 9px 12px; font-size: .85rem; cursor: pointer;
}
.user-drop button:hover { background: #131A2E; color: #00E5FF; }
.pf-label { color: #8590A6; font-size: .72rem; font-weight: 700; margin: 8px 0 4px; }

/* ---- Modal (guardar plantilla, etc.) ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000; display: flex;
  align-items: center; justify-content: center;
  background: rgba(3, 6, 14, 0.66); backdrop-filter: blur(3px);
  animation: modalFade .12s ease;
}
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  width: 380px; max-width: 92vw; background: #0C1322;
  border: 1px solid #243150; border-radius: 14px; padding: 20px 22px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.6); animation: modalPop .14s ease;
}
@keyframes modalPop { from { transform: translateY(8px) scale(.98); } to { transform: none; } }
.modal-title { font-size: 1.05rem; font-weight: 800; color: #00E5FF; letter-spacing: .3px; }
.modal-msg { font-size: .82rem; color: #8590A6; margin: 6px 0 14px; line-height: 1.4; white-space: pre-line; }
.modal-input {
  width: 100%; background: #131A2E; color: #E8EEF7; border: 1px solid #2A3A5C;
  border-radius: 9px; padding: 11px 13px; font-size: .95rem; outline: none;
}
.modal-input:focus { border-color: rgba(0,229,255,0.55); box-shadow: 0 0 0 3px rgba(0,229,255,0.12); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-btn {
  border-radius: 9px; padding: 9px 18px; font-size: .88rem; font-weight: 700; cursor: pointer;
  border: 1px solid transparent; transition: all .12s;
}
.modal-btn.ghost { background: transparent; color: #8590A6; border-color: #2A3A5C; }
.modal-btn.ghost:hover { color: #E8EEF7; border-color: #3A4A6C; }
.modal-btn.primary { background: linear-gradient(135deg, #00E5FF, #0091EA); color: #001018; }
.modal-btn.primary:hover { filter: brightness(1.08); }

/* ---- Modal de planes ---- */
.plans-box {
  width: 880px; max-width: 94vw; max-height: 92vh; overflow: auto;
  background: #0C1322; border: 1px solid #243150; border-radius: 16px;
  padding: 22px 24px; box-shadow: 0 24px 80px rgba(0,0,0,0.6); animation: modalPop .14s ease;
}
.plans-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.plans-title { font-size: 1.25rem; font-weight: 900; color: #00E5FF; letter-spacing: .3px; }
.plans-sub { font-size: .8rem; color: #8590A6; margin-top: 3px; }
.plans-x { background: transparent; border: none; color: #8590A6; font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.plans-x:hover { color: #E8EEF7; background: #131A2E; }
.plans-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 720px) { .plans-grid { grid-template-columns: 1fr; } }
.plan-card {
  position: relative; background: #0A0F1C; border: 1px solid #1F2942; border-radius: 14px;
  padding: 20px 18px; display: flex; flex-direction: column;
}
.plan-card.featured { border-color: rgba(0,229,255,0.55); box-shadow: 0 0 0 1px rgba(0,229,255,0.25), 0 12px 40px rgba(0,229,255,0.08); }
.plan-badge {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: linear-gradient(135deg, #00E5FF, #0091EA); color: #001018;
  font-size: .6rem; font-weight: 800; letter-spacing: .5px; padding: 3px 12px; border-radius: 20px; text-transform: uppercase;
}
.plan-name { font-size: 1.05rem; font-weight: 800; color: #E8EEF7; }
.plan-price { font-size: 2rem; font-weight: 900; color: #fff; margin: 6px 0 14px; }
.plan-price span { font-size: .8rem; font-weight: 600; color: #8590A6; }
.plan-feats { list-style: none; padding: 0; margin: 0 0 18px; flex: 1; }
.plan-feats li { font-size: .82rem; color: #B7C0D0; padding: 6px 0 6px 22px; position: relative; border-bottom: 1px solid #131A2E; }
.plan-feats li::before { content: "✓"; position: absolute; left: 0; color: #00FF85; font-weight: 800; }
.plan-btn {
  background: #131A2E; color: #E8EEF7; border: 1px solid #2A3A5C; border-radius: 10px;
  padding: 11px; font-size: .9rem; font-weight: 800; cursor: pointer; transition: all .12s;
}
.plan-btn:hover { border-color: rgba(0,229,255,0.5); color: #00E5FF; }
.plan-card.featured .plan-btn { background: linear-gradient(135deg, #00E5FF, #0091EA); color: #001018; border: none; }
.plan-card.featured .plan-btn:hover { filter: brightness(1.08); color: #001018; }
.plan-card.current { opacity: .92; }
.plan-card.current .plan-btn { background: #0A0F1C; color: #00FF85; border: 1px solid rgba(0,255,133,0.4); cursor: default; }
.plans-note { text-align: center; color: #FFB800; font-size: .82rem; margin-top: 16px; min-height: 18px; }

#tip {
  position: fixed; z-index: 999; display: none; pointer-events: none;
  background: #141E32; border: 1px solid #2a3a5c; border-radius: 6px;
  padding: 6px 9px; font-size: 11px; line-height: 1.5; color: #E8EEF7;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.card-head {
  padding: 8px 12px; font-size: .8rem; font-weight: 700; color: #00E5FF;
  border-bottom: 1px solid #1F2942; display: flex; align-items: center; gap: 12px;
}
.card-head .walls { color: #8590A6; font-weight: 600; font-size: .72rem; }
.card-head .updated { margin-left: auto; color: #8590A6; font-weight: 500; font-size: .68rem; }
#chart-wrap { position: relative; flex: 1; min-height: 0; }
#chart { position: absolute; inset: 0; }
#overlay { position: absolute; inset: 0; pointer-events: none; }
#profile { flex: 1; width: 100%; min-height: 0; }
