:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #111827;
  --muted: #6b7280;
  --line: #d8dee6;
  --line-2: #edf1f5;
  --accent: #0f766e;
  --accent-strong: #0b5e58;
  --danger: #b42318;
  --success: #067647;
  --warn: #9a6700;
  --sidebar: #111827;
  --sidebar-muted: #9ca3af;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.appFrame { min-height: 100vh; display: grid; grid-template-columns: 248px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; color: var(--sidebar-muted); font-size: 12px; margin-top: 2px; }
.mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}
.tabs { display: grid; gap: 6px; }
.tabs button {
  justify-content: flex-start;
  width: 100%;
  background: transparent;
  border-color: transparent;
  color: #d1d5db;
}
.tabs button.active { background: rgba(255,255,255,0.10); color: #fff; }
.sideMeta {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.12);
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
}
.sideMeta span { color: var(--sidebar-muted); font-size: 12px; }
.sideMeta strong { font-size: 13px; margin-bottom: 8px; }

.main { min-width: 0; padding: 24px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 24px; letter-spacing: 0; }
h2 { font-size: 18px; letter-spacing: 0; }
p { color: var(--muted); margin-top: 4px; }
.topActions, .filterGroup { display: flex; align-items: center; gap: 8px; }

input, select, button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  font: inherit;
}
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button:disabled { opacity: .65; cursor: wait; }
button.ghost { background: #fff; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--surface-2); border-color: #c5ced8; }
button.danger { background: var(--danger); border-color: var(--danger); }
label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }

.alert {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #efd184;
  border-radius: 8px;
  background: #fff8e6;
  color: var(--warn);
  font-weight: 650;
}
.hidden { display: none; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metrics div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.metrics span, .metrics small { display: block; color: var(--muted); }
.metrics span { font-size: 12px; font-weight: 800; text-transform: uppercase; }
.metrics strong { display: block; margin: 8px 0 3px; font-size: 24px; line-height: 1; font-variant-numeric: tabular-nums; }
.metrics small { font-size: 12px; }

.panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel.active { display: block; }
.panelHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line-2);
  background: #fff;
}
.tableWrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 920px; }
body[data-tab="report"] .metrics div:nth-child(2),
body[data-tab="report"] .metrics div:nth-child(3) { display: none; }
body[data-tab="report"] .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body[data-tab="portfolio"] .metrics div:nth-child(1),
body[data-tab="portfolio"] .metrics div:nth-child(4) { display: none; }
body[data-tab="portfolio"] .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: #4b5563;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: "sort"; margin-left: 6px; color: #9ca3af; font-size: 10px; text-transform: lowercase; }
th[data-sort].sorted[data-dir="asc"]::after { content: "asc"; color: var(--accent); }
th[data-sort].sorted[data-dir="desc"]::after { content: "desc"; color: var(--accent); }
th.resizable {
  resize: horizontal;
  overflow: auto;
  min-width: 92px;
  max-width: 220px;
}
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
td { font-size: 14px; }
.stockCell {
  width: 155px;
  max-width: 155px;
}
.stockCell strong,
.stockCell span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
tbody tr:hover { background: #fbfcfd; }
td span { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 42px 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.positive { color: var(--success); }
.negative { color: var(--danger); }
.pill {
  display: inline-flex;
  align-items: center;
  min-width: 58px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8f5f2;
  color: var(--accent);
  font-weight: 800;
  font-size: 12px;
}

@media (max-width: 900px) {
  .appFrame { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sideMeta { display: none; }
  .topbar, .panelHead { align-items: stretch; flex-direction: column; }
  .topActions { flex-wrap: wrap; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .main { padding: 14px; }
  .metrics { grid-template-columns: 1fr; }
  .topActions, .filterGroup { align-items: stretch; flex-direction: column; }
  input, select, button { width: 100%; }
}
