/* ============ SiteUnit — design system ============ */
:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --text: #1a2032;
  --text-2: #67708a;
  --border: #e4e7f0;
  --accent: #4f6ef7;
  --accent-strong: #3d59e6;
  --danger: #e5484d;
  --ok: #2fb673;
  --warn: #f0a020;
  --shadow: 0 1px 2px rgba(20,28,60,.06), 0 4px 16px rgba(20,28,60,.06);
  --shadow-hover: 0 2px 4px rgba(20,28,60,.08), 0 12px 28px rgba(20,28,60,.14);
  --radius: 14px;
  --radius-sm: 10px;
}
:root[data-theme="dark"] {
  --bg: #12141c;
  --surface: #1b1e2a;
  --surface-2: #212534;
  --text: #e8eaf2;
  --text-2: #9aa2bd;
  --border: #2b3044;
  --accent: #6d84ff;
  --accent-strong: #8397ff;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  --shadow-hover: 0 2px 4px rgba(0,0,0,.35), 0 12px 28px rgba(0,0,0,.4);
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #12141c; --surface: #1b1e2a; --surface-2: #212534;
    --text: #e8eaf2; --text-2: #9aa2bd; --border: #2b3044;
    --accent: #6d84ff; --accent-strong: #8397ff;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    --shadow-hover: 0 2px 4px rgba(0,0,0,.35), 0 12px 28px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px clamp(14px, 4vw, 44px);
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.brand-mark {
  font-size: 24px; width: 44px; height: 44px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #9b6ef7);
  border-radius: 12px; box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .3px; }
.brand-sub { margin: 0; font-size: 12px; color: var(--text-2); }
.view-tabs { display: flex; gap: 4px; }
.tab {
  border: 1px solid transparent; background: transparent; color: var(--text-2);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
  transition: background .12s, color .12s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.on { background: var(--surface); color: var(--text); border-color: var(--border); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: flex-end; }

/* search */
.search-box { position: relative; display: flex; align-items: center; flex: 0 1 380px; min-width: 160px; }
.search-icon { width: 16px; height: 16px; position: absolute; left: 12px; color: var(--text-2); pointer-events: none; }
.search-box input {
  width: 100%; padding: 9px 32px 9px 36px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 13.5px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.search-clear {
  position: absolute; right: 8px; border: 0; background: none; color: var(--text-2);
  cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px;
}
.search-clear:hover { color: var(--text); background: var(--surface-2); }

/* buttons */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font-size: 13.5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: transform .06s, background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { padding: 8px 10px; font-size: 13px; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn-plus { font-size: 15px; line-height: 1; }

/* select bar */
.select-bar { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }

/* ---------- layout ---------- */
main { padding: 22px clamp(14px, 4vw, 44px) 40px; max-width: 1480px; margin: 0 auto; width: 100%; }
.state-msg { text-align: center; color: var(--text-2); padding: 80px 0; }
.groups .group + .group { margin-top: 30px; }
.group-title {
  font-size: 13px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 1.1px;
  display: flex; align-items: center; gap: 8px; margin: 0 0 12px;
}
.group-count {
  font-size: 11px; font-weight: 600; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; letter-spacing: 0;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* ---------- card ---------- */
.card {
  position: relative; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); cursor: pointer; min-height: 92px;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s;
  outline: none;
}
.card:hover, .card:focus-visible {
  transform: translateY(-2px); box-shadow: var(--shadow-hover);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.card.busy { opacity: .6; }
.card.pinned { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.card.broken { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); }
.card[draggable="true"] { cursor: grab; }
.card[draggable="true"]:active { cursor: grabbing; }
:root[data-density="compact"] .grid { gap: 8px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
:root[data-density="compact"] .card { padding: 10px; min-height: 76px; gap: 5px; }
:root[data-density="compact"] .logo { width: 32px; height: 32px; }
:root[data-density="compact"] .card-name { font-size: 13.5px; }

.card-check { position: absolute; top: 8px; left: 8px; z-index: 3; }
.card-actions {
  position: absolute; top: 6px; right: 6px; display: flex; gap: 1px;
  opacity: 0; transform: translateY(-2px); transition: opacity .12s, transform .12s;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-radius: 8px; padding: 2px;
}
.card:hover .card-actions, .card:focus-within .card-actions { opacity: 1; transform: none; }
.icon-btn {
  border: 0; background: none; cursor: pointer; font-size: 14px; line-height: 1;
  color: var(--text-2); padding: 5px; border-radius: 7px; transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn.on { color: var(--accent); }
.icon-btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

.card-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 40px; height: 40px; flex: none; border-radius: 10px;
  object-fit: contain; background: var(--surface-2); padding: 4px;
}
.logo-fallback { display: grid; place-items: center; padding: 0; color: #fff; font-size: 18px; font-weight: 700; }
.card-title-wrap { min-width: 0; flex: 1; }
.card-name { margin: 0; font-size: 14.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-url { margin: 1px 0 0; font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-desc {
  margin: 0; font-size: 12px; color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; min-height: 18px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; min-width: 0; }
.tag {
  font-size: 10.5px; color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
  padding: 1px 7px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tag:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.meta { font-size: 10.5px; color: var(--text-2); white-space: nowrap; }
.badge { font-size: 13px; line-height: 1; }
.badge-bad { color: var(--warn); }

/* ---------- empty state ---------- */
.empty-state { text-align: center; padding: 80px 20px; color: var(--text-2); }
.empty-emoji { font-size: 48px; margin-bottom: 10px; }
.empty-state h2 { color: var(--text); margin: 0 0 8px; }
.empty-state p { margin: 0 0 22px; }

/* ---------- footer ---------- */
.footbar {
  padding: 14px clamp(14px, 4vw, 44px); margin-top: auto;
  border-top: 1px solid var(--border); color: var(--text-2); font-size: 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.foot-sep { opacity: .5; }

/* ---------- overlay / modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10,14,30,.45); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
}
.modal, .palette {
  width: 100%; max-width: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; box-shadow: 0 24px 64px rgba(0,0,0,.28);
  animation: pop .15s ease;
}
.modal.wide { max-width: 560px; }
@keyframes pop { from { transform: scale(.96) translateY(6px); opacity: 0; } }
.modal h2 { margin: 0 0 16px; font-size: 17px; }
.modal label { display: block; margin-bottom: 13px; }
.modal label > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.req { color: var(--danger); font-style: normal; }
.hint { display: block; font-size: 11.5px; color: var(--text-2); font-style: normal; margin-top: 4px; }
.modal input[type="text"] {
  width: 100%; padding: 9px 11px; font-size: 13.5px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.modal input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.modal input:disabled { opacity: .6; }
.form-row { display: grid; grid-template-columns: 1fr 1.3fr; gap: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.cb { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-2); margin: 0; }
.cb input { accent-color: var(--accent); }
.form-error { color: var(--danger); font-size: 12.5px; margin: 0 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.spinner {
  width: 13px; height: 13px; border-radius: 50%; display: inline-block;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

/* segmented control */
.seg { display: inline-flex; gap: 2px; background: var(--surface-2); border-radius: 9px; padding: 2px; }
.seg-btn {
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  padding: 5px 11px; border-radius: 7px; font-size: 12.5px; transition: background .12s, color .12s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.seg-block { display: flex; margin-bottom: 14px; }

/* settings */
.set-group { margin-bottom: 16px; }
.set-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; }
.set-info { margin: 0; font-size: 12.5px; color: var(--text); }
.set-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* import */
.io-area { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.io-file { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 180px; }
.io-fname { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.io-actions { display: flex; gap: 6px; }
.io-preview { font-size: 13px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; margin: 8px 0; color: var(--text-2); }
.io-preview.ok { color: var(--ok); }
.io-divider { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.io-exports { display: flex; gap: 8px; flex-wrap: wrap; }
.io-exports label { cursor: pointer; }

/* command palette */
.palette { max-width: 560px; padding: 0; overflow: hidden; }
.palette-input { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.palette-icon { color: var(--text-2); font-size: 14px; }
.palette-input input { flex: 1; border: 0; background: transparent; color: var(--text); font-size: 15px; outline: none; }
.kbd { font-size: 11px; color: var(--text-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; }
.palette-list { list-style: none; margin: 0; padding: 6px; max-height: 60vh; overflow: auto; }
.palette-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px;
}
.palette-item.active { background: var(--surface-2); }
.palette-item-icon { width: 18px; color: var(--text-2); text-align: center; }
.palette-item-label { flex: 1; }
.palette-item-hint { font-size: 11.5px; color: var(--text-2); }
.palette-empty { margin: 0; padding: 20px; text-align: center; color: var(--text-2); font-size: 13px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 90; padding: 10px 18px; border-radius: 10px; font-size: 13.5px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow-hover);
}
.toast-error { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
.toast-success { border-color: color-mix(in srgb, var(--ok) 50%, var(--border)); }
.toast-enter-active, .toast-leave-active { transition: opacity .2s, transform .2s; }
.toast-enter-from, .toast-leave-to { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* ---------- stats view ---------- */
.stats-panel { display: flex; flex-direction: column; gap: 12px; }
.stats-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stats-title { margin: 0; font-size: 16px; }
.stats-grid {
  display: grid; gap: 12px; align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
}
.stat-tile, .stat-chart-card { grid-column: 1 / -1; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-2); letter-spacing: .4px; }
.stat-value { font-size: 32px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-chart-card { gap: 6px; }
.stat-chart { width: 100%; height: auto; display: block; border-bottom: 1px solid var(--border); }
.stat-chart .stat-bar { fill: var(--accent); transition: fill .12s; }
.stat-chart .stat-bar:hover { fill: var(--accent-strong); }
.stat-axis { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--text-2); }
.stat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.stat-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: var(--radius-sm);
  color: inherit; text-decoration: none; transition: background .12s; min-width: 0;
}
.stat-row:hover { background: var(--surface-2); }
.stat-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.stat-rank { flex: none; width: 20px; text-align: center; font-size: 12px; font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums; }
.stat-rank-top { color: var(--accent); }
.stat-logo { width: 28px; height: 28px; flex: none; border-radius: 8px; object-fit: contain; background: var(--surface-2); padding: 2px; }
.stat-logo-fallback { display: grid; place-items: center; padding: 0; color: #fff; font-size: 13px; font-weight: 700; }
.stat-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stat-row-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-row-host { font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-row-visits { flex: none; font-size: 12px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat-groups { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.stat-group { display: flex; align-items: center; gap: 10px; }
.stat-group-name { flex: none; width: 96px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-group-track { flex: 1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.stat-group-fill { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .25s ease; }
.stat-group-count { flex: none; min-width: 34px; text-align: right; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.stat-group-percent { flex: none; min-width: 42px; text-align: right; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.stats-empty { margin: 0; padding: 18px 0; text-align: center; color: var(--text-2); font-size: 12.5px; }
.stats-loading { padding: 48px 0; text-align: center; color: var(--text-2); font-size: 13.5px; }
.stats-error {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius); font-size: 13.5px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
}
.stats-error p { margin: 0; }
:root[data-density="compact"] .stats-panel { gap: 8px; }
:root[data-density="compact"] .stats-grid { gap: 8px; }
:root[data-density="compact"] .stat-card { padding: 11px 12px; gap: 7px; }
:root[data-density="compact"] .stat-value { font-size: 26px; }
:root[data-density="compact"] .stat-row { padding: 5px 6px; }

/* responsive */
@media (max-width: 768px) {
  .topbar { padding: 12px 14px; }
  .view-tabs { order: 3; width: 100%; }
  .topbar-actions { flex: 1; justify-content: flex-end; }
  .search-box { flex: 1; min-width: 0; }
  .btn-primary .btn-plus ~ " 添加" { } /* no-op */
  .form-row { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .card-actions { opacity: 1; transform: none; } /* touch */
}
@media (max-width: 430px) {
  .brand-sub { display: none; }
  .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  :root[data-density="compact"] .grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 26px; }
  .stat-group-name { width: 78px; }
  .stats-toolbar { flex-direction: column; align-items: stretch; }
  .stats-toolbar .seg { display: flex; }
  .stats-toolbar .seg-btn { flex: 1; }
}
