:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  /* Convention: gain/positive = green, loss/negative = red */
  --gain: #1f9254;
  --loss: #d6322f;
  --warn: #b45309;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 22px; }
.brand h1 { font-size: 17px; font-weight: 600; margin: 0; }
.brand-link { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 8px; }

/* Tab bar */
.tabs {
  display: flex; gap: 4px; padding: 0 20px; margin: 0 auto; max-width: 1180px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 57px; z-index: 9; flex-wrap: wrap;
}
.tab {
  appearance: none; background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  padding: 12px 16px; border-bottom: 2px solid transparent; transition: .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: 6px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.select-wrap { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
select, input {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; outline: none;
}
select:focus, input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* Buttons */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.icon-btn { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); }

/* Layout */
.container { max-width: 1180px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 20px; }

/* Summary cards — 7-up at desktop, 4-up at tablet, 2-up at mobile */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 14px;
}
.summary-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.summary-card .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.summary-card .value { font-size: 20px; font-weight: 700; letter-spacing: .2px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); font-size: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; }

/* Semantic colors — positive = green, negative = red */
.pos { color: var(--gain); font-weight: 600; }
.neg { color: var(--loss); font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.BUY { background: #e0edff; color: #1d4ed8; }
.badge.SELL { background: #fef3c7; color: var(--warn); }
.badge.DIVIDEND { background: #dcfce7; color: #15803d; }
.badge.reco-BUY { background: #dcfce7; color: var(--gain); }
.badge.reco-HOLD { background: #eef2f7; color: var(--muted); }
.badge.reco-SELL { background: #fde8e8; color: var(--loss); }
.badge.reco-WATCH { background: #fef3c7; color: var(--warn); }

/* Monthly-review action buttons (5 buckets) */
.reco-action-btn {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: .15s;
  font-family: inherit;
  letter-spacing: .02em;
}
.reco-action-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.reco-action-btn[data-action="加倉"]      { background: #2563eb; color: #fff; }
.reco-action-btn[data-action="维持不变"]  { background: #e2e8f0; color: #1e293b; }
.reco-action-btn[data-action="减倉"]      { background: #f59e0b; color: #fff; }
.reco-action-btn[data-action="清倉"]      { background: #dc2626; color: #fff; }
.reco-action-btn[data-action="其他"]      { background: transparent; color: var(--muted); border-color: var(--border); }

/* Summary modal — wider (760px), capped at viewport height, scrolls internally
   so tall content never pushes the title off the top of the screen. */
.reco-modal {
  max-width: 760px;
  width: 100%;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}
.reco-modal-body {
  padding: 18px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;          /* scroll inside when content is tall */
  flex: 1 1 auto;
  min-height: 0;             /* lets the flex child actually shrink & scroll */
  -webkit-overflow-scrolling: touch;
}
.reco-row { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.reco-label { color: var(--muted); min-width: 64px; font-size: 12px; }
.action-badge { display: inline-block; padding: 4px 10px; border-radius: 6px; font-weight: 600; font-size: 12px; }
.action-badge[data-action="加倉"]      { background: #2563eb; color: #fff; }
.action-badge[data-action="维持不变"]  { background: #e2e8f0; color: #1e293b; }
.action-badge[data-action="减倉"]      { background: #f59e0b; color: #fff; }
.action-badge[data-action="清倉"]      { background: #dc2626; color: #fff; }
.action-badge[data-action="其他"]      { background: transparent; color: var(--muted); border: 1px solid var(--border); }

/* 2x2 metadata card — ticker / action / month / style in one block,
   reclaims vertical space that the old one-row-per-line layout wasted. */
.reco-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
  padding: 14px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.reco-meta-grid .reco-row { font-size: 13.5px; }
/* On narrow screens, fall back to single-column to avoid label/value collisions. */
@media (max-width: 520px) {
  .reco-meta-grid { grid-template-columns: 1fr; }
}

.reco-summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  line-height: 1.7;
  font-size: 14px;
  white-space: pre-wrap;
  color: var(--text);
}

/* Price-target blocks (ADD: entry/target/stop / REDUCE-EXIT: exit/window) */
.reco-targets {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
}
.reco-targets .reco-target-row { display: grid; grid-template-columns: 96px 1fr auto; gap: 12px; align-items: center; }
.reco-targets .reco-num { font-variant-numeric: tabular-nums; font-weight: 600; }
.reco-targets .reco-num.gain { color: var(--gain); }
.reco-targets .reco-num.loss { color: var(--loss); }
.reco-targets .reco-meta { color: var(--muted); font-size: 12px; }

/* Drivers / risks — bullet lists inside the recommendation modal */
.reco-bullets {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}
.reco-bullets-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.reco-bullets ul { margin: 0; padding-left: 20px; line-height: 1.65; font-size: 13.5px; }
.reco-bullets .drivers-list li::marker { color: var(--gain); }
.reco-bullets .risks-list   li::marker { color: var(--loss); }

/* Import-recommendations modal */
.import-modal { max-width: 640px; }
.import-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.import-body p.muted { margin: 0; }
.import-body code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid var(--border);
}
#importTextarea {
  width: 100%;
  min-height: 200px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  resize: vertical;
  padding: 10px 12px;
}
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  background: var(--surface-2);
  transition: .15s;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.04);
}
.drop-zone p { margin: 0; color: var(--muted); font-size: 13px; }
.drop-zone a { color: var(--primary); text-decoration: none; font-weight: 600; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.import-result {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.import-result.success { border-color: var(--gain); background: rgba(31, 146, 84, 0.08); color: var(--text); }
.import-result.error   { border-color: var(--loss); background: rgba(214, 50, 47, 0.08); color: var(--text); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal.hidden, .hidden { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 480px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); z-index: 60;
}

@media (max-width: 880px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}
