/* Theme tokens. Dark is the default; [data-theme] on <html> picks the set. */
:root, [data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f4;
  --card: #ffffff;
  --ink: #111111;
  --muted: #7a7a76;
  --line: #ececea;
  --soft: #f3f3f1;
  --hover: #f8f8f6;
  --pos: #12a150;
  --neg: #e5484d;
  --accent: #111111;
  --accent-ink: #ffffff;
  --topbar: rgba(255, 255, 255, .88);
  --field: #ffffff;
  --seg-on: #ffffff;
  --pos-soft: #e7f6ee;
  --neg-soft: #fdecec;
  --div-soft: #eef1fd;
  --div-ink: #3e5bd8;
  --danger-line: #f3c7c8;
  --shadow: 0 1px 2px rgba(17,17,17,.04), 0 8px 24px rgba(17,17,17,.03);
  --chart-grid: #f1f1ef;
  --chart-tick: #9a9a95;
  --chart-line: #111111;
  --chart-invested: #bdbdb8;
  --bar: #111111;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0c;
  --card: #161617;
  --ink: #f2f2ef;
  --muted: #8f8f8a;
  --line: #252527;
  --soft: #1f1f21;
  --hover: #1c1c1e;
  --pos: #2fcf7a;
  --neg: #ff6369;
  --accent: #f2f2ef;
  --accent-ink: #111111;
  --topbar: rgba(11, 11, 12, .82);
  --field: #111112;
  --seg-on: #2c2c2f;
  --pos-soft: rgba(47, 207, 122, .14);
  --neg-soft: rgba(255, 99, 105, .14);
  --div-soft: rgba(110, 140, 255, .16);
  --div-ink: #9db0ff;
  --danger-line: rgba(255, 99, 105, .35);
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  --chart-grid: #222224;
  --chart-tick: #6f6f6b;
  --chart-line: #f2f2ef;
  --chart-invested: #55554f;
  --bar: #f2f2ef;
}
:root { --radius: 18px; --tabbar: 0px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px; -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
a { color: inherit; text-decoration: none; }
.num, td.r, .big { font-variant-numeric: tabular-nums; }

/* top bar */
.top { position: sticky; top: 0; z-index: 10; background: var(--topbar);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top); }
.top .in { max-width: 1240px; margin: 0 auto; padding: 14px 24px; display: flex;
  align-items: center; gap: 28px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 22px; letter-spacing: -.02em; font-weight: 600; }
.brand img { border-radius: 8px; }
.login .brand img { border-radius: 12px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 8px 14px; border-radius: 999px; color: var(--muted); white-space: nowrap; }
.nav a.on, .nav a:hover { background: var(--soft); color: var(--ink); }
.tools { display: flex; align-items: center; gap: 8px; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: transparent;
  color: var(--ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.iconbtn svg { width: 19px; height: 19px; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 500; cursor: pointer;
  transition: transform .05s, opacity .15s; }
.btn:active { transform: scale(.98); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.danger { background: transparent; color: var(--neg); border: 1px solid var(--danger-line); }

/* layout */
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.card { background: var(--card); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card h2 { font-size: 20px; font-weight: 600; margin: 0 0 16px; letter-spacing: -.01em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .flat { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.ellip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* hero */
.big { font-size: 40px; font-weight: 600; letter-spacing: -.02em; margin: 4px 0; }
.hero-change { display: flex; align-items: center; gap: 10px; font-weight: 500; flex-wrap: wrap; }
.chg { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; }
.chg .arrow { font-size: 12px; }
.hero-change .chg { padding: 3px 9px; border-radius: 999px; background: var(--soft); font-size: 14px; }
.hero-change .chg.pos { background: var(--pos-soft); } .hero-change .chg.neg { background: var(--neg-soft); }
td .sub .chg.pos { color: var(--pos); } td .sub .chg.neg { color: var(--neg); }
.chips { display: flex; gap: 4px; margin: 18px 0 8px; flex-wrap: wrap; }
.chips a { padding: 7px 14px; border-radius: 10px; color: var(--muted); font-size: 14px; }
.chips a.on { background: var(--soft); color: var(--ink); font-weight: 600; }
.chips.seg { background: var(--soft); border-radius: 12px; padding: 4px; gap: 2px; flex-wrap: nowrap; overflow-x: auto; }
.chips.seg a { padding: 6px 10px; font-size: 13px; flex: 1; text-align: center; }
.chips.seg a.on { background: var(--seg-on); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.chart { position: relative; height: 280px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 18px; }
.stat { background: var(--soft); border-radius: 14px; padding: 12px 14px; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-weight: 600; margin-top: 4px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 400; font-size: 13px; padding: 8px 6px;
  border-bottom: 1px solid var(--line); }
td { padding: 14px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--hover); }
tr.link td:first-child { border-radius: 12px 0 0 12px; } tr.link td:last-child { border-radius: 0 12px 12px 0; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.pill { display: inline-block; background: var(--soft); border-radius: 6px; padding: 1px 7px;
  font-size: 12px; color: var(--muted); margin-left: 6px; }
.logo { width: 40px; height: 40px; border-radius: 50%; background: var(--soft); flex: none; }
img.logo { object-fit: cover; box-shadow: 0 0 0 1px var(--line); background: #fff; }
.big-logo img.logo { width: 56px; height: 56px; }
.name { display: flex; align-items: center; gap: 12px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; font-weight: 500; }
.tag.BUY { background: var(--pos-soft); color: var(--pos); }
.tag.SELL { background: var(--neg-soft); color: var(--neg); }
.tag.DIVIDEND { background: var(--div-soft); color: var(--div-ink); }
.tag.TRANSFER_IN { background: var(--soft); color: var(--muted); }
.txrow { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.txrow:last-child { border-bottom: 0; }
.txrow img.logo { width: 34px; height: 34px; }

/* donut legend + bars */
.legend { margin-top: 14px; }
.legend .row { padding: 7px 0; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 8px; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 160px; margin-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.bars .b span { width: 100%; background: var(--bar); border-radius: 6px 6px 2px 2px; min-height: 2px; }

/* forms */
form.f { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
form.f .full { grid-column: 1 / -1; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: var(--field); color: var(--ink); }
input:focus, select:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.hits { border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; display: none; background: var(--field); }
.hits div { padding: 9px 12px; cursor: pointer; } .hits div:hover { background: var(--soft); }

.login { max-width: 360px; margin: 14vh auto; }
.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 10px 16px 30px; }

/* mobile tab bar (iPhone web app) */
.tabbar { display: none; }
@media (max-width: 960px) {
  :root { --tabbar: 64px; }
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .big { font-size: 34px; }
  .top .in { padding: 10px 16px; gap: 12px; }
  .top .nav { display: none; }
  .top .brand { flex: 1; font-size: 20px; }
  .wrap { padding: 14px 12px; }
  .card { padding: 18px 16px; border-radius: 20px; }
  .hide-m { display: none; }
  form.f { grid-template-columns: 1fr; }
  input, select { font-size: 16px; } /* stops iOS zooming into fields */
  .chart { height: 230px; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--topbar); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 10.5px; color: var(--muted); padding: 4px 0; }
  .tabbar a svg { width: 23px; height: 23px; }
  .tabbar a.on { color: var(--ink); }
}

/* positions P/L toggle */
#positions .pl-day, #positions .pl-period, #positions .pl-all { display: none; }
#positions[data-pl="day"] .pl-day, #positions[data-pl="period"] .pl-period, #positions[data-pl="all"] .pl-all { display: block; }
#positions th span.pl-day, #positions th span.pl-period, #positions th span.pl-all { display: none; }
#positions[data-pl="day"] th span.pl-day, #positions[data-pl="period"] th span.pl-period,
#positions[data-pl="all"] th span.pl-all { display: inline; }
.pltoggle { flex: none; }
.pltoggle a { padding: 5px 12px; }
.chips.seg a { white-space: nowrap; }
@media (max-width: 960px) {
  td { padding: 12px 3px; }
  td.r, th.r { white-space: nowrap; font-size: 14px; }
  td.r .sub { font-size: 12px; }
  #positions td:first-child { max-width: 44vw; }
  #positions .name { gap: 10px; }
  #positions .name > div { min-width: 0; }
  #positions .name > div > div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #positions img.logo { width: 34px; height: 34px; }
  #positions .pill { display: none; }
  .pltoggle a { padding: 5px 10px; }
}
.grid > * { min-width: 0; }
@media (max-width: 960px) {
  .card { overflow-x: auto; }
  .tx-table td:nth-child(2) { max-width: 30vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tx-table td:nth-child(3), .tx-table th:nth-child(3) { display: none; }
  .tx-table td:first-child { font-size: 13px; }
}
.tx-table td:nth-child(2) .sub { display: none; }
@media (max-width: 960px) { .tx-table td:nth-child(2) .sub { display: block; } }
@media (max-width: 960px) {
  .filters { flex-wrap: wrap; }
  .filters input { flex: 1 1 100%; }
  .filters select { flex: 1; max-width: none !important; }
}
@media (max-width: 960px) { #positions th span { display: none !important; } }
