:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #182132;
  --border: #253147;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.14);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.14);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.15);
  --neutral-bg: rgba(156, 163, 175, 0.14);
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 14px 32px;
}

.top-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.header-main h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.header-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-dot.is-ok {
  background: var(--green);
}

.status-dot.is-error {
  background: var(--red);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.section-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.section-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title-group h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.tabs {
  display: inline-flex;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px 12px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.is-active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}

.tab-btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

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

.btn-primary,
.btn-secondary {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

.btn-secondary:hover {
  border-color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-neutral {
  background: var(--neutral-bg);
  color: var(--muted);
}

.badge-amber {
  background: var(--amber-bg);
  color: var(--amber);
}

.badge-ok {
  background: var(--green-bg);
  color: var(--green);
}

.badge-danger {
  background: var(--red-bg);
  color: var(--red);
}

.state-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 0.875rem;
}

.state-loading {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  justify-content: flex-start;
}

.state-error {
  background: var(--red-bg);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

.error-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  word-break: break-word;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.kpi-label {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.kpi-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.kpi-sub {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.kpi-badge-wrap {
  min-height: 28px;
  display: flex;
  align-items: center;
}

.is-positive {
  color: var(--green);
}

.is-negative {
  color: var(--red);
}

.positions-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.positions-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.positions-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.empty-box,
.placeholder-box {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 18px 14px;
  color: var(--muted);
}

.placeholder-box h3 {
  margin: 10px 0 6px;
  color: var(--text);
  font-size: 1rem;
}

.placeholder-box p {
  margin: 0;
  font-size: 0.875rem;
}

/* Mobile-first (<720px): moi vi the thanh 1 card 2 cot, khong tran ngang 390px */
.positions-table {
  width: 100%;
  border-collapse: collapse;
}

.positions-table thead {
  display: none;
}

.positions-table tbody {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.positions-table tbody tr {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.positions-table tbody td {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.positions-table tbody td::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
}

.cell-symbol {
  font-weight: 700;
}

@media (min-width: 520px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 720px) {
  .app-shell {
    padding: 24px 20px 40px;
  }

  .top-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .card {
    padding: 18px;
  }

  .section-head {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .tabs {
    width: auto;
    min-width: 240px;
  }

  .positions-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
  }

  .positions-table thead {
    display: table-header-group;
    background: rgba(11, 15, 23, 0.45);
  }

  .positions-table th {
    text-align: left;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }

  .positions-table th.num,
  .positions-table td.num {
    text-align: right;
  }

  .positions-table tbody {
    display: table-row-group;
  }

  .positions-table tbody tr {
    display: table-row;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  .positions-table tbody tr + tr td {
    border-top: 1px solid var(--border);
  }

  .positions-table tbody td {
    display: table-cell;
    padding: 11px 12px;
    vertical-align: middle;
  }

  .positions-table tbody td::before {
    content: none;
  }
}

@media (min-width: 980px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
