:root {
  --ink: #eef6f4;
  --muted: #9bb4b0;
  --line: rgba(238, 246, 244, 0.12);
  --accent: #2dd4a8;
  --accent2: #f0b429;
  --danger: #ff6b6b;
  --card: rgba(18, 42, 46, 0.88);
  --ok: #3ecf8e;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Syne", var(--font);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --pad: 14px;
  --sidebar-w: 248px;
  --header-h: 56px;
  --sidebar-bg: #0a171a;
  --surface: rgba(12, 28, 32, 0.72);
}

*, *::before, *::after { box-sizing: border-box; }
html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  width: 100%;
  max-width: 100vw;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(165deg, #071416 0%, #0b1c1f 50%, #10282d 100%);
}
img, svg, video { max-width: 100%; height: auto; }

.noise, .bg-orb { pointer-events: none; position: fixed; z-index: 0; }
.noise {
  inset: 0; opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.bg-orb { border-radius: 50%; filter: blur(50px); }
.orb-a { width: 55vw; height: 55vw; max-width: 240px; max-height: 240px; background: rgba(45,212,168,.2); top: 8%; left: -20vw; }
.orb-b { width: 50vw; height: 50vw; max-width: 200px; max-height: 200px; background: rgba(240,180,41,.14); bottom: 12%; right: -18vw; }

/* ===== App shell ===== */
.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
}

.sidebar-mask {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.sidebar-mask.open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  width: var(--sidebar-w);
  max-width: 86vw;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  padding: calc(12px + var(--safe-t)) 12px calc(12px + var(--safe-b));
  transform: translateX(-105%);
  transition: transform .22s ease;
  overflow: hidden;
}
.sidebar.open { transform: none; }

.sidebar-brand {
  flex: 0 0 auto;
  padding: 4px 8px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #19b98f);
  color: #042018;
  font-family: var(--display);
  font-weight: 800;
}
.brand-text {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text em {
  font-style: normal;
  color: var(--accent);
  margin-left: 2px;
}

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 4px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 12px 8px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { color: var(--ink); background: rgba(255,255,255,.05); }
.nav-item.active {
  color: var(--ink);
  background: rgba(45, 212, 168, .14);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-ico {
  width: 20px;
  text-align: center;
  font-style: normal;
  opacity: .9;
  flex: 0 0 auto;
}

.sidebar-foot {
  flex: 0 0 auto;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.sidebar-user {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
}
.sidebar-user .name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.sidebar-user .meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.sidebar-user .login-link {
  display: block;
  text-align: center;
  text-decoration: none;
  color: #042018;
  background: linear-gradient(135deg, var(--accent), #19b98f);
  padding: 11px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
}

.shell-main {
  flex: 1;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.shell-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--header-h);
  padding: calc(8px + var(--safe-t)) var(--pad) 8px;
  background: rgba(7, 20, 22, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.shell-title {
  flex: 1;
  min-width: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shell-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 55%;
}
.menu-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: var(--ink);
  cursor: pointer;
}
.menu-btn span {
  display: block;
  width: 16px;
  height: 2px;
  margin: 0 auto;
  background: currentColor;
  box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor;
}

.balance-pill {
  font-size: 11px;
  color: var(--accent2);
  background: rgba(240,180,41,.12);
  border: 1px solid rgba(240,180,41,.28);
  padding: 5px 8px;
  border-radius: 999px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-name-desk { display: none; }

main#app, main {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + var(--safe-b));
  flex: 1;
  min-height: 0;
}

body.auth-mode .sidebar,
body.auth-mode .sidebar-mask,
body.auth-mode .menu-btn { display: none !important; }
body.auth-mode .shell-header { justify-content: center; }
body.auth-mode .shell-title { text-align: center; }
body.auth-mode .shell-actions { display: none; }

/* ===== Page pieces ===== */
.hero {
  width: 100%;
  padding: 8px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.hero h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(22px, 6vw, 32px);
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}
.cta-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}
.cta-row .btn {
  width: 100%;
  text-align: center;
  text-decoration: none;
}
.dash-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  width: 100%;
}
.dash-tile {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  transition: border-color .15s, background .15s;
}
.dash-tile:hover { border-color: rgba(45,212,168,.35); background: rgba(45,212,168,.06); }
.dash-tile h3 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 16px;
}
.dash-tile p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.btn {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font); font-weight: 600; font-size: 15px;
  padding: 12px 14px; border-radius: 12px; width: auto; max-width: 100%;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), #19b98f); color: #042018; }
.btn-secondary { background: rgba(255,255,255,.07); color: var(--ink); border: 1px solid var(--line); }
.btn-warn { background: linear-gradient(135deg, var(--accent2), #d89a16); color: #2a1c00; }
.btn-danger { background: rgba(255,107,107,.14); color: var(--danger); border: 1px solid rgba(255,107,107,.3); }
.btn-sm { padding: 8px 10px; font-size: 12px; border-radius: 9px; }
.btn-block { width: 100%; }

.panel {
  width: 100%;
  max-width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  overflow: hidden;
}
.panel h2 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: clamp(18px, 5.5vw, 22px);
  word-break: break-word;
}
.panel .sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.grid-2 { display: flex; flex-direction: column; gap: 12px; width: 100%; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
input, textarea, select {
  display: block; width: 100%; max-width: 100%;
  background: rgba(0,0,0,.3); border: 1px solid var(--line); color: var(--ink);
  border-radius: 12px; padding: 12px; margin-bottom: 10px;
  font-size: 16px; font-family: inherit;
}
.form-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.form-actions .btn { width: 100%; }

.table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 12px;
}
th, td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 500; white-space: nowrap; }

.card-list { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.list-card {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.22);
  border-radius: 12px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.list-card .row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.list-card .k { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.list-card .v { text-align: right; font-size: 13px; word-break: break-all; min-width: 0; flex: 1; }
.list-card .actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px;
}
.list-card .actions .btn { flex: 1 1 calc(50% - 4px); min-width: 0; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.badge-pending { background: rgba(240,180,41,.15); color: var(--accent2); }
.badge-ok { background: rgba(62,207,142,.15); color: var(--ok); }
.badge-bad { background: rgba(255,107,107,.15); color: var(--danger); }
.badge-info { background: rgba(45,212,168,.15); color: var(--accent); }

.notice {
  width: 100%;
  border-left: 3px solid var(--accent);
  background: rgba(45,212,168,.08);
  padding: 10px 12px; border-radius: 0 10px 10px 0;
  color: var(--muted); margin-bottom: 12px; font-size: 13px; line-height: 1.5;
}
.copy-box {
  width: 100%;
  background: rgba(0,0,0,.3);
  border: 1px dashed rgba(45,212,168,.4);
  border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 12px;
}
.copy-box .btn { width: 100%; }

.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 14px 0 16px;
  padding: 16px;
  border-radius: 14px;
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(45,212,168,.25);
}
.qr-wrap #depositQr,
.qr-wrap #orderQr {
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-wrap img, .qr-wrap canvas {
  display: block;
  width: 200px !important;
  height: 200px !important;
  border-radius: 4px;
}
.qr-caption {
  margin: 0;
  font-size: 12px;
  color: #3a4a46;
  text-align: center;
}

.tut-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.tut-item {
  display: block; width: 100%; text-decoration: none; color: inherit;
  padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0,0,0,.2);
}
.tut-item h3 { margin: 0 0 4px; font-family: var(--display); font-size: 15px; }
.tut-item p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.markdown { line-height: 1.65; color: #d7e8e4; font-size: 14px; overflow-wrap: anywhere; width: 100%; }
.markdown h1, .markdown h2, .markdown h3 { font-family: var(--display); font-size: 16px; }
.markdown ol { padding-left: 1.15rem; margin: 0; }
.markdown code { background: rgba(0,0,0,.35); padding: 1px 5px; border-radius: 5px; word-break: break-all; }

.chat-layout, .chat-box { width: 100%; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.chat-sessions {
  display: flex; gap: 8px; overflow-x: auto; width: 100%;
  padding-bottom: 4px; -webkit-overflow-scrolling: touch;
}
.session-item {
  flex: 0 0 auto; width: min(70vw, 200px);
  padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.2);
}
.session-item.active { border-color: rgba(45,212,168,.4); background: rgba(45,212,168,.1); }
.chat-msgs {
  width: 100%; max-height: 50vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 85%; padding: 10px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45;
  word-break: break-word;
}
.bubble.me { align-self: flex-end; background: rgba(45,212,168,.28); }
.bubble.them { align-self: flex-start; background: rgba(255,255,255,.08); }
.bubble .meta { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.chat-input { display: flex; gap: 8px; width: 100%; align-items: stretch; }
.chat-input input { margin: 0; flex: 1; min-width: 0; }
.chat-input .btn { flex: 0 0 auto; width: auto; padding-inline: 14px; }

.auth-card { width: 100%; max-width: 100%; margin: 8px 0; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; width: 100%; }
.tab {
  text-align: center; padding: 12px 8px; border-radius: 10px; cursor: pointer;
  background: rgba(0,0,0,.22); color: var(--muted); border: 1px solid var(--line); font-size: 14px;
}
.tab.active { color: var(--ink); background: rgba(45,212,168,.14); border-color: rgba(45,212,168,.35); }

.toast {
  position: fixed; left: 12px; right: 12px; z-index: 60;
  bottom: calc(12px + var(--safe-b));
  background: #14343a; border: 1px solid var(--line); padding: 12px;
  border-radius: 12px; text-align: center; font-size: 14px;
}
.toast.error { border-color: rgba(255,107,107,.4); }
.hidden { display: none !important; }

.stats { display: grid; grid-template-columns: 1fr; gap: 8px; width: 100%; margin-bottom: 12px; }
.stat { background: rgba(0,0,0,.25); border-radius: 12px; padding: 12px; border: 1px solid var(--line); }
.stat b { display: block; font-family: var(--display); font-size: 20px; margin-top: 4px; }
.stat span { color: var(--muted); font-size: 12px; }

.empty-hint { color: var(--muted); font-size: 13px; text-align: center; padding: 16px 8px; }

/* pay page */
.pay-wrap { width: 100%; max-width: 100%; margin: 0; padding: calc(12px + var(--safe-t)) 12px calc(16px + var(--safe-b)); }
body.pay-page { padding-bottom: var(--safe-b); }
.pay-amount { font-family: var(--display); font-size: clamp(28px, 10vw, 36px); color: var(--accent2); margin: 6px 0 12px; }
.pay-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--line); width: 100%;
}
.pay-row span { color: var(--muted); flex: 0 0 auto; font-size: 13px; }
.pay-row b {
  flex: 1; min-width: 0; text-align: right; font-size: 13px; word-break: break-all;
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; align-items: center;
}
.pay-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-top: 14px; }
.pay-actions .btn { width: 100%; }

/* ===== Desktop ===== */
@media (min-width: 960px) {
  .sidebar-mask { display: none !important; }
  .menu-btn { display: none !important; }
  .sidebar {
    transform: none;
    max-width: none;
  }
  .shell-main {
    margin-left: var(--sidebar-w);
    width: calc(100% - var(--sidebar-w));
  }
  .shell-header {
    padding: 12px 24px;
    background: rgba(7, 20, 22, 0.85);
  }
  .shell-title { font-size: 18px; }
  .shell-actions { max-width: none; gap: 8px; }
  .shell-actions .btn-sm,
  .user-name-desk { display: inline-flex; }
  .balance-pill { font-size: 13px; max-width: none; }

  main#app, main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
  }

  .dash-grid { grid-template-columns: repeat(3, 1fr); }
  .cta-row { flex-direction: row; flex-wrap: wrap; }
  .cta-row .btn { width: auto; }
  .grid-2 { display: grid; grid-template-columns: 1.05fr .95fr; gap: 14px; }
  .form-actions { flex-direction: row; }
  .form-actions .btn { width: auto; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  table { min-width: 0; font-size: 14px; }
  th, td { padding: 10px 8px; }
  .chat-layout.admin { display: grid; grid-template-columns: 240px 1fr; gap: 12px; }
  .chat-sessions {
    display: block;
    max-height: 560px;
    overflow: auto;
    border-right: 1px solid var(--line);
    padding-right: 8px;
  }
  .session-item { width: auto; margin-bottom: 6px; }
  .chat-msgs { max-height: 420px; }
  .auth-card { max-width: 420px; margin: 48px auto; }
  .toast { left: auto; right: 16px; bottom: 16px; width: auto; min-width: 200px; }
  .copy-box { flex-direction: row; align-items: center; justify-content: space-between; }
  .copy-box .btn { width: auto; }
  .pay-wrap { max-width: 480px; margin: 24px auto; }
  .pay-actions { flex-direction: row; }
  .pay-actions .btn { width: auto; flex: 1; }
  .list-card .actions .btn { flex: 0 0 auto; }

  body.auth-mode .shell-main {
    margin-left: 0;
    width: 100%;
  }
}
