/* ─── RESET & BASE ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1c2230;
  --border: #21262d;
  --border2: #2d333b;
  --blue: #2979ff;
  --blue-light: #448aff;
  --blue-dim: rgba(41,121,255,0.15);
  --blue-glow: rgba(41,121,255,0.35);
  --green: #3fb950;
  --green-dim: rgba(63,185,80,0.15);
  --red: #f85149;
  --red-dim: rgba(248,81,73,0.15);
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #484f58;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── HEADER ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 60px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--blue-light);
  letter-spacing: 0.04em;
}

.btn-add {
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-add:hover { background: var(--blue-light); transform: translateY(-1px); }
.btn-add:active { transform: translateY(0); }

/* ─── VIEWS ─── */
.view { display: none; }
.view.active { display: block; }
/* dashboardView needs flex layout when shown — must be more specific than .view */
#dashboardView.view.active { display: flex; }

/* ─── DASHBOARD ─── */
#dashboardView {
  max-width: 1300px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
  flex-direction: column;
  gap: 1.5rem;
}

/* ─── SUMMARY CARDS ─── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.summary-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.card-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text2);
  font-weight: 600;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

/* ─── CHARTS ─── */
.chart-card { padding: 1.5rem; }

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.chart-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.chart-wrap canvas { width: 100% !important; height: 100% !important; }

.empty-chart-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  font-size: 0.9rem;
  pointer-events: none;
}

/* ─── TIMEFRAME TABS ─── */
.timeframe-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.2rem;
}

.tf-btn {
  background: transparent;
  border: none;
  color: var(--text2);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tf-btn:hover { color: var(--text); background: var(--border); }
.tf-btn.active {
  background: var(--blue);
  color: #fff;
}

/* ─── HOLDINGS TABLE ─── */
.holdings-card { padding: 1.5rem; }

.holdings-header {
  margin-bottom: 1rem;
}

.holdings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.holdings-table th {
  text-align: left;
  color: var(--text2);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.holdings-table th[data-sort]:hover { color: var(--text1); }
.holdings-table th.sort-active { color: var(--accent, #2979ff); }
.sort-arrow { font-size: 0.7rem; opacity: 0.6; }
th.sort-active .sort-arrow { opacity: 1; }

.holdings-table td {
  padding: 0.85rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.holdings-table tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}
.holdings-table tbody tr:hover { background: var(--bg3); }
.holdings-table tbody tr:last-child td { border-bottom: none; }

.sym-badge {
  display: inline-block;
  background: var(--blue-dim);
  color: var(--blue-light);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  border: 1px solid rgba(68,138,255,0.3);
  letter-spacing: 0.02em;
}

.change-positive { color: var(--green); font-weight: 600; }
.change-negative { color: var(--red); font-weight: 600; }
.change-neutral { color: var(--text2); }

.sparkline-cell { width: 90px; }
.sparkline-cell canvas { display: block; }

/* ─── EMPTY STATE ─── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text2);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state p { margin-bottom: 1.25rem; font-size: 0.9rem; }

/* ─── ALLOCATION CARD ─── */
.allocation-card { padding: 1.5rem; }

.alloc-wrap {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  flex-wrap: wrap;
}

.alloc-chart-wrap {
  width: 200px;
  height: 200px;
  flex-shrink: 0;
}

.alloc-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.alloc-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}

.alloc-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.alloc-sym { font-weight: 700; color: var(--text); min-width: 50px; }
.alloc-pct { color: var(--text2); margin-left: auto; }

/* ─── STOCK DETAIL VIEW ─── */
#stockView {
  max-width: 1300px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
}

.stock-view-inner {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.btn-back {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  width: fit-content;
  transition: color 0.15s, border-color 0.15s;
}
.btn-back:hover { color: var(--text); border-color: var(--text2); }

.stock-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.stock-hero-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.stock-badge {
  background: var(--blue-dim);
  color: var(--blue-light);
  border: 1px solid rgba(68,138,255,0.4);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  min-width: 80px;
  text-align: center;
}

.stock-name {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.stock-price-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.stock-price {
  font-size: 1.8rem;
  font-weight: 700;
}

.stock-change {
  font-size: 1rem;
  font-weight: 600;
}

.scrub-label {
  font-size: 0.78rem;
  color: var(--text2);
  min-height: 1.1em;
  opacity: 0;
  transition: opacity 0.15s;
  margin-top: 3px;
  letter-spacing: 0.01em;
}

/* ─── STOCK DETAILS GRID ─── */
.stock-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.detail-card { padding: 1.5rem; }

.detail-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text2);
  margin-bottom: 1rem;
}

.detail-rows { display: flex; flex-direction: column; gap: 0; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.detail-row:last-child { border-bottom: none; }

.detail-label { color: var(--text2); }
.detail-val { font-weight: 600; }

/* ─── REMOVE BUTTON ─── */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #3fb950;
  background: rgba(63,185,80,0.08);
  border: 1px solid rgba(63,185,80,0.25);
  border-radius: 20px;
  padding: 4px 12px;
  user-select: none;
}
.live-badge #liveTime {
  font-weight: 400;
  letter-spacing: 0.04em;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3fb950;
  box-shadow: 0 0 0 0 rgba(63,185,80,0.6);
  animation: livePulse 2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0 rgba(63,185,80,0.6); }
  60%  { box-shadow: 0 0 0 6px rgba(63,185,80,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,185,80,0); }
}
.live-badge.market-closed {
  color: #484f58;
  background: rgba(72,79,88,0.08);
  border-color: rgba(72,79,88,0.25);
}
.live-badge.market-closed .live-dot {
  background: #484f58;
  box-shadow: none;
  animation: none;
}

/* ─── SECTOR BREAKDOWN ─── */
.sector-card { padding: 1.5rem; }

.sector-row {
  display: grid;
  grid-template-columns: 160px 1fr 120px;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.sector-row:last-child { border-bottom: none; }

.sector-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.sector-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sector-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.sector-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.sector-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
  opacity: 0.85;
}

.sector-meta {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  align-items: baseline;
}
.sector-pct {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  min-width: 38px;
  text-align: right;
}
.sector-val {
  font-size: 0.78rem;
  color: var(--text2);
  white-space: nowrap;
}

/* ─── REMOVE / OUTLINE BUTTONS ─── */
.btn-remove {
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-remove:hover { background: var(--red-dim); }

/* ─── OUTLINE BLUE BUTTON ─── */
.btn-outline-blue {
  background: transparent;
  border: 1px solid var(--blue);
  color: var(--blue-light);
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-outline-blue:hover { background: var(--blue-dim); }

/* ─── STOCK ACTION BUTTONS ROW ─── */
.stock-action-btns {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ─── ROW ICON BUTTONS (holdings table) ─── */
.row-actions {
  text-align: right;
  white-space: nowrap;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  margin-left: 0.2rem;
}
.icon-btn:hover { color: var(--text); border-color: var(--text2); background: var(--bg3); }
.icon-btn.edit-btn:hover { color: var(--blue-light); border-color: var(--blue); background: var(--blue-dim); }
.icon-btn.del-btn:hover  { color: var(--red);        border-color: var(--red);  background: var(--red-dim); }

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  padding: 1.75rem;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.modal-title { font-size: 1.1rem; font-weight: 700; }

.modal-close {
  background: transparent;
  border: none;
  color: var(--text2);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--border); }

.form-group { margin-bottom: 1.1rem; }

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text2);
  margin-bottom: 0.45rem;
}

.form-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  padding: 0.6rem 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--blue); }
.form-input::placeholder { color: var(--text3); }

/* ─── SEARCH SUGGESTIONS ─── */
.search-wrap { position: relative; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  z-index: 300;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.suggestions.open { display: block; }

.suggestion-item {
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: background 0.1s;
  font-size: 0.88rem;
}
.suggestion-item:hover { background: var(--border); }
.suggestion-item .s-sym { font-weight: 700; color: var(--blue-light); min-width: 65px; }
.suggestion-item .s-name { color: var(--text2); }

.selected-stock-info {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  color: var(--green);
  min-height: 1.2em;
}

.modal-error {
  color: var(--red);
  font-size: 0.83rem;
  min-height: 1.2em;
  margin-bottom: 0.5rem;
}

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.btn-cancel {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-cancel:hover { color: var(--text); border-color: var(--text2); }

.btn-confirm {
  background: var(--blue);
  border: none;
  color: #fff;
  padding: 0.55rem 1.3rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-confirm:hover { background: var(--blue-light); }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .stock-details-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  #dashboardView, #stockView { padding: 1rem 1rem 3rem; }
  .summary-cards { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
  .header { padding: 0 1rem; }
  .holdings-table { font-size: 0.8rem; }
  .holdings-table th:nth-child(2),
  .holdings-table td:nth-child(2) { display: none; }
  .chart-wrap { height: 200px; }
  .alloc-chart-wrap { width: 160px; height: 160px; }
  .sector-row { grid-template-columns: 120px 1fr 90px; }
  .sector-val { display: none; }
}
