:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.16);
  --text: #1c1e21;
  --text-2: #5f6368;
  --text-3: #8a8f98;
  --accent: #1f6feb;
  --accent-soft: #e8f1ff;
  --ok: #1a7f47;
  --ok-soft: #e6f5ec;
  --warn: #a2600a;
  --warn-soft: #fdf3e2;
  --err: #b3261e;
  --err-soft: #fdeceb;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 500; font-size: 14px; letter-spacing: .5px;
  flex: none;
}
.brand h1 { margin: 0; font-size: 15px; font-weight: 500; }
.brand p { margin: 1px 0 0; font-size: 12px; color: var(--text-3); }

.topbar-status {
  font-size: 12px;
  color: var(--text-2);
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  white-space: nowrap;
}

/* ---------- 卡片 ---------- */
main { padding-top: 22px; padding-bottom: 8px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 500; }
.hint { font-size: 12px; color: var(--text-3); }
.card-body { padding: 18px 20px; }

/* ---------- 表单 ---------- */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row-add { align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 160px; }
.field-grow { flex: 1 1 340px; min-width: 260px; }
.field > span { font-size: 12px; color: var(--text-2); }
.field-btn { flex-direction: row; gap: 8px; align-items: center; }

input[type=text], input[type=password], select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 8px 10px;
  width: 100%;
  min-height: 36px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--text-3); }

.btn {
  font: inherit; font-size: 13px;
  border-radius: 7px;
  padding: 8px 16px;
  min-height: 36px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1a5fd0; }
.btn-ghost { background: #fff; color: var(--text-2); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--text-3); color: var(--text); }
.btn-sm { padding: 3px 9px; min-height: 26px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.note { margin: 10px 0 0; font-size: 12px; min-height: 18px; color: var(--text-3); }
.note.ok { color: var(--ok); }
.note.err { color: var(--err); }
.note.warn { color: var(--warn); }

/* ---------- 源站列表 ---------- */
.srclist { list-style: none; margin: 14px 0 0; padding: 0; }
.srclist li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 7px;
  font-size: 13px;
}
.srclist .url {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text);
}
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  flex: none;
}
.tag.auto { background: var(--bg); color: var(--text-3); }

/* ---------- 链接网格 ---------- */
.linkgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 12px;
}
.linkcard {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.linkcard h3 { margin: 0; font-size: 13px; font-weight: 500; }
.linkcard .url {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--text-2);
  word-break: break-all;
  background: var(--bg);
  border-radius: 6px;
  padding: 7px 9px;
}
.linkcard .actions { display: flex; gap: 7px; }

/* ---------- 城市选择 ---------- */
.citylist {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.citylist:empty { display: none; }
.citylist .empty { width: 100%; padding: 10px; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--text-2);
}

/* ---------- 预览表 ---------- */
.preview-wrap { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.preview-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.preview-head h3 { margin: 0; font-size: 13px; font-weight: 500; }
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 460px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; white-space: nowrap; }
th, td { padding: 7px 11px; text-align: left; border-bottom: 1px solid var(--line); }
th {
  background: #fafbfc;
  font-weight: 500;
  color: var(--text-2);
  position: sticky; top: 0;
  font-size: 12px;
}
td { color: var(--text); }
tbody tr:hover td { background: #f9fbff; }
tbody tr:last-child td { border-bottom: none; }
.empty { padding: 26px; text-align: center; color: var(--text-3); font-size: 13px; margin: 0; }

.foot { padding: 6px 24px 28px; color: var(--text-3); font-size: 12px; }

@media (max-width: 640px) {
  .wrap { padding: 0 14px; }
  .topbar-inner { flex-direction: column; align-items: flex-start; }
  .field { min-width: 100%; }
}
