:root {
  --bg: #0b0d12;
  --bg-elev: #12151c;
  --bg-elev-2: #181c25;
  --border: #232834;
  --border-strong: #2e3441;
  --text: #e6e8ee;
  --text-dim: #8a93a6;
  --text-faint: #5b6273;
  --accent: #7c5cff;
  --accent-2: #00d4ff;
  --pos: #29d391;
  --neg: #ff5577;
  --radius: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    'Inter',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
}

.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  min-height: 640px;
}

/* Sidebar */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px 0;
  letter-spacing: -0.01em;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px rgba(124, 92, 255, 0.6);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.ghost-btn {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}

.ghost-btn:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

.preset-wrap {
  position: relative;
}

.preset-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 24px 5px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='%238a93a6' d='M1.5 3.5L5 7l3.5-3.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  outline: none;
  transition: all 0.15s;
}

.preset-select:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.preset-select:focus {
  border-color: var(--accent);
}

.preset-select option {
  background: var(--bg-elev-2);
  color: var(--text);
}

/* Search */
.search-wrap {
  position: relative;
}

.search {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.search::placeholder {
  color: var(--text-faint);
}

.search:focus {
  border-color: var(--accent);
  background: var(--bg-elev);
}

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  z-index: 20;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.suggestions.hidden {
  display: none;
}

.suggestion {
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.suggestion:last-child {
  border-bottom: none;
}

.suggestion:hover,
.suggestion.active {
  background: var(--bg-elev);
}

.suggestion .symbol {
  font-weight: 600;
  font-size: 13px;
}

.suggestion .name {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.suggestion .exchange {
  color: var(--text-faint);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Auth panel */
.auth-panel {
  padding: 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 8px;
}

.auth-signed-out {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-cta {
  width: 100%;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.18), rgba(0, 212, 255, 0.12));
  border: 1px solid rgba(124, 92, 255, 0.35);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s;
}

.auth-cta:hover {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.28), rgba(0, 212, 255, 0.18));
}

.auth-form {
  display: flex;
  gap: 6px;
}

.auth-form.hidden {
  display: none;
}

.auth-email {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 12px;
  padding: 8px 10px;
  outline: none;
  font-family: inherit;
  min-width: 0;
}

.auth-email:focus {
  border-color: var(--accent);
}

.auth-submit {
  background: var(--accent);
  color: #fff;
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  transition: filter 0.15s;
}

.auth-submit:hover {
  filter: brightness(1.1);
}

.auth-message {
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 2px 0 2px;
  line-height: 1.4;
}

.auth-message.hidden {
  display: none;
}

.auth-message.error {
  color: var(--neg);
}

.auth-message.success {
  color: var(--pos);
}

.auth-signed-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.auth-signed-in.hidden {
  display: none;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.auth-user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pos);
  flex-shrink: 0;
}

.auth-user-email {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Saved portfolios */
.saved {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 40px;
}

.saved.empty {
  align-items: center;
  justify-content: center;
}

.saved-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.saved-item:hover {
  border-color: var(--border-strong);
  background: #1c2029;
}

.saved-item.active {
  border-color: var(--accent);
  background: rgba(124, 92, 255, 0.08);
}

.saved-item-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.saved-item-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-item-meta {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.saved-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.saved-item:hover .saved-actions {
  opacity: 1;
}

.saved-action-btn {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  color: var(--text-faint);
  font-size: 13px;
  transition: all 0.15s;
}

.saved-action-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.saved-action-btn.danger:hover {
  background: rgba(255, 85, 119, 0.12);
  color: var(--neg);
}

/* Holdings */
.holdings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}

.holdings.empty {
  align-items: center;
  justify-content: center;
}

.empty-state {
  color: var(--text-faint);
  font-size: 12px;
  padding: 20px 0;
  text-align: center;
}

.holding {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s;
}

.group-input {
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  color: var(--text-dim);
  font-family: inherit;
  outline: none;
  width: 72px;
  transition: all 0.15s;
}

.group-input::placeholder {
  color: var(--text-faint);
}

.group-input:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.group-input:focus {
  border-style: solid;
  border-color: var(--accent);
  color: var(--text);
  background: var(--bg);
}

.group-input.has-value {
  background: rgba(124, 92, 255, 0.1);
  border-color: rgba(124, 92, 255, 0.3);
  border-style: solid;
  color: var(--text);
}

.holding:hover {
  border-color: var(--border-strong);
}

.holding-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.holding-symbol {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.holding-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s;
  flex-shrink: 0;
}

.holding-dot::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot-color, currentColor);
  box-shadow: inset 0 0 0 2px transparent;
  transition: all 0.15s;
}

.holding-dot.hidden-line::before {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--dot-color, currentColor);
  opacity: 0.55;
}

.holding-dot:hover::before {
  transform: scale(1.15);
}

.holding-name {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.weight-input {
  width: 56px;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  text-align: right;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.weight-input:focus {
  border-color: var(--accent);
}

.weight-unit {
  font-size: 11px;
  color: var(--text-faint);
  margin-left: -6px;
  margin-right: 2px;
}

.remove-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-faint);
  font-size: 16px;
  transition: all 0.15s;
}

.remove-btn:hover {
  background: rgba(255, 85, 119, 0.12);
  color: var(--neg);
}

.weight-summary {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 4px 0 4px;
  font-variant-numeric: tabular-nums;
}

#totalWeight.warn {
  color: var(--neg);
}

#totalWeight.ok {
  color: var(--pos);
}

/* Stats */
.stats {
  margin-top: auto;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  gap: 12px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.stat-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-value.pos {
  color: var(--pos);
}

.stat-value.neg {
  color: var(--neg);
}

/* Main */
.main {
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow: hidden;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
}

.main-title {
  margin: 0 0 4px 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.main-subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

.ranges {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.ranges button {
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  border-radius: 7px;
  transition: all 0.15s;
}

.ranges button:hover {
  color: var(--text);
}

.ranges button.active {
  background: var(--bg-elev-2);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Chart */
.chart-card {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 24px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.chart-headline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.chart-return {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.chart-return.pos {
  color: var(--pos);
}

.chart-return.neg {
  color: var(--neg);
}

.chart-return-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 2px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 60%;
  justify-content: flex-end;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 13px;
  pointer-events: none;
}

.chart-empty.hidden {
  display: none;
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 13, 18, 0.4);
  backdrop-filter: blur(2px);
  border-radius: 8px;
}

.chart-loading.hidden {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

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

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #3a4151;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main {
    padding: 24px 20px;
  }
  .chart-card {
    min-height: 420px;
  }
}
