:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1f2430;
  --muted: #7a8290;
  --primary: #2f5fd6;
  --primary-dark: #24499f;
  --up: #1a8f4c;
  --down: #d0392c;
  --alert-bg: #fff6da;
  --alert-border: #f0c34a;
  --radius: 10px;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: hidden;
  width: 100%;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.page-header h1 { font-size: 19px; font-weight: 600; margin: 0; letter-spacing: 0.2px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-size: 12px; }

.refresh-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--up); display: inline-block;
  animation: pulse 2s infinite ease-in-out;
}
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

.icon-btn-outline {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.icon-btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.market-status[hidden] { display: none; }
.market-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
  white-space: nowrap;
}
.market-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}
.market-status.status-open { background: #e6f6ed; color: var(--up); }
.market-status.status-open::before { background: var(--up); }
.market-status.status-pre,
.market-status.status-post { background: #fff6da; color: #8a6a00; }
.market-status.status-pre::before,
.market-status.status-post::before { background: #d9a300; }
.market-status.status-closed,
.market-status.status-weekend,
.market-status.status-holiday { background: #f0f1f3; color: var(--muted); }
.market-status.status-closed::before,
.market-status.status-weekend::before,
.market-status.status-holiday::before { background: var(--muted); }

/* ---- 提醒设置面板 ---- */
.settings-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 16px;
  margin-bottom: 10px;
}
.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0; /* 允许grid/flex子项收缩到小于内容固有宽度，避免撑出容器 */
}
.settings-grid label.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text);
}
.settings-grid input[type="number"] {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  background: #fbfcfd;
  font-family: inherit;
  -moz-appearance: textfield;
}
.settings-grid input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}
/* 去掉原生上下调节箭头：视觉更干净，同时减少浏览器分配给输入框的固有最小宽度 */
.settings-grid input[type="number"]::-webkit-outer-spin-button,
.settings-grid input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.settings-actions { display: flex; align-items: center; gap: 10px; }
.settings-actions button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.settings-actions button:hover { background: var(--primary-dark); }
.settings-panel .hint { margin: 10px 0 0; font-size: 11.5px; color: var(--muted); }
.settings-panel code {
  background: #f0f1f3;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

/* ---- 总览卡片 ---- */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.card-label { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.card-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---- 工具栏（新建/添加） ---- */
.toolbar[hidden] { display: none; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.mini-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 100%;
}
.mini-form input, .mini-form select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12.5px;
  background: #fbfcfd;
  font-family: inherit;
  min-width: 0;
}
.mini-form input:focus, .mini-form select:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}
.mini-form input { width: 130px; max-width: 100%; flex: 1 1 110px; }
.mini-form select { width: 110px; max-width: 100%; flex: 0 1 100px; }
.mini-form button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}
.mini-form button:hover { background: var(--primary-dark); }


/* 代码输入框自动大写显示（实际值也会通过JS强制转为大写） */
.symbol-input { text-transform: uppercase; }
.symbol-input::placeholder { text-transform: none; }

/* ---- 主看板：左右分区 ---- */
.board { display: flex; flex-direction: column; gap: 20px; }
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.empty-hint { color: var(--muted); font-size: 12px; padding: 8px 2px; }

/* ---- 观察列表：横向排列的竖列卡片 ---- */
.watchlists-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.watchlist-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 300px;
  flex: 1 1 260px;
  overflow: hidden;
  cursor: grab;
}
.watchlist-card.dragging { opacity: 0.4; }

.card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.drag-handle { color: var(--muted); font-size: 12px; cursor: grab; user-select: none; }
.card-title { font-weight: 600; font-size: 13px; flex: 1; }
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.icon-btn:hover { color: var(--down); background: #fdecea; }

.watchlist-list { padding: 4px 0; }
.watchlist-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid #f0f1f3;
  font-variant-numeric: tabular-nums;
}
.watchlist-row:last-child { border-bottom: none; }
.watchlist-row.is-alert {
  background: var(--alert-bg);
  border-left: 3px solid var(--alert-border);
  font-weight: 700;
}
.wl-symbol { font-weight: 600; width: 44px; flex-shrink: 0; }
.wl-price { width: 58px; text-align: right; flex-shrink: 0; }
.wl-change-group {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
}
.wl-change-amt { font-size: 10.5px; white-space: nowrap; }
.wl-change-pct { font-size: 12px; white-space: nowrap; flex-shrink: 0; }
.wl-time { color: var(--muted); font-size: 10px; width: 32px; text-align: right; flex-shrink: 0; }
.wl-gear {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 12px; padding: 0 1px; flex-shrink: 0; line-height: 1;
}
.wl-gear:hover { color: var(--primary); }
.wl-gear.has-threshold { color: var(--primary); }
.wl-remove {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 0 0 0 2px; flex-shrink: 0;
}
.wl-remove:hover { color: var(--down); }
.watchlist-empty { padding: 10px; color: var(--muted); font-size: 12px; }
.alert-badge {
  display: inline-block;
  text-transform: uppercase;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #92660a;
  background: #fdecc8;
  border: 1px solid var(--alert-border);
  border-radius: 4px;
  padding: 1px 4px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ---- 持仓组合：紧凑表格卡片，纵向堆叠 ---- */
.portfolios-col { display: flex; flex-direction: column; gap: 12px; }
.portfolio-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.portfolio-card.dragging { opacity: 0.4; }

.portfolio-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  cursor: grab;
}
.portfolio-summary {
  margin-left: auto;
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.portfolio-summary b { color: var(--text); font-weight: 700; }
.portfolio-summary b.up { color: var(--up); }
.portfolio-summary b.down { color: var(--down); }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: #fcfcfd;
  white-space: nowrap;
}
th.al, td.symbol-cell { text-align: left; }
th.ac, td.ac { text-align: center; }
th.ar, td.ar { text-align: right; }

tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.is-alert td { background: var(--alert-bg); font-weight: 700; }
tbody tr.is-alert td.symbol-cell { border-left: 3px solid var(--alert-border); }
.symbol-cell { font-weight: 600; letter-spacing: 0.3px; }

.row-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.del-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  width: 22px;
  height: 22px;
  line-height: 1;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.del-btn:hover { color: var(--down); border-color: var(--down); }

.cell-input {
  width: 76px;
  text-align: right;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-family: inherit;
  -webkit-user-drag: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.cell-input:hover { border-color: var(--border); background: #fbfcfd; }
.cell-input:focus { outline: none; border-color: var(--primary); background: #fff; }
.cell-input.up { color: var(--up); font-weight: 600; }
.cell-input.down { color: var(--down); font-weight: 600; }
.cell-input::-webkit-outer-spin-button,
.cell-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell-input[type="number"] { -moz-appearance: textfield; }

.portfolio-empty { padding: 14px; text-align: center; color: var(--muted); font-size: 12px; }

.pf-gear {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 0 3px; line-height: 1;
  vertical-align: middle;
}
.pf-gear:hover { color: var(--primary); }
.pf-gear.has-threshold { color: var(--primary); }

/* ---- 弹窗：按代码设置提醒阈值 ---- */
.modal-overlay[hidden] {
  display: none;
}
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 18, 26, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  overscroll-behavior: contain;
}
.modal {
  background: var(--panel);
  border-radius: 12px;
  padding: 18px 20px;
  width: 340px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
.modal h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; }
.modal .settings-grid { grid-template-columns: repeat(2, 1fr); margin-bottom: 8px; }
.modal .hint { margin: 6px 0 12px; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.modal-actions button {
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.modal-actions #ssm-save { background: var(--primary); color: #fff; }
.modal-actions #ssm-save:hover { background: var(--primary-dark); }
.modal-actions .btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.modal-actions .btn-ghost:hover { border-color: var(--muted); }

/* 防止表单控件被当作卡片拖拽触发 */
input, select, button { -webkit-user-drag: none; }

@media (min-width: 980px) {
  .board { display: block; }
  .board::after { content: ""; display: table; clear: both; }
  .watchlists-section {
    float: right;
    width: 300px;
    margin-left: 18px;
    margin-bottom: 18px;
  }
  .watchlists-row { flex-direction: column; }
  .watchlist-card { width: 100%; flex: none; }
  /* 建立新的块格式化上下文：内容高度未超过观察列表时自动避让在其左侧，
     超出观察列表高度的部分则自动占满整行宽度，无需手动判断高度 */
  .portfolios-section { overflow: hidden; }
}

@media (max-width: 720px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .portfolio-card { overflow-x: auto; }
  .watchlists-row { justify-content: center; }
}

@media (max-width: 400px) {
  .summary-cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .modal { width: 100%; padding: 16px; }
  .modal .settings-grid { grid-template-columns: 1fr; }
  .watchlist-card { max-width: 100%; }
}
