:root {
  color-scheme: dark;
  --surface-page: #0d0d0d;
  --surface-panel: #141414;
  --surface-panel-alt: #1a1a19;
  --ink-primary: #ffffff;
  --ink-secondary: #c3c2b7;
  --ink-muted: #898781;
  --border-hairline: rgba(255, 255, 255, 0.1);
  --grid-line: #232320;
  --accent: #3987e5;
  --good: #0ca30c;
  --critical: #d03b3b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--surface-page);
  color: var(--ink-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

a {
  color: var(--accent);
}
a:visited {
  color: #9085e9;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border-hairline);
}

.app-title {
  font-size: 1rem;
  font-weight: 600;
}

.app-header nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.app-header nav a {
  text-decoration: none;
  color: var(--ink-secondary);
  font-size: 0.85rem;
}
.app-header nav a.active {
  color: var(--ink-primary);
  font-weight: 600;
}

button {
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 0.85rem;
}

main {
  padding: 1.25rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.6rem;
}

.panel {
  background: var(--surface-panel);
  border: 1px solid var(--grid-line);
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
}

.panel.span2 {
  grid-column: span 2;
}
.panel.span3 {
  grid-column: span 3;
}
.panel.span6 {
  grid-column: span 6;
}

@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .panel.span2,
  .panel.span3,
  .panel.span6 {
    grid-column: span 2;
  }
  .panel.tile {
    grid-column: span 1;
  }
}

.tile .k {
  font-size: 0.68rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tile .v {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 0.15rem;
  font-variant-numeric: tabular-nums;
}

.tile .spark {
  display: block;
  width: 100%;
  height: 28px;
  margin-top: 0.35rem;
}

.panel h2 {
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  table-layout: fixed;
}
th {
  text-align: left;
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--grid-line);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--grid-line);
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
}
tr:hover td {
  background: var(--surface-panel-alt);
}

/* Wallet / Market / Outcome are always the first three columns in every
   dashboard table, so pinning their widths keeps every table's opening
   columns visually aligned regardless of what the remaining columns hold. */
th:nth-child(1),
td:nth-child(1) {
  width: 14%;
}
th:nth-child(2),
td:nth-child(2) {
  width: 32%;
}
th:nth-child(3),
td:nth-child(3) {
  width: 8%;
}

/* Open Positions and Closed Positions additionally share Entry as their
   4th column — pin it too so both tables line up through that column. */
.positions-table th:nth-child(4),
.positions-table td:nth-child(4) {
  width: 10%;
}

/* Category | Trades | Win Rate | Total P&L | Avg P&L % — a different shape
   than the Wallet/Market/Outcome layout the generic nth-child rules above
   assume, so override all five column widths for this table specifically. */
.category-table th:nth-child(1),
.category-table td:nth-child(1) {
  width: 30%;
}
.category-table th:nth-child(2),
.category-table td:nth-child(2) {
  width: 14%;
}
.category-table th:nth-child(3),
.category-table td:nth-child(3) {
  width: 14%;
}
.category-table th:nth-child(4),
.category-table td:nth-child(4) {
  width: 21%;
}
.category-table th:nth-child(5),
.category-table td:nth-child(5) {
  width: 21%;
}

.pnl-positive {
  color: var(--good);
}
.pnl-negative {
  color: var(--critical);
}

#pnl-chart {
  width: 100%;
  height: 200px;
}

#category-performance-chart {
  width: 100%;
  height: 200px;
}

form#login-form {
  background: var(--surface-panel);
  padding: 2rem;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 280px;
  border: 1px solid var(--border-hairline);
}

form#login-form input {
  padding: 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--grid-line);
  background: var(--surface-page);
  color: var(--ink-primary);
}

.error {
  color: var(--critical);
  margin: 0;
  min-height: 1.2em;
  font-size: 0.85rem;
}

/* Chrome's `::details-content` internal box keeps a closed <details>'s
   content at zero size regardless of any `display` override on its
   children, so the desktop nav can't be a "forced open" <details> - it's a
   plain <nav>, shown only >=901px. The hamburger <details> is mobile-only,
   shown only <=900px, where its native open/closed toggle is left
   untouched (that's exactly the behavior <details> is designed for). */
/* Scoped as ".app-header nav.nav-desktop" (not just ".nav-desktop") so this
   `display: none` outranks the pre-existing ".app-header nav { display:
   flex }" rule above, which matches BOTH <nav> copies below - a bare
   ".nav-desktop" selector loses that specificity fight and the desktop nav
   never actually hides on mobile. */
.app-header nav.nav-desktop {
  display: none;
  align-items: center;
  gap: 1rem;
}

.app-header details.nav-toggle {
  display: none;
  position: relative;
}
.app-header details.nav-toggle summary {
  list-style: none;
  cursor: pointer;
  font-size: 1.3rem;
  color: var(--ink-secondary);
}
.app-header details.nav-toggle summary::-webkit-details-marker {
  display: none;
}

@media (min-width: 901px) {
  .app-header nav.nav-desktop {
    display: flex;
  }
}

@media (max-width: 900px) {
  .app-header details.nav-toggle {
    display: block;
  }
  .app-header details.nav-toggle nav {
    display: none;
  }
  .app-header details.nav-toggle[open] nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: absolute;
    right: 0;
    top: 2.2rem;
    background: var(--surface-panel);
    border: 1px solid var(--border-hairline);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    gap: 0.6rem;
    z-index: 10;
    min-width: 160px;
  }
}

.table-desktop {
  display: table;
}
.table-mobile {
  display: none;
}

@media (max-width: 900px) {
  .table-desktop {
    display: none;
  }
  .table-mobile {
    display: block;
  }
}

.table-mobile .row-card {
  background: var(--surface-panel-alt);
  border: 1px solid var(--grid-line);
  border-radius: 6px;
  margin-bottom: 0.5rem;
}
.table-mobile .row-card summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  list-style: none;
  font-size: 0.82rem;
}
.table-mobile .row-card summary::-webkit-details-marker {
  display: none;
}
.table-mobile .row-card summary .market {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-mobile .row-card .row-detail {
  padding: 0 0.6rem 0.6rem;
  font-size: 0.78rem;
  color: var(--ink-secondary);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.5rem;
}
.table-mobile .row-card .row-detail .k {
  color: var(--ink-muted);
}

.table-scroll {
  overflow-x: auto;
}

.load-more {
  display: block;
  width: 100%;
  margin-top: 0.6rem;
}
