:root{
  --bg:#0f1720;
  --card:#0b1220;
  --accent:#00b894;
  --muted:#98a0ac;
  --text:#e6eef6;
  --glass: rgba(255,255,255,0.03);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

/* Prevent any accidental horizontal scrolling and ensure elements respect their container */
html, body, #app-shell { overflow-x: hidden; /* clamp lateral overflow globally */ }
#app-shell { -webkit-overflow-scrolling: touch; box-sizing: border-box; }

/* Ensure images and large content scale responsively and never exceed their container width */
img, .hero-img, .logo-image { max-width: 100%; width: 100%; height: auto; display: block; box-sizing: border-box; }

/* Make tables wrap and avoid causing sideways scroll */
table { width: 100%; table-layout: fixed; border-collapse: collapse; box-sizing: border-box; }
th, td { word-break: break-word; overflow-wrap: break-word; }

/* Ensure dropdowns, modals and other full-width components honor padding and do not overflow */
.dropdown, .modal-inner, .catalog-list, .catalog-item, .server, .list, .catalog-full {
  box-sizing: border-box;
  max-width: 100%;
  overflow-x: hidden;
}

/* Constrain long inline text/links to wrap instead of forcing width growth */
a, .muted, .nav-label, .circle-label { word-break: break-word; overflow-wrap: break-word; }

/* Keep buttons and inputs from exceeding container on tiny screens */
button, input, .nav-btn { max-width: 100%; box-sizing: border-box; }

/* Small tweak: ensure bottom nav items shrink safely */
.bottom-nav .nav-btn { min-width: 0; }
*{box-sizing:border-box}
html,body,#app-shell{height:100%}
body{
  margin:0;
  background:linear-gradient(180deg,var(--bg),#071021);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  padding:10px;
  display:flex;
  align-items:stretch;
  justify-content:center;
  overflow-x:hidden; /* prevent lateral scrolling */
}
#app-shell{
  width:100%;
  max-width:420px; /* tighter mobile width */
  display:flex;
  flex-direction:column;
  gap:10px;
  height:100vh; /* fill viewport to manage vertical layout */
  padding-bottom:12px;
}
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:8px 12px; /* slightly more horizontal padding for alignment */
  background:transparent;
}
.brand{font-weight:700;color:var(--text);font-size:16px}
.nav{
  display:flex;
  gap:6px;
  align-items:center;
  flex-wrap:nowrap; /* keep buttons on a single row */
  width:100%;
  overflow:visible; /* allow dropdown to escape the nav row */
  position:relative;
}

/* bottom navigation bar styling */
.bottom-nav{
  display:flex;
  gap:6px;
  align-items:center;
  padding:8px;
  background:transparent;
  border-radius:12px;
  width:100%;
  box-sizing:border-box;
}
.bottom-nav .nav-btn{
  flex:1 1 auto;
  min-height:48px;
}
.nav-btn{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:3px;
  background:transparent;
  border:1px solid rgba(255,255,255,0.04);
  color:var(--text);
  padding:6px 6px;
  border-radius:10px;
  min-height:48px;
  flex:1 1 auto; /* responsive buttons that share space */
  min-width:0;
  font-size:11px;
}
.nav-btn .nav-icon{line-height:1}
.nav-btn .nav-icon svg{display:block}
.nav-label{font-size:10px;color:var(--muted);margin-top:1px}
.nav-btn.active{background:var(--accent);color:#042018;border-color:transparent}

/* Bell badge (small red/accent circle) */
.bell-badge{
  position:absolute;
  top:2px;
  right:6px;
  min-width:18px;
  height:18px;
  padding:0 5px;
  border-radius:9px;
  background:var(--accent);
  color:#042018;
  font-weight:700;
  font-size:11px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  transform:translate(6px,-6px);
  box-shadow:0 2px 6px rgba(0,0,0,0.4);
}
.bell-badge.hidden{display:none}
.dropdown-wrap{
  /* Place bell + menu inline with the topbar title and anchored to the right */
  position:relative;
  top:0;
  right:0;
  margin-left:auto; /* push to far right of the header row */
  width:auto;
  z-index:110;
  display:flex;
  gap:8px;
  align-items:center;
}
.dropdown{
  position:absolute;
  right:0;
  top:44px;
  list-style:none;
  margin:0;
  padding:8px;
  width:86vw;
  max-width:300px;
  background:var(--card);
  border-radius:10px;
  box-shadow:0 8px 20px rgba(2,6,12,0.6);
  z-index:120; /* ensure dropdown appears above content */
}
.dropdown.hidden{display:none}
.dropdown li{margin:6px 0}
.menu-item{
  background:transparent;border:none;color:var(--text);text-align:left;padding:8px 10px;width:100%;border-radius:8px
}
.menu-item:hover{background:rgba(255,255,255,0.02)}
.app-content{
  display:block;
  padding:0 0 8px 0;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  flex:1 1 auto; /* let main content grow and scroll vertically inside viewport */
}
.card{
  background:var(--card);
  padding:12px;
  border-radius:12px;
  box-shadow: 0 6px 18px rgba(3,6,12,0.6);
  min-height:56px;
  margin-bottom:8px;
}
.row{display:flex;gap:8px;align-items:center}
.row.between{justify-content:space-between}
.label{font-size:13px;color:var(--muted);margin-bottom:6px}
.big{font-size:22px;font-weight:600;word-break:break-word}
.small-actions{display:flex;flex-direction:column;gap:8px}
.card button{background:var(--accent);border:none;color:#042018;padding:8px 12px;border-radius:8px;font-weight:600}
input[type="number"], input[type="text"], input[type="password"]{
  flex:1;padding:10px;border-radius:8px;border:1px solid rgba(255,255,255,0.04);background:var(--glass);color:var(--text);min-width:0
}
.list{
  /* Let the main app-content handle scrolling; avoid internal scrollable boxes */
  display:flex;
  flex-direction:column;
  gap:8px;
  margin-top:8px;
  padding-right:6px;
}
.server{
  padding:10px;border-radius:8px;background:linear-gradient(90deg, rgba(255,255,255,0.02), transparent);
  display:flex;justify-content:space-between;gap:8px;align-items:center;font-size:13px
}
.server .meta{color:var(--muted);font-size:12px}
.muted{color:var(--muted);font-size:12px;margin-top:8px}
.footer{font-size:12px;text-align:center;opacity:0.9}
.switch{position:relative;display:inline-block;width:52px;height:30px}
.switch input{opacity:0;width:0;height:0}
.slider{position:absolute;cursor:pointer;top:0;left:0;right:0;bottom:0;background:#2b3540;border-radius:34px;transition:.2s}
.slider:before{position:absolute;content:"";height:24px;width:24px;left:3px;bottom:3px;background:white;border-radius:50%;transition:.2s}
.switch input:checked + .slider{background:var(--accent)}
.switch input:checked + .slider:before{transform:translateX(22px)}
.modal{position:fixed;inset:0;background:rgba(2,6,12,0.6);display:flex;align-items:center;justify-content:center;padding:12px}
.modal.hidden{display:none}
/* Make modal inner vertically constrained and scrollable for long admin lists */
.modal-inner{
  width:100%;
  max-width:420px;
  background:var(--card);
  padding:12px;
  border-radius:12px;
  display:flex;
  flex-direction:column;
  max-height: calc(100vh - 40px); /* keep some breathing room from viewport edges */
  overflow:hidden; /* children handle scrolling */
}
.modal-title{font-weight:700;margin-bottom:8px}
.modal-body{
  margin-bottom:12px;
  padding-right:8px;
  /* Modal content will not create internal scrolls; the modal-inner controls overall size */
}
.modal-actions{display:flex;gap:8px;justify-content:flex-end;flex-shrink:0}
.modal button{padding:8px 12px;border-radius:8px;border:none;background:var(--accent);color:#042018}
.small-btn{background:transparent;border:1px solid rgba(255,255,255,0.04);color:var(--text);padding:8px 10px;border-radius:8px}
/* Catalog full-page styles */
.catalog-full{
  display:flex;
  flex-direction:column;
  gap:10px;
  padding-bottom:12px;
}
.catalog-header{padding:6px 2px}
.catalog-list{
  display:flex;
  flex-direction:column;
  gap:10px;
  padding:6px 0;
  /* Avoid internal scrolling; main viewport scrolls instead */
}
.catalog-item{
  padding:12px;
  border-radius:10px;
  background:linear-gradient(90deg, rgba(255,255,255,0.02), transparent);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}

/* keep the small responsive tweak */
@media (max-height:640px){
  #app-shell{gap:8px;padding-bottom:8px}
}

/* Hero image shown on Home above balances */
.hero-img{
  width:100%;
  height:140px;
  border-radius:10px;
  object-fit:cover;
  display:block;
  margin-bottom:10px;
  background:linear-gradient(90deg, rgba(0,0,0,0.15), rgba(255,255,255,0.02));
}

/* Circular action buttons under balances on Home (refined/professional) */
.action-circles{
  display:flex;
  gap:8px;
  justify-content:space-between;
  margin-top:8px;
  align-items:center;
}
.circle-btn{
  flex:1 1 0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:4px;
  padding:2px;
  background:transparent;
  border:0;
  cursor:pointer;
  -webkit-tap-highlight-color: transparent;
}
.circle-icon{
  width:34px;
  height:34px;
  border-radius:50%;
  /* subtle frosted glass with soft vertical gradient */
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:800;
  color:var(--text);
  border:1px solid rgba(255,255,255,0.05);
  box-shadow: 0 6px 12px rgba(2,6,12,0.45), inset 0 1px 0 rgba(255,255,255,0.02);
  transition: transform .12s ease, box-shadow .12s ease;
  font-size:13px;
}
.circle-label{
  font-size:10px;
  color:var(--muted);
  text-align:center;
  line-height:1.1;
  max-width:44px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.circle-btn:hover .circle-icon{
  transform: translateY(-1.5px);
  box-shadow: 0 7px 14px rgba(2,6,12,0.55), inset 0 1px 0 rgba(255,255,255,0.03);
}
.circle-btn:active .circle-icon{
  transform: translateY(1px) scale(.995);
  box-shadow: 0 5px 10px rgba(2,6,12,0.36);
}

/* Accent variation when circle is meant to highlight primary action */
.circle-btn.primary .circle-icon{
  background: linear-gradient(180deg, rgba(0,184,148,0.14), rgba(0,184,148,0.05));
  border-color: rgba(0,184,148,0.10);
  color: #042018;
  font-weight:800;
}

/* Company logo under the action circles */
.company-logo{
  background:transparent;
  border:1px solid rgba(255,255,255,0.04);
  padding:6px 10px;
  border-radius:10px;
  color:var(--text);
  display:flex;
  align-items:center;
  gap:8px;
  cursor:pointer;
  justify-content:center;
}
.company-logo .logo-mark{
  font-weight:800;
  color:var(--accent);
  letter-spacing:0.6px;
  font-size:14px;
  padding-right:6px;
}
.company-logo {font-size:13px}

/* Small inline logo image used on Home (tappable, opens company modal) */
.logo-image{
  width:88%;
  max-width:320px;
  height:86px;
  object-fit:cover;
  border-radius:10px;
  border:1px solid rgba(255,255,255,0.04);
  box-shadow: 0 8px 18px rgba(2,6,12,0.45);
  cursor:pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.logo-image:hover{ transform: translateY(-3px); box-shadow: 0 12px 26px rgba(2,6,12,0.55); }

/* Referral table: more ordered, compact and mobile-friendly */
.table-wrap{
  width:100%;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  border-radius:10px;
  background:transparent;
  padding-bottom:6px;
}
.ref-table{
  width:100%;
  border-collapse:collapse;
  font-size:13px;
  min-width:720px; /* allow horizontal scroll on very small viewports while preserving column proportions */
}
.ref-table thead th{
  position:sticky;
  top:0;
  background:linear-gradient(180deg, rgba(11,18,32,0.96), rgba(11,18,32,0.94));
  padding:10px 8px;
  text-align:left;
  font-weight:700;
  border-bottom:1px solid rgba(255,255,255,0.06);
  z-index:10;
}
.ref-table tbody td{
  padding:10px 8px;
  border-bottom:1px solid rgba(255,255,255,0.03);
  vertical-align:middle;
  color:var(--text);
}
.ref-table .th-left{text-align:left;}

/* zebra rows and subtle separators for readability */
.ref-row.even{ background: linear-gradient(90deg, rgba(255,255,255,0.005), transparent); }
.ref-row.odd{ background: transparent; }

/* compact column sizing helpers */
.ref-username{ width:24%; max-width:220px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ref-id{ width:18%; max-width:160px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--muted); font-size:12px }
.ref-role{ width:10%; text-transform:capitalize; color:var(--muted); font-size:12px }
.ref-code{ width:12%; color:var(--muted); font-size:12px }
.ref-referred{ width:12%; color:var(--muted); font-size:12px }
.ref-level{ width:6%; text-align:center; font-weight:700; color:var(--accent) }
.ref-created{ width:18%; text-align:right; color:var(--muted); font-size:12px }

/* ensure small devices don't overflow the whole app; the modal/company view already allows full-screen */
.table-wrap::-webkit-scrollbar { height:8px; }
.table-wrap::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.04); border-radius:6px; }

/* Full-screen company modal styles */
.modal.company-modal{
  align-items:flex-start;
  justify-content:flex-start;
}
.modal.company-modal .modal-inner{
  width:100%;
  max-width:100%;
  height:100vh;
  max-height:100vh;
  border-radius:0;
  padding:18px;
  box-shadow:none;
}
.modal.company-modal .modal-title{font-size:18px}
.modal.company-modal .modal-body{overflow:auto;padding-right:6px}
.modal.company-modal .modal-actions{position:fixed;bottom:18px;right:18px;left:auto;z-index:140}