/* style.css —— 全部样式（响应式，浅色报表主题）
   设计取向：这是个看数字的工具，表格是主角。
   所以：细边框代替阴影、圆角收到 3px、数字用等宽对齐、行高压紧、
   强调色用低饱和墨绿而不是 SaaS 后台那种亮蓝。 */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #f6f5f2;            /* 微暖的纸色，不是冷灰 */
  --surface: #ffffff;
  --border: #dddbd3;        /* 中性偏暖，能压住白底 */
  --border-strong: #b4b1a6; /* 表头/合计行这类需要分量的分隔线 */
  --text: #1c1b18;
  --text-2: #56544c;
  --text-3: #8b8880;
  --primary: #1e5a48;       /* 墨绿 */
  --primary-soft: #e5eeea;
  --danger: #9a2f26;
  --success: #1e5a48;
  --warn: #8a5f18;
  --radius: 3px;
  --shadow: none;
  /* 数字用等宽，位数才能对齐 */
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 13.5px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 9px;
  background: #fff; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(30, 90, 72, .14); }

/* ---------- 布局 ---------- */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: 208px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 40;
  transition: transform .22s ease;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 14px 14px; border-bottom: 1px solid var(--border); }
.brand-logo {
  width: 28px; height: 28px; border-radius: var(--radius); background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px;
}
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: .01em; }
#nav { flex: 1; padding: 8px 0; overflow-y: auto; }
/* 用左侧竖线标记当前项，比整块高亮更接近文档目录的观感 */
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  color: var(--text-2); font-size: 13.5px; border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { border-left-color: var(--primary); color: var(--primary); font-weight: 600; background: var(--primary-soft); }
.sidebar-foot { padding: 14px 16px; font-size: 12px; color: var(--text-3); border-top: 1px solid var(--border); }
#main { flex: 1; margin-left: 208px; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  position: sticky; top: 0; z-index: 30; background: rgba(246, 245, 242, .94);
  backdrop-filter: blur(6px); padding: 11px 22px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
}
#topbar h1 { font-size: 15px; font-weight: 600; letter-spacing: .01em; }
#menu-btn { display: none; background: none; border: none; color: var(--text); padding: 4px; }
#view { padding: 20px 22px 48px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- 通用组件 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: #fff; color: var(--text); font-size: 13px; font-weight: 500;
}
.btn:hover { background: var(--bg); border-color: var(--border-strong); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #17493a; border-color: #17493a; }
.btn-danger { color: var(--danger); border-color: #d8b5b0; }
.btn-danger:hover { background: #faf0ef; }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.card h3 { font-size: 13.5px; font-weight: 600; margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 16px; font-weight: 600; letter-spacing: .01em; }
.muted { color: var(--text-2); font-size: 12.5px; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: var(--radius); font-size: 11.5px; font-weight: 500;
  background: var(--bg); color: var(--text-2); border: 1px solid var(--border);
}
.tag-blue { background: var(--primary-soft); color: var(--primary); border-color: #c6d8d1; }
.tag-green { background: #e7efe9; color: var(--success); border-color: #c6d8cb; }
.tag-red { background: #f7ecea; color: var(--danger); border-color: #ddc3bf; }
.tag-amber { background: #f6efdf; color: var(--warn); border-color: #ddd0b0; }
.tag-gray { background: var(--bg); color: var(--text-2); }
.empty { text-align: center; color: var(--text-3); padding: 44px 0; font-size: 13.5px; }
.empty .big { font-size: 34px; margin-bottom: 8px; opacity: .6; }
.spinner {
  width: 18px; height: 18px; border: 2.5px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 表格 ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 6px 11px; border-bottom: 1px solid var(--border); white-space: nowrap; }
/* 表头做成小字距的标签感，底边加重一档，把「表头」和「数据」明确分开 */
.tbl th {
  font-size: 11px; color: var(--text-2); font-weight: 600; background: var(--bg);
  letter-spacing: .06em; text-transform: uppercase;
  border-bottom: 1px solid var(--border-strong); padding-top: 8px; padding-bottom: 8px;
}
.tbl tr:hover td { background: #faf9f6; }
/* 数字列用等宽体，位数才能上下对齐 —— 这是报表能不能扫读的关键 */
.tbl .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.tbl th.num { text-align: right; font-family: inherit; font-size: 11px; }
.up { color: var(--success); }
.down { color: var(--danger); }
.flat { color: var(--text-3); }

/* ---------- 统计卡片 ---------- */
/* 指标卡：扁平、贴边、等高。
   试过让它们共用边框拼成一条数据带，但指标个数不固定（这里是 7 个），
   一换行最后一个就变成孤零零的半截，圆角也对不上，所以还是各自独立。 */
.stat-grid {
  display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  margin-bottom: 18px; align-items: stretch;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 13px;
}
.stat .label { font-size: 11px; color: var(--text-2); letter-spacing: .05em; text-transform: uppercase; }
.stat .value { font-size: 21px; font-weight: 600; margin-top: 3px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }

/* ---------- 项目卡片 ---------- */
.project-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
/* 不做位移和投影 —— 边框变深就够了，位移在密集列表里很晃眼 */
.pcard { cursor: pointer; transition: border-color .12s; position: relative; }
.pcard:hover { border-color: var(--border-strong); }
.pcard .pname { font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.pcard .meta { margin-top: 9px; font-size: 12.5px; color: var(--text-2); display: flex; flex-direction: column; gap: 4px; }
.pcard .actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; opacity: 0; transition: opacity .12s; }
.pcard:hover .actions { opacity: 1; }
.pcard .actions button { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 3px 7px; font-size: 12px; color: var(--text-2); }
.pcard .actions button:hover { color: var(--danger); border-color: #d8b5b0; }
.pcard .url-count b { font-family: var(--font-mono); }

/* ---------- 表单 ---------- */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
/* 表单里两段之间的独立提示，和下一行之间要留口气 */
.hint + .form-row { margin-top: 12px; }
/* 表单分组：GSC / GA4 两个数据源各自独立选账号 */
.form-section {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px 2px; margin-bottom: 12px; background: var(--bg);
}
.form-section-title {
  font-size: 11px; font-weight: 600; color: var(--text-2);
  margin-bottom: 9px; letter-spacing: .06em; text-transform: uppercase;
}
.form-section .hint { margin-bottom: 12px; }
/* 本期没有数据的行 */
tr.no-data td { color: var(--text-3); }
/* 自定义区间日期选择器 */
.date-range { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.date-range input[type="date"] { width: auto; }

/* ---------- 历史数据表（列很多，横向滚动 + 前两列吸附） ---------- */
/* 注意：必须用 border-collapse: separate —— 用 collapse 时 Safari 的
   position:sticky 在 th/td 上不生效，列会跟着横向滚动跑掉 */
/* 用 table.tbl-history 而不是 .tbl-history：上面的 table.tbl 也是「元素+类」，
   单靠一个类名压不过它，border-collapse 会被覆盖回 collapse */
table.tbl-history {
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
}
.tbl-history th, .tbl-history td { border-bottom: 1px solid var(--border); }
.tbl-history th[data-sort]:hover { color: var(--primary); }

/* 项目/URL 两列吸附在左侧。两个 left 偏移必须和第 1 列的固定宽度对上 */
.tbl-history th:nth-child(1), .tbl-history td:nth-child(1) { width: 140px; min-width: 140px; max-width: 140px; }
.tbl-history th:nth-child(2), .tbl-history td:nth-child(2) { min-width: 240px; }
/* URL 用等宽体：一列路径上下对照时，等宽比比例字体好认得多 */
.tbl-history td:nth-child(2) { font-family: var(--font-mono); font-size: 12px; }
.tbl-history .sticky-col { position: sticky; background: var(--surface); }
.tbl-history td.sticky-col { z-index: 1; }
.tbl-history th.sticky-col { z-index: 3; }
.tbl-history th:nth-child(1).sticky-col, .tbl-history td:nth-child(1).sticky-col { left: 0; }
.tbl-history th:nth-child(2).sticky-col, .tbl-history td:nth-child(2).sticky-col {
  left: 140px; box-shadow: 1px 0 0 var(--border-strong);
}
.tbl-history th.sticky-col { background: var(--bg); }
.tbl-history tbody tr:hover .sticky-col { background: #faf9f6; }

/* 合计行 */
.tbl-history tfoot td { border-top: 2px solid var(--border-strong); border-bottom: none; background: var(--bg); }
.tbl-history tfoot .sticky-col { background: var(--bg); }

@media (max-width: 700px) {
  /* 手机上吸附列会挤掉数据列，干脆让它跟着一起滚 */
  .tbl-history .sticky-col { position: static; }
  .tbl-history th:nth-child(1), .tbl-history td:nth-child(1) { width: auto; min-width: 100px; max-width: none; }
}
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- 模态框 ---------- */
#modal-mask {
  position: fixed; inset: 0; background: rgba(28, 27, 24, .42); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
#modal-mask.hidden, #toast.hidden, .hidden { display: none !important; }
#modal {
  background: #fff; border-radius: var(--radius); width: 100%; max-width: 560px;
  padding: 20px 22px; border: 1px solid var(--border-strong);
  box-shadow: 0 16px 40px rgba(28, 27, 24, .16); animation: pop .15s ease;
}
#modal.wide { max-width: 760px; }
@keyframes pop { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-x { background: none; border: none; font-size: 20px; color: var(--text-3); line-height: 1; padding: 2px 6px; }
.modal-x:hover { color: var(--text); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: #26251f; color: #fff; padding: 9px 18px; border-radius: var(--radius); font-size: 13px;
  box-shadow: 0 8px 24px rgba(28, 27, 24, .28); max-width: 86vw;
}
#toast.ok { background: var(--success); }
#toast.err { background: var(--danger); }

/* ---------- 数据看板 ---------- */
.filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar select, .filter-bar input { width: auto; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 2px; gap: 2px; }
.seg button { border: none; background: none; padding: 4px 12px; border-radius: 2px; font-size: 12.5px; color: var(--text-2); }
.seg button.on { background: #fff; color: var(--primary); font-weight: 600; border: 1px solid var(--border); }
.fetch-status { font-size: 12.5px; color: var(--text-2); }
.url-add { display: flex; gap: 8px; margin-bottom: 0; flex-wrap: wrap; }

/* ---------- 单元格选区 ---------- */
/* 拖拽期间禁掉原生文本选择，否则会和矩形选区抢 */
.cell-selecting { user-select: none; }
.tbl [data-r] { cursor: cell; }
/* 用 box-shadow 而不是 background 画选中态：吸附列自带背景色，
   直接改 background 会被它盖掉，inset 阴影则能叠在上面 */
.tbl td.cell-sel { box-shadow: inset 0 0 0 999px var(--primary-soft); }
.tbl td.cell-anchor { outline: 1.5px solid var(--primary); outline-offset: -1.5px; }
.sel-info { color: var(--primary); font-weight: 500; }

/* ---------- 可搜索下拉 ---------- */
.combo { position: relative; }
.combo-input { padding-right: 28px; }
.combo-input:disabled { background: var(--bg); color: var(--text-3); cursor: default; }
.combo-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; border: none; background: none; line-height: 1;
  font-size: 16px; color: var(--text-3); border-radius: 4px;
}
.combo-clear:hover { color: var(--text); background: var(--bg); }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 6px 18px rgba(28, 27, 24, .12);
}
.combo-opt { padding: 7px 10px; cursor: pointer; }
.combo-opt.active { background: var(--primary-soft); }
.combo-opt.selected .combo-opt-label { font-weight: 600; }
.combo-opt-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-opt-note { font-size: 11.5px; color: var(--text-3); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-empty { padding: 12px 10px; color: var(--text-3); text-align: center; }

/* 弹窗里的小节标题（项目详情下半部分的「跟踪的 URL」） */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section-head h4 { font-size: 14px; font-weight: 600; }

/* 两步删除：第一下点亮成实心红，提醒下一下才是真删 */
.btn-danger.armed { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------- 账号 ---------- */
.acc-card { display: flex; align-items: center; gap: 14px; }
.acc-avatar {
  width: 36px; height: 36px; border-radius: var(--radius); background: #8c3a30; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px; flex-shrink: 0;
}
.acc-card .email { font-weight: 600; font-size: 14.5px; word-break: break-all; }
.acc-card .info { flex: 1; min-width: 0; }
.acc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.acc-actions button { font-size: 12.5px; }

/* ---------- 移动端响应式 ---------- */
@media (max-width: 900px) {
  #sidebar { transform: translateX(-100%); box-shadow: 0 0 0 9999px transparent; }
  #sidebar.open { transform: none; box-shadow: 0 0 0 9999px rgba(17, 24, 39, .4); }
  #main { margin-left: 0; }
  #menu-btn { display: block; }
  #view { padding: 16px 14px 40px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  #modal { padding: 18px; }
  .page-head h2 { font-size: 16px; }
}

/* ---------- 登录 / 改密（全屏覆盖）---------- */
/* 未登录时不该看到侧边栏和内容，所以直接盖满一屏，而不是弹窗 */
#auth-screen {
  position: fixed; inset: 0; z-index: 300; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px; overflow-y: auto;
}
.auth-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px 26px; width: 100%; max-width: 360px;
}
.auth-brand {
  display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 600;
  margin-bottom: 20px; justify-content: center;
}
.auth-submit { width: 100%; justify-content: center; margin-top: 4px; }
.auth-err {
  background: #f7ecea; color: var(--danger); border: 1px solid #ddc3bf;
  border-radius: var(--radius); padding: 7px 10px; font-size: 12.5px; margin: 10px 0;
}

/* ---------- 侧边栏底部的当前用户 ---------- */
.userbar-name { font-size: 12.5px; color: var(--text); font-weight: 500; margin-bottom: 3px; }
.userbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.userbar-actions a { font-size: 11.5px; color: var(--text-3); }
.userbar-actions a:hover { color: var(--primary); }

/* ---------- 初始密码展示 ---------- */
/* 这串东西只显示一次，要足够醒目、足够好复制 */
.cred-box { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.cred-row { display: flex; align-items: baseline; gap: 12px; padding: 5px 0; }
.cred-label { font-size: 12px; color: var(--text-2); width: 62px; flex-shrink: 0; }
.cred-row code {
  font-family: var(--font-mono); font-size: 14px; font-weight: 600;
  user-select: all; word-break: break-all;
}
