/* TSRA Settlement — light and dark themes, phone first. */

/* Tessara brand tokens (brand/tessara/tessara-concepts.html): Basalt, Marble,
   Tufa, Vein, Gold accent; Schibsted Grotesk, DM Mono, Castoro Titling. */
:root {
  color-scheme: light;
  --basalt: #111214;
  --basalt-2: #1B1D20;
  --marble: #F0F0ED;
  --tufa: #6E6C68;
  --vein: #D9D8D3;
  --gold-light: #94742A;
  --gold-dark: #CFA652;
  --gold-text: #7A5F1E;

  --page: #F7F7F5;
  --surface: #FFFFFF;
  --surface-2: #F0F0ED;
  --ink: #111214;
  --ink-2: #4A4945;
  --muted: #66645F;
  --line: #E8E7E3;
  --line-strong: #DEDDD8;
  --border: #DEDDD8;
  --shadow: none;
  --brand: #111214;
  --accent: #7A5F1E;
  --accent-soft: rgba(148, 116, 42, 0.12);
  --accent-ink: #FFFFFF;
  --button: #111214;
  --button-ink: #F0F0ED;
  --mark-fg: #111214;
  --mark-acc: #94742A;
  /* Data colours: bid/ask for profit/loss, ink/gold for personal/cold */
  --pos: #1F9D6B;
  --neg: #E0484F;
  --pos-text: #17805A;
  --neg-text: #C8363D;
  --personal: #6E6C68;
  --cold: #94742A;
  --grid: #ECEBE7;
  --axis: #D9D8D3;
  --alert-bg: #FBEDEE;
  --alert-ink: #8A1F25;
  --warn-bg: #F6F0E2;
  --warn-ink: #5E4916;
  --radius: 4px;
  --radius-sm: 4px;
  --tabbar-h: 64px;
  --f-title: "Castoro Titling", "Cormorant SC", "Trajan Pro", Georgia, serif;
  --f-sans: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0D0E10;
    --surface: #16181B;
    --surface-2: #1B1D20;
    --ink: #ECEBE7;
    --ink-2: #C4C2BB;
    --muted: #9A978F;
    --line: #222428;
    --line-strong: #2A2C30;
    --border: #2A2C30;
    --brand: #ECEBE7;
    --accent: #CFA652;
    --accent-soft: rgba(207, 166, 82, 0.14);
    --accent-ink: #111214;
    --button: #CFA652;
    --button-ink: #111214;
    --mark-fg: #ECEBE7;
    --mark-acc: #CFA652;
    --pos: #1F9D6B;
    --neg: #E0484F;
    --pos-text: #3DBB88;
    --neg-text: #F0767B;
    --personal: #9A978F;
    --cold: #CFA652;
    --grid: #1F2124;
    --axis: #2A2C30;
    --alert-bg: #3A1618;
    --alert-ink: #FFC9CB;
    --warn-bg: #2E2614;
    --warn-ink: #EAD7A6;
  }
}

/* Manual choice from the header switch wins over the system setting. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0D0E10;
  --surface: #16181B;
  --surface-2: #1B1D20;
  --ink: #ECEBE7;
  --ink-2: #C4C2BB;
  --muted: #9A978F;
  --line: #222428;
  --line-strong: #2A2C30;
  --border: #2A2C30;
  --brand: #ECEBE7;
  --accent: #CFA652;
  --accent-soft: rgba(207, 166, 82, 0.14);
  --accent-ink: #111214;
  --button: #CFA652;
  --button-ink: #111214;
  --mark-fg: #ECEBE7;
  --mark-acc: #CFA652;
  --pos: #1F9D6B;
  --neg: #E0484F;
  --pos-text: #3DBB88;
  --neg-text: #F0767B;
  --personal: #9A978F;
  --cold: #CFA652;
  --grid: #1F2124;
  --axis: #2A2C30;
  --alert-bg: #3A1618;
  --alert-ink: #FFC9CB;
  --warn-bg: #2E2614;
  --warn-ink: #EAD7A6;
}


* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 var(--f-sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* Header */

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { display: flex; align-items: center; gap: 28px; height: 60px; }

.brand { display: flex; align-items: center; gap: 8px; color: var(--brand); }
.brand:hover { text-decoration: none; }
.mark { width: 24px; height: 24px; display: block; }
.mark .fg { fill: var(--mark-fg); }
.mark .acc { fill: var(--mark-acc); }
.brand { gap: 10px; }
.brand .word { font-weight: 600; letter-spacing: 0.24em; text-transform: uppercase; font-size: 14px; line-height: 1; }
.brand .sub { color: var(--muted); font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; padding-left: 10px; border-left: 1px solid var(--line-strong); line-height: 1; }

.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { color: var(--ink-2); padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.topnav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.topnav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }

.who { display: flex; align-items: center; gap: 10px; }
.who form { margin: 0; }
.who-name { color: var(--ink-2); font-size: 14px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; font-family: var(--f-mono);
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 13px;
}
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: 1px solid transparent; background: none; color: var(--ink-2); border-radius: 10px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .sun { display: none; }
  :root:not([data-theme]) .theme-toggle .moon { display: block; }
}
.icon-btn svg, .tabbar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Bottom tab bar (phones) */

.tabbar { display: none; }

/* Page */

main { padding-top: 28px; padding-bottom: 32px; }
h1 { font-family: var(--f-title); font-weight: 400; font-size: 32px; line-height: 1.1; margin: 0; letter-spacing: 0.02em; }
h2 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.label, .eyebrow, .tile-label, .hero-label, th, .legend, .tabbar a span {
  font-family: var(--f-mono); letter-spacing: 0.08em; text-transform: uppercase;
}

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.eyebrow { color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-size: 14px; margin-bottom: 6px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card > h2 { margin-bottom: 14px; }

/* "Your share" hero */

.hero {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; align-items: center;
  background: var(--basalt); border: 1px solid var(--basalt-2);
  color: var(--marble); border-radius: var(--radius); padding: 28px; margin-bottom: 16px;
}
.hero-label { font-size: 11px; color: #9A978F; }
.hero-value { font-family: var(--f-mono); font-size: 40px; font-weight: 500; letter-spacing: -0.02em; line-height: 1.1; margin: 8px 0 8px; font-variant-numeric: tabular-nums; }
.hero-value .ccy { font-size: 14px; color: var(--gold-dark); margin-left: 8px; letter-spacing: 0.08em; }
.hero-sub { font-size: 14px; color: var(--vein); }
.hero-sub strong { color: var(--marble); font-weight: 600; }
.split { display: flex; flex-direction: column; gap: 10px; }
.split-bar { display: block; width: 100%; height: 8px; }
.split-bar .track { fill: rgba(240, 240, 237, 0.08); }
.split-bar .p { fill: var(--marble); }
.split-bar .c { fill: var(--gold-dark); }
.split-rows { display: grid; gap: 6px; font-size: 14px; }
.split-row { display: flex; justify-content: space-between; gap: 12px; color: var(--vein); }
.split-row strong { color: var(--marble); font-family: var(--f-mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 1px; }
.dot.p { background: var(--marble); }
.dot.c { background: var(--gold-dark); }

/* KPI tiles */

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.tile-label { color: var(--muted); font-size: 11px; }
.tile-value { font-family: var(--f-mono); font-size: 24px; font-weight: 500; letter-spacing: -0.02em; margin: 8px 0 4px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.tile-value.pos { color: var(--pos-text); }
.tile-value.neg { color: var(--neg-text); }
.tile-sub { color: var(--muted); font-size: 13px; }

/* Tables */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 400; color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--line-strong); padding: 8px 10px; white-space: nowrap; }
td { border-bottom: 1px solid var(--line); padding: 11px 10px; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-family: var(--f-mono); font-size: 13.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.strong { font-weight: 600; }
.pos-text { color: var(--pos-text); }
.neg-text { color: var(--neg-text); }
.nowrap { white-space: nowrap; }
.small-role { font-size: 13px; font-weight: 400; }
tr.me td { background: var(--accent-soft); }
tr.total td { font-weight: 650; border-top: 1px solid var(--line-strong); }
tr.link-row { cursor: pointer; }
tr.link-row:hover td { background: var(--surface-2); }
.badge { display: inline-block; font-family: var(--f-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 2px 8px; margin-left: 6px; vertical-align: 1px; }
.scroll { overflow-x: auto; }

/* Chart */

.legend { display: flex; gap: 16px; font-size: 11px; color: var(--muted); }
.sw { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; }
.sw.pos { background: var(--pos); }
.sw.neg { background: var(--neg); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart-sm { display: none; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-family: var(--f-mono); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar.pos { fill: var(--pos); }
.chart .bar.neg { fill: var(--neg); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: var(--ink); fill-opacity: 0.04; }
.tooltip {
  position: absolute; top: 0; pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px 10px; font-size: 13px; display: flex; flex-direction: column; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tooltip[hidden] { display: none; }

/* Forms */

.stack { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 550; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 11px 12px; width: 100%;
  min-height: 46px;
}
input:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
input[inputmode="decimal"] { font-variant-numeric: tabular-nums; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0; display: flex; flex-direction: column; gap: 14px; min-width: 0; background: var(--surface-2); }
legend { font-weight: 650; padding: 0 6px; }
.pct-input { display: flex; align-items: center; gap: 8px; max-width: 180px; }
.pct-input span { font-family: var(--f-mono); color: var(--muted); }
.month-pick-value { font-family: var(--f-mono); font-size: 20px; margin: 4px 0; }
.warn:last-child { margin-bottom: 0; }
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

button, .button {
  font: inherit; font-size: 15px; font-weight: 550; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 16px;
}
.button:hover, button:hover { text-decoration: none; filter: brightness(0.97); }
button.primary, .button.primary { background: var(--button); border-color: var(--button); color: var(--button-ink); }
button.danger { color: var(--neg-text); }

.alert { background: var(--alert-bg); color: var(--alert-ink); padding: 12px 14px; border-radius: var(--radius-sm); margin: 0 0 16px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 12px 14px; border-radius: var(--radius-sm); margin: 0 0 16px; }

.muted { color: var(--ink-2); }
.small { font-size: 13px; margin: 14px 0 0; }
.notes { white-space: pre-wrap; margin: 0; }
code.detail { font-size: 12px; color: var(--ink-2); word-break: break-word; }

.empty { text-align: center; padding: 48px 20px; }
.empty p { color: var(--ink-2); max-width: 460px; margin: 10px auto 18px; }

/* Sign-in */

.login { max-width: 400px; margin: 48px auto; }
.login .brand { justify-content: center; margin-bottom: 20px; }
.login .mark { width: 44px; height: 44px; }
.login .brand { flex-direction: column; gap: 14px; }
.login .brand .word { font-size: 16px; }
.login .brand .sub { border-left: 0; padding-left: 0; }
.login h1 { font-size: 26px; margin-bottom: 6px; }
.login .muted { margin: 0 0 18px; }
.login button { width: 100%; }

.login.wide { max-width: 520px; }
.code-input { font-family: var(--f-mono); font-size: 24px; letter-spacing: 0.3em; text-align: center; }
.steps { margin: 18px 0 0; padding-left: 20px; display: grid; gap: 18px; }
.steps li { padding-left: 4px; }
.steps .hint { margin: 10px 0 6px; }
.qr-box { margin-top: 12px; display: inline-block; background: #FFFFFF; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.qr { display: block; width: 200px; height: 200px; }
.manual-key { display: block; font-family: var(--f-mono); font-size: 15px; letter-spacing: 0.06em; background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius); word-break: break-all; user-select: all; }
.setup-form { margin-top: 10px; }
/* People */
.who-link { display: flex; align-items: center; gap: 10px; color: inherit; }
.who-link:hover { text-decoration: none; }
.person-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
fieldset.choice { background: none; padding: 12px 14px; gap: 8px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; }
label.inline input { width: auto; min-height: 0; }
.notice { border-color: var(--accent); }
.creds { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0; }
.creds dt { color: var(--muted); font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; align-self: center; }
.creds dd { margin: 0; }
.shares-table .pct-input { margin-left: auto; max-width: 140px; }
.shares-table input[type=checkbox] { width: 20px; height: 20px; min-height: 0; }

/* Journal */
.privacy { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin: -6px 0 16px; }
.privacy svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; }
.seg-tabs { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg-tabs a { padding: 8px 16px; color: var(--ink-2); font-size: 14px; font-weight: 500; }
.seg-tabs a + a { border-left: 1px solid var(--line-strong); }
.seg-tabs a:hover { text-decoration: none; background: var(--surface-2); }
.seg-tabs a[aria-current="page"] { background: var(--ink); color: var(--page); }
.journal-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: end; }
.calc { padding: 8px 0; }
.calc-value { font-family: var(--f-mono); font-size: 24px; margin: 4px 0 2px; }
.calc-value.pos, .tile-value.pos { color: var(--pos-text); }
.calc-value.neg, .tile-value.neg { color: var(--neg-text); }
.journal-form .form-actions { display: flex; gap: 8px; margin-top: 16px; }
.journal-form > .hint { margin: 10px 0 0; }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 12px; }
.month-nav .icon-btn { font-size: 18px; border: 1px solid var(--line-strong); }
.month-nav span.icon-btn { border-color: transparent; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions form { margin: 0; }
.small-btn { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.foot { color: var(--muted); font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.04em; padding-bottom: 32px; }

/* Tablet */

@media (max-width: 860px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .journal-grid { grid-template-columns: 1fr 1fr; }
  .hero { grid-template-columns: 1fr; gap: 18px; }
}

/* Phone */

@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar-inner { height: 54px; gap: 12px; }
  .topnav, .who-name { display: none; }
  .who { margin-left: auto; }
  .brand .sub { display: none; }

  body.signed-in { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--border);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); font-size: 11px; font-weight: 550;
  }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .tabbar svg { width: 24px; height: 24px; }

  main { padding-top: 22px; }
  h1 { font-size: 26px; }
  .page-head { margin-bottom: 14px; align-items: center; }
  .page-head .hide-phone { display: none; } /* the tab bar has "Enter" */

  .card { padding: 16px; margin-bottom: 12px; }
  .hero { padding: 20px; margin-bottom: 12px; }
  .hero-value { font-size: 34px; }
  .tiles { gap: 10px; margin-bottom: 12px; }
  .tile { padding: 14px; }
  .tile-value { font-size: 20px; }

  .chart-lg { display: none; }
  .chart-sm { display: block; }
  .chart-sm .tick { font-size: 11px; }

  /* Tables become stacked cards */
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
  .rtable tbody tr:last-child { border-bottom: 0; }
  .rtable td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .rtable td::before { content: attr(data-label); color: var(--muted); font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; text-align: left; align-self: center; }
  .rtable td.primary { display: block; text-align: left; font-weight: 600; font-size: 15px; padding-bottom: 6px; }
  .rtable td.primary::before { content: none; }
  .rtable td:empty { display: none; }
  .rtable tr.me td { background: none; }
  .rtable tr.me { background: var(--accent-soft); margin: 0 -16px; padding: 10px 16px; width: calc(100% + 32px); }
  .rtable tr.total td { border-top: 0; }

  .tiles.three { grid-template-columns: 1fr; }
  .person-grid { grid-template-columns: 1fr; }
  .journal-grid { grid-template-columns: 1fr 1fr; }
  .journal-grid label:first-child { grid-column: 1 / -1; }
  .calc { grid-column: 1 / -1; padding: 0; }
  .journal-form .form-actions button { flex: 1; }
  .rtable td.row-actions { justify-content: flex-start; padding-top: 8px; }
  .rtable td.row-actions::before { content: none; }
  .seg-tabs { width: 100%; }
  .seg-tabs a { flex: 1; text-align: center; }
  .accounts-grid { grid-template-columns: 1fr; }
  .form-actions button { width: 100%; }
  .actions { width: 100%; }
  .actions .button, .actions form, .actions button { flex: 1; }
  .foot { padding-bottom: 20px; }
}
