:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-strong: #f7f9fb;
  --text: #111318;
  --muted: #747b86;
  --line: #e6e9ee;
  --accent: #111318;
  --accent-soft: #f0f2f5;
  --gain: #d64b42;
  --loss: #12a667;
  --shadow: none;
  --body-bg:
    linear-gradient(180deg, #ffffff 0%, var(--bg) 34%, #eef1f4 100%);
  --panel-bg: var(--panel);
  --control-bg: #ffffff;
  --active-tab-bg: #ffffff;
  --surface-muted: #f1f3f5;
  --chart-muted: #edf0f3;
  --bill-primary: #2f7df3;
  --bill-reference: #e33b4f;
  --bill-hero-bg: linear-gradient(180deg, #4b96f6 0%, #1169ed 100%);
  --bill-hero-text: #ffffff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080a0d;
  --panel: #12161c;
  --panel-strong: #171d25;
  --text: #f4f7fb;
  --muted: #8d98a8;
  --line: #252c36;
  --accent: #f4f7fb;
  --accent-soft: rgba(244, 247, 251, 0.12);
  --gain: #f6465d;
  --loss: #0ecb81;
  --shadow: none;
  --body-bg:
    linear-gradient(180deg, #0c1016 0%, var(--bg) 42%, #050608 100%);
  --panel-bg: var(--panel);
  --control-bg: #0c1016;
  --active-tab-bg: #1c232d;
  --surface-muted: #0f141b;
  --chart-muted: #222a35;
  --bill-primary: #f4f7fb;
  --bill-reference: #f6465d;
  --bill-hero-bg: linear-gradient(180deg, #171d25 0%, #10151d 100%);
  --bill-hero-text: #f4f7fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--body-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 30px 16px 148px;
  padding-top: max(30px, calc(env(safe-area-inset-top, 0px) + 18px));
  padding-bottom: calc(148px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 18px;
}

.brand-word {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--control-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.brand-word:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.12;
}

h2 {
  font-size: 17px;
}

.theme-toggle {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.theme-icon {
  font-size: 18px;
  line-height: 1;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.bottom-tabs {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  width: min(calc(100% - 32px), 448px);
  margin: 0;
  transform: translateX(-50%);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.12);
}

.bottom-flow-controls {
  position: fixed;
  left: 50%;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  z-index: 21;
  display: none;
  transform: translateX(-50%);
}

.bottom-flow-controls.active {
  display: block;
}

.sheet-backdrop[hidden] {
  display: none;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.46);
}

.portfolio-sheet {
  width: min(100%, 480px);
  max-height: min(78vh, 620px);
  overflow: auto;
  padding: 10px 22px 26px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--panel-bg);
  color: var(--text);
}

.add-position-sheet {
  max-height: min(88vh, 760px);
}

.sheet-handle {
  width: 44px;
  height: 4px;
  margin: 0 auto 18px;
  border-radius: 999px;
  background: var(--line);
}

.sheet-head,
.sheet-total-row,
.portfolio-combo-row,
.sheet-add-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.sheet-head {
  margin-bottom: 22px;
}

.sheet-head h2 {
  font-size: 24px;
  font-weight: 900;
}

.sheet-link {
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
}

.sheet-total-row {
  margin-bottom: 26px;
}

.sheet-total-row div {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.sheet-total-row span,
.portfolio-combo-main em {
  color: var(--muted);
  font-size: 14px;
  font-style: normal;
}

.sheet-total-row strong {
  overflow-wrap: anywhere;
  font-size: 31px;
  line-height: 1.05;
}

.sheet-pill {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--text);
  color: var(--panel-bg);
  cursor: pointer;
  font-weight: 800;
}

.portfolio-combo-row,
.sheet-add-row {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.portfolio-combo-row {
  padding: 16px 0 28px;
}

.portfolio-combo-list {
  display: grid;
  gap: 8px;
}

.portfolio-combo-item {
  padding: 14px 0;
  border-radius: 8px;
}

.portfolio-combo-item.active {
  outline: 1px solid var(--text);
  outline-offset: 4px;
}

.portfolio-ring {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1;
  background: radial-gradient(circle at center, var(--panel-bg) 56%, transparent 57%), var(--chart-muted);
  box-shadow: inset 0 0 0 1px var(--line);
  pointer-events: none;
}

.portfolio-combo-main {
  display: grid;
  flex: 1 1 auto;
  gap: 7px;
  min-width: 0;
}

.portfolio-combo-main strong {
  font-size: 20px;
}

.portfolio-combo-main small {
  color: var(--text);
  font-size: 18px;
}

.portfolio-name-input {
  height: 38px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
}

.portfolio-manage-hint {
  color: var(--muted);
  font-size: 12px;
}

.portfolio-delete-button {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: #9c2f2a;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.sheet-chevron {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 34px;
  line-height: 1;
}

.sheet-add-row {
  padding: 22px 0 2px;
  border-top: 1px solid var(--line);
  justify-content: flex-start;
  font-size: 19px;
}

.sheet-add-row span {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 2px solid var(--text);
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
}

.sheet-form {
  border: 0;
  padding: 0;
  background: transparent;
}

.sheet-records {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.more-option {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 13px 0;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.more-option:first-of-type {
  border-top: 0;
}

.more-option strong {
  font-size: 15px;
}

.more-option small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tab {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.active {
  background: var(--active-tab-bg);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(18, 24, 38, 0.06);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 14px;
}

.summary-panel,
.section-block,
.record-form,
.settings-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.summary-panel {
  padding: 18px;
}

.overview-minimal .summary-panel {
  min-height: calc(100vh - 230px);
  display: grid;
  align-content: start;
  padding: 28px 18px;
}

.summary-main {
  display: grid;
  gap: 7px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.overview-minimal .summary-main {
  min-height: 190px;
  align-content: center;
  border-bottom: 0;
}

.summary-main span,
.summary-grid span,
.section-title span,
label span,
.source-card span {
  color: var(--muted);
  font-size: 13px;
}

.summary-main strong {
  font-size: 34px;
  letter-spacing: 0;
}

.overview-minimal .summary-main strong {
  font-size: 42px;
  line-height: 1.08;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding-top: 15px;
}

.overview-minimal .summary-grid {
  display: none;
}

.summary-grid div {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.summary-grid strong {
  overflow-wrap: anywhere;
  font-size: 16px;
}

.data-status {
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.overview-action-bar {
  position: fixed;
  left: 50%;
  bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  z-index: 19;
  grid-template-columns: 1fr;
  width: min(calc(100% - 32px), 448px);
  margin: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-bg);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.12);
  transform: translateX(-50%);
}

.overview-action-bar .primary-button {
  height: 62px;
  font-size: 17px;
  font-weight: 850;
}

.section-block,
.settings-panel {
  padding: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.portfolio-section {
  overflow: hidden;
}

.segment-control {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.segment-control button {
  min-width: 52px;
  height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segment-control button.active {
  background: var(--active-tab-bg);
  color: var(--text);
  font-weight: 800;
}

.flow-scroll {
  overflow: auto;
  padding: 2px 0 4px;
}

.portfolio-flow {
  min-height: 420px;
}

.portfolio-flow.portrait {
  min-width: 320px;
}

.portfolio-flow svg {
  display: block;
  width: 100%;
  height: auto;
}

.flow-label {
  fill: var(--text);
  font-size: 22px;
  font-weight: 650;
}

.flow-root-label {
  fill: var(--accent);
}

.flow-value {
  fill: var(--muted);
  font-size: 19px;
}

.flow-empty {
  min-height: 300px;
  display: grid;
  align-content: center;
}

.allocation-list,
.position-list,
.record-list {
  display: grid;
  gap: 10px;
}

.allocation-row {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  align-items: center;
  gap: 10px;
}

.allocation-row strong {
  font-size: 14px;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--chart-muted);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.position-card,
.record-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-strong);
}

.position-card {
  display: grid;
  gap: 12px;
}

.position-head,
.position-metrics,
.position-actions,
.record-head,
.record-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.position-actions,
.record-actions {
  justify-content: flex-end;
  gap: 14px;
}

.position-actions button,
.record-actions button {
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.position-actions button:last-child,
.record-actions button:last-child {
  color: #9c2f2a;
}

.asset-name {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.asset-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-name span,
.metric span,
.record-card span,
.record-card small {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.position-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.metric {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.metric strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.gain {
  color: var(--gain);
}

.loss {
  color: var(--loss);
}

.record-form {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.form-header {
  display: grid;
  gap: 6px;
}

.form-header p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

label {
  display: grid;
  gap: 7px;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.hidden {
  display: none !important;
}

input,
select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--text);
  padding: 0 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.12);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.secondary-button {
  height: 46px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  border: 0;
  background: var(--accent);
  color: #fff;
}

:root[data-theme="dark"] .primary-button {
  color: #080a0d;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--text);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

.record-card {
  display: grid;
  gap: 8px;
}

.settings-panel {
  display: grid;
  gap: 14px;
}

.bill-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
}

.bill-head,
.bill-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bill-head span {
  color: var(--muted);
  font-size: 13px;
}

.bill-head strong {
  font-size: 15px;
}

.bill-hero {
  display: grid;
  gap: 7px;
  min-height: 128px;
  align-content: center;
  padding: 20px 16px;
  border-radius: 8px;
  background: var(--bill-hero-bg);
  color: var(--bill-hero-text);
  text-align: center;
}

.bill-hero span,
.bill-hero small,
.bill-hero .gain,
.bill-hero .loss {
  color: inherit;
}

.bill-hero span {
  font-size: 14px;
  opacity: 0.86;
}

.bill-hero strong {
  overflow-wrap: anywhere;
  font-size: 34px;
  line-height: 1.08;
}

.bill-hero small {
  font-size: 14px;
  opacity: 0.9;
}

.bill-range-scroll {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  padding: 0 0 2px;
  scrollbar-width: none;
}

.bill-range-scroll::-webkit-scrollbar {
  display: none;
}

.bill-range-scroll button {
  position: relative;
  flex: 0 0 auto;
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.bill-range-scroll button.active {
  color: var(--text);
  font-weight: 800;
}

.bill-range-scroll button.active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: var(--bill-primary);
  transform: translateX(-50%);
}

.bill-chart-head {
  align-items: flex-start;
}

.bill-chart-head strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-align: right;
}

.bill-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.bill-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.bill-legend i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.primary-line {
  background: var(--bill-primary);
}

.reference-line {
  background: var(--bill-reference);
}

.bill-chart {
  min-height: 260px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel-bg);
}

.bill-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.bill-grid {
  stroke: var(--line);
  stroke-dasharray: 5 7;
  stroke-width: 1;
}

.bill-zero {
  stroke: var(--muted);
  stroke-dasharray: 4 5;
  stroke-opacity: 0.32;
  stroke-width: 1;
}

.bill-axis {
  fill: var(--muted);
  font-size: 12px;
}

.bill-area {
  fill: url(#billAreaFill);
}

.bill-main-line,
.bill-ref-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bill-main-line {
  stroke: var(--bill-primary);
  stroke-width: 3.2;
}

.bill-ref-line {
  stroke: var(--bill-reference);
  stroke-width: 2.8;
  stroke-opacity: 0.9;
}

.bill-metric-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.bill-metric-switch button {
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.bill-metric-switch button.active {
  background: var(--active-tab-bg);
  color: var(--text);
  font-weight: 800;
}

.bill-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.bill-empty {
  min-height: 240px;
  display: grid;
  align-content: center;
}

.toggle-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.toggle-line span {
  display: grid;
  gap: 4px;
}

.toggle-line strong {
  color: var(--text);
  font-size: 14px;
}

.toggle-line small {
  color: var(--muted);
  line-height: 1.35;
}

.toggle-line input {
  width: 20px;
  height: 20px;
}

.source-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-muted);
}

.source-card p {
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.empty-state {
  padding: 22px 12px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
}

.empty-state p {
  font-size: 13px;
}

.visual-grid {
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 14px;
}

.donut-card,
.pnl-chart {
  min-width: 0;
}

.donut {
  display: grid;
  place-items: center;
  width: 128px;
  height: 128px;
  margin: 2px auto 12px;
  border-radius: 50%;
  background: var(--chart-muted);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: var(--panel-bg);
}

.donut span {
  position: relative;
  z-index: 1;
  font-weight: 800;
}

.legend-list,
.pnl-bars {
  display: grid;
  gap: 8px;
}

.legend-row,
.pnl-row-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 7px;
  font-size: 12px;
}

.legend-row i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.legend-row span,
.pnl-row-head span {
  color: var(--muted);
}

.pnl-chart h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.pnl-row {
  display: grid;
  gap: 5px;
}

.pnl-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--chart-muted);
}

.pnl-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.gain-bg {
  background: var(--gain);
}

.loss-bg {
  background: var(--loss);
}

.empty-inline {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

@media (max-width: 380px) {
  .summary-grid,
  .position-metrics,
  .split,
  .visual-grid,
  .quick-actions {
    grid-template-columns: 1fr;
  }

  .allocation-row {
    grid-template-columns: 60px 1fr;
  }

  .allocation-row strong:last-child {
    grid-column: 2;
  }

  .overview-action-bar {
    grid-template-columns: 1fr;
  }

  .position-head,
  .record-head {
    display: grid;
  }

  .position-actions,
  .record-actions {
    justify-content: flex-start;
  }
}
