/* EazyTrade customer app shell — light theme, sidebar nav. Distinct product
   surface from the dark /chart terminal; shared by Dashboard now and
   Học viện/Affiliate/Hướng dẫn later. */
:root {
  --shell-bg: #f4f6fa;
  --shell-panel: #ffffff;
  --shell-panel-2: #f0f3f9;
  --shell-border: #e4e8f0;
  --shell-text: #101828;
  --shell-muted: #667085;
  --shell-muted-2: #98a2b3;
  --shell-brand: #2f7de0;
  --shell-brand-deep: #1d63bd;
  --shell-brand-soft: rgba(47, 125, 224, .10);
  --shell-info: #4da3ff;
  --shell-green: #00c853;
  --shell-danger: #e5484d;
  --shell-sidebar-w: 240px;
  --shell-content-max: 1240px;
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --font-display: "Montserrat", "Segoe UI", sans-serif;
  --shell-shadow-sm: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.05);
  --shell-shadow-md: 0 4px 14px rgba(16,24,40,.06), 0 2px 6px rgba(16,24,40,.05);
  --shell-shadow-lg: 0 12px 32px rgba(16,24,40,.10), 0 4px 12px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.app-body {
  background: var(--shell-bg);
  color: var(--shell-text);
  font-family: var(--font-ui);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app-shell { display: flex; min-height: 100vh; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@keyframes shellFadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.shell-fade-up { animation: shellFadeUp .4s cubic-bezier(.16,1,.3,1) both; }
.shell-fade-up.d1 { animation-delay: .04s; }
.shell-fade-up.d2 { animation-delay: .08s; }
.shell-fade-up.d3 { animation-delay: .12s; }
.shell-fade-up.d4 { animation-delay: .16s; }

@keyframes shellShimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.shell-skel {
  border-radius: 8px; color: transparent !important; pointer-events: none;
  background: linear-gradient(90deg, var(--shell-panel-2) 25%, #e9edf4 37%, var(--shell-panel-2) 63%);
  background-size: 400% 100%;
  animation: shellShimmer 1.4s ease infinite;
}

/* ---------- sidebar ---------- */
.app-sidebar {
  width: var(--shell-sidebar-w);
  flex: none;
  background: var(--shell-panel);
  border-right: 1px solid var(--shell-border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh; /* mobile browser chrome shrinks the real visible viewport — 100vh alone pushes the sidebar footer (lang switch/logout) off-screen */
  overflow-y: auto;
}
.app-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit;
  padding: 4px 8px 22px;
}
.app-brand svg { width: 24px; height: 24px; }
.app-brand .wordmark { font-size: 17px; font-family: var(--font-display); font-weight: 700; }
.app-brand .wordmark .trade { color: var(--shell-brand); font-weight: 600; }

.app-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.app-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--shell-muted); text-decoration: none;
  font-size: 14px; font-weight: 500;
  position: relative;
  transition: background .15s ease, color .15s ease;
}
.app-nav-item svg { width: 18px; height: 18px; flex: none; transition: transform .15s ease; }
.app-nav-item:hover { background: var(--shell-panel-2); color: var(--shell-text); }
.app-nav-item:hover svg { transform: translateX(1px); }
.app-nav-item.active { background: var(--shell-brand-soft); color: var(--shell-brand); font-weight: 600; }
.app-nav-item.active::before {
  content: ""; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--shell-brand);
}
.app-nav-item.disabled {
  color: #b0b7c3; cursor: default; pointer-events: none;
}
.app-nav-soon {
  margin-left: auto; font-size: 10px; font-weight: 700;
  background: #eef1f6; color: #98a2b3;
  border-radius: 999px; padding: 2px 7px;
}
.app-nav-badge {
  margin-left: auto; font-size: 10.5px; font-weight: 800;
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 999px;
  background: var(--shell-danger); color: #fff;
  display: flex; align-items: center; justify-content: center; flex: none;
}

.app-sidebar-foot {
  border-top: 1px solid var(--shell-border);
  padding-top: 12px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--shell-muted);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.app-lang-switch { display: flex; gap: 4px; background: #f0f3f9; border-radius: 8px; padding: 3px; }
.app-lang-switch button {
  flex: 1;
  border: none; background: none; cursor: pointer;
  padding: 6px 10px; border-radius: 6px; font-size: 12.5px; font-weight: 600;
  color: var(--shell-muted); display: flex; align-items: center; justify-content: center; gap: 6px;
}
.app-lang-switch button.active { background: var(--shell-panel); color: var(--shell-text); box-shadow: 0 1px 2px rgba(16,24,40,.06); }
.lang-flag { width: 18px; height: auto; display: inline-block; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(16,24,40,.08); }

/* ---------- account popup (sidebar foot) ---------- */
.app-account-wrap { position: relative; }
.app-account-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: none; cursor: pointer; text-align: left;
  padding: 8px 6px; border-radius: 8px; font-family: inherit;
}
.app-account-btn:hover { background: var(--shell-panel-2); }
.app-account-avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--shell-brand), var(--shell-brand-deep));
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.app-account-info { min-width: 0; display: flex; flex-direction: column; }
.app-account-name { font-size: 12.5px; font-weight: 700; color: var(--shell-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-account-email { font-size: 11px; color: var(--shell-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-account-menu {
  position: absolute; bottom: calc(100% + 8px); left: 0; right: 0;
  background: var(--shell-panel); border: 1px solid var(--shell-border); border-radius: 12px;
  box-shadow: var(--shell-shadow-md); overflow: hidden; z-index: 50;
  display: none;
}
.app-account-menu.show { display: block; animation: shellFadeUp .15s ease both; }
.app-account-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: none; border: none; color: var(--shell-text); font-size: 13px;
  padding: 10px 14px; cursor: pointer; font-family: inherit;
}
.app-account-menu button svg { width: 15px; height: 15px; flex: none; color: var(--shell-muted); }
.app-account-menu button:hover { background: var(--shell-panel-2); }
.app-account-menu button.app-menu-danger { color: var(--shell-danger); border-top: 1px solid var(--shell-border); }
.app-account-menu button.app-menu-danger svg { color: var(--shell-danger); }

/* ---------- main column ---------- */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Mobile-only top bar — logo + hamburger to open the sidebar drawer.
   Desktop has no top bar at all (lang switch + logout live in the sidebar). */
.app-topbar-mobile { display: none; }
.app-topbar-brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: inherit;
}
.app-topbar-brand svg { width: 20px; height: 20px; flex: none; }
.app-topbar-brand .wordmark { font-size: 15px; font-family: var(--font-display); font-weight: 700; }
.app-topbar-brand .wordmark .trade { color: var(--shell-brand); font-weight: 600; }
.app-topbar-mobile .mobile-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--shell-text);
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.app-topbar-mobile .mobile-toggle svg { width: 22px; height: 22px; flex: none; }

.app-content { flex: 1; padding: 28px; width: 100%; }
.app-content-inner { max-width: var(--shell-content-max); margin: 0 auto; }

/* ---------- shared widgets used across dashboard/academy/etc ---------- */
.app-card {
  background: var(--shell-panel);
  border: 1px solid var(--shell-border);
  border-radius: 14px;
  padding: 22px;
  overflow-x: auto;
  box-shadow: var(--shell-shadow-sm);
  transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
}
.app-card h2 {
  font-family: var(--font-display);
  font-size: 15.5px; font-weight: 700; margin: 0 0 14px; letter-spacing: -.01em;
}
.app-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.app-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 9px; cursor: pointer;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  padding: 9px 16px; text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, opacity .15s ease;
}
.app-btn:active:not(:disabled) { transform: scale(.97); }
.app-btn-primary { background: var(--shell-brand); color: #fff; box-shadow: 0 4px 12px -2px rgba(47,125,224,.4); }
.app-btn-primary:hover:not(:disabled) { background: var(--shell-brand-deep); transform: translateY(-1px); box-shadow: 0 6px 16px -2px rgba(47,125,224,.45); }
.app-btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.app-btn-ghost { background: var(--shell-panel-2); color: var(--shell-text); }
.app-btn-ghost:hover:not(:disabled) { background: #e4e9f2; }
.app-btn-accent { background: var(--shell-green); color: #fff; }
.app-btn-accent:hover:not(:disabled) { background: #00a844; transform: translateY(-1px); }
.app-btn-accent:disabled { opacity: .6; cursor: not-allowed; }
.app-btn-done {
  background: var(--shell-panel-2); color: var(--shell-muted); cursor: default; pointer-events: none;
  border: 1px dashed var(--shell-border);
}
.app-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
}
.app-badge-paid { background: color-mix(in srgb, var(--shell-green) 15%, transparent); color: #067a3a; }
.app-badge-pending { background: color-mix(in srgb, #f79009 15%, transparent); color: #b54708; }
.app-badge-failed, .app-badge-refunded { background: color-mix(in srgb, var(--shell-danger) 12%, transparent); color: #c0202b; }

.app-status-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 700;
  padding: 6px 14px; border-radius: 999px;
}
.app-status-chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.app-status-chip.is-active { background: color-mix(in srgb, var(--shell-green) 14%, transparent); color: #067a3a; }
.app-status-chip.is-active .dot { background: var(--shell-green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--shell-green) 22%, transparent); }
.app-status-chip.is-trial { background: color-mix(in srgb, var(--shell-info) 14%, transparent); color: #1d63bd; }
.app-status-chip.is-trial .dot { background: var(--shell-info); box-shadow: 0 0 0 3px color-mix(in srgb, var(--shell-info) 22%, transparent); }
.app-status-chip.is-none { background: var(--shell-panel-2); color: var(--shell-muted); }
.app-status-chip.is-none .dot { background: var(--shell-muted-2); }

/* ---------- shared modals (Cập nhật thông tin / Đổi mật khẩu — injected by
   app-shell.js on every AppShell-mounted page). Own .app-modal-* names,
   distinct from any page-local .modal-* CSS (eg affiliate.html declares its
   own unused .modal-overlay) to avoid cross-page style bleed. ---------- */
.app-modal-overlay { display: none; position: fixed; inset: 0; background: rgba(16,24,40,.5); backdrop-filter: blur(2px); z-index: 60; align-items: center; justify-content: center; }
.app-modal-overlay.show { display: flex; animation: shellFadeUp .2s ease both; }
.app-modal-box { background: var(--shell-panel); border-radius: 14px; padding: 24px; width: 100%; max-width: 380px; box-shadow: var(--shell-shadow-lg); margin: 16px; }
.app-modal-box h3 { font-family: var(--font-display); margin: 0 0 16px; font-size: 16px; color: var(--shell-text); }
.app-modal-field { margin-bottom: 12px; }
.app-modal-field label { display: block; font-size: 12.5px; color: var(--shell-muted); margin-bottom: 5px; }
.app-modal-field input {
  width: 100%; border: 1px solid var(--shell-border); border-radius: 8px; padding: 9px 11px;
  font-family: inherit; font-size: 13.5px; color: var(--shell-text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.app-modal-field input:focus { outline: none; border-color: var(--shell-brand); box-shadow: 0 0 0 3px var(--shell-brand-soft); }
.app-modal-error { display: none; color: var(--shell-danger); font-size: 12.5px; margin-bottom: 10px; }
.app-modal-error.show { display: block; }
.app-modal-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .app-sidebar {
    position: fixed; left: 0; top: 0; z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 8px 0 24px rgba(16,24,40,.12);
  }
  .app-sidebar.open { transform: translateX(0); }
  .app-topbar-mobile {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--shell-border);
    background: var(--shell-panel);
    position: sticky; top: 0; z-index: 5;
  }
  .app-content { padding: 18px; }
  .app-grid-2 { grid-template-columns: 1fr; }
  table.app-table { font-size: 12px; }
  table.app-table th, table.app-table td { padding: 8px 6px; }
  .app-sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 35;
  }
  .app-sidebar-backdrop.show { display: block; }
}
