:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --border: #e4e2da;
  --text-primary: #24231f;
  --text-secondary: #6b6a63;
  --text-muted: #9a988f;
  --green: #3b6d11;
  --red: #a32d2d;
  --mono: 'IBM Plex Mono', monospace;
  --sans: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--sans);
}

.hidden { display: none !important; }

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem;
  min-height: 100vh;
}

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

.brand {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.menu-toggle {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 0;
  flex-shrink: 0;
  order: 2;
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 35, 31, 0);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, background 0.25s ease, visibility 0s linear 0.25s;
}

.menu-overlay.menu-open {
  opacity: 1;
  visibility: visible;
  background: rgba(36, 35, 31, 0.45);
  transition: opacity 0.25s ease, background 0.25s ease, visibility 0s linear 0s;
}

.side-menu {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 240px;
  max-width: 80vw;
  background: var(--surface);
  padding: 1.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  box-shadow: -2px 0 16px rgba(0, 0, 0, 0.1);
}

.menu-overlay.menu-open .side-menu {
  transform: translateX(0);
}

.side-menu-link {
  background: transparent;
  border: none;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}

.side-menu-link:hover { background: var(--surface-2); }

.side-menu-link.side-menu-active {
  background: var(--text-primary);
  color: #fff;
}

.side-menu-divider {
  height: 0.5px;
  background: var(--border);
  margin: 8px 4px;
}

.ghost-btn {
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.ghost-btn:hover { background: var(--surface-2); }

.connect-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 16px;
  padding: 1.75rem;
}

.connect-card + .connect-card {
  margin-top: 12px;
}

.connect-card h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 8px;
}

.muted {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 1.5rem;
}

#connect-form label,
#auth-form label,
#settings-form label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin: 1rem 0 6px;
}

#connect-form label:first-child,
#auth-form label:first-child,
#settings-form label:first-child {
  margin-top: 0;
}

#connect-form input,
#auth-form input,
#settings-form input {
  width: 100%;
  height: 40px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  padding: 0 12px;
  font-size: 14px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: var(--sans);
}

#connect-form input:focus,
#auth-form input:focus,
#settings-form input:focus {
  outline: none;
  border-color: #b4b2a9;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

#connect-form button,
#auth-form button,
#settings-form button {
  width: 100%;
  height: 42px;
  border-radius: 8px;
  border: none;
  background: var(--text-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 1.5rem;
}

#connect-form button:hover,
#auth-form button:hover,
#settings-form button:hover { opacity: 0.9; }
#connect-form button:disabled,
#auth-form button:disabled,
#settings-form button:disabled { opacity: 0.5; cursor: default; }

.error {
  color: var(--red);
  font-size: 13px;
  margin-top: 1rem;
}

.total-bar {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 12px;
}

.total-bar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.total-bar .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.total-bar .value {
  font-size: 30px;
  font-weight: 600;
  margin: 0;
  font-family: var(--mono);
}

.total-bar .sub-line {
  font-size: 12px;
  margin: 6px 0 0;
  font-family: var(--mono);
  color: var(--text-secondary);
}

.total-bar .sub-line .diff-positive { color: var(--green); }
.total-bar .sub-line .diff-negative { color: var(--red); }

.rebalance-btn {
  background: var(--text-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.rebalance-btn:hover { opacity: 0.9; }
.rebalance-btn:disabled { opacity: 0.5; cursor: default; }

.rebalance-result {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rebalance-result.result-error {
  border-color: var(--red);
  color: var(--red);
}

.rebalance-result #rebalance-result-text {
  flex: 1;
}

.result-close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  opacity: 0.6;
  flex-shrink: 0;
}

.result-close:hover { opacity: 1; }

.summary-row {
  display: flex;
  gap: 12px;
  margin-bottom: 1.25rem;
}

.summary-card {
  flex: 1;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.summary-card .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.summary-card .value {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 8px;
  font-family: var(--mono);
}

.nu-doel {
  margin: 0;
  font-size: 12px;
  font-family: var(--mono);
  display: flex;
  justify-content: space-between;
}

.nu-doel .nu {
  color: var(--text-primary);
  font-weight: 600;
}

.nu-doel .doel {
  color: var(--text-muted);
}

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

.top20-section {
  margin-top: 2rem;
}

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

.section-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.5;
}

.toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
  text-decoration: underline;
}

.toggle-btn:hover { color: var(--text-primary); }

.top20-list {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.top20-row {
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--border);
}

.top20-row:last-child { border-bottom: none; }

.top20-row-top,
.top20-row-bottom,
.top20-row-target {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.top20-row-top { margin-bottom: 2px; }
.top20-row-target { margin-top: 2px; padding-left: 28px; }

.top20-rank {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12px;
  min-width: 18px;
}

.top20-name {
  flex: 1;
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.top20-fullname {
  font-weight: 400;
  color: var(--text-secondary);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top20-amount {
  font-family: var(--mono);
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  margin-left: 28px;
}

.top20-value {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

.top20-target {
  font-family: var(--mono);
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 35, 31, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}

.modal-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 380px;
  width: 100%;
}

.modal-card h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 10px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 0.5rem;
}

.modal-actions button {
  flex: 1;
  height: 42px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.modal-actions .ghost-btn {
  height: 42px;
}

.confirm-btn {
  background: var(--text-primary);
  color: #fff;
  border: none;
}

.confirm-btn:hover { opacity: 0.9; }


.settings-success {
  color: var(--green);
  font-size: 13px;
  margin-top: 1rem;
}

.settings-active-box {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 0.5px solid var(--border);
}

.settings-active-line {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.6;
}

.danger-btn {
  background: var(--red);
}

.danger-btn:hover {
  opacity: 0.9;
}
