/* Portfolio Manager styles */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #F4F6FA;
  color: #1c2430;
  font-size: 15px;
}
a { color: #1E4FAE; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  background: linear-gradient(180deg, #0A1D3D, #0A1B38); color: #fff;
  padding: 0.6rem 1.4rem; border-bottom: 1px solid rgba(255,255,255,.07);
  position: sticky; top: 0; z-index: 50;
}
.brand-link { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: .02em; }
.brand-link .one { color: #C9A96A; }
.brand-link:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 0.2rem; flex: 1; align-items: center; }
.nav-link {
  color: #cbd5e1; padding: 0.45rem 0.7rem; border-radius: 6px;
  font-weight: 500; cursor: default;
}
a.nav-link:hover { background: #16305C; color: #fff; text-decoration: none; }
.nav-link.active { background: #16305C; color: #fff; }
.nav-group { position: relative; }
.nav-group:hover .dropdown { display: block; }
.dropdown {
  display: none; position: absolute; top: 100%; left: 0;
  background: #fff; border: 1px solid #dde3ea; border-radius: 8px;
  min-width: 210px; box-shadow: 0 8px 24px rgba(16,24,39,.14); padding: 0.35rem;
}
.dropdown a { display: block; padding: 0.5rem 0.8rem; color: #1c2430; border-radius: 6px; }
.dropdown a:hover { background: #eef2f7; text-decoration: none; }

.container { max-width: 1250px; margin: 1.4rem auto; padding: 0 1.2rem; }

h1 { font-size: 1.45rem; margin: 0.2rem 0 1rem; color: #0A1D3D; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 0.6rem; color: #0A1D3D; }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.8rem; }
.page-head .actions { display: flex; gap: 0.5rem; align-items: center; }

.flash { padding: 0.7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.notice { background: #e5f6ec; color: #14532d; border: 1px solid #b7e4c7; }
.flash.alert { background: #fdecec; color: #7f1d1d; border: 1px solid #f5c2c2; }

.card {
  background: #fff; border: 1px solid #E2E8F2; border-radius: 12px;
  padding: 1rem 1.2rem; margin-bottom: 1.2rem; box-shadow: 0 1px 2px rgba(10,29,61,.04);
}
.stat-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.stat {
  background: #fff; border: 1px solid #E2E8F2; border-radius: 12px;
  padding: 0.9rem 1.2rem; flex: 1; min-width: 180px; box-shadow: 0 1px 2px rgba(10,29,61,.04);
}
.stat .label { color: #64748b; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.35rem; font-weight: 700; margin-top: 0.2rem; color: #0A1D3D; }

table.data { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e4e8ee; border-radius: 10px; overflow: hidden; }
table.data th {
  text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: .03em;
  color: #52627D; background: #F6F8FB; padding: 0.55rem 0.7rem; border-bottom: 1px solid #E2E8F2;
}
table.data td { padding: 0.5rem 0.7rem; border-bottom: 1px solid #eef1f5; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #F5F8FC; }
table.data .num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.total td { font-weight: 700; background: #EEF3FA; color: #0A1D3D; }
.gain { color: #15803d; }
.loss { color: #b91c1c; }
.muted { color: #64748b; }
.small { font-size: 0.85rem; }

.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.buy, .badge.confirmed, .badge.committed { background: #e5f6ec; color: #14532d; }
.badge.sell, .badge.failed { background: #fdecec; color: #7f1d1d; }
.badge.suggested, .badge.parsed, .badge.pending { background: #fef3c7; color: #92400e; }
.badge.neutral { background: #e2e8f0; color: #334155; }

.btn {
  display: inline-block; background: #173F8C; color: #fff; border: none;
  padding: 0.5rem 0.95rem; border-radius: 8px; font-weight: 600; font-size: 0.9rem;
  cursor: pointer;
}
.btn:hover { background: #122E63; text-decoration: none; color: #fff; }
.btn-secondary { background: #E9EEF6; color: #16305C; }
.btn-secondary:hover { background: #DCE5F2; color: #16305C; }
.btn-quiet { background: transparent; color: #cbd5e1; font-weight: 500; }
.btn-quiet:hover { background: #16305C; color: #fff; }
.btn-danger { background: transparent; color: #b91c1c; font-weight: 500; padding: 0.2rem 0.4rem; }
.btn-danger:hover { background: #fdecec; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

form.standard { max-width: 560px; }
form.standard .field { margin-bottom: 0.9rem; }
form.standard label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.88rem; }
form.standard input[type=text], form.standard input[type=number], form.standard input[type=date],
form.standard input[type=password], form.standard input[type=email], form.standard input[type=file],
form.standard select, form.standard textarea {
  width: 100%; padding: 0.5rem 0.65rem; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 0.95rem; background: #fff;
}
form.standard .hint { color: #64748b; font-size: 0.8rem; margin-top: 0.2rem; }
.inline-form { display: inline; }
.errors { background: #fdecec; border: 1px solid #f5c2c2; color: #7f1d1d; border-radius: 8px; padding: 0.7rem 1rem; margin-bottom: 1rem; }

.filter-bar { display: flex; gap: 0.6rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-bar label { font-size: 0.8rem; font-weight: 600; display: block; margin-bottom: 0.2rem; }
.filter-bar input, .filter-bar select { padding: 0.4rem 0.6rem; border: 1px solid #cbd5e1; border-radius: 8px; }

.review-table input, .review-table select { width: 100%; border: 1px solid #cbd5e1; border-radius: 6px; padding: 0.3rem 0.4rem; font-size: 0.85rem; }
.review-table td { min-width: 80px; }

.auth-box { max-width: 380px; margin: 8vh auto; }
/* The wrapper is the sideways scroller, so it takes over the rounded-corner
   clipping — the table's own overflow:hidden would break the sticky column */
.table-scroll { overflow-x: auto; border-radius: 10px; }
.table-scroll table.data { overflow: visible; }
/* First column stays pinned while a wrapped table scrolls sideways */
.table-scroll table.data th:first-child, .table-scroll table.data td:first-child {
  position: sticky; left: 0; z-index: 1; background: #fff;
  box-shadow: 2px 0 4px rgba(16,24,39,.06);
}
.table-scroll table.data th:first-child { background: #F6F8FB; }
.table-scroll table.data tr.total td:first-child { background: #EEF3FA; }
.table-scroll table.data tr:hover td:first-child { background: #F5F8FC; }

/* Portfolio switcher in the top bar */
.portfolio-switcher .nav-link { background: rgba(255,255,255,0.12); border-radius: 6px; font-weight: 700; }
.dropdown-btn { display: block; width: 100%; text-align: left; padding: 0.5rem 0.8rem; background: none; border: none; color: #1c2430; border-radius: 6px; cursor: pointer; font-size: 0.95rem; }
.dropdown-btn:hover { background: #eef2f7; }

/* Sortable table headers */
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { background: #E3EAF5; }
table.data th.sort-asc::after { content: " ▲"; font-size: 0.7em; }
table.data th.sort-desc::after { content: " ▼"; font-size: 0.7em; }

/* Page-head action bars: keep filter forms on one line with the buttons */
.page-head .actions .filter-bar { margin-bottom: 0; align-items: center; }
.page-head .actions .filter-bar > div { display: flex; align-items: center; gap: 0.35rem; }
.page-head .actions .filter-bar label { margin-bottom: 0; }

/* Dashboard: extra holdings hidden until expanded */
tr.extra-holding { display: none; }
table.data.show-all tr.extra-holding { display: table-row; }

/* ---------- Mobile ---------- */
/* Dropdowns also open on tap/keyboard focus, not only hover (touch screens
   have no hover) — the nav-link spans carry tabindex=0 in the layout. */
.nav-group:focus-within .dropdown { display: block; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 0.3rem; padding: 0.5rem 0.7rem; row-gap: 0.2rem; }
  .topbar nav { flex-wrap: wrap; flex-basis: 100%; order: 3; row-gap: 0.1rem; }
  .nav-link { padding: 0.4rem 0.55rem; font-size: 0.9rem; }
  /* Open menus join the page flow full-width instead of floating (nothing
     gets clipped or hangs off-screen) */
  .nav-group { position: static; }
  .dropdown { position: static; width: 100%; min-width: 0; box-shadow: none; margin: 0.2rem 0; }

  .container { margin: 0.9rem auto; padding: 0 0.7rem; }
  h1 { font-size: 1.2rem; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .actions { flex-wrap: wrap; }

  .stat { min-width: 140px; padding: 0.7rem 0.9rem; }
  .stat .value { font-size: 1.15rem; }

  /* Wide tables scroll sideways within themselves; the page never does */
  table.data { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  /* iOS zooms into inputs below 16px — keep them at 16px on phones */
  input, select, textarea { font-size: 16px !important; }

  .auth-box { margin: 4vh auto; padding: 0 0.4rem; }
  .filter-bar { gap: 0.4rem; }
  .btn { padding: 0.55rem 0.9rem; }
}

/* Side-by-side sections that stack on phones */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; margin-top: 1.4rem; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
/* Grid/flex children may not shrink below their content unless told —
   without this a wide table inside a column forces the page to scroll */
.two-col > * { min-width: 0; }
/* Vector charts scale down to fit narrow screens */
svg[viewBox] { max-width: 100%; height: auto; }

/* Collapsible table rows (recent-activity tables and the like) */
tr.extra-row { display: none; }
table.data.show-all tr.extra-row { display: table-row; }

/* ---------- Holdings on phones ---------- */
.mobile-only { display: none; }
@media (max-width: 760px) {
  .mobile-only { display: inline-block; }
  .hide-mobile { display: none !important; }

  /* One money view at a time: local by default, the toggle switches the
     three cost/value/gain columns to the reporting currency */
  #holdings-table .col-reporting { display: none; }
  #holdings-table.show-reporting .col-reporting { display: table-cell; }
  #holdings-table.show-reporting .col-local { display: none; }

  /* The stock-name column stays pinned while the table scrolls sideways */
  table.data th:first-child, table.data td:first-child {
    position: sticky; left: 0; z-index: 1; background: #fff;
    box-shadow: 2px 0 4px rgba(16,24,39,.06);
  }
  table.data th:first-child { background: #f8fafc; }
  table.data tr.total td:first-child { background: #f1f5f9; }
}

/* Whole-number money on phones (helper money_r renders both spans) */
.money-round { display: none; }
@media (max-width: 760px) {
  .money-full { display: none; }
  .money-round { display: inline; }
}

/* Auth pages (login / signup / password) — landing-page branding */
body.auth-page {
  min-height: 100vh; margin: 0;
  background: linear-gradient(165deg, #0A1D3D 0%, #071429 70%);
  display: flex; align-items: center; justify-content: center;
}
.auth-wrap { width: 100%; max-width: 420px; padding: 2rem 1.2rem; text-align: center; }
.auth-logo { display: inline-block; color: #fff; font-weight: 700; font-size: 1.5rem; letter-spacing: .02em; margin-bottom: 1.4rem; }
.auth-logo:hover { text-decoration: none; color: #fff; }
.auth-logo .one { color: #C9A96A; }
.auth-card {
  background: #fff; border-radius: 14px; padding: 1.8rem 1.9rem; text-align: left;
  box-shadow: 0 18px 50px rgba(4, 12, 28, .45);
}
.auth-card h1 { font-size: 1.25rem; margin: 0 0 0.3rem; color: #0A1D3D; }
.auth-card .auth-sub { color: #5b6b82; font-size: .92rem; margin: 0 0 1.2rem; }
.auth-card form.standard { max-width: none; }
.auth-card .btn { width: 100%; padding: 0.65rem; font-size: 0.95rem; }
.auth-links { margin-top: 1rem; text-align: center; color: #5b6b82; font-size: .88rem; }
.auth-foot { color: #7d90ad; font-size: .82rem; margin-top: 1.5rem; }


/* Focus states — deep-blue ring on every input */
form.standard input:focus, form.standard select:focus, form.standard textarea:focus,
.filter-bar input:focus, .filter-bar select:focus, .review-table input:focus, .review-table select:focus {
  outline: none; border-color: #173F8C; box-shadow: 0 0 0 3px rgba(23, 63, 140, .13);
}
