/* ============================================================
   Portfolio Tracker — Modern Dark UI
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg:        #0a0e1a;
  --bg-2:      #0f1424;
  --surface:   #131826;
  --surface-2: #1a2032;
  --border:    rgba(255,255,255,0.06);
  --border-2:  rgba(255,255,255,0.12);
  --text:      #e6e9f2;
  --muted:     #8b94ad;
  --muted-2:   #5c647a;
  --accent:    #6366f1;
  --accent-2:  #a855f7;
  --up:        #22c55e;
  --down:      #ef4444;
  --warning:   #f59e0b;
  --gradient:  linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --shadow:    0 8px 32px rgba(0,0,0,.35);
  --radius:    14px;
  --radius-sm: 10px;
}

html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(at 0% 0%, rgba(99,102,241,0.10) 0, transparent 50%),
    radial-gradient(at 100% 0%, rgba(168,85,247,0.08) 0, transparent 45%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
small { font-size: 12px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

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

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,14,26,0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 50;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px; letter-spacing: -0.01em;
}
.logo-dot {
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--gradient);
  box-shadow: 0 0 18px rgba(99,102,241,0.55);
}
.nav { display: flex; align-items: center; gap: 8px; }
.nav-link {
  padding: 8px 14px; border-radius: 8px;
  color: var(--muted); font-weight: 500; font-size: 14px;
  transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.active { color: var(--text); background: var(--surface-2); }
.nav-logout { display: inline-flex; align-items: center; padding: 8px; }

/* ============================================================
   Container / Sections
   ============================================================ */
.container { max-width: 1200px; margin: 0 auto; padding: 32px 24px 80px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 32px 0 16px;
}

/* ============================================================
   Hero / Detail head
   ============================================================ */
.hero {
  padding: 24px 28px;
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(168,85,247,0.06));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.hero-label {
  font-size: 13px; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.hero-value {
  font-size: 42px; font-weight: 700; letter-spacing: -0.025em;
  background: linear-gradient(135deg, #fff, #c5c9d8);
  background-clip: text; -webkit-background-clip: text; color: transparent;
}
.hero-meta {
  display: flex; gap: 16px; flex-wrap: wrap;
  margin-top: 10px; font-size: 14px;
}

.detail-head {
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    var(--surface);
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.detail-head::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(at top right, color-mix(in srgb, var(--accent) 25%, transparent), transparent 50%);
  pointer-events: none;
}

/* ============================================================
   Cards / Grid
   ============================================================ */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: transform .15s, border-color .15s, background .15s;
}
.portfolio-card {
  display: block; position: relative; overflow: hidden;
  padding-left: 24px;
}
.portfolio-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-2);
  background: var(--surface-2);
}
.card-accent {
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.card-title { font-weight: 600; font-size: 16px; }
.card-sub   { font-size: 12px; color: var(--muted); }
.card-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.card-meta  { margin-top: 6px; font-size: 13px; }

.chart-card { padding: 20px; }
.chart-card .card-head { margin-bottom: 16px; }
.chart-empty {
  padding: 40px 20px; text-align: center;
  color: var(--muted); font-size: 14px;
  border: 1px dashed var(--border-2); border-radius: var(--radius-sm);
}
.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 8px;
}

/* ============================================================
   P/L colors
   ============================================================ */
.pl { font-weight: 600; }
.pl.up   { color: var(--up); }
.pl.down { color: var(--down); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px; border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 500; font-size: 14px;
  background: var(--surface-2); color: var(--text);
  transition: background .15s, transform .05s, border-color .15s, color .15s;
}
.btn:hover  { background: #232a3f; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--gradient); color: white;
  box-shadow: 0 4px 16px rgba(99,102,241,0.35);
}
.btn-primary:hover { filter: brightness(1.05); background: var(--gradient); }
.btn-ghost {
  background: transparent; border-color: var(--border-2); color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-ghost { color: var(--down); border-color: rgba(239,68,68,0.3); }
.btn-danger-ghost:hover { background: rgba(239,68,68,0.08); }
.btn-sm    { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: transparent; border: 1px solid transparent;
  border-radius: 8px; color: var(--muted);
  font-size: 20px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-danger:hover { background: rgba(239,68,68,0.1); color: var(--down); }

/* ============================================================
   Forms
   ============================================================ */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form label > span { font-weight: 500; }
.form input[type="text"],
.form input[type="password"],
.form input[type="number"],
.form input[type="email"] {
  width: 100%; padding: 11px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border-2); border-radius: 10px;
  color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color .15s, background .15s;
}
.form input:focus {
  outline: none; border-color: var(--accent);
  background: var(--bg-2);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.18);
}
.form input[type="color"] {
  width: 48px; height: 36px; padding: 2px;
  background: var(--bg-2);
  border: 1px solid var(--border-2); border-radius: 8px;
  cursor: pointer;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.color-row { display: flex; align-items: center; gap: 12px; }
.color-presets { display: flex; gap: 6px; }
.color-presets button {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid transparent;
  transition: transform .12s, border-color .12s;
}
.color-presets button:hover { transform: scale(1.15); border-color: var(--text); }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }

.seg {
  display: inline-flex; background: var(--bg-2); padding: 3px;
  border-radius: 10px; border: 1px solid var(--border-2);
}
.seg input { display: none; }
.seg label {
  padding: 7px 14px; border-radius: 7px; font-size: 13px;
  color: var(--muted); cursor: pointer; font-weight: 500;
  transition: color .15s, background .15s;
}
.seg input:checked + label {
  background: var(--accent); color: white;
}

.lookup-result {
  padding: 12px 14px; background: rgba(34,197,94,0.06);
  border: 1px solid rgba(34,197,94,0.25); border-radius: 10px;
  font-size: 13px;
}
.lookup-result.err {
  background: rgba(239,68,68,0.06);
  border-color: rgba(239,68,68,0.25);
  color: var(--down);
}

.alert {
  padding: 12px 14px; border-radius: 10px;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5; font-size: 14px;
}

/* ============================================================
   Auth page
   ============================================================ */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.auth-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px;
  margin-bottom: 24px;
}
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card .muted { font-size: 14px; margin-bottom: 24px; }

/* ============================================================
   Positions table
   ============================================================ */
.positions-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.positions { width: 100%; border-collapse: collapse; }
.positions th, .positions td {
  padding: 14px 18px; text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.positions thead th {
  background: var(--surface-2);
  font-weight: 600; font-size: 12px;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom-color: var(--border-2);
}
.positions tbody tr { transition: background .12s; }
.positions tbody tr:hover { background: rgba(99,102,241,0.04); }
.positions tbody tr:last-child td { border-bottom: 0; }
.positions .num { text-align: right; font-variant-numeric: tabular-nums; }
.asset { display: flex; align-items: center; gap: 12px; }
.asset-name { font-weight: 600; }
.asset-sym  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tag {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 42px; padding: 4px 8px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  border-radius: 6px;
}
.tag-stock  { background: rgba(99,102,241,0.15);  color: #a5b4fc; }
.tag-etf    { background: rgba(16,185,129,0.15);  color: #6ee7b7; }
.tag-crypto { background: rgba(245,158,11,0.15);  color: #fcd34d; }

.dot.stale {
  display: inline-block; width: 7px; height: 7px;
  background: var(--warning); border-radius: 50%;
  margin-left: 6px; vertical-align: middle;
}

/* ============================================================
   Back row / chips
   ============================================================ */
.back-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--muted); padding: 6px 10px;
  border-radius: 8px; transition: color .12s, background .12s;
}
.back-link:hover { color: var(--text); background: var(--surface-2); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.chip-group { display: inline-flex; gap: 4px; background: var(--bg-2); border-radius: 8px; padding: 3px; border: 1px solid var(--border); }
.chip {
  padding: 5px 10px; border: 0; background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 500; border-radius: 6px;
}
.chip.active { background: var(--surface-2); color: var(--text); }

/* ============================================================
   Legend
   ============================================================ */
.legend { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; font-size: 13px; }
.legend-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.legend-key { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }

/* ============================================================
   Empty state
   ============================================================ */
.empty-state {
  padding: 48px 24px; text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
  grid-column: 1 / -1;
}
.empty-state p { color: var(--muted); margin: 0 0 16px; }

/* ============================================================
   Modal
   ============================================================ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5,8,16,0.7);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fadeIn .15s ease;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  padding: 24px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slideUp .2s ease;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  padding-top: 8px; border-top: 1px solid var(--border);
  margin-top: 4px;
}
.modal-actions { padding-top: 16px; }

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

/* ============================================================
   Toast
   ============================================================ */
#toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  max-width: 360px;
}
.toast.ok  { border-left-color: var(--up); }
.toast.err { border-left-color: var(--down); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .container       { padding: 20px 14px 60px; }
  .topbar          { padding: 12px 14px; }
  .brand span:last-child { display: none; }
  .nav-link:not(.nav-logout) { display: none; }
  .hero            { padding: 18px 18px; }
  .hero-value      { font-size: 32px; }
  .detail-head     { padding: 20px; }
  .grid            { grid-template-columns: 1fr; }
  .section-head h2 { font-size: 17px; }
  h1               { font-size: 22px; }

  /* Positions table → cards on mobile */
  .positions-wrap { background: transparent; border: 0; border-radius: 0; }
  .positions, .positions thead, .positions tbody, .positions tr, .positions td { display: block; }
  .positions thead { display: none; }
  .positions tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 10px;
  }
  .positions td {
    border-bottom: 0; padding: 4px 0;
    display: flex; justify-content: space-between; align-items: center;
  }
  .positions td.num { text-align: right; }
  .positions td::before {
    content: attr(data-label);
    color: var(--muted); font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.05em;
  }
  .positions td:first-child::before { display: none; }
  .form-row { grid-template-columns: 1fr; }
}
