/* ZenvoxTect Portfolio Portal — dark theme, green accent
 * Visual language: matches ZenvoxTrade desktop client
 * Fonts: Sarabun (Thai) + Inter fallback — declared only, no remote import
 * Last updated: 2026-04-27
 */

/* =========================================================
   CSS Custom Properties
   ========================================================= */
:root {
  /* Base palette — identical to desktop client */
  --bg:         #0b0d12;
  --bg-b:       #12151c;
  --surface:    #141822;
  --surface-2:  #1c2030;
  --border:     #242836;
  --border-2:   #2e3347;

  /* Text */
  --text:       #e6e7ea;
  --muted:      #9097a3;
  --dim:        #555e72;

  /* Brand accent — green (copy-trading results, not program status) */
  --accent:         #21c87a;
  --accent-soft:    #3dde93;
  --accent-dim:     rgba(33, 200, 122, .10);
  --accent-glow:    rgba(33, 200, 122, .22);

  /* Semantic */
  --profit:     #21c87a;
  --profit-dim: rgba(33, 200, 122, .10);
  --loss:       #e85d5d;
  --loss-dim:   rgba(232, 93, 93, .10);
  --warn:       #f0a500;
  --warn-dim:   rgba(240, 165, 0, .12);
  --info:       #4a9eff;
  --info-dim:   rgba(74, 158, 255, .10);

  /* Shape */
  --radius-lg:  16px;
  --radius-md:  12px;
  --radius-sm:  8px;
  --radius-xs:  5px;

  /* Elevation */
  --shadow-card: 0 1px 2px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.04);
  --shadow-md:   0 8px 24px -6px rgba(0,0,0,.55);

  /* Spacing rhythm (4px base) */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
}

/* =========================================================
   Reset & Base
   ========================================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  background-color: var(--bg);
  background-image: radial-gradient(ellipse at 50% 0%, var(--bg-b) 0%, var(--bg) 65%);
  color: var(--text);
  font-family: "Sarabun", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* =========================================================
   Layout container
   ========================================================= */
#app {
  max-width: 680px;
  margin: 0 auto;
  padding: var(--sp-4);
  padding-bottom: var(--sp-8);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* =========================================================
   Topbar
   ========================================================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  position: sticky;
  top: var(--sp-4);
  z-index: 10;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(20, 24, 34, .92);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.brand-icon {
  flex-shrink: 0;
  line-height: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .3px;
  line-height: 1.2;
}

.brand-tag {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-top: 1px;
}

/* Portfolio page — right side of topbar */
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.account-chip {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  letter-spacing: .3px;
  font-variant-numeric: tabular-nums;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
  font-family: inherit;
}

.btn-logout:hover {
  color: var(--text);
  border-color: var(--border-2);
  background: var(--surface-2);
}

/* =========================================================
   Offline Banner
   ========================================================= */
.offline-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 12px var(--sp-4);
  background: rgba(240, 165, 0, .08);
  border: 1px solid rgba(240, 165, 0, .25);
  border-radius: var(--radius-md);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.5;
  animation: fade-in .3s ease;
}

.offline-banner svg {
  flex-shrink: 0;
  margin-top: 2px;
}

/* =========================================================
   KPI Cards
   ========================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: var(--sp-3);
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: border-color .2s ease;
}

.kpi-card::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .45;
}

.kpi-card--full {
  grid-column: 1 / -1;
}

.kpi-card--full::after {
  opacity: 0; /* profit card accent determined by sign */
}

.kpi-card--full.is-profit::after {
  background: linear-gradient(90deg, transparent, var(--profit), transparent);
  opacity: .55;
}

.kpi-card--full.is-loss::after {
  background: linear-gradient(90deg, transparent, var(--loss), transparent);
  opacity: .55;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: var(--sp-2);
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.3px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.kpi-card--full .kpi-value {
  font-size: 32px;
  text-align: center;
}

.kpi-pnl.is-profit { color: var(--profit); }
.kpi-pnl.is-loss   { color: var(--loss); }

/* =========================================================
   Panel (section wrapper)
   ========================================================= */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  animation: fade-in .35s ease;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.counter {
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
  min-width: 26px;
  text-align: center;
}

/* Days selector */
.days-select {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  padding: 4px 24px 4px 10px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239097a3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color .15s ease, color .15s ease;
}

.days-select:hover,
.days-select:focus {
  border-color: var(--border-2);
  color: var(--text);
  outline: none;
}

/* =========================================================
   Data Tables
   ========================================================= */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.data-table thead th {
  padding: 9px var(--sp-4);
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table thead th.num {
  text-align: right;
}

.data-table tbody tr {
  transition: background .12s ease;
}

.data-table tbody tr:hover td {
  background: var(--surface-2);
}

.data-table tbody td {
  padding: 11px var(--sp-4);
  border-bottom: 1px solid rgba(36, 40, 54, .6);
  vertical-align: middle;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table .num {
  text-align: right;
}

/* Symbol cell */
.sym {
  font-weight: 600;
  letter-spacing: .3px;
  color: var(--text);
}

/* Direction badge */
.dir-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: .5px;
}

.dir-badge.buy  { background: var(--profit-dim); color: var(--profit); }
.dir-badge.sell { background: var(--loss-dim);   color: var(--loss); }

/* P&L cell */
.pnl.profit { color: var(--profit); font-weight: 600; }
.pnl.loss   { color: var(--loss);   font-weight: 600; }

/* Empty state */
.empty-row td { border: none !important; }

.empty-cell {
  text-align: center !important;
  color: var(--dim) !important;
  padding: var(--sp-6) !important;
  font-size: 13px;
}

/* Timestamp */
.ts-cell {
  color: var(--dim);
  font-size: 12px;
}

/* =========================================================
   Heatmap
   ========================================================= */
.heatmap-summary {
  display: flex;
  gap: var(--sp-4);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.hm-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 80px;
}

.hm-stat-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .8px;
}

.hm-stat-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.heatmap-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: 4px;
  padding: var(--sp-4);
}

/* Individual heatmap cell */
.hm-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--surface-2);
  cursor: default;
  position: relative;
  transition: transform .1s ease, filter .1s ease;
}

.hm-cell:hover {
  transform: scale(1.15);
  z-index: 2;
  filter: brightness(1.25);
}

/* Tooltip via title attr — visible on hover via browser */
.hm-cell[title] { cursor: help; }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4) var(--sp-4);
}

.legend-band {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg,
    #8b1a1a 0%,
    #e85d5d 30%,
    #2a2e3a 50%,
    #21c87a 70%,
    #0d6b40 100%
  );
}

/* =========================================================
   Auth pages (login / set-password / error)
   ========================================================= */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 120px);
  padding: var(--sp-4);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  animation: slide-up .3s ease;
}

.auth-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  text-align: center;
}

.auth-icon {
  margin-bottom: var(--sp-1);
  line-height: 0;
}

.auth-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .2px;
}

.auth-subtitle {
  font-size: 13px;
}

.auth-help {
  text-align: center;
  font-size: 12.5px;
  line-height: 1.7;
}

.auth-help strong {
  color: var(--text);
  font-weight: 600;
}

.auth-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}

.auth-link:hover,
.auth-link:focus {
  text-decoration: underline;
}

.field-hint {
  margin: 6px 2px 0;
  font-size: 11.5px;
  line-height: 1.45;
}

/* Alert boxes */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 10px var(--sp-4);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}

.alert svg { flex-shrink: 0; margin-top: 2px; }

.alert-error {
  background: var(--loss-dim);
  border: 1px solid rgba(232, 93, 93, .2);
  color: var(--loss);
}

/* Info banner */
.info-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 10px var(--sp-4);
  background: var(--info-dim);
  border: 1px solid rgba(74, 158, 255, .18);
  border-radius: var(--radius-sm);
  color: var(--info);
  font-size: 12.5px;
  line-height: 1.6;
}

.info-banner svg { flex-shrink: 0; margin-top: 2px; }

/* Form fields */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .3px;
}

.field-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 11px var(--sp-4);
  transition: border-color .15s ease, box-shadow .15s ease;
  outline: none;
  -webkit-appearance: none;
}

.field-input::placeholder {
  color: var(--dim);
}

.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 12px var(--sp-5);
  transition: transform .14s ease, background .15s ease, box-shadow .15s ease;
  text-decoration: none;
}

.btn:hover  { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--accent);
  color: #0a1a12;
  box-shadow: 0 4px 14px -4px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-soft);
  box-shadow: 0 6px 18px -4px var(--accent-glow);
}

.btn-full {
  width: 100%;
}

/* Error page — large code number */
.error-card {
  text-align: center;
}

.error-code {
  font-size: 72px;
  font-weight: 900;
  letter-spacing: -4px;
  line-height: 1;
  color: var(--surface-2);
  /* Gradient overlay for depth */
  background: linear-gradient(180deg, var(--border-2) 0%, var(--surface-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: -var(--sp-4);
}

/* =========================================================
   Utility
   ========================================================= */
.muted  { color: var(--muted); }
.small  { font-size: 12px; }
.profit { color: var(--profit); }
.loss   { color: var(--loss); }

/* =========================================================
   Animations
   ========================================================= */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   Scrollbar
   ========================================================= */
::-webkit-scrollbar        { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--surface-2); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* =========================================================
   Responsive — tablet (≥ 520px)
   ========================================================= */
@media (min-width: 520px) {
  #app { padding: var(--sp-6); gap: var(--sp-5); }

  .topbar { top: var(--sp-6); }

  .kpi-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .kpi-card--full {
    grid-column: auto;
  }

  .kpi-value { font-size: 26px; }

  .kpi-card--full .kpi-value { font-size: 26px; }
}

/* =========================================================
   Responsive — mobile (< 480px)
   ========================================================= */
@media (max-width: 479px) {
  .hide-xs { display: none !important; }

  .kpi-value { font-size: 22px; }

  .kpi-card--full .kpi-value { font-size: 26px; }

  .account-chip { display: none; }

  .logout-label { display: none; }

  .btn-logout { padding: 5px 8px; }

  .heatmap-row {
    grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
    gap: 3px;
  }
}

/* =========================================================
   Responsive — very small (< 360px)
   ========================================================= */
@media (max-width: 359px) {
  .hide-sm { display: none !important; }

  .auth-card { padding: var(--sp-4); }

  .data-table thead th,
  .data-table tbody td {
    padding-left: var(--sp-3);
    padding-right: var(--sp-3);
  }
}

/* =========================================================
   Print (safety — hide nav chrome)
   ========================================================= */
@media print {
  .topbar, .btn-logout, .days-select { display: none; }
  body { background: #fff; color: #000; }
}

/* ============================================================
   Auth form spacing fix (2026-04-27 v2.2.14):
   Form had no flex layout so fields were squeezed together.
   Now stack with breathing room + slightly more label/input gap.
   ============================================================ */
.auth-card form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.auth-card .field {
  gap: 6px;
}

.auth-card .field-input {
  padding: 12px var(--sp-4);
}

.auth-card .info-banner {
  padding: 12px var(--sp-4);
  line-height: 1.7;
}

.auth-card .auth-help {
  margin-top: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}
