/* ============================================================
   广点通数据拉取工作台
   设计语言沿用「巨量素材库工作台」那套 Apple 体系令牌
   ============================================================ */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --panel-thin: rgba(255, 255, 255, 0.62);
  --line: rgba(0, 0, 0, 0.055);
  --line-strong: rgba(0, 0, 0, 0.10);
  --inner-light: rgba(255, 255, 255, 0.92);

  --text: #1d1d1f;
  --text-2: #424245;
  --sub: #6e6e73;
  --sub-2: #a1a1a6;

  --brand: #0071e3;
  --brand-dark: #0062c4;
  --brand-soft: rgba(0, 113, 227, 0.09);

  --ok: #1d9d55;
  --warn: #d98300;
  --bad: #e0322f;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;

  --shadow: 0 0.5px 1px rgba(0, 0, 0, 0.035), 0 4px 20px rgba(0, 0, 0, 0.055);
  --shadow-hover: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 34px rgba(0, 0, 0, 0.085);
  --glass-blur: blur(24px) saturate(180%);

  --seg-track: rgba(118, 118, 128, 0.12);
  --seg-active: #ffffff;
  --seg-shadow: 0 1px 2px rgba(0, 0, 0, 0.10), 0 0 0 0.5px rgba(0, 0, 0, 0.06);

  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --row-h: 44px;
  --num: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0d;
  --panel: rgba(30, 30, 34, 0.66);
  --panel-solid: #1c1c1f;
  --panel-thin: rgba(40, 40, 46, 0.5);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --inner-light: rgba(255, 255, 255, 0.10);
  --text: #f5f5f7;
  --text-2: #d2d2d7;
  --sub: #98989d;
  --sub-2: #6e6e73;
  --brand: #0a84ff;
  --brand-dark: #64a9ff;
  --brand-soft: rgba(10, 132, 255, 0.16);
  --shadow: 0 0.5px 1px rgba(0, 0, 0, 0.5), 0 8px 32px rgba(0, 0, 0, 0.42);
  --shadow-hover: 0 1px 2px rgba(0, 0, 0, 0.5), 0 16px 44px rgba(0, 0, 0, 0.55);
  --seg-track: rgba(255, 255, 255, 0.09);
  --seg-active: rgba(255, 255, 255, 0.17);
  --seg-shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 0 0 0.5px rgba(255, 255, 255, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(1100px 620px at 8% -12%, rgba(0, 113, 227, 0.07), transparent 62%),
    radial-gradient(900px 520px at 96% 4%, rgba(120, 90, 255, 0.055), transparent 60%),
    radial-gradient(760px 480px at 62% 108%, rgba(0, 190, 160, 0.045), transparent 62%);
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ================= 侧栏 ================= */
.sidebar {
  width: 252px;
  flex: 0 0 252px;
  display: flex;
  flex-direction: column;
  padding: 16px 12px 10px;
  background: var(--panel);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 14px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, #2f9bff, #0071e3 62%, #0059b3);
  color: #fff; font-size: 15px; font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 113, 227, 0.34), inset 0 0.5px 0 rgba(255, 255, 255, 0.5);
  letter-spacing: -0.5px;
}
.brand-text { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.brand-text strong { font-size: 13.5px; font-weight: 600; letter-spacing: -0.2px; }
.brand-text span { font-size: 10.5px; color: var(--sub-2); letter-spacing: 0.24px; }

.acct-card {
  margin: 0 4px 14px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-thin);
  border: 1px solid var(--line);
  box-shadow: inset 0 0.5px 0 var(--inner-light);
}
.acct-row { display: flex; align-items: center; gap: 7px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--sub-2); flex: 0 0 6px; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(29, 157, 85, 0.14); }
.dot.off { background: var(--bad); box-shadow: 0 0 0 3px rgba(224, 50, 47, 0.13); }
.acct-name { font-size: 12.5px; font-weight: 550; letter-spacing: -0.1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-meta { margin-top: 7px; font-size: 11px; color: var(--sub); line-height: 1.65; }
.acct-meta b { color: var(--text-2); font-weight: 550; font-variant-numeric: tabular-nums; }

.side-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 7px;
  font-size: 11px; font-weight: 550; color: var(--sub-2); letter-spacing: 0.3px;
}
.org-list { flex: 1; overflow-y: auto; padding: 0 2px; }
.org-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 9px; margin-bottom: 2px;
  border-radius: 7px; font-size: 12px; color: var(--text-2);
  cursor: default;
  transition: background 0.16s var(--ease);
}
.org-item:hover { background: var(--brand-soft); }
.org-item .org-idx {
  font-family: var(--num); font-size: 9.5px; color: var(--sub-2);
  min-width: 14px;
}
.org-item .org-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-foot { padding: 8px 4px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 5px; }
.side-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 9px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--text-2);
  font-family: inherit; font-size: 12px; text-align: left; cursor: pointer;
  transition: background 0.16s var(--ease);
}
.side-btn:hover { background: var(--brand-soft); color: var(--brand); }
.side-btn .ic { width: 14px; text-align: center; opacity: 0.65; font-size: 12px; }
.side-ver { padding: 5px 9px 2px; font-size: 10px; color: var(--sub-2); font-family: var(--num); letter-spacing: 0.2px; }

/* ================= 主区 ================= */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 52px; padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}
.view-tabs { display: flex; gap: 2px; }
.view-tabs button {
  padding: 6px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--sub);
  font-family: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: all 0.16s var(--ease);
}
.view-tabs button:hover { color: var(--text); background: var(--seg-track); }
.view-tabs button.active {
  color: var(--text); font-weight: 600;
  background: var(--panel-solid);
  box-shadow: var(--seg-shadow);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.seg {
  display: inline-flex; padding: 2px; gap: 2px;
  border-radius: 9px; background: var(--seg-track);
}
.seg button {
  padding: 4.5px 11px; border: 0; border-radius: 7px;
  background: transparent; color: var(--sub);
  font-family: inherit; font-size: 12px; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: all 0.16s var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button.active {
  background: var(--seg-active); color: var(--text);
  font-weight: 600; box-shadow: var(--seg-shadow);
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px; border: 0; border-radius: 8px;
  background: var(--brand); color: #fff;
  font-family: inherit; font-size: 12.5px; font-weight: 550;
  cursor: pointer; transition: all 0.16s var(--ease);
  box-shadow: 0 1px 2px rgba(0, 113, 227, 0.24);
}
.btn:hover { background: var(--brand-dark); transform: translateY(-0.5px); }
.btn:active { transform: none; }
.btn.ghost {
  background: var(--seg-track); color: var(--text-2);
  box-shadow: none;
}
.btn.ghost:hover { background: var(--line-strong); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }

/* ================= 工具条 ================= */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tb-group { display: flex; align-items: center; gap: 7px; }
.tb-sep { width: 1px; height: 18px; background: var(--line-strong); margin: 0 2px; }

input[type="date"], input[type="text"], select {
  padding: 5.5px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--text);
  font-family: inherit; font-size: 12.5px;
  outline: none;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
input[type="date"] { font-family: var(--num); font-size: 12px; }
input:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
select { cursor: pointer; padding-right: 26px; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6' viewBox='0 0 9 6'%3E%3Cpath d='M1 1l3.5 3.5L8 1' stroke='%236e6e73' stroke-width='1.3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
html[data-theme="dark"] select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6' viewBox='0 0 9 6'%3E%3Cpath d='M1 1l3.5 3.5L8 1' stroke='%2398989d' stroke-width='1.3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); }

.search-wrap { position: relative; }
.search-wrap input { padding-left: 27px; width: 196px; }
.search-wrap::before {
  content: "⌕"; position: absolute; left: 9px; top: 50%; transform: translateY(-52%);
  font-size: 13px; color: var(--sub-2); pointer-events: none;
}

/* ================= 汇总卡 ================= */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 9px;
  padding: 14px 18px 4px;
}
.sum-card {
  padding: 10px 12px 11px;
  border-radius: var(--radius-sm);
  background: var(--panel-thin);
  border: 1px solid var(--line);
  box-shadow: inset 0 0.5px 0 var(--inner-light);
  transition: all 0.18s var(--ease);
}
.sum-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.sum-label { font-size: 10.5px; color: var(--sub); letter-spacing: 0.2px; }
.sum-value {
  margin-top: 4px;
  font-family: var(--num); font-size: 17px; font-weight: 600;
  letter-spacing: -0.4px; font-variant-numeric: tabular-nums;
  color: var(--text);
}
.sum-card.primary .sum-value { color: var(--brand); }

/* ================= 表格 ================= */
.table-wrap {
  flex: 1; min-height: 0;
  margin: 12px 18px 0;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  overflow: auto;
  position: relative;
}
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; z-index: 3;
  padding: 9px 10px;
  text-align: left; white-space: nowrap;
  font-size: 11px; font-weight: 600; color: var(--sub);
  letter-spacing: 0.2px;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--line-strong);
  cursor: pointer; user-select: none;
}
thead th:hover { color: var(--text); background: var(--seg-track); }
thead th .arrow { opacity: 0; font-size: 9px; margin-left: 3px; transition: opacity 0.15s var(--ease); }
thead th:hover .arrow { opacity: 0.45; }
thead th.sorted .arrow { opacity: 1; color: var(--brand); }
tbody td {
  padding: 0 10px; height: var(--row-h);
  border-bottom: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 260px;
  color: var(--text-2);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--brand-soft); }
td.num, th.num { text-align: right; font-family: var(--num); font-variant-numeric: tabular-nums; }
td.strong { color: var(--text); font-weight: 550; }
td.mono { font-family: var(--num); font-size: 11.5px; }
.th-sticky, .td-sticky {
  position: sticky; left: 0; z-index: 2;
  background: var(--panel-solid);
  box-shadow: 1px 0 0 var(--line);
}
thead th.th-sticky { z-index: 4; }
tbody tr:hover .td-sticky { background: #eef5fe; }
html[data-theme="dark"] tbody tr:hover .td-sticky { background: #1b2733; }
td .sub-cell { display: block; font-size: 10.5px; color: var(--sub-2); font-family: var(--num); }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 60px 20px; color: var(--sub); text-align: center;
}
.empty .big { font-size: 26px; opacity: 0.5; }
.empty h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-2); }
.empty p { margin: 0; font-size: 12px; max-width: 420px; line-height: 1.7; }

/* ================= 底栏 ================= */
.footbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 18px 11px;
  font-size: 11px; color: var(--sub-2);
}
.footbar .grow { margin-left: auto; }
.pager { display: flex; align-items: center; gap: 4px; }
.pager button {
  min-width: 26px; height: 26px; padding: 0 7px;
  border: 1px solid var(--line-strong); border-radius: 7px;
  background: var(--panel-solid); color: var(--text-2);
  font-family: var(--num); font-size: 11.5px; cursor: pointer;
}
.pager button:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.pager button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager button:disabled { opacity: 0.36; cursor: default; }

/* ================= 视图 ================= */
.view { display: none; flex-direction: column; min-height: 0; flex: 1; overflow: hidden; }
.view.active { display: flex; }

/* 字段字典 */
.dict-toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 18px 4px; }
.dict-meta { font-size: 11.5px; color: var(--sub); }
.dict-table td.cat { color: var(--sub-2); font-size: 11px; }
.dict-table td.name { font-family: var(--num); font-size: 11.5px; color: var(--brand); }
.dict-table td.unit { font-family: var(--num); font-size: 11px; color: var(--sub); }
.chip {
  display: inline-block; padding: 1.5px 7px; border-radius: 20px;
  font-size: 10.5px; background: var(--brand-soft); color: var(--brand);
  font-family: var(--num);
}

/* 原始返回 */
.raw-wrap { flex: 1; min-height: 0; margin: 12px 18px 0; display: flex; flex-direction: column; }
.raw-head { display: flex; align-items: center; gap: 10px; padding-bottom: 9px; }
.raw-head .hint { font-size: 11.5px; color: var(--sub); }
pre.raw {
  flex: 1; min-height: 0; overflow: auto; margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  font-family: var(--num); font-size: 11.5px; line-height: 1.65;
  color: var(--text-2);
  white-space: pre-wrap; word-break: break-all;
}

/* ================= 弹层 ================= */
.mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.24);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center;
  padding: 24px;
}
.mask.show { display: flex; }
.modal {
  width: 100%; max-width: 560px; max-height: 84vh;
  display: flex; flex-direction: column;
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  border: 1px solid var(--line);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; letter-spacing: -0.2px; }
.modal-head .close {
  margin-left: auto; width: 26px; height: 26px;
  border: 0; border-radius: 7px; background: var(--seg-track);
  color: var(--sub); font-size: 14px; cursor: pointer; line-height: 1;
}
.modal-head .close:hover { background: var(--line-strong); color: var(--text); }
.modal-body { padding: 14px 18px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-foot {
  display: flex; align-items: center; gap: 9px;
  padding: 12px 18px; border-top: 1px solid var(--line);
  background: var(--panel-thin);
}
.modal-foot .grow { margin-left: auto; font-size: 11.5px; color: var(--sub); }

.field-block { margin-bottom: 14px; }
.field-block label { display: block; font-size: 11.5px; font-weight: 550; color: var(--sub); margin-bottom: 6px; }
.field-block textarea {
  width: 100%; min-height: 132px; resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-xs);
  background: var(--panel-thin); color: var(--text);
  font-family: var(--num); font-size: 11px; line-height: 1.6;
  outline: none;
}
.field-block textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.tip { font-size: 11px; color: var(--sub); line-height: 1.75; }
.tip code {
  font-family: var(--num); font-size: 10.5px;
  padding: 1px 5px; border-radius: 4px;
  background: var(--seg-track); color: var(--text-2);
}

/* 指标选择 */
.ind-search { margin-bottom: 10px; }
.ind-search input { width: 100%; }
.ind-group-title {
  position: sticky; top: 0; z-index: 1;
  padding: 7px 4px 5px;
  font-size: 11px; font-weight: 600; color: var(--sub);
  background: var(--panel-solid);
  border-bottom: 1px solid var(--line);
}
.ind-item {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 6px; border-radius: 7px;
  cursor: pointer; font-size: 12.5px;
}
.ind-item:hover { background: var(--brand-soft); }
.ind-item input[type="checkbox"] { accent-color: var(--brand); width: 14px; height: 14px; cursor: pointer; }
.ind-item .k { font-family: var(--num); font-size: 10.5px; color: var(--sub-2); margin-left: auto; }
.ind-item.on .nm { color: var(--brand); font-weight: 550; }

/* 提示条 */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 14px);
  z-index: 80;
  padding: 9px 16px; border-radius: 20px;
  background: rgba(29, 29, 31, 0.92); color: #fff;
  font-size: 12.5px; letter-spacing: 0.1px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  opacity: 0; pointer-events: none;
  transition: all 0.26s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: rgba(190, 32, 29, 0.95); }

/* 骨架 / 加载 */
.loading-bar {
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  z-index: 20; overflow: hidden; display: none;
  background: var(--brand-soft);
}
.loading-bar.show { display: block; }
.loading-bar::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--brand), transparent);
  animation: slide 1.1s infinite linear;
}
@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-row { display: flex; gap: 12px; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.skeleton-row i {
  height: 11px; border-radius: 4px; background: var(--seg-track);
  animation: pulse 1.4s infinite ease-in-out;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.42; } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 6px;
  border: 2.5px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--sub-2); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 980px) {
  .sidebar { display: none; }
  .summary { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  .search-wrap input { width: 140px; }
}

/* ================= 平台切换 ================= */
.pf-seg {
  display: flex;
  gap: 2px;
  margin: 0 4px 12px;
  padding: 2px;
  border-radius: 9px;
  background: var(--seg-track);
}
.pf-seg button {
  flex: 1;
  padding: 6px 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--sub);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.16s var(--ease);
}
.pf-seg button:hover { color: var(--text); }
.pf-seg button.active {
  background: var(--seg-active);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--seg-shadow);
}
