:root {
  --bg: #F4F3EF;
  --surface: #FFFFFF;
  --navy: #1B2F44;
  --navy-light: #EFF2F6;
  --navy-muted: #4A647A;
  --bronze: #BC7840;
  --bronze-light: #F4EAE0;
  --positive: #1A8A6B;
  --positive-bg: #E6F4EF;
  --negative: #C44D4D;
  --negative-bg: #FBF0F0;
  --neutral: #8A8A8A;
  --border: #E3E0D7;
  --text: #1A1A1A;
  --text-secondary: #5E5E5E;
  --text-muted: #949494;
  --tag-bg: #EDEAE3;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 8px;
  --radius-sm: 6px;
}

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

html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1020px; margin: 0 auto; padding: 0 20px; }

/* ===== Header ===== */
.header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 28px 0 0; }
.header-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { font-family: 'Playfair Display', serif; font-weight: 700; font-size: 1.7rem; color: var(--navy); letter-spacing: -0.01em; line-height: 1.1; }
.brand small { display: block; font-family: 'Inter', sans-serif; font-weight: 400; font-size: 0.72rem; color: var(--text-muted); letter-spacing: 0.03em; text-transform: uppercase; margin-top: 2px; }
.header-meta { text-align: right; font-size: 0.78rem; color: var(--text-muted); }
.header-meta .date { font-weight: 500; color: var(--text-secondary); }

/* ===== Navigation tabs ===== */
.tabs { display: flex; gap: 0; margin-top: 20px; border-bottom: 1px solid var(--border); }
.tab-btn { padding: 10px 20px; font-size: 0.82rem; font-weight: 500; color: var(--text-secondary); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; transition: all 0.15s; font-family: inherit; position: relative; bottom: -1px; }
.tab-btn:hover { color: var(--navy); }
.tab-btn.active { color: var(--navy); border-bottom-color: var(--bronze); font-weight: 600; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 640px; }
.responsive-grid { display: grid; gap: 14px; }
.responsive-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.responsive-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.compact-gap { gap: 10px; }

/* ===== Portfolio Summary ===== */
.portfolio-summary { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 28px; margin: 24px 0; box-shadow: var(--shadow-sm); }
.portfolio-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.portfolio-title { font-family: 'Playfair Display', serif; font-weight: 700; font-size: 1.3rem; color: var(--navy); }
.portfolio-title .badge { display: inline-block; font-family: 'Inter', sans-serif; font-size: 0.65rem; font-weight: 600; background: var(--navy); color: #fff; padding: 2px 10px; border-radius: 12px; vertical-align: middle; margin-left: 8px; letter-spacing: 0.03em; }
.portfolio-total { text-align: right; }
.portfolio-total .amount { font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: 1.45rem; color: var(--navy); }
.portfolio-total .label { font-size: 0.72rem; color: var(--text-muted); }

.allocation-bar { display: flex; height: 32px; border-radius: 6px; overflow: hidden; margin-bottom: 16px; }
.allocation-bar .seg { display: flex; align-items: center; justify-content: center; font-size: 0.62rem; font-weight: 600; color: #fff; letter-spacing: 0.02em; transition: flex 0.3s; min-width: 0; overflow: hidden; white-space: nowrap; }
.allocation-bar .seg.s1 { background: #1B2F44; }
.allocation-bar .seg.s2 { background: #2C4A68; }
.allocation-bar .seg.s3 { background: #4A6B8A; }
.allocation-bar .seg.s4 { background: #BC7840; }
.allocation-bar .seg.s5 { background: #D4935C; }

.allocation-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.allocation-table th { text-align: left; font-weight: 500; color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; padding-bottom: 6px; }
.allocation-table td { padding: 5px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
.allocation-table tr:last-child td { border-bottom: none; }
.allocation-table .name-cell { font-weight: 600; color: var(--navy); }
.allocation-table .code-cell { font-family: 'JetBrains Mono', monospace; font-size: 0.72rem; color: var(--text-muted); }
.allocation-table .amt-cell { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.allocation-table .tag-cell .atag { font-size: 0.62rem; padding: 1px 6px; border-radius: 3px; font-weight: 500; }
.atag.etf { background: var(--navy-light); color: var(--navy); }
.atag.stock { background: var(--bronze-light); color: var(--bronze); }
.atag.def { background: var(--positive-bg); color: var(--positive); }

/* ===== Tab content ===== */
.tab-content { display: none; padding: 4px 0 20px; }
.tab-content.active { display: block; }
.section-title { font-family: 'Playfair Display', serif; font-weight: 700; font-size: 1.2rem; color: var(--navy); margin: 24px 0 14px; }
.section-sub { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 16px; }

/* ===== Cards ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; box-shadow: var(--shadow-sm); overflow: hidden; transition: border-color 0.15s, box-shadow 0.15s; }
.card:hover { border-color: #CCC8BE; box-shadow: var(--shadow-md); }
.card-main { padding: 18px 22px; display: grid; grid-template-columns: 1fr auto; gap: 16px; cursor: pointer; }
.card-main.expanded { padding-bottom: 10px; }
.card-left { min-width: 0; }

.card-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.c-name { font-family: 'Playfair Display', serif; font-weight: 700; font-size: 1.1rem; color: var(--navy); }
.c-code { font-family: 'JetBrains Mono', monospace; font-size: 0.72rem; color: var(--text-muted); background: var(--tag-bg); padding: 1px 7px; border-radius: 4px; }
.c-type-badge { font-size: 0.6rem; font-weight: 600; padding: 1px 8px; border-radius: 8px; letter-spacing: 0.03em; }
.c-type-badge.etf { background: var(--navy-light); color: var(--navy); }
.c-type-badge.stock { background: var(--bronze-light); color: var(--bronze); }

.c-price { font-family: 'JetBrains Mono', monospace; font-weight: 500; font-size: 1.05rem; color: var(--text); margin: 4px 0 6px; }
.c-price .currency { font-size: 0.72rem; color: var(--text-muted); font-weight: 400; }
.c-price .unit { font-size: 0.65rem; color: var(--text-muted); font-weight: 400; }

.c-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.c-tag { font-size: 0.66rem; font-weight: 500; padding: 1px 7px; border-radius: 3px; background: var(--tag-bg); color: #555; }
.c-tag.safe { background: var(--positive-bg); color: var(--positive); }
.c-tag.hot { background: var(--bronze-light); color: var(--bronze); }
.c-analysis { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.55; max-width: 520px; }

/* Scores */
.c-scores { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 80px; padding-left: 14px; border-left: 1px solid var(--border); }
.score-row { display: flex; flex-direction: column; align-items: center; }
.score-circle { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: 0.95rem; color: #fff; }
.score-circle.high { background: var(--positive); }
.score-circle.mid { background: var(--bronze); }
.score-circle.low { background: var(--negative); }
.score-circle.safe-bg { background: var(--navy); }
.score-label { font-size: 0.6rem; color: var(--text-muted); margin-top: 3px; font-weight: 500; letter-spacing: 0.02em; white-space: nowrap; }

/* Detail panel */
.card-detail { display: none; border-top: 1px solid var(--border); padding: 18px 22px; background: #FAF9F6; }
.card-detail.open { display: block; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.detail-section h4 { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }

/* Grid visual */
.grid-visual { margin: 8px 0; }
.gv-bar { position: relative; height: 36px; background: var(--tag-bg); border-radius: 4px; overflow: hidden; }
.gv-buy { position: absolute; top: 0; left: 0; height: 100%; background: linear-gradient(90deg, var(--negative-bg), var(--positive-bg)); opacity: 0.6; }
.gv-sell { position: absolute; top: 0; height: 100%; background: linear-gradient(90deg, var(--positive-bg), #E0EDE6); opacity: 0.6; }
.gv-current { position: absolute; top: 0; height: 100%; width: 2px; background: var(--navy); z-index: 2; }
.gv-labels { display: flex; justify-content: space-between; font-size: 0.64rem; font-family: 'JetBrains Mono', monospace; color: var(--text-secondary); margin-top: 2px; }

.grid-levels { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; }
.gl { font-size: 0.62rem; padding: 1px 5px; border-radius: 3px; font-family: 'JetBrains Mono', monospace; white-space: nowrap; }
.gl.buy { background: var(--negative-bg); color: var(--negative); }
.gl.sell { background: var(--positive-bg); color: var(--positive); }
.gl.now { background: var(--navy); color: #fff; font-weight: 600; }

.param-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.param-table th { text-align: left; font-weight: 500; color: var(--text-secondary); padding: 3px 8px 3px 0; width: 52%; }
.param-table td { font-family: 'JetBrains Mono', monospace; font-weight: 500; padding: 3px 0; color: var(--text); }
.param-table tr + tr { border-top: 1px solid var(--border); }

.tip-text { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.55; }
.checklist-item { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.82rem; color: var(--text-secondary); line-height: 1.8; }
.checklist-item input[type="checkbox"] { accent-color: var(--navy); width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }
.strategy-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); transition: border-color 0.15s; }
.strategy-card:hover { border-color: #CCC8BE; }
.strategy-card .sc-body { padding: 18px 20px; }
.strategy-ul { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.7; padding-left: 16px; }

/* Expand indicator */
.expand-indicator { text-align: center; padding: 6px 0 0; font-size: 0.7rem; color: var(--text-muted); font-weight: 500; cursor: pointer; user-select: none; }
.expand-indicator:hover { color: var(--navy); }
.expand-indicator .arrow { display: inline-block; transition: transform 0.2s; }
.expand-indicator .arrow.open { transform: rotate(180deg); }

/* Risk */
.risk-banner { background: var(--bronze-light); border: 1px solid #E4D3C2; border-radius: var(--radius); padding: 16px 20px; margin: 20px 0; font-size: 0.76rem; color: var(--text-secondary); line-height: 1.5; }
.risk-banner strong { color: var(--bronze); font-weight: 600; }
.footer { text-align: center; padding: 24px 0 32px; font-size: 0.7rem; color: var(--text-muted); border-top: 1px solid var(--border); }

/* Responsive */
@media (max-width: 720px) {
  html { font-size: 14px; }
  .container { padding: 0 14px; }
  .header { padding-top: 18px; }
  .brand { font-size: 1.35rem; }
  .tabs { overflow-x: auto; overflow-y: hidden; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .tab-btn { flex: 0 0 auto; padding: 10px 14px; font-size: 0.76rem; }
  .portfolio-summary { padding: 18px 16px; }
  .allocation-bar { height: 28px; }
  .allocation-bar .seg { font-size: 0.56rem; }
  .responsive-grid-2,
  .responsive-grid-3 { grid-template-columns: 1fr; }
  .card-main { grid-template-columns: 1fr; }
  .c-scores { border-left: none; border-top: 1px solid var(--border); padding-left: 0; padding-top: 10px; flex-direction: row; gap: 16px; min-width: 0; }
  .score-row { flex-direction: row; gap: 6px; }
  .score-label { margin-top: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .allocation-table { font-size: 0.72rem; }
  .header-top { flex-direction: column; align-items: flex-start; }
  .header-meta { text-align: left; }
  .section-title { font-size: 1.05rem; }
  .card-main,
  .card-detail { padding-left: 16px; padding-right: 16px; }
  .risk-banner { padding: 14px 16px; }
}

@media (max-width: 1024px) {
  .responsive-grid-3 { grid-template-columns: 1fr; }
}

@media (min-width: 721px) and (max-width: 1024px) {
  .container { padding: 0 18px; }
  .responsive-grid-2,
  .responsive-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .portfolio-summary { padding: 22px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
