/* Portfolio detail page: the positions table and its empty state.
   Colours follow /assets/css/theme.css (light by default, deep navy under
   <html data-theme="dark">), with the same palette as the portfolio list and VestAlchemy Score.
   theme.css and institution-holding-style.css style bare table/th/td elements, some with
   !important in dark mode; the .pd-table rules below are scoped and marked !important where
   they have to win over those. */

:root {
  --pd-card: #ffffff;
  --pd-line: #e3e8ef;
  --pd-row-line: #edf1f6;
  --pd-text: #0f1e36;
  --pd-muted: #5b6b82;
  --pd-soft: #f4f7fb;
  --pd-head: #f7f9fc;
  --pd-hover: #f1f6ff;
  --pd-accent: #0d6efd;
  --pd-accent-soft: rgba(13, 110, 253, .10);
  --pd-up: #1f9d55;
  --pd-down: #d63445;
  --pd-shadow: 0 1px 2px rgba(15, 30, 54, .05), 0 8px 24px rgba(15, 30, 54, .06);
}
[data-theme="dark"] {
  --pd-card: #10203a;
  --pd-line: #1d3454;
  --pd-row-line: #172b47;
  --pd-text: #e6edf7;
  --pd-muted: #93a7c4;
  --pd-soft: #0d1a30;
  --pd-head: #0d1a30;
  --pd-hover: #14294a;
  --pd-accent: #4da3ff;
  --pd-accent-soft: rgba(77, 163, 255, .14);
  --pd-up: #34c26f;
  --pd-down: #f26b78;
  --pd-shadow: 0 10px 30px rgba(0, 0, 0, .28);
}

/* ---------- Card ---------- */
.pd-card {
  background: var(--pd-card);
  border: 1px solid var(--pd-line);
  border-radius: 16px;
  box-shadow: var(--pd-shadow);
  color: var(--pd-text);
  overflow: hidden;
  margin-bottom: 24px;
}
.pd-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--pd-line);
}
.pd-icon {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  color: var(--pd-accent);
  background: var(--pd-accent-soft);
}
.pd-card-head h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  color: var(--pd-text);
}
.pd-card-head .pd-sub {
  font-size: .8rem;
  color: var(--pd-muted);
}
.pd-count {
  margin-left: auto;
  font-size: .78rem;
  font-weight: 600;
  color: var(--pd-muted);
  background: var(--pd-soft);
  border: 1px solid var(--pd-line);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

/* ---------- Table ---------- */
.pd-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--pd-line) transparent;
}
[data-theme="dark"] .pd-scroll { color-scheme: dark; }
.pd-table {
  width: 100%;
  min-width: 820px;
  margin: 0 !important;
  border-collapse: separate !important;
  border-spacing: 0;
  table-layout: auto !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  font-size: .9rem !important;
  color: var(--pd-text) !important;
}
.pd-table th,
.pd-table td {
  border: 0 !important;
  border-bottom: 1px solid var(--pd-row-line) !important;
  padding: 12px 14px !important;
  vertical-align: middle;
  text-align: left;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.pd-table thead th {
  background: var(--pd-head) !important;
  color: var(--pd-muted) !important;
  font-size: .7rem !important;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--pd-line) !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
}
.pd-table tbody tr,
.pd-table tbody tr:nth-child(even) { background: transparent !important; }
.pd-table tbody tr:hover { background: var(--pd-hover) !important; }
.pd-table tbody tr:last-child td { border-bottom: 0 !important; }
.pd-table .pd-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pd-table .pd-nowrap { white-space: nowrap; }

/* Symbol + company name in one cell. */
.pd-stock { display: flex; flex-direction: column; gap: 2px; min-width: 150px; }
.pd-ticker {
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--pd-text);
}
.pd-name {
  font-size: .78rem;
  color: var(--pd-muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* A watchlist symbol's note, under its name. */
.pd-note {
  font-size: .76rem;
  font-style: italic;
  color: var(--pd-muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pw-table .pd-note { max-width: 190px; }
/* The General tab's Notes column on a watchlist: wraps, within a readable width. */
.pw-table td.pw-notes { min-width: 160px; max-width: 320px; white-space: normal; font-size: .85rem; }
/* The owner's advice on a position, as a coloured pill: buy green, hold amber, sell red. */
.pw-table td.pw-advice { white-space: nowrap; }
.pd-advice {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.5;
  border: 1px solid transparent;
}
.pd-advice-buy  { color: #11724a; background: #e3f6ec; border-color: #bfe8d3; }
.pd-advice-hold { color: #8a5a00; background: #fff4dc; border-color: #f3dfae; }
.pd-advice-sell { color: #b3261e; background: #fde8e6; border-color: #f5c6c2; }
[data-theme="dark"] .pd-advice-buy  { color: #6fe0a8; background: rgba(46, 160, 104, .16); border-color: rgba(46, 160, 104, .35); }
[data-theme="dark"] .pd-advice-hold { color: #f3c46b; background: rgba(214, 158, 46, .16); border-color: rgba(214, 158, 46, .35); }
[data-theme="dark"] .pd-advice-sell { color: #ff8f86; background: rgba(220, 70, 60, .16); border-color: rgba(220, 70, 60, .35); }
.pd-muted { color: var(--pd-muted); }

/* Gain badge. */
.pd-gain {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 700;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
.pd-gain .bi { font-size: .75em; }
.pd-gain.pd-up   { color: var(--pd-up);   background: color-mix(in srgb, var(--pd-up) 13%, transparent); }
.pd-gain.pd-down { color: var(--pd-down); background: color-mix(in srgb, var(--pd-down) 13%, transparent); }
.pd-gain.pd-flat { color: var(--pd-muted); background: var(--pd-soft); }

/* Position stop. */
.pd-stop { font-size: .84rem; color: var(--pd-text); min-width: 120px; display: inline-block; }

/* Research report link. */
.pd-report {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  font-size: .85rem;
  text-decoration: none;
  min-width: 190px;
  max-width: 300px;
  line-height: 1.35;
}
.pd-report .bi { margin-top: 2px; flex: 0 0 auto; }
.pd-report:hover span { text-decoration: underline; }
.pd-report-form { display: flex; gap: 6px; align-items: center; min-width: 240px; }
.pd-report-form .form-select {
  min-width: 170px;
  max-width: 260px;
  font-size: .82rem;
  padding: 4px 28px 4px 8px;
  border-radius: 8px;
}

/* Row actions: compact icon buttons. */
.pd-table .pd-actions { white-space: nowrap; text-align: right !important; }
.pd-table .pd-actions form { display: inline; margin: 0; }
.pd-table .pd-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 0 4px;
  padding: 4px 10px;
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.4;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--pd-line);
  color: var(--pd-text);
  text-decoration: none;
  cursor: pointer;
}
.pd-table .pd-btn:hover,
.pd-table .pd-btn:focus {
  border-color: var(--pd-accent);
  color: var(--pd-accent);
  background: var(--pd-accent-soft);
}
/* theme.css colours every dark-mode a:not(.btn) blue; keep the Edit link a neutral button. */
[data-theme="dark"] .pd-table a.pd-btn { color: var(--pd-text); }
[data-theme="dark"] .pd-table a.pd-btn:hover,
[data-theme="dark"] .pd-table a.pd-btn:focus { color: var(--pd-accent); }
.pd-table .pd-btn-danger {
  color: var(--pd-down);
  border-color: color-mix(in srgb, var(--pd-down) 45%, transparent);
}
.pd-table .pd-btn-danger:hover,
.pd-table .pd-btn-danger:focus {
  background: var(--pd-down);
  border-color: var(--pd-down);
  color: #fff;
}
.pd-table .pd-btn-primary {
  background: var(--pd-accent);
  border-color: var(--pd-accent);
  color: #fff;
}
[data-theme="dark"] .pd-table .pd-btn-primary { color: #06142a; }
.pd-table .pd-btn-primary:hover,
.pd-table .pd-btn-primary:focus {
  background: color-mix(in srgb, var(--pd-accent) 85%, #000);
  border-color: color-mix(in srgb, var(--pd-accent) 85%, #000);
  color: #fff;
}

/* Keep the stock column visible while the table scrolls sideways on a phone. */
@media (max-width: 767.98px) {
  .pd-table th:first-child,
  .pd-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--pd-card) !important;
    box-shadow: 1px 0 0 var(--pd-line);
  }
  .pd-table thead th:first-child { background: var(--pd-head) !important; }
  .pd-table tbody tr:hover td:first-child { background: var(--pd-hover) !important; }
  .pd-card-head { padding: 14px 16px; }
  .pd-card-head .pd-sub { display: none; }
}

/* ---------- Empty state ---------- */
.pd-empty {
  text-align: center;
  padding: 44px 24px;
  background: var(--pd-card);
  border: 1px dashed var(--pd-line);
  border-radius: 16px;
  color: var(--pd-muted);
  margin-bottom: 24px;
}
.pd-empty .pd-icon {
  width: 52px;
  height: 52px;
  font-size: 1.5rem;
  border-radius: 15px;
  margin: 0 auto 12px;
}
.pd-empty h3 { font-size: 1.1rem; font-weight: 700; color: var(--pd-text); margin-bottom: 6px; }
.pd-empty p { margin: 0; font-size: .9rem; }


/* ---------------------------------------------------------------- ratings & comments */
.rv-stars { color: #f5a623; letter-spacing: 1px; white-space: nowrap; }
.rv-badge { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; font-size: .9rem; font-weight: 600;
            color: var(--pd-text); text-decoration: none; vertical-align: middle; }
.rv-badge i { color: #f5a623; }
.rv-badge-n { color: var(--pd-muted); font-weight: 400; }
.rv-flash { margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; font-size: .9rem; }
.rv-ok { background: rgba(31, 157, 85, .10); color: var(--pd-up); }
.rv-err { background: rgba(214, 52, 69, .10); color: var(--pd-down); }
.rv-form { border: 1px solid var(--pd-line); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; background: var(--pd-soft); }
.rv-form-title { font-weight: 600; margin-bottom: 4px; color: var(--pd-text); }
.rv-form textarea { width: 100%; border: 1px solid var(--pd-line); border-radius: 8px; padding: 8px 10px;
                    background: var(--pd-card); color: var(--pd-text); resize: vertical; }
.rv-form-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
/* Star picker: radios in reverse order, so "this star and every one before it" lights with ~.
   The colour is set on the icon, not the label: the dark theme forces every label's colour with
   !important (theme.css), and this page's inline styles give every label min-width: 100px. */
.rv-pick { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; }
.rv-input { position: relative; display: inline-flex; flex-direction: row-reverse; justify-content: flex-end;
            border: 0; padding: 0; margin: 0; }
.rv-input input { position: absolute; left: 0; top: 0; opacity: 0; width: 1px !important; height: 1px; padding: 0 !important;
                  border: 0 !important; pointer-events: none; }
.rv-input label { display: inline-block; min-width: 0; margin: 0; font-size: 1.5rem; cursor: pointer; padding: 0 2px; line-height: 1; }
/* Unselected, selected (the checked star and every one before it), then a hover preview that
   overrides both. Specificity rises in that order; no !important needed. */
.rv-input label > i { color: #c9d1dc; }
[data-theme="dark"] .rv-input label > i { color: #3a4f6e; }
.rv-input input:checked ~ label > i { color: #f5a623; }
.rv-input.rv-input:hover label > i { color: #c9d1dc; }
[data-theme="dark"] .rv-input.rv-input:hover label > i { color: #3a4f6e; }
.rv-input.rv-input:hover label:hover > i,
.rv-input.rv-input:hover label:hover ~ label > i { color: #f5a623; }
.rv-input input:focus-visible + label { outline: 2px solid var(--pd-accent); outline-offset: 2px; border-radius: 4px; }
.rv-pick-value { font-weight: 600; color: var(--pd-text); font-variant-numeric: tabular-nums; }
.rv-note { color: var(--pd-muted); font-size: .9rem; margin: 4px 0 12px; }
.rv-list { list-style: none; margin: 0; padding: 0; }
.rv-list li { padding: 12px 0; border-top: 1px solid var(--pd-row-line); }
.rv-list li.rv-mine { background: var(--pd-accent-soft); padding-left: 10px; padding-right: 10px; border-radius: 8px; }
.rv-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rv-you { font-size: .75rem; background: var(--pd-accent); color: #fff; border-radius: 999px; padding: 1px 8px; }
.rv-comment { margin: 6px 0 0; white-space: pre-line; overflow-wrap: anywhere; color: var(--pd-text); }
.rv-del { margin-left: auto; }
.rv-del-btn { border: 0; background: none; color: var(--pd-muted); padding: 2px 6px; border-radius: 6px; }
.rv-del-btn:hover { color: var(--pd-down); background: rgba(214, 52, 69, .08); }

/* The average as a partly filled row of stars (to 0.1): grey stars, gold ones clipped on top.
   No gaps between the icons, so the width maps straight onto the five stars. */
.rv-meter { position: relative; display: inline-block; white-space: nowrap; line-height: 1; vertical-align: -1px; }
.rv-meter i { margin: 0; letter-spacing: 0; }
.rv-meter-bg { color: #c9d1dc; }
[data-theme="dark"] .rv-meter-bg { color: #3a4f6e; }
.rv-meter-fg { position: absolute; left: 0; top: 0; width: var(--rv-fill, 0%); overflow: hidden; color: #f5a623; }
