/* ============ 全局 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", sans-serif;
  background: #f5f6fa;
  color: #2c3e50;
  font-size: 14px;
}

/* ============ 布局 ============ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: #2c3e50;
  color: #ecf0f1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}
.brand { padding: 20px 18px; border-bottom: 1px solid #34495e; }
.brand h1 { font-size: 18px; font-weight: 600; }
.brand .subtitle { font-size: 11px; color: #95a5a6; margin-top: 4px; }

.nav { flex: 1; padding: 12px 0; }
.nav a {
  display: block;
  padding: 11px 22px;
  color: #bdc3c7;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav a:hover { background: #34495e; color: #fff; }
.nav a.active {
  background: #34495e;
  color: #fff;
  border-left-color: #3498db;
}

.sidebar-footer { padding: 12px 18px; border-top: 1px solid #34495e; }
.btn-refresh {
  width: 100%;
  padding: 8px;
  background: #34495e;
  color: #ecf0f1;
  border: 1px solid #465a72;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 10px;
}
.btn-refresh:hover { background: #465a72; }
.status { font-size: 11px; color: #95a5a6; line-height: 1.6; }
.status code { color: #bdc3c7; }

.main {
  flex: 1;
  margin-left: 240px;
  padding: 24px 32px;
  min-width: 0;
}

/* ============ 页面标题 ============ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e0e6ed;
}
.page-header h2 { font-size: 22px; color: #2c3e50; }
.page-meta { font-size: 12px; color: #7f8c8d; }

/* ============ 通用卡片 ============ */
.card {
  background: #fff;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid #e8ecef;
}
.card h3 {
  font-size: 15px;
  color: #34495e;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ecf0f1;
}

/* ============ KPI 卡片网格 ============ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi {
  background: #fff;
  border-radius: 8px;
  padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border-left: 4px solid #3498db;
}
.kpi.success { border-left-color: #27ae60; }
.kpi.warning { border-left-color: #f39c12; }
.kpi.danger  { border-left-color: #e74c3c; }
.kpi .label { font-size: 12px; color: #7f8c8d; margin-bottom: 6px; }
.kpi .value { font-size: 22px; font-weight: 600; color: #2c3e50; }
.kpi .delta { font-size: 12px; margin-top: 4px; }
.kpi .delta.up { color: #27ae60; }
.kpi .delta.down { color: #e74c3c; }

/* ============ 紧凑统计网格（区间统计用） ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
.stat-item {
  background: #fff;
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  border-left: 3px solid #3498db;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 64px;
}
.stat-item.success { border-left-color: #27ae60; }
.stat-item.danger  { border-left-color: #e74c3c; }
.stat-item.warning { border-left-color: #f39c12; }
.stat-item .stat-label {
  font-size: 11px;
  color: #7f8c8d;
  margin-bottom: 3px;
  letter-spacing: 0.3px;
}
.stat-item .stat-value {
  font-size: 17px;
  font-weight: 600;
  color: #2c3e50;
  line-height: 1.2;
}
.stat-item .stat-sub {
  font-size: 11px;
  color: #95a5a6;
  margin-top: 2px;
}
.stat-item .stat-value.text-success { color: #27ae60; }
.stat-item .stat-value.text-danger  { color: #e74c3c; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #fff;
}
th, td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid #ecf0f1;
  white-space: nowrap;
}
th {
  background: #f8f9fb;
  color: #34495e;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
tbody tr:hover { background: #f8f9fb; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.pos { color: #27ae60; }
td.neg { color: #e74c3c; }

/* ============ 状态徽章 ============ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.badge.high   { background: #fdecea; color: #e74c3c; }
.badge.medium { background: #fef5e7; color: #f39c12; }
.badge.low    { background: #eafaf1; color: #27ae60; }
.badge.extreme { background: #fadbd8; color: #c0392b; }

/* ============ Plotly 图表容器 ============ */
.chart {
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.chart-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 1100px) { .chart-grid-2 { grid-template-columns: 1fr; } }

/* ============ Flash 消息 ============ */
.flash-container { margin-bottom: 16px; }
.flash {
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 8px;
  font-size: 13px;
}
.flash-success { background: #eafaf1; color: #27ae60; border: 1px solid #abebc6; }
.flash-error   { background: #fdecea; color: #e74c3c; border: 1px solid #f5b7b1; }

/* ============ 空状态 / 提示 ============ */
.empty {
  padding: 40px;
  text-align: center;
  color: #7f8c8d;
  background: #fff;
  border-radius: 8px;
}
.alert {
  padding: 12px 16px;
  border-radius: 4px;
  margin-bottom: 14px;
  font-size: 13px;
}
.alert-info  { background: #e8f4fd; color: #2980b9; border: 1px solid #aed6f1; }
.alert-warn  { background: #fef5e7; color: #d68910; border: 1px solid #f8d7a3; }
.alert-danger{ background: #fdecea; color: #c0392b; border: 1px solid #f5b7b1; }
.alert-success{ background: #eafaf1; color: #229954; border: 1px solid #abebc6; }

/* ============ 表单 ============ */
.form-inline {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.form-inline label { font-size: 13px; color: #34495e; }
.form-inline input, .form-inline select {
  padding: 6px 10px;
  border: 1px solid #d5dbdb;
  border-radius: 4px;
  font-size: 13px;
}
.form-inline button {
  padding: 7px 16px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.form-inline button:hover { background: #2980b9; }

/* ============ 工具类 ============ */
.text-right { text-align: right; }
.muted { color: #7f8c8d; }
.mono { font-family: "Consolas", monospace; }

/* ============ 持仓管理：表单 ============ */
.btn-add {
  display: inline-block;
  padding: 8px 18px;
  background: #27ae60;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
}
.btn-add:hover { background: #229954; }

.btn-action {
  display: inline-block;
  padding: 4px 10px;
  background: #ecf0f1;
  color: #2c3e50;
  text-decoration: none;
  border-radius: 3px;
  font-size: 12px;
  margin-right: 4px;
  border: 1px solid #d5dbdb;
  cursor: pointer;
}
.btn-action:hover { background: #d5dbdb; }
.btn-action.btn-delete { color: #e74c3c; }
.btn-action.btn-delete:hover { background: #fdecea; }

.form-section {
  border: 1px solid #e8ecef;
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 18px;
  background: #fafbfc;
}
.form-section legend {
  font-size: 14px;
  font-weight: 600;
  color: #34495e;
  padding: 0 8px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px 20px;
}
.form-field {
  display: flex;
  flex-direction: column;
}
.form-field label {
  font-size: 12px;
  color: #34495e;
  margin-bottom: 5px;
  font-weight: 500;
}
.form-field input, .form-field select {
  padding: 7px 10px;
  border: 1px solid #d5dbdb;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
}
.form-field input:focus, .form-field select:focus {
  border-color: #3498db;
  outline: none;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}
.form-field input[readonly] {
  background: #f4f6f7;
  color: #7f8c8d;
}
.form-field small {
  font-size: 11px;
  color: #95a5a6;
  margin-top: 4px;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #34495e;
  padding-top: 28px;
}
.checkbox-label input[type=checkbox] {
  width: 16px;
  height: 16px;
}
.preview-box {
  background: #fff;
  border: 1px dashed #bdc3c7;
  border-radius: 4px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.8;
}
.preview-box span {
  font-weight: 600;
  color: #2c3e50;
}
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.btn-primary {
  padding: 10px 28px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary:hover { background: #2980b9; }
.btn-cancel {
  padding: 10px 24px;
  background: #ecf0f1;
  color: #2c3e50;
  text-decoration: none;
  border-radius: 4px;
  font-size: 14px;
  border: 1px solid #d5dbdb;
  display: inline-block;
}
.btn-cancel:hover { background: #d5dbdb; }

/* ============ 敲出票息分段表 ============ */
.schedule-table {
  width: 100%;
  font-size: 13px;
  margin-top: 8px;
}
.schedule-table th, .schedule-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #ecf0f1;
}
.schedule-table input {
  padding: 5px 8px;
  border: 1px solid #d5dbdb;
  border-radius: 3px;
  font-size: 13px;
}

/* ============ 过滤栏（历史回溯/标的价格页） ============ */
.filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-bar label { font-size: 13px; color: #34495e; }
.filter-bar input, .filter-bar select {
  padding: 6px 10px;
  border: 1px solid #d5dbdb;
  border-radius: 4px;
  font-size: 13px;
}
.filter-bar button {
  padding: 7px 16px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.filter-bar button:hover { background: #2980b9; }

/* ============ 移动端：汉堡菜单按钮 & 遮罩 ============ */
.menu-toggle {
  display: none;
  background: #2c3e50;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 16px;
  cursor: pointer;
  margin-bottom: 10px;
  line-height: 1;
}
.menu-toggle:hover { background: #34495e; }
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
}

/* ============ 移动端适配 ============ */
@media (max-width: 768px) {
  /* 显示汉堡按钮 */
  .menu-toggle { display: inline-block; }

  /* 侧边栏：默认隐藏，滑入显示 */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1000;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }

  /* 主内容：全宽，缩小内边距 */
  .main {
    margin-left: 0;
    padding: 14px 14px;
  }

  /* 页面标题：允许换行 */
  .page-header {
    flex-wrap: wrap;
    gap: 6px;
  }
  .page-header h2 { font-size: 18px; }

  /* KPI 网格：两列 */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 18px; }

  /* 区间统计网格：两列 */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* 表单行内布局：纵向堆叠 */
  .form-inline {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .form-inline label,
  .form-inline input,
  .form-inline select,
  .form-inline button { width: 100%; }
  .form-inline button { padding: 9px 16px; }

  /* 过滤栏：纵向堆叠 */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar label,
  .filter-bar input,
  .filter-bar select,
  .filter-bar button { width: 100%; }

  /* 表单网格：单列 */
  .form-grid { grid-template-columns: 1fr; }

  /* 表格：横向滚动 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { padding: 7px 8px; font-size: 12px; }

  /* 卡片：缩小内边距 */
  .card { padding: 12px 14px; }

  /* 表单操作按钮：堆叠 */
  .form-actions { flex-direction: column; }
  .form-actions .btn-primary,
  .form-actions .btn-cancel {
    width: 100%;
    text-align: center;
  }

  /* 复选框标签：取消顶部留白 */
  .checkbox-label { padding-top: 6px; }
}

@media (max-width: 480px) {
  /* 极小屏：KPI/统计单列 */
  .kpi-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .main { padding: 10px 10px; }
  .page-header h2 { font-size: 16px; }
}
