:root {
  --bg: #0b0e11;
  --panel: #1e2329;
  --card: #181a20;
  --hover: #2b3139;
  --border: #2b3139;
  --accent: #ffcc00;
  --text: #eaecef;
  --muted: #848e9c;
  --green: #0ecb81;
  --red: #f6465d;
  --logo-size: 44px;
  --topnav-height: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* Top Nav */
#topnav {
  height: var(--topnav-height);
  flex-shrink: 0;
}

.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topnav-height);
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topnav-left { display: flex; align-items: center; gap: 24px; }

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  line-height: 1;
}

.site-logo {
  width: var(--logo-size);
  height: var(--logo-size);
  border-radius: 10px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.logo-power,
.logo-crypto {
  transform: translateY(-4px);
}

.logo-power { font-weight: 700; color: var(--accent); }
.logo-crypto { font-weight: 300; color: var(--text); }

.topnav-links { display: none; gap: 16px; }
.topnav-links a {
  font-size: 0.875rem;
  transition: color 0.2s;
}
.topnav-links a:hover, .topnav-links a.active { color: var(--accent); }
.topnav-links a.active { font-weight: 600; position: relative; }
.topnav-links a.active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.topnav-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}
.icon-btn:hover { color: var(--text); background: var(--hover); }

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
}
.icon svg { display: block; }

.sidebar-icon svg { width: 18px; height: 18px; }
.sidebar-link.active .sidebar-icon { color: var(--accent); }

.feature-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(255, 204, 0, 0.1);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.feature-icon svg { width: 24px; height: 24px; }

.doc-type-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 204, 0, 0.1);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.doc-type-icon-wrap svg { width: 28px; height: 28px; }

.topnav-username {
  font-size: 0.875rem;
  color: var(--muted);
}

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  padding: 4px 10px;
}

.inline-icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
}
.inline-icon-btn:hover { color: var(--accent); }

.eye-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  padding: 2px;
  margin-left: 4px;
}
.eye-btn:hover { color: var(--text); }
.eye-btn svg { width: 16px; height: 16px; }

.btn-deposit {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 6px 16px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
}
.btn-deposit:hover { opacity: 0.9; }
.btn-deposit.active {
  box-shadow: 0 0 0 2px rgba(255, 204, 0, 0.45);
}

.icon-btn.topnav-extra-icon.active {
  color: var(--accent);
  background: rgba(255, 204, 0, 0.1);
}

.topnav-support-link {
  display: inline-flex;
  flex-shrink: 0;
}

.topnav-support-link.active {
  color: var(--accent);
  background: rgba(255, 204, 0, 0.1);
}

/* Layout */
.app-body { display: flex; min-height: calc(100vh - var(--topnav-height)); }

.sidebar {
  width: 224px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: none;
  position: sticky;
  top: var(--topnav-height);
  align-self: flex-start;
  height: calc(100vh - var(--topnav-height));
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg);
  z-index: 90;
}

.sidebar-nav { list-style: none; }

.sidebar-item { margin-bottom: 2px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--muted);
  border-left: 3px solid transparent;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.sidebar-link:hover { background: rgba(43,49,57,0.5); color: var(--text); }
.sidebar-link.active {
  background: rgba(255, 204, 0, 0.08);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  margin-left: auto;
  font-size: 0.75rem;
}

.sidebar-sub {
  list-style: none;
  margin-left: 28px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  display: none;
}
.sidebar-sub.open { display: block; }
.sidebar-sub a {
  display: block;
  padding: 6px 8px;
  font-size: 0.75rem;
  color: var(--muted);
}
.sidebar-sub a:hover, .sidebar-sub a.active { color: var(--accent); }

.main { flex: 1; padding: 16px 24px; overflow: auto; }
.container { max-width: 1100px; margin: 0 auto; }

/* Cards */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 1.5rem; font-weight: 600; }
.page-header p { color: var(--muted); font-size: 0.875rem; margin-top: 4px; }

.btn {
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  border: none;
  font-weight: 500;
}
.btn-primary { background: var(--accent); color: #000; }
.btn-secondary { background: var(--hover); color: var(--text); border: 1px solid var(--border); }
.btn-outline { background: transparent; border: 1px solid rgba(255,204,0,0.4); color: var(--accent); font-size: 0.75rem; padding: 4px 12px; }

/* Profile */
.profile-card { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; }
.profile-left { display: flex; align-items: center; gap: 16px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--border); }
.profile-name { font-size: 1.25rem; font-weight: 600; }
.profile-uid { font-size: 0.875rem; color: var(--muted); margin-top: 4px; }
.profile-stats { display: flex; gap: 32px; }
.profile-stats label { font-size: 0.875rem; color: var(--muted); display: block; }
.profile-stats span { font-weight: 500; }

/* Portfolio */
.portfolio { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 24px; }
.portfolio-value { font-size: 1.875rem; font-weight: 600; margin-top: 8px; }
.portfolio-usd { color: var(--muted); font-size: 0.875rem; margin-top: 4px; }
.portfolio-pnl { color: var(--green); font-size: 0.875rem; margin-top: 8px; }
.portfolio-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.portfolio-actions a {
  background: var(--hover);
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 0.875rem;
  transition: background 0.2s;
}
.portfolio-actions a:hover { background: var(--border); }
.portfolio-chart { width: 192px; height: 64px; }
.portfolio-chart canvas { width: 100%; height: 100%; }

.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding-bottom: 12px;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header h2 { font-size: 1.125rem; font-weight: 600; }
.card-header a { color: var(--muted); font-size: 0.875rem; }
.card-header a:hover { color: var(--accent); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; color: var(--muted); font-weight: 400; padding-bottom: 12px; }
td { padding: 16px 8px 16px 0; border-top: 1px solid rgba(43,49,57,0.5); }
td:last-child, th:last-child { text-align: right; }

.coin-cell { display: flex; align-items: center; gap: 12px; }
.coin-icon {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; color: #000;
  flex-shrink: 0;
}
.coin-icon-pwr { color: #fff; font-weight: 800; }
.coin-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: block;
  object-fit: contain;
  background: var(--card);
}
.coin-symbol { font-weight: 500; }
.coin-name { font-size: 0.75rem; color: var(--muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.link-accent { color: var(--accent); }
.link-accent:hover { text-decoration: underline; }

.sub-text { font-size: 0.75rem; color: var(--muted); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.875rem; color: var(--muted); margin-bottom: 8px; }
.form-input, .form-select {
  width: 100%;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

.trade-panel { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.trade-chart {
  height: 256px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-align: center;
}
.order-book { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; font-size: 0.875rem; }
.order-row { display: flex; justify-content: space-between; padding: 2px 0; }

.trade-tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 4px; margin-bottom: 16px; }
.trade-tab {
  flex: 1; padding: 8px; border: none; border-radius: 6px;
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  background: transparent; color: var(--muted);
}
.trade-tab.buy.active { background: var(--green); color: #fff; }
.trade-tab.sell.active { background: var(--red); color: #fff; }

.filter-pills { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.pill {
  padding: 6px 12px; border-radius: 4px; font-size: 0.875rem;
  border: none; cursor: pointer; background: var(--hover); color: var(--muted);
}
.pill.active { background: var(--accent); color: #000; }

@media (min-width: 1024px) {
  .sidebar { display: block; }
  .topnav-links { display: flex; }
  .sidebar-toggle-btn { display: none !important; }
  .sidebar-mobile-section { display: none; }
  .sidebar-backdrop { display: none !important; }
}

@media (max-width: 1023px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--topnav-height);
    left: 0;
    width: min(288px, 88vw);
    height: calc(100vh - var(--topnav-height));
    height: calc(100dvh - var(--topnav-height));
    max-height: calc(100dvh - var(--topnav-height));
    transform: translateX(-105%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 110;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    top: var(--topnav-height);
    z-index: 105;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .topnav-links { display: none; }
  .sidebar-toggle-btn { display: inline-flex; }

  .sidebar-mobile-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
  }

  .sidebar-mobile-heading {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
    padding: 0 12px;
  }

  .sidebar-mobile-links {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .sidebar-mobile-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--muted);
    transition: background 0.2s, color 0.2s;
  }

  .sidebar-mobile-link-highlight {
    color: var(--accent);
    border: 1px solid rgba(255, 204, 0, 0.2);
    background: rgba(255, 204, 0, 0.06);
    margin-bottom: 4px;
  }

  .sidebar-mobile-link:hover {
    background: rgba(43, 49, 57, 0.5);
    color: var(--text);
  }

  .sidebar-mobile-link.active {
    background: var(--hover);
    color: var(--accent);
  }

  .main { padding: 16px 18px; }
}

@media (max-width: 767px) {
  :root {
    --logo-size: 36px;
    --topnav-height: 52px;
  }

  .topnav {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .topnav-left { gap: 8px; min-width: 0; }
  .topnav-right { gap: 4px; flex-shrink: 0; }

  .logo { font-size: 1.08rem; gap: 8px; }

  .topnav-search-btn,
  .topnav-extra-icon { display: none; }

  .topnav-support-link { display: inline-flex; }

  .btn-deposit {
    padding: 6px 10px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .topnav-username { display: none; }

  .btn-logout {
    padding: 6px 8px;
    font-size: 0;
    gap: 0;
  }

  .btn-logout .icon { margin: 0; }

  .topnav-admin-link {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .main { padding: 12px 14px; }
  .container { width: 100%; }

  .card { padding: 16px; border-radius: 10px; }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .page-header h1 { font-size: 1.35rem; }
  .page-header .btn { width: 100%; text-align: center; }

  .profile-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .profile-left { width: 100%; }
  .profile-stats {
    width: 100%;
    gap: 16px;
    flex-wrap: wrap;
  }

  .portfolio {
    flex-direction: column;
    gap: 16px;
  }

  .portfolio-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .portfolio-actions a {
    flex: 1;
    text-align: center;
    min-width: calc(50% - 4px);
  }

  .portfolio-chart {
    width: 100%;
    max-width: 240px;
  }

  .portfolio-value { font-size: 1.5rem; }

  .grid-2,
  .grid-3,
  .trade-panel,
  .order-book { grid-template-columns: 1fr; }

  .doc-type-grid { grid-template-columns: 1fr; }

  .auth-card { padding: 24px; }
  .auth-header { padding: 14px 16px; }
  .auth-header-links { gap: 12px; font-size: 0.8rem; }
  .auth-actions { flex-direction: column; }
}

@media (max-width: 480px) {
  .logo { font-size: 1rem; gap: 6px; }

  .btn-signup,
  .btn-login {
    padding: 5px 8px;
    font-size: 0.78rem;
  }

  .tabs { gap: 16px; }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .trade-tabs { flex-direction: column; }
  .trade-tab { width: 100%; }

  .filter-pills { gap: 6px; }
  .pill { font-size: 0.8rem; padding: 5px 10px; }
}

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.auth-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.auth-header-links {
  display: flex;
  gap: 16px;
  font-size: 0.875rem;
}

.auth-header-links a { color: var(--muted); }
.auth-header-links a:hover { color: var(--accent); }

.auth-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
}

.auth-card-wide { max-width: 520px; }

.auth-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.auth-subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 24px;
}

.auth-steps {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
}

.auth-step {
  flex: 1;
  text-align: center;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

.auth-step.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.auth-step.done {
  color: var(--green);
  border-bottom-color: var(--green);
}

.form-error {
  color: var(--red);
  font-size: 0.75rem;
  margin-top: 6px;
  display: none;
}
.form-error.show { display: block; }

.form-input.error, .form-select.error {
  border-color: var(--red);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 0.75rem;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.875rem;
  color: var(--muted);
}
.auth-footer a { color: var(--accent); }
.auth-footer a:hover { text-decoration: underline; }

.password-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
}

.doc-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.doc-type-card {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--bg);
}
.doc-type-card:hover { border-color: var(--muted); }
.doc-type-card.selected {
  border-color: var(--accent);
  background: rgba(255, 204, 0, 0.08);
}
.doc-type-label { font-size: 0.875rem; font-weight: 500; }

.upload-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.875rem;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  background: var(--bg);
  position: relative;
}
.upload-zone:hover { border-color: var(--accent); }
.upload-zone input { display: none; }
.upload-zone.has-file { border-color: var(--green); border-style: solid; }
.upload-preview {
  max-width: 100%;
  max-height: 120px;
  margin-top: 12px;
  border-radius: 4px;
}

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 16px;
}
.alert-success {
  background: rgba(14, 203, 129, 0.12);
  border: 1px solid rgba(14, 203, 129, 0.3);
  color: var(--green);
}
.alert-error {
  background: rgba(246, 70, 93, 0.12);
  border: 1px solid rgba(246, 70, 93, 0.3);
  color: var(--red);
}

.btn-full { width: 100%; margin-top: 8px; }
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.875rem;
}
.btn-link:hover { text-decoration: underline; }

.auth-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.auth-actions .btn { flex: 1; }

.topnav-auth {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-login {
  font-size: 0.875rem;
  color: var(--text);
  padding: 6px 12px;
}
.btn-login:hover { color: var(--accent); }
.btn-signup {
  font-size: 0.875rem;
  padding: 6px 14px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
}
.btn-signup:hover { background: rgba(255, 204, 0, 0.1); }

/* Admin panel styles → css/admin.css */
.topnav-admin-link {
  font-size: 0.8rem;
  color: var(--accent);
  padding: 6px 10px;
  border: 1px solid rgba(255, 204, 0, 0.35);
  border-radius: 4px;
}
.topnav-admin-link:hover { background: rgba(255, 204, 0, 0.1); }
