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

:root {
  --bg:    #f3f4f7;
  --card:  #ffffff;
  --border:#e5e7eb;
  --text:  #1a1a2e;
  --text2: #5a6474;
  --cyan:  #06b6d4;
  --gain:  #e53e3e;  /* 日本株式慣習：プラス=赤 */
  --loss:  #38a169;  /* 日本株式慣習：マイナス=緑 */
  --c1:    #3b82f6;   /* 国内株: 青 */
  --c2:    #eab308;   /* 米国株: 黄色 */
  --c3:    #c084fc;   /* 投資信託: 薄紫 */
  --c4:    #22c55e;   /* 仮想通貨: 緑 */
  --hover: #f3f4f7;
  --radius:14px;
  --font: 'Segoe UI', 'Hiragino Kaku Gothic ProN', sans-serif;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.6; }

/* ── Header ── */
.pf-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 32px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.pf-header__left  { display: flex; align-items: center; gap: 12px; }
.pf-header__right { display: flex; align-items: center; gap: 20px; font-size: 12px; color: var(--text2); }
.pf-logo { flex-shrink: 0; display: block; }
.pf-header__brand { display: flex; flex-direction: column; gap: 1px; }
.pf-header__my    { font-size: 9px; font-weight: 700; color: var(--text2); letter-spacing: 0.1em; }
.pf-header__title { font-size: 15px; font-weight: 700; }
.pf-header__fx          { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 4px; }
.pf-header__updated-wrap { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text2); }
#updatedAt { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.pf-updated-label { display: flex; align-items: center; gap: 4px; }
.pf-header__fx-pair { font-weight: 600; color: var(--text); }
.pf-rate-val  { font-weight: 600; color: var(--text); }
.pf-rate-dot  { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; flex-shrink: 0; }
.pf-rate-dot--live    { background: #4ade80; }
.pf-rate-dot--offline { background: #f59e0b; }
.pf-rate-dot--loading { background: var(--cyan); animation: pf-pulse 1s ease-in-out infinite; }
@keyframes pf-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ── Main ── */
.pf-main { max-width: 1100px; margin: 0 auto; padding: 12px 24px 28px; display: flex; flex-direction: column; gap: 4px; }
#portfolioContent { display: flex; flex-direction: column; gap: 4px; }

/* ── Hero ── */
.pf-hero { display: flex; }
.pf-hero__card {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
  padding: 12px 24px 20px 20px; width: 100%;
}
.pf-hero__label    { font-size: 14px; font-weight: 600; color: var(--text2); letter-spacing: 0.05em; display: flex; align-items: center; gap: 6px; }
.pf-hero__total    { font-size: 44px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.1; }
.pf-hero__unit     { font-size: 0.5em; font-weight: 400; vertical-align: middle; letter-spacing: 0; }
.pf-hero__total-row { display: flex; align-items: flex-start; gap: 28px; }
.pf-hero__total-col { display: flex; flex-direction: column; gap: 6px; }
.pf-hero__gain     { display: flex; flex-direction: column; gap: 3px; }
.pf-hero__gain .pf-hero__stat-row { flex-direction: column; align-items: flex-start; gap: 2px; }
.pf-hero__stats    { display: flex; gap: 28px; margin-top: 10px; }
.pf-hero__stat     { display: flex; flex-direction: column; gap: 3px; }
.pf-hero__stat-row { display: flex; align-items: baseline; gap: 6px; font-size: 14px; font-weight: 600; }
.pf-hero__sublabel { font-size: 11px; color: var(--text2); font-weight: 400; }
.pf-hero__pct      { font-size: 12px; font-weight: 500; }
/* ── Owner tabs ── */
.pf-owner { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: -2px; overflow-x: auto; scrollbar-width: none; }
.pf-owner::-webkit-scrollbar { display: none; }
.pf-owner__btn {
  border: none; background: transparent; color: var(--text2);
  cursor: pointer; font-size: 13px; font-weight: 600;
  padding: 8px 18px; transition: all .15s;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  white-space: nowrap; flex-shrink: 0; -webkit-tap-highlight-color: transparent;
}
.pf-owner__btn:hover { color: var(--text); }
.pf-owner__btn--active { color: var(--text); border-bottom-color: var(--cyan); background: rgba(6,182,212,.10); border-radius: 6px 6px 0 0; }

/* ── Custom Dropdown ── */
.pf-dropdown { position: relative; display: inline-block; }
.pf-dropdown__btn {
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text);
  font-size: 12px; font-weight: 600; font-family: var(--font);
  padding: 5px 24px 5px 12px; cursor: pointer; outline: none;
  white-space: nowrap; position: relative; transition: border-color .15s;
}
.pf-dropdown__btn::after {
  content: '▾'; position: absolute; right: 8px; top: 50%;
  transform: translateY(-50%); font-size: 10px; color: var(--text2); pointer-events: none;
}
.pf-dropdown.is-open .pf-dropdown__btn { border-color: var(--cyan); }
.pf-dropdown__menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.14);
  list-style: none; z-index: 200; min-width: 100%; overflow: hidden; padding: 4px 0;
}
.pf-dropdown.is-open .pf-dropdown__menu { display: block; }
.pf-dropdown__menu li {
  padding: 9px 18px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.pf-dropdown__menu li:hover { background: var(--hover); }
.pf-dropdown__menu li.is-active { color: var(--cyan); font-weight: 700; }

/* ── Line chart ── */
.pf-line-section {
  background: var(--card); border-radius: var(--radius);
  padding: 12px 8px 16px; border: 1px solid var(--border);
}
.pf-line-section__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; padding: 0 4px; }
.pf-line-section__title { font-size: 14px; color: var(--text2); font-weight: 600; letter-spacing: 0.05em; margin-left: 8px; }
.pf-line-wrap { position: relative; width: 100%; }
.pf-line-wrap canvas { width: 100%; height: auto; display: block; }
.pf-tip {
  position: absolute; transform: translateX(-50%); pointer-events: none;
  background: var(--text); color: #fff;
  border-radius: 6px; padding: 6px 10px;
  font-size: 12px; white-space: nowrap; z-index: 2;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.pf-tip__date { opacity: .7; font-size: 11px; }
.pf-tip__val  { font-weight: 700; }

/* ── Rankings ── */
.pf-rankings { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.pf-ranking-block {
  background: var(--card); border-radius: var(--radius);
  padding: 16px 20px; border: 1px solid var(--border); min-width: 0;
}
.pf-ranking-title { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 4px; letter-spacing: 0.04em; }
.pf-ranking { list-style: none; display: flex; flex-direction: column; }
.pf-ranking li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.pf-ranking li:last-child { border-bottom: none; }
.pf-ranking__dot { width: 8px; height: 8px; border-radius: 3px; flex-shrink: 0; }
.pf-ranking__info { flex: 1; min-width: 0; }
.pf-ranking__name { font-size: 12px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-ranking__sub  { font-size: 11px; color: var(--text2); margin-top: 2px; display: flex; align-items: center; gap: 5px; overflow: hidden; }
.pf-ranking__ticker { font-size: 11px; color: var(--text2); }
.pf-ranking__right { display: flex; align-items: baseline; gap: 2px; flex-shrink: 0; }
.pf-ranking__pct  { font-weight: 700; font-size: 13px; width: 58px; text-align: right; }
.pf-ranking__jpy  { font-size: 11px; width: 70px; text-align: right; }

/* ── Asset allocation ── */
.pf-allocation {
  background: var(--card); border-radius: var(--radius);
  padding: 12px 24px 24px 12px; border: 1px solid var(--border);
  display: flex; align-items: center; gap: 40px; flex-wrap: wrap;
}
.pf-allocation__label { width: 100%; font-size: 14px; font-weight: 600; color: var(--text2); letter-spacing: 0.05em; margin-left: 8px; margin-bottom: -16px; }
.pf-donut-wrap { flex-shrink: 0; }
#donutChart { outline: none; width: 220px; height: 220px; }
.pf-cat-legend  { list-style: none; flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 18px; }
.pf-cat-legend li { display: flex; align-items: center; gap: 12px; -webkit-tap-highlight-color: transparent; }
.pf-cat-dot     { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.pf-cat-info    { display: flex; flex-direction: column; gap: 2px; width: 86px; flex-shrink: 0; }
.pf-cat-name    { font-size: 13px; font-weight: 700; }
.pf-cat-amount  { font-size: 11px; color: var(--text2); }
.pf-cat-bar-wrap { flex: 1; min-width: 60px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.pf-cat-bar     { height: 100%; border-radius: 3px; }
.pf-cat-pct     { width: 42px; text-align: right; font-size: 13px; font-weight: 700; color: var(--text); flex-shrink: 0; }
.pf-cat-right   { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 88px; flex-shrink: 0; }
.pf-cat-right span:first-child { font-size: 13px; font-weight: 700; white-space: nowrap; }
.pf-cat-right span:last-child  { font-size: 11px; white-space: nowrap; }

/* ── Holdings by category ── */
.pf-holdings { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.pf-cat-section + .pf-cat-section { border-top: 2px solid var(--border); }

.pf-cat-header {
  display: grid;
  grid-template-columns: 1fr repeat(3, 72px) 120px;
  gap: 16px; align-items: center;
  padding: 13px 20px;
  background: #f9fafb;
  border-left: 4px solid var(--cat-color, var(--cyan));
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
}
.pf-cat-header__name         { font-weight: 700; font-size: 15px; display: flex; align-items: baseline; gap: 6px; }
.pf-cat-header__count        { font-size: 12px; color: var(--text2); font-weight: 400; }
.pf-cat-header__metric       { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.pf-cat-header__metric-label { font-size: 10px; color: var(--text2); }
.pf-cat-header__metric-val   { font-size: 12px; font-weight: 600; white-space: nowrap; }
.pf-cat-header__summary { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.pf-cat-header__total   { font-size: 14px; font-weight: 700; white-space: nowrap; }
.pf-cat-header__gain    { font-size: 11px; font-weight: 600; white-space: nowrap; }

.pf-cat-body { overflow: hidden; transition: max-height .25s ease; }
.pf-cat-body.collapsed { max-height: 0 !important; }
.pf-cat-chevron { font-size: 9px; color: #b0b8c4; transition: transform .2s; margin-left: 8px; }
.pf-cat-header.collapsed .pf-cat-chevron { transform: rotate(-90deg); }
.pf-cat-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.pf-cat-table th, .pf-cat-table td { white-space: nowrap; }
.pf-cat-table th:first-child, .pf-cat-table td:first-child { max-width: 180px; overflow: hidden; }
.pf-cat-table th {
  text-align: right; padding: 8px 8px; /* was: 8px 16px */
  font-size: 11px; color: var(--text2);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.04em;
  user-select: none; white-space: nowrap;
}
.pf-cat-table th:hover { color: var(--text); }
.pf-cat-table th:first-child { text-align: left; }
.pf-cat-table th:nth-child(3), .pf-cat-table td:nth-child(3) { padding-right: 7px; }
.pf-cat-table th:nth-child(4), .pf-cat-table td:nth-child(4) { padding-right: 20px; }
.pf-cat-table td { padding: 11px 8px; /* was: 11px 16px */ border-bottom: 1px solid var(--border); font-size: 13px; text-align: right; }
.pf-cat-table td:first-child { text-align: left; }
.pf-cat-table tr:last-child td { border-bottom: none; }
.pf-cat-table tr:hover td { background: var(--hover); }
.pf-gain-sub  { font-size: 11px; margin-top: 2px; white-space: nowrap; }
.pf-name-main { font-size: 12px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-name-sub  { font-size: 11px; color: var(--text2); margin-top: 3px; display: flex; align-items: center; gap: 5px; overflow: hidden; }

/* ブローカーバッジ */
.pf-broker {
  display: inline-block; padding: 1px 7px; border-radius: 20px;
  font-size: 10px; font-weight: 700; white-space: nowrap;
}
.pf-broker--SBI      { background: #e0effe; color: var(--text2); }
.pf-broker--マネックス { background: #fefce8; color: var(--text2); }
.pf-broker--楽天      { background: #fee8e8; color: var(--text2); }
.pf-broker--bitFlyer  { background: #dcfce7; color: var(--text2); }

/* ── Gain/loss ── */
.pf-gain  { color: var(--gain); }
.pf-loss  { color: var(--loss); }
.pf-muted { color: var(--text2); }

/* ── Badge (kept for compat) ── */
.pf-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.pf-badge--国内株  { background: rgba(6,182,212,.15);  color: var(--c1); }
.pf-badge--外国株  { background: rgba(99,102,241,.15); color: var(--c2); }
.pf-badge--米国株  { background: rgba(99,102,241,.15); color: var(--c2); }
.pf-badge--投資信託{ background: rgba(192,132,252,.15);color: var(--c3); }
.pf-badge--仮想通貨{ background: rgba(245,158,11,.15); color: var(--c4); }


/* ── Responsive ── */
@media (max-width: 640px) {
  /* Header */
  .pf-header { padding: 10px 14px; flex-wrap: wrap; gap: 6px; }
  .pf-header__right { font-size: 11px; gap: 10px; }
  .pf-header__fx { display: none; }

  /* Main */
  .pf-main { padding: 6px 12px 12px; gap: 4px; }
  #portfolioContent { gap: 4px; }

  /* Hero */
  .pf-hero__total { font-size: 28px; }
  .pf-hero__total-row { gap: 16px; }
  .pf-hero__stats { gap: 28px; flex-wrap: wrap; }
  .pf-hero__stat-row { white-space: nowrap; }

  /* Rankings */
  .pf-rankings { grid-template-columns: 1fr; gap: 0; background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
  .pf-ranking-block { background: none; border-radius: 0; border: none; border-top: 1px solid var(--border); }
  .pf-ranking-block:first-child { border-top: none; }
  .pf-ranking__jpy { display: none; }
  .pf-ranking__pct { width: auto; }

  /* Allocation */
  .pf-allocation { flex-direction: column; align-items: flex-start; gap: 12px; }
  .pf-donut-wrap { align-self: center; }
  .pf-cat-legend { min-width: unset; width: 100%; }
  .pf-cat-legend li { gap: 8px; }
  .pf-cat-info { width: 70px; }
  .pf-cat-right { min-width: 94px; }
  .pf-cat-right span:first-child { font-size: 12px; }
  .pf-cat-right span:last-child  { font-size: 10px; }

  /* Holdings */
  .pf-cat-header { grid-template-columns: 1fr auto; }
  .pf-cat-header__metric { display: none; }
  .pf-cat-body { overflow-x: auto; scrollbar-width: none; }
  .pf-cat-body::-webkit-scrollbar { display: none; }
  .pf-cat-body.is-scrolling { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.25) transparent; }
  .pf-cat-body.is-scrolling::-webkit-scrollbar { display: block; height: 4px; }
  .pf-cat-body.is-scrolling::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.25); border-radius: 2px; }
  .pf-cat-table { min-width: unset; }
  .pf-cat-table th:first-child,
  .pf-cat-table td:first-child {
    position: sticky; left: 0; z-index: 1;
    background: var(--card); padding-left: 10px; padding-right: 6px;
  }
  .pf-cat-table tr:hover td:first-child { background: var(--hover); }
}

/* ── Market Tab ── */
.pf-owner__btn--market { margin-left: auto; }
.pf-owner__btn--market.pf-owner__btn--active { border-bottom-color: #eab308; color: var(--text); background: rgba(234,179,8,.10); }

#marketContent { display: flex; flex-direction: column; gap: 8px; }

.mkt-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.mkt-item {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; gap: 6px;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.mkt-item:hover { border-color: var(--border); }
.mkt-item--active { border-color: var(--border); }

.mkt-item__name {
  font-size: 11px; font-weight: 600;
  color: var(--text2); letter-spacing: 0.04em;
  text-transform: uppercase;
}
.mkt-item__price { font-size: 18px; font-weight: 700; color: var(--text); }
.mkt-item__price.mkt-skel { color: var(--border); }
.mkt-item__change { font-size: 11px; color: var(--text2); }
.mkt-up   { color: var(--gain); }
.mkt-down { color: var(--loss); }
.mkt-na   { color: var(--text2); }
.mkt-unit { font-size: 11px; color: var(--text2); font-weight: 500; margin-left: 2px; }

.mkt-chart-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px 12px;
}
.mkt-chart-meta {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 12px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.mkt-chart-name { font-size: 12px; font-weight: 600; color: var(--text2); letter-spacing: 0.04em; margin-bottom: 4px; }
.mkt-chart-price-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.mkt-chart-price { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.mkt-chart-chg { font-size: 13px; }

.mkt-periods { display: flex; gap: 4px; align-self: center; }
.mkt-period-btn {
  border: none; background: transparent;
  color: var(--text2); font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 7px; cursor: pointer;
  transition: all .15s;
}
.mkt-period-btn:hover:not(.mkt-period-btn--active) { color: var(--text); background: var(--hover); }
.mkt-period-btn--active { background: var(--cyan); color: #fff; }

@media (max-width: 700px) {
  .mkt-grid { grid-template-columns: repeat(2, 1fr); }
  .mkt-chart-price { font-size: 22px; }
}

