/* A dividend ledger: masthead with the takeaway, summary tiles, a stock filter rail,
   then holdings, dividend history beside the calendar, then events beside news. */
:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-2: #edf2f0;
  --ink: #13211e;
  --muted: #5a6a66;
  --line: #d9e2df;
  --accent: #0c6957;
  --accent-ink: #ffffff;
  --accent-soft: #ddefe9;
  --my: #0c6957;
  --my-soft: #ddefe9;
  --us: #3b4cae;
  --us-soft: #e5e8f9;
  --ok: #1a7742;
  --ok-soft: #e0f1e6;
  --bad: #b1352a;
  --bad-soft: #f8e2df;
  --warn: #965a00;
  --warn-soft: #f5ebd7;
  --tip-bg: #13211e;
  --tip-ink: #f3f6f5;
  --font-display: "Newsreader", "Iowan Old Style", Georgia, serif;
  --font-body: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
  --r: 12px;
  --r-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513;
    --surface: #151e1c;
    --surface-2: #1b2624;
    --ink: #e5eeeb;
    --muted: #93a39e;
    --line: #283532;
    --accent: #52c3a7;
    --accent-ink: #0b1513;
    --accent-soft: #17352e;
    --my: #52c3a7;
    --my-soft: #17352e;
    --us: #95a4ff;
    --us-soft: #222a4d;
    --ok: #63c98f;
    --ok-soft: #183526;
    --bad: #ff8274;
    --bad-soft: #3d1f1b;
    --warn: #e5a53f;
    --warn-soft: #3a2c14;
    --tip-bg: #e5eeeb;
    --tip-ink: #0e1513;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}
.page {
  max-width: 1160px;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(20px, env(safe-area-inset-top, 0px)) max(48px, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
h1, h2, h3, p { margin: 0; }
h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(30px, 6vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h2 { font-size: 17px; font-weight: 600; text-wrap: balance; }
.eyebrow { font-size: 12px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--accent); text-underline-offset: 2px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 500; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--accent); padding: 0 8px; min-height: 32px; }
.btn.quiet:hover { text-decoration: underline; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; color: var(--bad); font-size: 18px; line-height: 1;
}

/* Masthead */
.masthead { display: flex; flex-direction: column; gap: 14px; }
.mast-top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 24px; }
.mast-text { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1 1 340px; }
.takeaway { color: var(--muted); max-width: 66ch; }
.takeaway b { color: var(--ink); font-weight: 600; }
.mast-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 12px 14px; border-radius: var(--r); background: var(--warn-soft); font-size: 14px;
}
.banner .b-text { flex: 1 1 260px; min-width: 0; }
.banner.info { background: var(--accent-soft); }
.banner.err { background: var(--bad-soft); }

/* Tiles */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.tile .label { font-size: 13px; color: var(--muted); }
.tile .big {
  font-family: var(--font-display); font-size: 34px; line-height: 1.1;
  font-variant-numeric: tabular-nums lining-nums; letter-spacing: -0.01em; overflow-wrap: anywhere;
}
.tile .sub { font-size: 13px; color: var(--muted); }
.tile .sub b { color: var(--ink); font-weight: 500; }

/* Chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 13px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.MY { background: var(--my); }
.dot.US { background: var(--us); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.card-head p { font-size: 13px; color: var(--muted); }
.grid2 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); align-items: start; }

.mk { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }
.mk.MY { background: var(--my-soft); color: var(--my); }
.mk.US { background: var(--us-soft); color: var(--us); }
.pill {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.pill.paid { background: var(--ok-soft); color: var(--ok); }
.pill.announced, .pill.entitled { background: var(--accent-soft); color: var(--accent); }
.pill.expected { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }
.pill.example, .pill.wait { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.up { background: var(--ok-soft); color: var(--ok); }
.pill.down { background: var(--bad-soft); color: var(--bad); }
.up-t { color: var(--ok); }
.down-t { color: var(--bad); }

/* Holdings ledger */
.ledger { display: flex; flex-direction: column; }
.l-head, .l-row {
  display: grid; align-items: center; gap: 4px 14px;
  grid-template-columns: minmax(0, 1.9fr) repeat(6, minmax(0, 1fr));
}
.l-head { font-size: 12px; color: var(--muted); padding: 0 10px 8px; border-bottom: 1px solid var(--line); }
.l-head span:not(:first-child), .l-row .r { text-align: right; }
.l-row { padding: 12px 10px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: var(--r-sm); }
.l-row:last-child { border-bottom: 0; }
.l-row:hover { background: var(--surface-2); }
.l-row.sel { background: var(--accent-soft); }
.l-stock { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.l-name { font-weight: 600; overflow-wrap: anywhere; }
.l-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.l-val { font-variant-numeric: tabular-nums; font-weight: 500; }
.l-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-label { display: none; font-size: 11.5px; color: var(--muted); }
@media (max-width: 760px) {
  .l-head { display: none; }
  .l-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "stock stock" "shares price" "value pl" "div next";
    gap: 10px 14px;
  }
  .l-row > :nth-child(1) { grid-area: stock; }
  .l-row > :nth-child(2) { grid-area: shares; }
  .l-row > :nth-child(3) { grid-area: price; }
  .l-row > :nth-child(4) { grid-area: value; }
  .l-row > :nth-child(5) { grid-area: pl; }
  .l-row > :nth-child(6) { grid-area: div; }
  .l-row > :nth-child(7) { grid-area: next; }
  .l-row .r { text-align: left; }
  .cell-label { display: block; }
}

/* Dividend history small multiples */
.panels { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.panel { position: relative; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 12px 10px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.panel-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.panel-fig { font-family: var(--font-display); font-size: 22px; font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.panel-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.chart-box { width: 100%; min-height: 104px; }
.chart-box svg { display: block; width: 100%; height: auto; overflow: visible; }
.bar { cursor: pointer; }
.bar.past { fill: var(--accent); }
.bar.announced, .bar.entitled { fill: var(--accent); fill-opacity: .4; }
.bar.expected { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 2; }
.chart-box .axis { stroke: var(--line); stroke-width: 1; }
.chart-box .tick { fill: var(--muted); font-size: 11px; font-family: var(--font-body); font-variant-numeric: tabular-nums; }
.tip {
  position: absolute; z-index: 5; pointer-events: none; background: var(--tip-bg); color: var(--tip-ink);
  font-size: 12px; line-height: 1.35; padding: 6px 9px; border-radius: 7px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .lg-paid { background: var(--accent); }
.legend .lg-up { background: var(--accent); opacity: .4; }
.legend .lg-exp { border: 1.5px dashed var(--muted); }

/* Calendar */
.pay-list { display: flex; flex-direction: column; }
.pay-row { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.pay-row:last-child { border-bottom: 0; }
.pay-date { display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: var(--r-sm); background: var(--surface-2); padding: 6px 0; line-height: 1.05; }
.pay-date .d { font-family: var(--font-display); font-size: 22px; font-variant-numeric: tabular-nums lining-nums; }
.pay-date .m { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.pay-row.future .pay-date { background: var(--accent-soft); }
.pay-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pay-body .t { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.pay-body .s { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.pay-amt { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.pay-amt .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.section-label { font-size: 12px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding-top: 6px; }

/* Events */
.ev-list { display: flex; flex-direction: column; }
.ev { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ev:last-child { border-bottom: 0; }
.ev-date { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 2px; }
.ev-date b { display: block; color: var(--ink); font-weight: 600; font-size: 13.5px; }
.ev-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.ev-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ev-title { font-weight: 600; font-size: 14.5px; line-height: 1.35; overflow-wrap: anywhere; }
.ev-sum { font-size: 13.5px; color: var(--muted); overflow-wrap: anywhere; }
.ev-src { font-size: 12.5px; }
.impact { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.impact.positive { color: var(--ok); }
.impact.negative { color: var(--bad); }
.impact.neutral { color: var(--muted); }
.impact svg { width: 10px; height: 10px; }

/* News */
.news-list { display: flex; flex-direction: column; }
.news-item { padding: 11px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.news-item:last-child { border-bottom: 0; }
.news-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); }
.news-head { font-weight: 500; font-size: 14.5px; line-height: 1.4; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
a.news-head:hover { text-decoration: underline; color: var(--accent); }

.empty { border: 1px dashed var(--line); border-radius: var(--r-sm); padding: 18px; text-align: center; color: var(--muted); font-size: 14px; }
.more-row { display: flex; justify-content: center; }
.skel { display: block; height: 14px; border-radius: 6px; background: var(--surface-2); }
.skel.big { height: 36px; width: 60%; }
@media (prefers-reduced-motion: no-preference) {
  .skel { animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: .5; } }
}

/* Manage panel */
.drop {
  position: relative; border: 1.5px dashed var(--line); border-radius: var(--r); padding: 22px 16px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; background: var(--surface-2);
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumbs:empty { display: none; }
.thumb { position: relative; width: 84px; height: 110px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--tip-bg); color: var(--tip-ink); cursor: pointer; font-size: 14px; line-height: 1; }
.status { font-size: 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status.err { color: var(--bad); }
.status.ok { color: var(--ok); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); }
@media (prefers-reduced-motion: no-preference) { .spinner { animation: spin .9s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } }
.review { display: flex; flex-direction: column; gap: 10px; }
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
table.edit-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.edit-table th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.edit-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.edit-table tr:last-child td { border-bottom: 0; }
.edit-table tr.off td:not(:first-child) { opacity: .45; }
.w-add { width: 44px; } .w-tk { width: 130px; } .w-code { width: 104px; } .w-mk { width: 84px; } .w-sh { width: 116px; } .w-ch { width: 130px; } .w-rm { width: 52px; }
.field { font: inherit; font-size: 14px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; min-height: 34px; width: 100%; }
.field:focus { border-color: var(--accent); outline: none; }
.field.n { text-align: right; font-variant-numeric: tabular-nums; }
.field.invalid { border-color: var(--bad); }
.check { width: 18px; height: 18px; accent-color: var(--accent); }
.opts { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.opts label { display: flex; gap: 8px; align-items: center; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hint { font-size: 13px; color: var(--muted); }

footer.foot { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--muted); max-width: 80ch; }

/* Tabs: a row under the title on wide screens, a bottom bar on phones */
.tabbar { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabbar .tab {
  display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 10px 12px 11px; margin-bottom: -1px; cursor: pointer; font-weight: 500; color: var(--muted); font-size: 15px;
}
.tabbar .tab svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabbar .tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabbar .tab[aria-selected="true"] svg { stroke: var(--accent); }
.tabpanel { display: flex; flex-direction: column; gap: 18px; }
@media (max-width: 760px) {
  .page { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; gap: 0; border-bottom: 0; border-top: 1px solid var(--line);
    background: var(--surface);
    padding: 4px max(8px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }
  .tabbar .tab { flex: 1 1 0; flex-direction: column; gap: 3px; padding: 7px 2px 6px; font-size: 11.5px; border-bottom: 0; margin: 0; min-width: 0; }
  .tabbar .tab svg { width: 22px; height: 22px; }
  .tabbar .tab span { white-space: nowrap; }
}

.small { font-size: 13px; }
.stack-head { display: flex; flex-direction: column; gap: 2px; }
.head-fig { font-family: var(--font-display); font-size: 28px; font-variant-numeric: tabular-nums lining-nums; }
.chart-box.tall { min-height: 200px; position: relative; }
.legend .lg-my { background: var(--my); }
.legend .lg-us { background: var(--us); }
.bar-my { fill: var(--my); }
.bar-us { fill: var(--us); }
.gridline { stroke: var(--line); stroke-width: 1; }
#monthly { position: relative; }

.pos { color: var(--ok); }
.neg { color: var(--bad); }
.tile .big.pos, .tile .big.neg { font-weight: 400; }

/* Forms */
.seg { display: inline-flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--surface-2); align-self: flex-start; max-width: 100%; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); min-width: 0; }
.form-grid .full { grid-column: 1 / -1; }
.small-field { width: auto; min-width: 150px; max-width: 100%; }
.edit-table td.r, .edit-table th.r { text-align: right; }
.edit-table td { font-variant-numeric: tabular-nums; }
.edit-table .stock-cell { display: flex; flex-direction: column; gap: 3px; }
.w-pl { width: 170px; } .w-date { width: 110px; }
.tx-type { display: inline-flex; height: 22px; align-items: center; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.tx-type.buy { background: var(--ok-soft); color: var(--ok); }
.tx-type.sell { background: var(--bad-soft); color: var(--bad); }
.tx-type.opening { background: var(--surface-2); color: var(--muted); }
.icon-btn.armed { background: var(--bad); color: var(--surface); border-color: var(--bad); width: auto; padding: 0 10px; border-radius: 999px; font-size: 12.5px; }
/* Phones zoom into inputs smaller than 16px; keep them at 16px there. */
@media (max-width: 760px) { .field { font-size: 16px; } }
