:root {
  --primary: #1e3a5f;
  --primary-2: #2b557f;
  --rise: #e53935;
  --fall: #43a047;
  --text: #202124;
  --muted: #757575;
  --line: #e2e7ee;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --warn: #a86405;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: 74px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 0 18px;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

.topbar-title {
  min-width: 0;
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.topbar-subtitle {
  margin-top: 2px;
  color: #d7e2ee;
  font-size: 12px;
  font-weight: 500;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  width: 38px;
  color: inherit;
  background: rgba(255, 255, 255, 0.12);
}

.icon-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.primary-button {
  padding: 0 14px;
  color: #fff;
  background: var(--primary);
}

.secondary-button {
  padding: 0 12px;
  color: var(--primary);
  background: #e9eff6;
}

.danger-button {
  padding: 0 12px;
  color: #fff;
  background: var(--rise);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #d7e2ee;
  background: rgba(255, 255, 255, 0.1);
  white-space: nowrap;
}

.content {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 2px 12px;
  color: var(--muted);
  font-size: 12px;
}

.fund-list,
.config-list,
.holding-list,
.settings-grid {
  display: grid;
  gap: 10px;
}

.fund-card,
.config-card,
.holding-card,
.settings-panel,
.empty-state,
.error-message {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(30, 58, 95, 0.06);
}

.fund-card {
  padding: 13px 14px;
  cursor: pointer;
}

.fund-card.dragging,
.fund-card.drop-target {
  border-color: #8fb0d5;
  background: #eaf1fa;
}

.fund-title-row,
.baseline-row,
.config-row,
.holding-row,
.setting-row,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fund-name,
.config-name,
.holding-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--primary);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fund-code,
.small-muted {
  color: var(--muted);
  font-size: 13px;
}

.country-badge {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  margin-right: 6px;
  border-radius: 4px;
  padding: 0 5px;
  color: #fff;
  background: var(--primary-2);
  font-size: 11px;
  font-weight: 800;
}

.inline-error {
  margin-top: 8px;
  color: var(--rise);
  font-size: 12px;
  font-weight: 700;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--line);
}

.metric {
  min-width: 0;
}

.metric-label,
.sub-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-value {
  margin: 2px 0 4px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.sub-value,
.baseline-value {
  font-weight: 700;
}

.baseline-row {
  margin-top: 10px;
  flex-wrap: wrap;
}

.baseline-spacer,
.setting-row > label,
.config-main {
  flex: 1;
}

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

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

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

.error-message {
  margin-bottom: 12px;
  padding: 10px 12px;
  color: var(--rise);
  font-weight: 600;
}

.empty-state {
  padding: 34px 18px;
  text-align: center;
}

.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  margin-bottom: 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
}

.empty-title {
  color: var(--primary);
  font-weight: 700;
}

.empty-desc {
  margin-top: 5px;
  color: var(--muted);
}

.config-card,
.holding-card,
.settings-panel {
  padding: 14px;
}

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

.holding-price {
  min-width: 96px;
  text-align: right;
}

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

.settings-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  font-weight: 700;
}

.auth-form {
  display: grid;
  gap: 12px;
}

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

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.sync-status {
  color: var(--muted);
  font-size: 12px;
}

.setting-row {
  min-height: 48px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.setting-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary-2);
  outline: 2px solid rgba(43, 85, 127, 0.16);
}

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

.field-help a {
  color: var(--primary-2);
  font-weight: 700;
  text-decoration: none;
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.18s ease;
}

.switch span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
  content: "";
  transition: transform 0.18s ease;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  background: var(--primary);
  box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);
}

.bottom-nav-inner {
  display: grid;
  width: min(640px, 100%);
  grid-template-columns: repeat(4, 1fr);
}

.nav-item {
  display: grid;
  min-height: 62px;
  border: 0;
  color: #d7e2ee;
  background: transparent;
  cursor: pointer;
  place-items: center;
}

.nav-item.active {
  color: #fff;
}

.nav-item.active .nav-icon {
  background: #fff;
  color: var(--primary);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 24px;
  border-radius: 999px;
}

.nav-label {
  font-size: 12px;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.46);
}

.dialog {
  width: min(720px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.24);
}

.dialog-header {
  position: sticky;
  top: 0;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--primary);
  font-weight: 800;
}

.dialog-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px 18px;
}

.dialog-actions {
  justify-content: flex-end;
  padding: 14px 18px 18px;
}

.span-2 {
  grid-column: 1 / -1;
}

.spinner {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 680px) {
  .topbar {
    padding: 0 12px;
  }

  .content {
    padding: 10px;
  }

  .metrics-grid {
    gap: 7px;
  }

  .metric-label,
  .sub-label {
    font-size: 11px;
  }

  .metric-value {
    font-size: 14px;
  }

  .dialog-body {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .config-row,
  .holding-row {
    align-items: flex-start;
  }

  .config-actions {
    flex-direction: column;
  }
}
