:root {
  color-scheme: dark;
  --bg: #101312;
  --panel: #171b1a;
  --panel-soft: #1e2422;
  --surface: #121615;
  --line: #2e3935;
  --text: #f2f5f1;
  --muted: #9ba8a2;
  --accent: #ffff00;
  --accent-2: #abff00;
  --danger: #ff6b6b;
  --warning: #ffc857;
  --shadow: 0 18px 45px rgba(0, 0, 0, .28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body.alert-active {
  animation: alertPulse 1.2s ease-in-out infinite alternate;
}

@keyframes alertPulse {
  from { background: var(--bg); }
  to { background: linear-gradient(135deg, #101312 0%, rgba(255, 255, 0, .28) 52%, rgba(171, 255, 0, .22) 100%); }
}

button,
input,
select {
  font: inherit;
}

button,
select {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 8px;
}

button {
  cursor: pointer;
  padding: 10px 14px;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: default;
  opacity: .58;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1211;
  color: var(--text);
  padding: 10px 11px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 14px;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.summary-band,
.workspace,
.panel-head,
.asset-row,
.asset-main,
.topbar-actions,
.chart-controls,
.alert-row,
.bar-row {
  display: flex;
}

.topbar {
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.title-area {
  min-width: 280px;
}

.portfolio-title-line {
  display: flex;
  align-items: center;
  gap: 12px;
}

.portfolio-name-input {
  width: min(520px, 70vw);
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1;
  font-weight: 800;
}

.portfolio-name-input:focus {
  outline: 1px solid var(--accent);
  outline-offset: 6px;
  border-radius: 4px;
}

.platform-logo {
  width: auto;
  min-width: 58px;
  height: 58px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.05;
  padding: 0 8px;
  text-align: center;
}

.platform-logo img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-line img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.brand-line em {
  color: var(--accent-2);
  font-style: normal;
  letter-spacing: 0;
  text-transform: none;
}

.app-version {
  margin-left: 6px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: .02em;
  text-transform: none;
}

.document-status,
.subtle-line,
.asset-subtitle,
.asset-price,
.asset-profit,
#selectedMeta,
#tradingMeta {
  color: var(--muted);
}

.document-status {
  display: block;
  margin-top: 8px;
}

.topbar-actions {
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

#portfolioSelect {
  width: 180px;
}

#openInput,
#historyInput {
  display: none;
}

.summary-band {
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.summary-band > div {
  flex: 1;
  min-width: 170px;
  padding: 18px;
  background: var(--panel);
}

.summary-band span {
  color: var(--muted);
}

.summary-band strong {
  display: block;
  margin-top: 8px;
  font-size: 23px;
}

.summary-band strong small {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.range-controls {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.range-controls button {
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 11px;
}

.range-controls button.is-active {
  background: var(--accent);
  color: #07110d;
}

.workspace {
  align-items: flex-start;
  gap: 18px;
  margin-top: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.portfolio-panel {
  width: min(520px, 100%);
  padding: 18px;
  position: sticky;
  top: 16px;
}

.main-column {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: 18px;
}

.insight-panel,
.alerts-panel,
.chart-panel {
  padding: 18px;
}

.panel-head {
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.selected-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

.selected-heading img {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  object-fit: contain;
}

.selected-heading h2 {
  margin: 0;
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
}

.operation-form,
.alert-form {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.operation-form {
  grid-template-columns: 1fr 1fr;
  margin: 16px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.alert-form {
  grid-template-columns: 1fr 1.2fr 1fr auto;
  align-items: end;
}

.operation-form label,
.alert-form label,
.chart-controls label,
.currency-tools label,
.inline-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.form-title,
.operation-form button {
  grid-column: 1 / -1;
}

.operation-form button,
.alert-form button {
  background: var(--accent);
  color: #07110d;
  border-color: var(--accent);
  font-weight: 700;
}

.asset-list,
.alert-list,
.allocation-chart,
.compare-chart {
  display: grid;
  gap: 8px;
}

.cash-card {
  margin-bottom: 10px;
}

.cash-card .correction-fields {
  grid-template-columns: 1fr;
}

.asset-row {
  display: grid;
  grid-template-columns: minmax(132px, 1fr) minmax(102px, 128px) 74px 30px;
  align-items: center;
  gap: 8px;
  min-height: 62px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.asset-row.is-selected {
  border-color: var(--accent);
  background: #24240f;
}

.asset-main {
  align-items: center;
  min-width: 0;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.asset-main span:last-child {
  min-width: 0;
}

.asset-title,
.asset-subtitle {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-rank {
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 700;
}

.coin-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.coin-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.asset-numbers {
  min-width: 0;
  text-align: right;
}

.asset-numbers strong {
  font-size: 15px;
}

.asset-numbers small {
  font-size: 11px;
  line-height: 1.25;
}

.asset-numbers strong,
.asset-numbers small {
  display: block;
}

.inline-field {
  width: 100%;
  min-width: 0;
  gap: 3px;
  font-size: 11px;
}

.inline-field input {
  height: 32px;
  padding: 6px 7px;
}

.edit-button {
  width: 74px;
  height: 30px;
  padding: 0;
  font-size: 11px;
}

.correction-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.remove-button {
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--danger);
}

.asset-row .remove-button {
  grid-column: 4 / 5;
  grid-row: 1;
}

.chart-controls {
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chart-controls select,
.currency-tools select {
  width: 118px;
}

.currency-tools {
  display: flex;
  align-items: end;
  gap: 8px;
}

.currency-tools small {
  display: none;
}

#setDefaultCurrencyBtn {
  min-width: 158px;
}

.insight-grid {
  display: grid;
  grid-template-columns: minmax(170px, .7fr) minmax(360px, 1.4fr) minmax(190px, .9fr);
  gap: 10px;
}

.metric-card {
  min-height: 88px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card span,
.mini-chart-head small {
  color: var(--muted);
  font-size: 12px;
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  font-size: 20px;
}

.metric-card strong small {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.compare-metric {
  min-height: 116px;
}

.allocation-panel {
  margin-top: 16px;
}

.mini-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.compare-chart,
.allocation-chart {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.compare-chart {
  margin-top: 10px;
  border: 0;
  padding: 0;
  background: transparent;
}

.pie-chart {
  width: min(300px, 44vw);
  aspect-ratio: 1;
  margin: 20px auto;
  border-radius: 50%;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 38px #0f1211;
  position: relative;
  z-index: 1;
}

.pie-wrap {
  position: relative;
  min-height: 420px;
  display: grid;
  place-items: center;
}

.pie-callout {
  position: absolute;
  min-width: 96px;
  max-width: 126px;
  padding: 6px 8px;
  border-left: 3px solid;
  border-radius: 6px;
  background: #0f1211;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .22);
  z-index: 2;
}

.pie-callout strong,
.pie-callout span,
.pie-callout small {
  display: block;
}

.pie-callout strong {
  font-size: 13px;
}

.pie-callout span {
  font-weight: 800;
}

.pie-callout small {
  color: var(--muted);
  font-size: 11px;
}

.pie-label,
.pie-share,
.pie-value {
  display: block;
}

.pie-label {
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
}

.pie-share {
  font-size: 12px;
  font-weight: 800;
}

.pie-value {
  color: var(--muted);
  font-size: 11px;
}

.pie-leaders {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.pie-leaders path {
  fill: none;
  stroke-width: .55;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .78;
}

.bar-row {
  align-items: center;
  gap: 10px;
}

.bar-label {
  width: 108px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.bar-track {
  flex: 1;
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #0f1211;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.bar-fill.is-loss {
  background: linear-gradient(90deg, #ff6b6b, #ffc857);
}

.bar-value {
  width: 120px;
  text-align: right;
  font-size: 13px;
  font-weight: 800;
}

.alert-row {
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.alert-row.is-triggered {
  border-color: var(--accent);
  background: #252510;
}

.alert-row strong,
.alert-row small {
  display: block;
}

.app-dialog {
  max-width: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.app-dialog::backdrop {
  background: rgba(0, 0, 0, .72);
}

.app-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.app-dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.platform-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.platform-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
}

.platform-choice img {
  width: 24px;
  height: 24px;
}

.custom-platform-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.custom-platform-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.trading-view {
  width: 100%;
  height: min(62vh, 640px);
  min-height: 460px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1211;
}

.empty-state,
.status-line {
  padding: 18px;
  color: var(--muted);
}

.change-positive {
  color: var(--accent-2);
}

.change-negative {
  color: var(--danger);
}

.change-neutral {
  color: var(--muted);
}

@media print {
  body {
    background: #fff;
    color: #111;
  }

  .topbar-actions,
  .operation-form,
  .alerts-panel,
  .chart-panel,
  .remove-button,
  .inline-field {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .workspace,
  .summary-band,
  .allocation-panel,
  .insight-grid {
    display: block;
  }

  .panel,
  .summary-band,
  .summary-band > div,
  .asset-row,
  .metric-card,
  .compare-chart,
  .allocation-chart {
    background: #fff;
    color: #111;
    box-shadow: none;
    border-color: #ccc;
  }

  .portfolio-panel {
    position: static;
    width: 100%;
  }
}

@media (max-width: 1120px) {
  .workspace,
  .topbar,
  .summary-band {
    flex-direction: column;
  }

  .portfolio-panel {
    position: static;
    width: 100%;
  }

  .summary-band > div {
    width: 100%;
  }
}

@media (max-width: 820px) {
  .insight-grid,
  .alert-form {
    grid-template-columns: 1fr;
  }

  .chart-controls {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 16px;
  }

  .operation-form {
    grid-template-columns: 1fr;
  }

  .asset-row {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .asset-numbers,
  .inline-field {
    width: 100%;
    text-align: left;
  }
}
