/* PfCockpit next UI — single hand-rolled stylesheet, no framework. */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1d2530;
  --muted: #6b7686;
  --line: #dde2e9;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #b91c1c;
  --warn: #b45309;
  /* Tax-harvesting holding-row colours (original UI values) */
  --reap-gain: yellow;
  --reap-loss: orange;
  /* Buy-txn sub-rows (scheme B): hue = profit/loss; long-term rows use
     saturated fills with white text, short-term rows softened lights. */
  --long-profit: #2e7d32;
  --long-loss: #b71c1c;
  --short-profit: #b7e2bb;
  --short-loss: #f0a8a1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-weight: 600; }
h2 { font-size: 1.35rem; margin: 1.2rem 0 0.6rem; }
h3 { font-size: 1.1rem; margin: 0; }
small, .muted { color: var(--muted); }

/* ---- Shell ---- */

.topnav {
  background: #16202e;
  color: #e7ecf3;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.55rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topnav .brand { font-weight: 700; letter-spacing: 0.02em; color: #fff; }
.topnav a { color: #cdd8e6; }
.topnav a:hover { color: #fff; text-decoration: none; }
.topnav .spacer { flex: 1; }

.page { width: 100%; margin: 0 auto; padding: 0.5rem 1.25rem 3rem; }

.footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  padding: 1rem;
  margin-top: 2rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin: 0.75rem 0;
}
.panel > .panel-title { font-weight: 600; margin-bottom: 0.5rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.75rem 0; }
.toolbar .spacer { flex: 1; }
.toolbar input.filter-box { width: 300px; }
.inline-label { display: inline; font-weight: 600; margin: 0; }

/* Shrink-wrapped vertical stack: the widest child (a table) sets the
   width; sibling panels/toolbars stretch to match it. */
.stack-fit { width: fit-content; margin: 0 auto; }

.charts-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.charts-row .panel { flex: 1 1 340px; min-width: 300px; }
.charts-row .panel:first-child { flex: 2 1 480px; }
/* width:0 + min-width:100% — fill the panel without the canvas's own size
   feeding back into fit-content width calculations. */
.chart-box { position: relative; height: 300px; width: 0; min-width: 100%; }

/* ---- Buttons & forms ---- */

.btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 0.35rem 0.8rem;
  font: inherit;
  cursor: pointer;
}
.btn:hover { background: #f0f3f7; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #1d4fc4; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 0.15rem 0.5rem; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--accent);
  padding: 0 0.1rem;
  font-size: 0.8rem;
}
.icon-btn.danger { color: var(--danger); }

label { display: block; font-weight: 600; margin: 0.6rem 0 0.2rem; }
input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid #bfd3f7; border-color: var(--accent); }
.field-error { color: var(--danger); font-size: 0.85rem; margin-top: 0.15rem; }
.form-error { color: var(--danger); margin-top: 0.6rem; }

/* ---- Tables ---- */

/* Table panels shrink-wrap their table and center in the window. No inner
   scrollbox: a too-wide table overflows the document itself, which keeps
   pinch-zoom-out working on phones (the browser can only zoom out to the
   document width). */
.panel.tbl-wrap {
  width: fit-content;
  max-width: none;
  margin-left: auto;
  margin-right: auto;
  overflow-x: visible;
}
/* width:auto — columns hug their content; surplus page width stays outside
   the table instead of being distributed as padding around header names. */
table.tbl { border-collapse: collapse; width: auto; background: var(--panel); }
.tbl th, .tbl td {
  border-bottom: 1px solid var(--line);
  padding: 0.3rem 0.4rem;
  text-align: left;
  white-space: nowrap;
}
.tbl thead th {
  background: #eef1f5;
  position: sticky;
  top: 0;
  font-weight: 600;
}
.tbl tbody tr:hover { background: #f4f7fb; }
.tbl .num { text-align: right; }
.tbl .ctr { text-align: center; }
.tbl tr.totals td { font-weight: 700; border-top: 2px solid var(--ink); }
.tbl tr.subrow td { background: #fafbfd; color: var(--muted); font-size: 0.92em; }

/* Roomier variant (transactions page): wider cells -> wider table, and the
   chart above follows via the shared .stack-fit width. */
.tbl.tbl-roomy th, .tbl.tbl-roomy td { padding: 0.3rem 0.75rem; }

.sort-btn { cursor: pointer; color: var(--muted); border: none; background: none; padding: 0 0.15rem; }
.sort-btn.active { color: var(--accent); }
.hide-btn { cursor: pointer; color: var(--muted); border: none; background: none; padding: 0 0.15rem; font-size: 0.8em; }
.hidden-cols { font-size: 0.85rem; }
.hidden-cols a { margin-right: 0.4rem; cursor: pointer; }

/* Row colours (tax-harvesting + P/L) */
tr.ReapGain td { background: var(--reap-gain); }
tr.ReapLoss td { background: var(--reap-loss); }
/* Dark long-term fills carry white text; light short-term fills keep ink */
tr.subrow.Long-Profit td { background: var(--long-profit); color: #ffffff; }
tr.subrow.Long-Loss td { background: var(--long-loss); color: #ffffff; }
tr.subrow.Short-Profit td { background: var(--short-profit); color: var(--ink); }
tr.subrow.Short-Loss td { background: var(--short-loss); color: var(--ink); }

/* ---- Modal ---- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 1rem 1rem;
  z-index: 50;
}
.modal-box {
  background: var(--panel);
  border-radius: 10px;
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-box header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
}
.modal-box .modal-body { padding: 0.5rem 1rem 1rem; }
.modal-box .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--line);
}
.modal-box .close { border: none; background: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); }

/* ---- Typeahead ---- */

.typeahead { position: relative; }
.typeahead-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  max-height: 300px;
  overflow: auto;
  z-index: 60;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}
.typeahead-item { padding: 0.4rem 0.6rem; cursor: pointer; }
.typeahead-item:hover, .typeahead-item.active { background: #eef3fc; }
.typeahead-item small { display: block; }

/* ---- Misc ---- */

.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(245, 246, 248, 0.96);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 420px;
}

.alert {
  border: 1px solid #f1c3c3;
  background: #fdeaea;
  color: var(--danger);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  margin: 0.75rem 0;
}
.loading { color: var(--muted); padding: 1rem 0; }

.prefix-nav { display: flex; flex-wrap: wrap; gap: 0.15rem; margin: 0.5rem 0; }
.prefix-nav a {
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
.prefix-nav a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
