/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c222c;
  --border: #242b36;
  --text: #e6edf3;
  --text-dim: #8b95a5;
  --text-mute: #5c6573;
  --accent: #22c997;       /* emerald / profit */
  --accent-soft: rgba(34, 201, 151, 0.15);
  --accent-strong: #2bd9a6;
  --warn: #f0b429;
  --danger: #e5484d;       /* loss */
  --danger-soft: rgba(229, 72, 77, 0.14);
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

html, body {
  min-height: 100%;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
body { overflow-x: hidden; }

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font: inherit; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; }
code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.92em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--text);
}

/* ---------- Layout ---------- */
.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px rgba(34, 201, 151, 0.55);
}
.brand h1 { font-size: 18px; letter-spacing: 0.02em; font-weight: 700; }
.brand-sub {
  color: var(--text-dim);
  font-size: 12px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}

.toolbar { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.refresh {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.refresh__label { color: var(--text-dim); font-size: 12px; }
.select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}
.select:focus { border-color: var(--accent); }

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
}
.live__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-mute);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.live.is-live .live__dot {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(34, 201, 151, 0.7);
  animation: pulse 1.6s ease-in-out infinite;
}
.live.is-stale .live__dot { background: var(--warn); box-shadow: 0 0 10px rgba(240,180,41,0.6); }
.live.is-error .live__dot { background: var(--danger); box-shadow: 0 0 10px rgba(229,72,77,0.6); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- HUD ---------- */
.hud {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat--total { border-color: rgba(34, 201, 151, 0.35); }
.stat__label {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stat__value {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-weight: 700;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.is-profit { color: var(--accent); }
.is-loss { color: var(--danger); }
.flash { animation: flash 0.5s ease; }
@keyframes flash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel__head h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 600;
}
.panel__meta { color: var(--text-mute); font-size: 12px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.ptable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 760px;
}
.ptable thead th {
  color: var(--text-mute);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 6px 10px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ptable tbody td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ptable tbody tr:last-child td { border-bottom: none; }
.ptable tbody tr { transition: background 0.12s ease; }
.ptable tbody tr:hover { background: var(--surface-2); }
.ta-l { text-align: left; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.ptable td.ta-r, .ptable th.ta-r { text-align: right; }
.ptable td.ta-c, .ptable th.ta-c { text-align: center; }

.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

.sym-cell { display: flex; flex-direction: column; gap: 2px; }
.sym-name { font-weight: 700; letter-spacing: 0.02em; }
.sym-sub { color: var(--text-mute); font-size: 11px; }

.cmp-cell { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; }
.cmp-loading { color: var(--text-mute); font-style: italic; }

.row-actions { display: inline-flex; gap: 6px; justify-content: center; }
.icon-btn {
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  transition: all 0.12s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-mute); }
.icon-btn--sell { color: var(--accent); border-color: rgba(34,201,151,0.4); }
.icon-btn--sell:hover { background: var(--accent-soft); color: var(--accent-strong); }
.icon-btn--del:hover { color: var(--danger); border-color: rgba(229,72,77,0.5); background: var(--danger-soft); }

/* ---------- Empty states ---------- */
.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-dim);
}
.empty.hidden { display: none; }
.empty__sub { color: var(--text-mute); font-size: 12px; margin-top: 4px; }

/* ---------- Add row form ---------- */
.add-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}
.field input:focus { border-color: var(--accent); }
.field__note { font-size: 11px; color: var(--text-mute); min-height: 14px; }
.add-row__btn { height: 40px; }

.hint { color: var(--text-mute); font-size: 12px; margin-top: 12px; line-height: 1.6; }

/* ---------- Buttons / links ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.btn--primary { background: var(--accent); color: #052218; }
.btn--primary:hover { background: var(--accent-strong); transform: translateY(-1px); }
.btn--ghost { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); }
.btn--ghost:hover { color: var(--text); border-color: var(--text-mute); }
.link {
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}
.link:hover { color: var(--text); background: var(--surface-2); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 10, 14, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal__card {
  position: relative;
  width: min(420px, 92vw);
  padding: 26px 26px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal__card h2 { font-size: 19px; margin-bottom: 4px; }
.modal__card > p { color: var(--text-dim); margin-bottom: 18px; font-size: 13px; }
.modal__card form { display: flex; flex-direction: column; gap: 14px; }
.modal__card .field input {
  text-align: left;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-weight: 600;
}
.sell-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sell-preview .row { display: flex; justify-content: space-between; }
.sell-preview .row span { color: var(--text-dim); }
.sell-preview .row strong { font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---------- Footer ---------- */
.footer {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-mute);
  font-size: 12px;
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .hud { grid-template-columns: repeat(2, 1fr); }
  .stat--total { grid-column: span 2; }
}
@media (max-width: 620px) {
  .app { padding: 16px 14px 24px; }
  .add-row { grid-template-columns: 1fr 1fr; }
  .field--sym { grid-column: span 2; }
  .add-row__btn { grid-column: span 2; }
  .brand-sub { display: none; }
  .hud { grid-template-columns: 1fr 1fr; }
  .stat__value { font-size: 18px; }
}
