:root {
  --bg: #101010;
  --surface: #181a1b;
  --surface-2: #222527;
  --line: #33383b;
  --text: #f4f1ea;
  --muted: #a7a19a;
  --accent: #34d399;
  --accent-2: #f59e0b;
  --danger: #fb7185;
  --good: #57cc99;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body.is-private .money-value,
body.is-private .metric strong {
  color: transparent;
  text-shadow: 0 0 12px rgba(244, 241, 234, 0.7);
  user-select: none;
}

body.is-private .axis-label {
  fill: transparent;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) 16px max(90px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  max-width: 980px;
  margin: 0 auto 16px;
}

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 12px;
  line-height: 1.2;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.05;
  font-weight: 760;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
  font-weight: 720;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill,
.icon-button,
.primary-button,
.secondary-button,
.period-button,
.tab-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tg-theme-secondary-bg-color, var(--surface-2));
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.is-live {
  border-color: rgba(52, 211, 153, 0.45);
  color: var(--accent);
}

.status-pill.is-error {
  border-color: rgba(251, 113, 133, 0.45);
  color: var(--danger);
}

.icon-button,
.primary-button,
.secondary-button,
.period-button,
.tab-button {
  cursor: pointer;
}

.icon-button {
  padding: 0 12px;
}

.settings-panel,
.message-bar,
.content {
  max-width: 980px;
  margin: 0 auto;
}

.settings-panel,
.message-bar {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-panel {
  padding: 14px;
}

.settings-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

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

.settings-form input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #0c0d0d;
  color: var(--text);
}

.settings-actions {
  display: flex;
  gap: 8px;
}

.primary-button,
.secondary-button {
  padding: 0 14px;
}

.primary-button {
  border-color: rgba(52, 211, 153, 0.55);
  background: rgba(52, 211, 153, 0.16);
}

.secondary-button {
  color: var(--muted);
}

.message-bar {
  padding: 12px 14px;
  color: var(--muted);
}

.message-bar.is-error {
  border-color: rgba(251, 113, 133, 0.42);
  color: #ffd3db;
}

.content {
  display: block;
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric,
.chart-frame,
.row-card,
.alert-row,
.empty-state,
.stat-strip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tg-theme-secondary-bg-color, var(--surface));
}

.metric {
  min-height: 114px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric-wide {
  grid-column: span 2;
}

.metric-label,
.muted,
.item-meta,
.row-meta,
.metric small {
  color: var(--tg-theme-hint-color, var(--muted));
}

.metric strong {
  display: block;
  margin: 10px 0 4px;
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.metric small {
  font-size: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 10px;
}

.period-switcher {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.period-button {
  min-width: 42px;
  padding: 0 10px;
  color: var(--muted);
}

.period-button.is-active {
  border-color: rgba(245, 158, 11, 0.55);
  background: rgba(245, 158, 11, 0.14);
  color: var(--text);
}

.chart-frame {
  min-height: 210px;
  padding: 12px;
  overflow: hidden;
}

.chart-large {
  min-height: 330px;
}

.chart-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 186px;
}

.chart-large .chart-svg {
  min-height: 306px;
}

.axis-label {
  fill: var(--muted);
  font-size: 4px;
}

.stack-list,
.compact-list {
  display: grid;
  gap: 10px;
}

.compact-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.row-card,
.alert-row {
  padding: 13px 14px;
}

.row-top,
.alert-top,
.asset-row,
.stat-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.row-title,
.alert-title {
  min-width: 0;
  font-weight: 720;
}

.row-value,
.alert-severity {
  white-space: nowrap;
  font-weight: 720;
}

.row-meta,
.item-meta {
  margin-top: 4px;
  font-size: 12px;
}

.allocation-bar {
  height: 7px;
  margin: 12px 0;
  border-radius: 999px;
  background: #0c0d0d;
  overflow: hidden;
}

.allocation-bar span {
  display: block;
  height: 100%;
  width: var(--bar-width, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.asset-list {
  display: grid;
  gap: 6px;
}

.asset-row {
  min-height: 26px;
  font-size: 13px;
}

.asset-row span:first-child,
.alert-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.alert-severity {
  min-width: 34px;
  text-align: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(245, 158, 11, 0.18);
  color: #ffd188;
}

.alert-severity.high {
  background: rgba(251, 113, 133, 0.18);
  color: #ffbcc8;
}

.alert-severity.low {
  background: rgba(52, 211, 153, 0.14);
  color: #a8f0d0;
}

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

.stat-strip {
  margin-top: 10px;
  padding: 12px 14px;
  flex-wrap: wrap;
}

.stat-strip div {
  display: grid;
  gap: 3px;
}

.stat-strip strong {
  font-size: 18px;
}

.bottom-tabs {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(620px, calc(100% - 24px));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(16, 16, 16, 0.88);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.tab-button {
  min-width: 0;
  min-height: 40px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.tab-button.is-active {
  border-color: rgba(52, 211, 153, 0.48);
  background: rgba(52, 211, 153, 0.14);
  color: var(--text);
}

@media (max-width: 760px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    justify-content: flex-start;
  }

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

  .settings-actions {
    justify-content: stretch;
  }

  .settings-actions button {
    flex: 1;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-wide {
    grid-column: span 2;
  }

  .compact-list {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .period-switcher {
    width: 100%;
  }

  .period-button {
    flex: 1 0 auto;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 24px;
  }

  .metric {
    min-height: 104px;
    padding: 12px;
  }

  .metric strong {
    font-size: 25px;
  }

  .tab-button {
    font-size: 12px;
    padding: 0 4px;
  }
}
