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

/* ── Theme variables ── */
:root {
  --bg:           #0f172a;
  --bg2:          #1e293b;
  --border:       #334155;
  --text:         #e2e8f0;
  --text2:        #ffffff;
  --text-muted:   #94a3b8;
  --text-heading: #e2e8f0;
  --td-bg:        #0f172a;
  --hover-bg:     #1e293b;
  --totals-bg:    #1e293b;
  --zebra-bg:     rgba(255, 255, 255, 0.10);
}

body.light {
  --bg:           #f8fafc;
  --bg2:          #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text2:        #334155;
  --text-muted:   #64748b;
  --text-heading: #0f172a;
  --td-bg:        #f8fafc;
  --hover-bg:     #f1f5f9;
  --totals-bg:    #e2e8f0;
  --zebra-bg:     #eaf3fc;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

/* ── Theme toggle ── */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-track {
  width: 36px;
  height: 20px;
  background: #334155;
  border-radius: 99px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

body.light .toggle-track { background: #3b82f6; }

.toggle-thumb {
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: left 0.2s;
}

body.light .toggle-thumb { left: 19px; }

/* ── Header ── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  width: 28px;
  height: 28px;
}

header h1 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-heading);
}

.market-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.market-badge.market-open   { background: #14532d; color: #86efac; }
.market-badge.market-closed { background: #7f1d1d; color: #fca5a5; }

.market-asof {
  color: var(--text-heading);
  font-size: 0.75rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.2s, opacity 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary        { background: #3b82f6; color: #fff; }
.btn-primary:hover  { background: #2563eb; }
.btn-secondary      { background: var(--border); color: var(--text2); }
.btn-secondary:hover{ background: var(--text-muted); }
.btn-danger         { background: #7f1d1d; color: #fca5a5; }
.btn-danger:hover   { background: #991b1b; }

/* ── Main ── */
main {
  padding: 6px 24px;
}

/* ── States ── */
.state-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
  text-align: center;
}

.state-panel h2 { color: var(--text-heading); font-size: 1.2rem; }
.state-panel p  { color: var(--text-muted); font-size: 0.9rem; max-width: 360px; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Summary bar ── */
.summary-bar {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 3px;
}

.summary-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 10px;
  min-width: 160px;
}

.clickable-card {
  cursor: pointer;
}

.clickable-card:hover {
  border-color: #3b82f6;
}

.summary-card .label {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.summary-card .value {
  color: var(--text-heading);
  font-size: 1.15rem;
  font-weight: 600;
}

/* ── Account section ── */
.account-section {
  margin-bottom: 40px;
}

.account-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.account-header h2 {
  color: var(--text-heading);
  font-size: 1rem;
  font-weight: 600;
}

.account-name {
  cursor: pointer;
  border-bottom: 1px dashed var(--border);
}

.account-name:hover {
  color: #3b82f6;
  border-bottom-color: #3b82f6;
}

.account-type {
  background: #1d4ed8;
  color: #bfdbfe;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.account-total {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  white-space: nowrap;
}

thead th {
  background: var(--bg2);
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  padding: 3px 12px;
  text-align: right;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}

thead th:first-child,
thead th:last-child { text-align: left; }

thead th:hover             { color: var(--text2); }
thead th.sort-asc::after   { content: ' ▲'; color: #3b82f6; }
thead th.sort-desc::after  { content: ' ▼'; color: #3b82f6; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:hover      { background: var(--hover-bg); }
tbody tr:last-child { border-bottom: none; }

tbody tr:nth-child(even):not(.group-header):not(.group-subtotal):not(.cash-row):not(.totals-row) td {
  background: var(--zebra-bg);
}

td {
  padding: 0px 10px;
  color: var(--text2);
  text-align: right;
  background: var(--td-bg);
}

td:first-child  { text-align: left; }
td:last-child   { text-align: left; color: var(--text-muted); min-width: 270px; overflow: hidden; text-overflow: ellipsis; }

.sym { color: var(--text-heading); font-weight: 600; font-size: 0.88rem; }

.pos { color: #16a34a; }
.neg { color: #dc2626; }
.neu { color: var(--text-muted); }

/* ── Total row ── */
tr.group-header td {
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
}

tr.group-subtotal td {
  background: var(--bg2);
  font-weight: 600;
  border-top: 1px solid var(--border);
}

tr.cash-row td {
  color: var(--text2);
  font-style: italic;
}

tr.totals-row td {
  background: var(--totals-bg);
  color: var(--text-heading);
  font-weight: 600;
  border-top: 1px solid var(--border);
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.refresh-time {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-left: auto;
}

.error-banner {
  background: #450a0a;
  border: 1px solid #7f1d1d;
  color: #fca5a5;
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 0.85rem;
  margin-bottom: 20px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  min-width: 320px;
}

.modal-box h3 {
  color: var(--text-heading);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.modal-table th {
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-align: right;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
}

.modal-table th:first-child { text-align: left; }

.modal-table td {
  color: var(--text2);
  text-align: right;
  padding: 5px 10px;
}

.modal-table td:first-child {
  text-align: left;
  color: var(--text-heading);
  font-weight: 600;
}

.modal-table tfoot td {
  border-top: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-heading);
}

.modal-close {
  margin-top: 16px;
  text-align: right;
}
