/* XJETON core — application shell: sidebar, topbar, content, right rail, mobile tab bar, guest layout. */

.app {
  display: grid;
  grid-template-columns: var(--sb-w) minmax(0, 1fr) var(--rail-w);
  min-height: 100vh; min-height: 100dvh;
}

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; padding: 16px 18px 12px; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; flex: none;
  background: linear-gradient(135deg, #ffd35a, var(--brand-2)); color: var(--brand-ink);
  box-shadow: 0 8px 22px rgba(255, 138, 0, .32), inset 0 1px 0 rgba(255, 255, 255, .45);
}
.brand-mark .ic { width: 26px; height: 26px; stroke-width: 2.2; }
.brand-mark.sm { width: 32px; height: 32px; border-radius: 10px; }
.brand-mark.sm .ic { width: 19px; height: 19px; }
.brand-name { line-height: 1.35; padding: 1px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 150px; font-size: 19px; font-weight: 900; letter-spacing: .12em; background: linear-gradient(90deg, #ffe08a, var(--brand) 55%, var(--brand-2)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
[data-theme="light"] .brand-name { background: linear-gradient(90deg, #c77700, #e68a00); -webkit-background-clip: text; background-clip: text; }

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh; z-index: 40;
  display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
  background: var(--bg-2); border-right: 1px solid var(--line);
  padding-left: var(--sal); transition: width .25s var(--ease);
}
.nav { flex: 1 1 auto; padding: 2px 12px 12px; }
.nav-group { margin-bottom: 18px; }
.nav-title { padding: 8px 10px 6px; font-size: 10.5px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 42px; padding: 0 12px;
  margin-bottom: 2px; border-radius: 12px; color: var(--text-2); font-weight: 650; font-size: 14px; text-align: left; white-space: nowrap;
  transition: background-color var(--t), color var(--t);
}
.nav-item .ic { width: 22px; height: 22px; }
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) { .nav-item:hover { background: var(--surface-2); color: var(--text); } }
.nav-item.is-active {
  color: var(--text); background: linear-gradient(90deg, rgba(76, 141, 255, .16), rgba(76, 141, 255, .05));
}
.nav-item.is-active::before { content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 3px; background: var(--brand); box-shadow: 0 0 12px var(--brand); }
.nav-item.is-active .ic { color: var(--brand); }
.nav-logout { color: var(--danger); }
.nav-logout:hover { background: var(--danger-soft); color: var(--danger); }
.sidebar-foot { padding: 12px 14px calc(16px + var(--sab)); border-top: 1px solid var(--line); }

/* collapsed (desktop) */
.sb-collapsed .app { grid-template-columns: var(--sb-w-min) minmax(0, 1fr) var(--rail-w); }
.sb-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sb-collapsed .brand-name, .sb-collapsed .nav-label, .sb-collapsed .nav-title, .sb-collapsed .nav-item .pill { display: none; }
.sb-collapsed .nav { padding-left: 12px; padding-right: 12px; }
.sb-collapsed .nav-title { display: block; height: 1px; padding: 0; margin: 8px 8px 12px; background: var(--line); font-size: 0; }
.sb-collapsed .nav-item { justify-content: center; padding: 0; }
.sb-collapsed .nav-item::after {
  content: attr(data-tip); position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%) translateX(-4px);
  background: var(--surface-3); color: var(--text); padding: 6px 12px; border-radius: 9px; font-size: 13px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: all var(--t); box-shadow: var(--shadow-sm); z-index: 80;
}
.sidebar { overflow-x: visible; }
.sb-collapsed .sidebar { overflow: visible; }
@media (hover: hover) { .sb-collapsed .nav-item:hover::after { opacity: 1; transform: translateY(-50%); } }

/* ---------- main column ---------- */
.main-wrap { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px;
  height: calc(var(--top-h) + var(--sat)); padding: var(--sat) 22px 0;
  background: var(--topbar-bg); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
}
.topbar-spacer { flex: 1; }
.topbar-brand { display: none; align-items: center; gap: 10px; font-weight: 900; letter-spacing: .1em; font-size: 17px; }
.menu-btn { background: linear-gradient(180deg, #ffc23d, var(--brand-2)); color: var(--brand-ink); border-radius: 12px; width: 36px; height: 36px; padding: 0; box-shadow: 0 4px 14px rgba(255, 138, 0, .28); }
.menu-btn:hover { background: linear-gradient(180deg, #ffd15e, #ff9a1f) !important; color: var(--brand-ink) !important; }
.chip-balance { display: none; }

.th-ic { display: none; }
[data-theme-pref="dark"] .th-dark, [data-theme-pref="light"] .th-light, [data-theme-pref="system"] .th-system { display: inline-flex; }

.content { width: 100%; max-width: 1120px; margin: 0 auto; padding: 20px 22px 44px; outline: none; }

/* ---------- right rail ---------- */
.rail { position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; padding: 18px 18px 18px 4px; display: flex; flex-direction: column; gap: 12px; }
.rail:empty { display: none; }

/* ---------- mobile tab bar ---------- */
.tabbar { display: none; }
.scrim { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 70; background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: xj-fade .2s both; }
@keyframes xj-fade { from { opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1239px) {
  .app, .sb-collapsed .app { grid-template-columns: var(--sb-w) minmax(0, 1fr); }
  .sb-collapsed .app { grid-template-columns: var(--sb-w-min) minmax(0, 1fr); }
  .rail { display: none; }
  .chip-balance { display: inline-flex; }
}

@media (max-width: 899px) {
  .app, .sb-collapsed .app { display: block; }
  .sidebar, .sb-collapsed .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(86vw, 320px); z-index: 80; overflow-y: auto; overflow-x: hidden;
    transform: translateX(-102%); transition: transform .3s var(--ease); box-shadow: none; padding-top: var(--sat);
  }
  .sb-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .sb-collapsed .brand-name, .sb-collapsed .nav-label, .sb-collapsed .nav-title { display: revert; }
  .sb-collapsed .nav-title { height: auto; padding: 10px 12px 8px; margin: 0; background: none; font-size: 11px; }
  .sb-collapsed .nav-item { justify-content: flex-start; padding: 0 14px; }
  .sb-collapsed .nav-item::after { display: none; }
  .sb-collapsed .nav-item .pill { display: inline-flex; }
  .sb-collapsed .brand { justify-content: flex-start; padding: 16px 18px 12px; }
  .menu-btn { display: none; }
  .topbar { padding-left: calc(14px + var(--sal)); padding-right: calc(14px + var(--sar)); }
  .topbar-brand { display: flex; }
  .content { padding: 14px calc(14px + var(--sar)) calc(var(--tab-h) + var(--sab) + 22px) calc(14px + var(--sal)); }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid; grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tab-h) + var(--sab)); padding: 6px calc(8px + var(--sar)) var(--sab) calc(8px + var(--sal));
    background: var(--topbar-bg); border-top: 1px solid var(--line);
    -webkit-backdrop-filter: saturate(1.4) blur(16px); backdrop-filter: saturate(1.4) blur(16px);
  }
  .tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 700; border-radius: 14px; transition: color var(--t); min-width: 0; }
  .tab .ic { width: 24px; height: 24px; transition: transform .25s var(--ease); }
  .tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
  .tab.is-active { color: var(--brand); }
  .tab.is-active .ic { transform: translateY(-2px) scale(1.08); }
  .tab.is-active::before { content: ""; position: absolute; top: -7px; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: var(--brand); box-shadow: 0 2px 12px var(--brand); }
  .tab:active { background: var(--surface-2); }
  .page-head { margin-bottom: 14px; }
}

@media (max-width: 560px) {
  .hide-sm { display: none !important; }
  .show-xs { display: block; }
  .topbar { gap: 4px; }
  .topbar .dropdown > .icon-btn { padding: 0 8px; min-width: 38px; }
  #themeBtn { display: none; }
  .topbar .lang-code { display: none; }
  .chip-balance { height: 36px; padding: 0 12px; }
}

/* ---------- guest layout ---------- */
.guest-tools { position: fixed; z-index: 40; top: calc(12px + var(--sat)); right: calc(14px + var(--sar)); display: flex; gap: 6px; padding: 4px; background: var(--topbar-bg); border: 1px solid var(--line); border-radius: 14px; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.guest-main { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: calc(72px + var(--sat)) 16px calc(32px + var(--sab)); position: relative; }
body.is-guest::before {
  content: ""; position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 50% at 15% 0%, var(--hero-a), transparent 70%),
    radial-gradient(50% 45% at 100% 100%, var(--hero-b), transparent 70%);
}
body.is-error .content { max-width: 720px; }

.brand, .topbar-brand { min-width: 0; }

.tb-name { max-width: 150px; }
@media (max-width: 560px) { .tb-name { max-width: 92px; } }

/* pages that need the full width (games): add body_class 'no-rail' */
.no-rail .app { grid-template-columns: var(--sb-w) minmax(0, 1fr); }
.sb-collapsed .no-rail .app { grid-template-columns: var(--sb-w-min) minmax(0, 1fr); }
.no-rail .rail { display: none; }
@media (max-width: 899px) { .no-rail .app, .sb-collapsed .no-rail .app { grid-template-columns: minmax(0, 1fr); } }

/* admin: always full width, left-aligned, identical on every page */
.adm-wide .content { max-width: none; margin: 0; }
