/* ===== 基础 ===== */
:root {
  --red: #e63946;
  --red-dark: #c1121f;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2430;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --line: #e5e7eb;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
  --accent: var(--red);
  --accent-grad: linear-gradient(135deg, #ff5f6d, #e63946);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1680px;
  margin: 0 auto;
}

/* ===== 顶部栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 800;
  box-shadow: 0 4px 10px rgba(230, 57, 70, 0.35);
}

.brand-text h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.brand-text p { font-size: 12px; color: var(--text-2); }

.tabs {
  display: flex;
  background: #eef0f3;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  flex: 1;
  max-width: 420px;
}

.tab {
  flex: 1;
  padding: 9px 18px;
  border: none;
  background: transparent;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.tab.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.source-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: #eef0f3;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
}

.source-badge .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #f59e0b;
}
.source-badge.live .dot { background: #22c55e; }
.source-badge.mock .dot { background: #f59e0b; }
.source-badge.err  .dot { background: #ef4444; }

.lock-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.lock-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, #fff);
}

/* ===== 主布局 ===== */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 13fr) minmax(0, 7fr);
  gap: 16px;
  padding: 16px 20px;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 20px 14px;
  gap: 12px;
}

.panel-header h2 { font-size: 17px; font-weight: 700; }
.panel-header .subtitle { font-size: 12px; color: var(--text-2); margin-top: 3px; }

/* ===== 按钮 ===== */
.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 9px;
  font-size: 13px; font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.ghost-btn:hover { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, white); }

.primary-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 26px;
  border: none;
  border-radius: 12px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 15px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform 0.1s, box-shadow 0.15s;
  font-family: inherit;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 45%, transparent); }
.primary-btn:active { transform: translateY(0); }

.copy-btn {
  margin-left: auto;
  padding: 8px 16px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 9px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.copy-btn:hover { background: color-mix(in srgb, var(--accent) 10%, white); }

/* ===== 走势图（号码分布走势） ===== */
.trend-scroll {
  flex: 1;
  overflow: auto;
  padding: 0 12px 16px;
}

.trend-table-wrap {
  position: relative;
  display: inline-block;
  min-width: fit-content;
}

.trend-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  table-layout: fixed;
}

.trend-table th,
.trend-table td {
  width: 16px;
  min-width: 16px;
  max-width: 16px;
  padding: 3px 0;
  text-align: center;
  border-right: 1px solid #f0f1f3;
  border-bottom: 1px solid #f0f1f3;
  white-space: nowrap;
}

.trend-table th:last-child,
.trend-table td:last-child { border-right: none; }

/* 表头 */
.trend-table thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  font-weight: 600;
  font-size: 11px;
  color: #fff;
  padding: 6px 2px;
}

.trend-table .issue-head {
  width: 52px;
  min-width: 52px;
  background: #f7f8fa;
  color: var(--text);
  border-bottom: 1px solid var(--line);
  z-index: 5;
  left: 0;
  font-size: 11px;
}

.trend-table .red-group {
  background: linear-gradient(180deg, #ff8a95, #e63946);
  border-bottom: 1px solid #c1121f;
}

.trend-table .blue-group {
  background: linear-gradient(180deg, #60a5fa, #2563eb);
  border-bottom: 1px solid #1d4ed8;
}

.trend-table .num-head {
  position: sticky;
  background: #f7f8fa;
  color: var(--text-2);
  top: 27px;
  font-size: 9px;
  z-index: 3;
}

/* 期号列 */
.trend-table td:first-child {
  position: sticky;
  left: 0;
  width: 52px;
  min-width: 52px;
  background: #fff;
  z-index: 3;
  text-align: left;
  padding-left: 6px;
  font-weight: 600;
  font-size: 10px;
  color: var(--text-2);
}

.trend-table tbody tr:hover td { background: #fff8f8; }
.trend-table tbody tr:hover td:first-child { background: #fff; }

/* 球 */
.ball {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 14px; height: 14px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 8px;
  line-height: 1;
  font-family: "SF Mono", ui-monospace, monospace;
  box-shadow: inset 0 -1px 2px rgba(0,0,0,0.25), 0 1px 1px rgba(0,0,0,0.15);
  text-shadow: 0 1px 1px rgba(0,0,0,0.3);
}

.ball.red  { background: radial-gradient(circle at 32% 28%, #ff7b66, #e63946 60%, #b3131f); }
.ball.blue { background: radial-gradient(circle at 32% 28%, #60a5fa, #2563eb 60%, #173a8a); }

/* 命中格与遗漏格 */
.hit-cell { padding: 2px 0; position: relative; z-index: 2; }
.omit-cell {
  color: #b0b5be;
  font-size: 8px;
  line-height: 1;
  font-family: "SF Mono", ui-monospace, monospace;
}
.omit-cell.cold {
  color: #f59e0b;
  font-weight: 600;
  background: #fffbeb;
}
.omit-cell.very-cold {
  color: #ef4444;
  font-weight: 700;
  background: #fef2f2;
}
.omit-cell.blue-omit.cold {
  color: #3b82f6;
  background: #eff6ff;
}
.omit-cell.blue-omit.very-cold {
  color: #1d4ed8;
  background: #dbeafe;
}

/* 列高亮 */
.trend-table tbody td:hover { background: #fff1f2; }
.trend-table tbody td:first-child:hover { background: #fff; }

/* 统计行 */
.stats-row td { border-top: 2px solid var(--line); }
.stats-row .stats-label {
  background: #f7f8fa;
  color: var(--text-2);
  font-size: 9px;
}
.stats-cell {
  color: var(--text-2);
  font-size: 9px;
  font-weight: 600;
  background: #fafbfc;
}
.stats-count .stats-cell { color: var(--accent); }
.stats-max .stats-cell { color: #f59e0b; }
.stats-current .stats-cell { color: #10b981; }

/* 连线 SVG */
.trend-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ===== 生成器 ===== */
.generator-panel { overflow-y: auto; }

.config { padding: 0 20px; }

.field { margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 13px; font-weight: 600;
  color: var(--text-2);
  margin-bottom: 8px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}

.mode-chip {
  padding: 9px 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  text-align: center;
}
.mode-chip:hover { border-color: var(--accent); color: var(--accent); }
.mode-chip.active {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 35%, transparent);
}

.mode-desc {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-2);
  background: #f7f8fa;
  border-radius: 10px;
  padding: 9px 12px;
  line-height: 1.5;
}

.field input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.field input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }

.hint-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--text-2);
  background: #f7f8fa;
  border-radius: 10px;
  padding: 10px 12px;
  line-height: 1.5;
}
.hint-row svg { flex-shrink: 0; }

.divider { height: 1px; background: var(--line); margin: 6px 0 16px; }

.field-row {
  display: flex; gap: 40px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.stepper {
  display: inline-flex; align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
}

.step-btn {
  width: 34px; height: 36px;
  border: none;
  background: transparent;
  font-size: 17px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s;
  font-family: inherit;
}
.step-btn:hover { background: color-mix(in srgb, var(--accent) 10%, white); color: var(--accent); }

.step-value {
  min-width: 64px;
  text-align: center;
  font-size: 14px; font-weight: 600;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0 10px;
  line-height: 36px;
}

.actions {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* ===== 结果卡片 ===== */
.results {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  color: var(--text-3);
  padding: 48px 0;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
}
.empty-state svg { opacity: 0.5; }
.empty-state p { font-size: 14px; }

.result-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: #fbfbfc;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-top {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.result-index { font-size: 13px; font-weight: 700; color: var(--text-2); }

.tag {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.tag-mode { background: color-mix(in srgb, var(--accent) 12%, white); color: var(--accent); }
.tag-mult {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff7ed;
  color: #ea580c;
}
.tag-mult svg { width: 12px; height: 12px; }

.result-balls {
  display: flex; flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.result-balls .ball { width: 40px; height: 40px; font-size: 16px; }

.ball-sep { align-self: center; color: var(--text-3); font-size: 16px; padding: 0 4px; }

.result-note {
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
}

.result-note .prob {
  display: flex; align-items: center; gap: 5px;
  margin-bottom: 4px;
  font-weight: 600;
}
.result-note .prob .num { color: var(--accent); font-family: "SF Mono", ui-monospace, monospace; font-weight: 700; }
.result-note .basis { color: var(--text-2); }

/* ===== 底部 ===== */
.footer {
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: var(--text-3);
  border-top: 1px solid var(--line);
  background: var(--panel);
}

/* ===== 登录页 ===== */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 44px 48px;
  width: 380px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
  text-align: center;
  animation: fadeUp 0.4s ease;
}
.login-logo .brand-icon {
  width: 64px; height: 64px;
  font-size: 30px;
  border-radius: 16px;
  margin: 0 auto 16px;
}
.login-logo h2 { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.login-logo p { font-size: 13px; color: var(--text-2); margin-bottom: 26px; }
.login-input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  text-align: center;
  letter-spacing: 4px;
  outline: none;
  margin-bottom: 14px;
  transition: border-color 0.15s;
  font-family: inherit;
}
.login-input:focus { border-color: #764ba2; box-shadow: 0 0 0 3px rgba(118, 75, 162, 0.15); }
.login-btn { width: 100%; justify-content: center; }
.login-error { color: #ef4444; font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ===== 右侧列布局 ===== */
.right-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overflow: hidden;
}
.generator-panel { flex: 1 1 55%; min-height: 0; }
.side-panel { flex: 1 1 45%; min-height: 0; overflow-y: auto; }

/* ===== 备选记录 ===== */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}
.selected-list {
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}
.selected-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 24px 0;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
}
.selected-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fbfbfc;
}
.selected-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  background: #f7f8fa;
  user-select: none;
}
.selected-group-head:hover { background: #eef0f3; }
.selected-group-head .issue {
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
}
.selected-group-head .info {
  font-size: 11px;
  color: var(--text-2);
  flex: 1;
}
.selected-group-head .arrow {
  width: 16px; height: 16px;
  color: var(--text-3);
  transition: transform 0.2s;
}
.selected-group-head .arrow.open { transform: rotate(90deg); }
.selected-group-head .pill-current {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.selected-group-body {
  display: none;
  padding: 10px 12px;
  flex-direction: column;
  gap: 8px;
}
.selected-group.open .selected-group-body { display: flex; }
.selected-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #fff;
  border: 1px solid #f0f1f3;
  border-radius: 9px;
  flex-wrap: wrap;
}
.selected-note .balls {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  flex: 1;
}
.selected-note .ball {
  width: 20px; height: 20px;
  font-size: 9px;
}
.selected-note .sep { color: var(--text-3); font-size: 11px; }
.selected-note .del {
  width: 22px; height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}
.selected-note .del:hover { background: #fee2e2; color: #ef4444; }

/* 手动添加 */
.manual-add {
  display: flex;
  gap: 8px;
  padding: 12px 20px 4px;
}
.manual-input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
  outline: none;
  font-family: "SF Mono", ui-monospace, monospace;
  transition: border-color 0.15s;
}
.manual-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.primary-btn.small { padding: 9px 18px; font-size: 13px; }

/* ===== 备忘录 ===== */
.memo-panel { display: flex; flex-direction: column; }
.memo-text {
  flex: 1;
  min-height: 160px;
  margin: 0 20px 20px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.7;
  font-family: inherit;
  resize: vertical;
  outline: none;
  background: #fbfbfc;
  transition: border-color 0.15s;
}
.memo-text:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.save-hint {
  font-size: 11px;
  color: #10b981;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s;
}
.save-hint.show { opacity: 1; }
.save-hint.offline { color: #f59e0b; }

/* 添加到备选按钮 */
.add-selected-btn {
  margin-left: auto;
  padding: 5px 12px;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, white);
  color: var(--accent);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.add-selected-btn:hover {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
}

/* 轻提示 */
.toast-box {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(31, 36, 48, 0.92);
  color: #fff;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast-box.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 响应式 ===== */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    overflow: auto;
  }
  .app { height: auto; min-height: 100vh; }
  .trend-scroll { max-height: 480px; }
  .generator-panel, .side-panel { flex: none; }
  .side-panel { overflow: visible; }
}

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .tabs { max-width: none; }
  .layout { padding: 12px; }
}
