/* 三国冰河时代·富甲天下 —— 冰河蓝 + 坊市金主题 */
:root {
  --bg: #eaf1f7;
  --card: #ffffff;
  --line: #d5e0ea;
  --text: #1a2a3a;
  --muted: #6b7f94;
  --primary: #1a6fb5;
  --primary-d: #145a96;
  --primary-soft: #e7f1fa;
  --primary-line: #c5daf0;
  --accent: #c9a227;
  --accent-d: #a8861a;
  --accent-soft: #fbf6e6;
  --danger: #e5484d;
  --success: #2f9e44;
  --shadow: 0 2px 12px rgba(15, 42, 68, 0.08);
  --topbar-grad: linear-gradient(100deg, #0f2a44 0%, #1a5a8a 55%, #2b7ab3 100%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(120, 180, 220, 0.18), transparent 60%),
    radial-gradient(900px 320px at 90% 0%, rgba(201, 162, 39, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 24px;
  background: var(--topbar-grad);
  color: #fff;
  box-shadow: 0 2px 14px rgba(15, 42, 68, 0.28);
  border-bottom: 2px solid rgba(201, 162, 39, 0.45);
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: 0.5px; }
.topbar .sub { font-size: 13px; opacity: 0.88; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.nav-link {
  color: #fff; text-decoration: none; font-size: 13px; opacity: .95;
  border: 1px solid rgba(255,255,255,.45); padding: 6px 12px; border-radius: 8px;
  background: rgba(255,255,255,.08);
}
.nav-link:hover { background: rgba(255,255,255,.18); border-color: rgba(201,162,39,.6); }
.nav-user { font-size: 13px; opacity: .95; }
.nav-btn {
  border: 0; background: rgba(255,255,255,.16); color: #fff;
  font-size: 13px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.35);
}
.nav-btn:hover { background: rgba(255,255,255,.3); }

/* 顶栏用户菜单（统一：改密 / 退出） */
.user-menu-wrap { position: relative; }
.nav-user-btn {
  border: 1px solid rgba(255,255,255,.5); background: rgba(255,255,255,.12);
  color: #fff; font-size: 13px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.nav-user-btn:hover { background: rgba(255,255,255,.3); }
.user-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px;
  background: #fff; color: #2f3a56; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; z-index: 50;
}
.user-menu .um-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-bottom: 1px solid #f0f2f7; margin-bottom: 4px;
  font-size: 13px; font-weight: 600;
}
.um-badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: #e7f1fa; color: #1a6fb5; }
.um-item {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 9px 10px; border-radius: 7px; font-size: 13px; cursor: pointer; color: #2f3a56;
}
.um-item:hover { background: #f0f7fc; }
.um-item.danger { color: #e5484d; }
.um-item.danger:hover { background: #fff0f1; }

/* 修改密码弹窗 */
.modal {
  position: fixed; inset: 0; background: rgba(18,24,38,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal[hidden] { display: none; }
.modal .modal-box {
  background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal .modal-box h3 { margin: 0 0 16px; font-size: 17px; }
.modal .field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.modal .field label { font-size: 12px; color: var(--muted); }
.modal .field .input { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  padding: 18px 24px;
  align-items: start;
}
.col-left, .col-right { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
/* 未登录：右侧「数据管理」隐藏，左栏独占整行 */
.layout.no-side { grid-template-columns: 1fr; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }

/* 后台：左侧纵向菜单 + 右侧分页面板 */
.admin-shell {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  padding: 16px 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-nav { flex-direction: row; flex-wrap: wrap; position: static; }
  .admin-nav-item { flex: 1 1 auto; text-align: center; }
}
.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  box-shadow: var(--shadow);
}
.admin-nav-item {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.admin-nav-item:hover { background: var(--primary-soft); }
.admin-nav-item.active {
  background: linear-gradient(180deg, #1a6fb5, #145a96);
  color: #fff;
  font-weight: 600;
}
.admin-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.admin-panel[hidden] { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 14px;
  font-size: 16px;
  color: #143a5c;
  letter-spacing: 0.3px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
/* 自动刷新控件：与图表标签同一行、靠右显示 */
.refresh-ctl { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg-btn {
  border: 0; background: #fff; padding: 7px 14px; cursor: pointer;
  font-size: 13px; color: var(--muted);
}
.seg-btn.active {
  background: linear-gradient(180deg, #1a6fb5, #145a96);
  color: #fff;
}

.select, .input {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; color: var(--text); background: #fff;
}
.select:focus, .input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(26,111,181,.12); }
.select { min-width: 130px; }
.select.region { min-width: 130px; width: auto; }
/* 查价格「按州府」合并控件：输入框约 6 个汉字宽 */
#pqRegionInput { width: 7.8em; min-width: 0; box-sizing: border-box; }
/* 自定义下拉菜单：宽度约 3 个汉字宽（独立于输入框宽度） */
.pq-combo { position: relative; display: inline-block; }
.pq-combo-menu {
  position: absolute; z-index: 60; left: 0; top: calc(100% + 4px);
  width: 4.8em; min-width: 0; margin: 0; padding: 4px 0; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 220px; overflow-y: auto;
  box-sizing: border-box;
}
.pq-combo-menu li {
  padding: 6px 10px; font-size: 13px; color: var(--text); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pq-combo-menu li:hover, .pq-combo-menu li.active { background: rgba(26,111,181,.10); }
/* 数据管理区「州府」搜索下拉：宽度与原 <select> 一致（表单内 50%），输入框占满组合框 */
#inRegionCombo, #sellInRegionCombo { display: block; width: 50%; box-sizing: border-box; }
#inRegion, #sellInRegion { width: 100%; box-sizing: border-box; }
/* 传闻「州府」搜索下拉：沿用原 .sell-region 宽度（72px） */
.rumor-region-combo { display: inline-block; }
.rumor-region-combo .sell-region { width: 72px; box-sizing: border-box; }
/* 文本识别「州府」搜索下拉：沿用原 .ocr-region 最小宽度（110px） */
.ocr-region-combo { display: inline-block; }
.ocr-region-combo .ocr-region { width: 110px; box-sizing: border-box; }

/* 文本识别面板 */
.ocr-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.ocr-bar label { font-size: 12px; color: var(--muted); }
.ocr-text { width: 100%; min-height: 170px; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; font-family: inherit; line-height: 1.6; resize: vertical; }
.ocr-text:focus { outline: none; border-color: var(--primary); }
.ocr-preview { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.ocr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 8px 10px; border: 1px solid #e4edf5; border-radius: 8px; background: #f6fafc; }
.ocr-row .ocr-idx { font-size: 12px; color: #8a93a6; min-width: 18px; }
.ocr-cell { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.ocr-cell > .select, .ocr-cell > .prod-price { font-size: 13px; }
.ocr-preview .ocr-region, .ocr-preview .ocr-commodity { min-width: 110px; }
.ocr-preview .ocr-dir { min-width: 64px; }
.ocr-preview .ocr-price { width: 90px; }
.ocr-empty-hint { color: #8a93a6; font-size: 13px; padding: 6px 2px; }

/* 页面底部版权信息 */
/* 页脚贴底：作为 body 弹性列的最后一个流内元素，内容不足时自动被推至视口底部 */
#footerMount { margin-top: auto; }
.site-footer {
  margin-top: 24px; padding: 16px 8px;
  border-top: 1px solid var(--line);
  text-align: center; font-size: 12px; color: var(--muted); line-height: 1.8;
  background: linear-gradient(180deg, transparent, rgba(15,42,68,.04));
}
.site-footer .footer-sep { margin: 0 8px; color: #c4c9d4; }

.btn {
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  font-size: 13px; font-weight: 600;
}
.btn.primary {
  background: linear-gradient(180deg, #1a6fb5, #145a96);
  color: #fff;
  box-shadow: 0 1px 3px rgba(20,90,150,.25);
}
.btn.primary:hover { background: linear-gradient(180deg, #1763a3, #114e85); }
.btn.ghost { background: var(--primary-soft); color: var(--primary); border: 1px solid var(--primary-line); }
.btn.ghost:hover { background: #d9e9f7; }

.chart { width: 100%; height: 420px; }
.min-prices { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 2px 8px; }
.min-chip {
  background: var(--accent-soft); color: #3d4a5c; border: 1px solid #e8d9a8;
  border-radius: 999px; padding: 4px 12px; font-size: 12px;
}
.min-chip b { color: var(--accent-d); margin-left: 2px; font-weight: 700; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 2px 0; }

.add-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 14px;
  background: #f6fafc;
  border: 1px dashed var(--line);
  border-radius: 10px;
  margin-bottom: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; overflow-wrap: anywhere; }
.field label { font-size: 12px; color: var(--muted); }
/* 窄屏下表单改单列，避免录入框挤压/重叠 */
@media (max-width: 900px) { .add-form { grid-template-columns: 1fr; } }
.field input {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 13px;
}
.add-form .btn.primary { grid-column: 1 / -1; justify-self: start; }
/* 委托表单：录入框宽度缩短为原来的一半；数值右对齐 */
.add-form .field .input, .add-form .field .select { width: 50%; box-sizing: border-box; }
.add-form .field input[type="number"] { text-align: right; }
/* 委托地：可搜索筛选提示的下拉（宽度与输入框保持一致） */
#cConsignPlaceCombo { width: 50%; display: block; box-sizing: border-box; }
#cConsignPlace { width: 100%; box-sizing: border-box; }
#cConsignPlaceMenu { width: 100%; min-width: 6.5em; }
/* 委托标题栏 */
.consign-title { font-size: 14px; font-weight: 600; color: #3d5570; margin-right: 4px; }
/* 今日委托：州府搜索框（格式同「价格查询」的州府搜索，输入宽 7.8em、菜单 4.8em） */
#consignSearchCombo { flex: 0 0 auto; }
#consignSearchInput { width: 7.8em; min-width: 0; box-sizing: border-box; flex: 0 0 auto; }
/* 委托列表：合理安排各列宽度；压缩内边距与字号，让表格尽量不超出外层卡片 */
#consignTable { table-layout: fixed; min-width: 620px; font-size: 12px; }
#consignTable thead th { padding: 8px 6px; font-size: 12px; }
#consignTable tbody td { padding: 7px 6px; }
#consignTable th { white-space: nowrap; }
#consignTable td { word-break: break-word; vertical-align: middle; }
#consignTable th:nth-child(1) { width: 8%; }   /* 委托地 */
#consignTable th:nth-child(2) { width: 8%; }   /* 目的地 */
#consignTable th:nth-child(3) { width: 9%; }   /* 物品 */
#consignTable th:nth-child(4) { width: 6%; }   /* 数量 */
#consignTable th:nth-child(5) { width: 13%; }  /* 实际收益（单倍 / 双倍 两行） */
#consignTable th:nth-child(6) { width: 13%; }  /* 采购地（每行一个地区 + 价格） */
#consignTable th:nth-child(7) { width: 10%; }  /* 参考价 */
#consignTable th:nth-child(8) { width: 10%; }  /* 成本 */
#consignTable th:nth-child(9) { width: 23%; }  /* 操作 */
/* 表头与内容上下对齐：数值列表头同样右对齐，操作列左对齐 */
#consignTable th:nth-child(4), #consignTable th:nth-child(5),
#consignTable th:nth-child(7), #consignTable th:nth-child(8) { text-align: right; }
#consignTable th:nth-child(9) { text-align: left; }
/* 数值列右对齐；仅「数量」禁止换行，其余金额列允许换行以防溢出重叠 */
#consignTable td.num, #consignTable th.num { text-align: right; }
#consignTable td:nth-child(4) { white-space: nowrap; }
#consignTable td.money { font-variant-numeric: tabular-nums; white-space: normal; }
/* 委托表单：采购地推荐 chips */
.c-suggest { font-size: 12px; color: #5a6477; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.c-chip {
  display: inline-block; padding: 2px 9px; border: 1px solid var(--line, #e6e9f0);
  border-radius: 999px; background: #f5f7fb; color: #1a6fb5; cursor: pointer; user-select: none;
  font-size: 12px; transition: background .15s, border-color .15s;
}
.c-chip:hover { background: #e7f0fa; border-color: #1a6fb5; }
.c-chip.selected { background: #1a6fb5; border-color: #1a6fb5; color: #fff; }
.c-chip.selected .c-price { color: #d6e9ff; }
.c-price { font-weight: 600; margin-left: 2px; }
.c-hint { color: #5a6477; }
/* 委托表单：是否双倍 勾选标签 */
.field label.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.field label.chk input { width: auto; }
/* 列表：委托金额单元格（金额 + 是否双倍）；空间不足时换行但不重叠 */
.dbl-flag { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-left: 6px; font-size: 12px; font-weight: 400; color: #5a6477; vertical-align: middle; }
.dbl-flag input { width: auto; vertical-align: middle; flex: none; }
/* 委托列表：实际收益按「单倍 / 双倍」两行展示 */
.pl { display: block; font-size: 12px; line-height: 1.5; color: #5a6477; white-space: normal; }
.muted { color: #7a869a; font-size: 12px; margin-top: 2px; }

.table-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.table-tools .input { flex: 1; }
.count { font-size: 12px; color: var(--muted); white-space: nowrap; }
/* 查价格结果提示：允许自动换行（不限制单行） */
#pqCount { white-space: normal; line-height: 1.6; }

.table-wrap {
  max-height: 360px; overflow: auto;
  border: 1px solid var(--line); border-radius: 10px;
  overscroll-behavior-x: contain;
  scrollbar-width: thin; scrollbar-color: #b9c7d8 #eef3f7;
}
/* 横向宽度不够时出现横向滚动条（可拖动查看），而非列内容重叠 */
.table-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.table-wrap::-webkit-scrollbar-track { background: #eef3f7; border-radius: 999px; }
.table-wrap::-webkit-scrollbar-thumb { background: #b9c7d8; border-radius: 999px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: #93a7bf; }
.table-wrap::-webkit-scrollbar-corner { background: #eef3f7; }
/* 今日委托列表：不固定高度，随内容自动撑开（由整页滚动），不再局限在固定长度内滚动 */
#consignPanel .table-wrap { max-height: none; }
/* 查价格「按商品」模式的结果表：不限制纵向高度，纵向不出现拖动条（随整页滚动；仅在横向内容溢出时才横向滚动） */
#pqTableWrap { max-height: none; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
/* 其余表格的最小宽度：容器不足时横向滚动，避免列内容重叠（尽量不超出外层卡片） */
#pqTable { min-width: 320px; }
.pq-sub { min-width: 260px; }
/* 查价格结果：更新时间列（月-日 时:分，单行显示） */
.pq-time { white-space: nowrap; color: #7a869a; font-size: 12px; font-variant-numeric: tabular-nums; }
#recTable, #mineRecTable { min-width: 360px; }
/* 查价格「按州府」分组：分组内表格独立横向滚动 */
.pq-group { overflow-x: auto; scrollbar-width: thin; scrollbar-color: #b9c7d8 #eef3f7; }
.pq-group::-webkit-scrollbar { width: 10px; height: 10px; }
.pq-group::-webkit-scrollbar-track { background: #eef3f7; border-radius: 999px; }
.pq-group::-webkit-scrollbar-thumb { background: #b9c7d8; border-radius: 999px; }
.pq-group::-webkit-scrollbar-thumb:hover { background: #93a7bf; }
thead th {
  position: sticky; top: 0;
  background: linear-gradient(180deg, #e8f0f7, #eef5fa);
  text-align: left;
  padding: 10px 12px; font-weight: 600; color: #3d5570;
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 9px 12px; border-bottom: 1px solid #eef3f7; }
tbody tr:hover { background: #f4f9fd; }
.del { color: var(--danger); cursor: pointer; border: 0; background: none; font-size: 13px; }

.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: #0f2a44; color: #fff; padding: 12px 22px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s;
  z-index: 99;
  border: 1px solid rgba(201,162,39,.35);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); border-color: transparent; }

/* 自定义日期时间选择器（替代原生 datetime-local 弹层，分钟精度） */
.dtp-trigger { cursor: pointer; }
.dtp-popup {
  z-index: 1100; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 34px rgba(15, 42, 68, .20); padding: 10px; width: 256px;
  font-size: 13px; color: var(--text);
}
.dtp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.dtp-title { font-weight: 600; }
.dtp-nav { border: 1px solid #e6e9f0; background: #f6f8fc; border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 15px; line-height: 1; color: var(--text); }
.dtp-nav:hover { background: #eef2f8; }
.dtp-week, .dtp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dtp-week span { text-align: center; font-size: 11px; color: #8a93a6; padding: 2px 0; }
.dtp-cell { border: 0; background: #fff; border-radius: 6px; padding: 6px 0; cursor: pointer; font-size: 13px; color: var(--text); }
.dtp-cell:hover { background: #eef2f8; }
.dtp-cell.empty { visibility: hidden; cursor: default; }
.dtp-cell.sel { background: var(--primary); color: #fff; font-weight: 700; }
.dtp-time { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; }
.dtp-time-label { font-size: 12px; color: var(--muted); }
.dtp-time-input { border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; font-size: 13px; }
.dtp-foot { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.dtp-btn { border: 1px solid #d8dee9; background: #fff; border-radius: 6px; padding: 5px 12px; font-size: 13px; cursor: pointer; color: #3a4256; }
.dtp-btn:hover { background: #eef2f8; }
.dtp-btn.dtp-ok { background: var(--primary); color: #fff; border-color: var(--primary-d); }
.dtp-btn.dtp-ok:hover { background: var(--primary-d); }

/* 查价格「按州府」：差价<0 的亏损州府折叠区 */
.pq-loss { margin-top: 8px; }
.pq-loss > summary { cursor: pointer; color: #c2410c; font-size: 13px; font-weight: 600; padding: 4px 2px; user-select: none; }
.pq-loss > summary:hover { text-decoration: underline; }
.pq-loss .pq-sub { margin-top: 6px; }
