:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #172033;
  --ink-soft: #5a6579;
  --muted: #8a94a6;
  --line: #e5e9f2;
  --brand: #3b5bdb;
  --brand-soft: #edf0ff;
  --good: #1f9d55;
  --good-soft: #e6f6ec;
  --warn: #c47d0a;
  --bad: #d64545;
  --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(20,30,60,.06), 0 8px 24px rgba(20,30,60,.06);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 14px 26px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: var(--brand); color: #fff; border-radius: 10px; font-size: 20px;
}
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -.2px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.tab:hover { background: var(--bg); }
.tab.active { background: var(--brand-soft); color: var(--brand); }

main { max-width: 1200px; margin: 0 auto; padding: 24px 26px 60px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Uploader ---------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 54px 24px; text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
.dz-icon { font-size: 34px; color: var(--brand); }
.dz-title { font-size: 18px; font-weight: 600; margin: 12px 0 4px; }
.dz-sub { color: var(--muted); margin: 0; }
.link { color: var(--brand); cursor: pointer; text-decoration: underline; }
.upload-status { margin-top: 14px; text-align: center; color: var(--ink-soft); }

/* ---------- Domain bar ---------- */
.domain-bar {
  display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.mini-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 4px; }
.domain-edit { display: flex; gap: 8px; }
#domainInput {
  font-size: 18px; font-weight: 700; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-width: 240px;
}
.source-meta { display: flex; align-items: center; gap: 10px; flex: 1; }
.domain-actions { display: flex; gap: 8px; margin-left: auto; }
.chip {
  background: var(--bg); border: 1px solid var(--line); border-radius: 20px;
  padding: 4px 12px; font-size: 12px; color: var(--ink-soft);
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }

/* ---------- Scorecards ---------- */
.scorecards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.scorecard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.scorecard .sc-label { font-size: 12px; color: var(--muted); }
.scorecard .sc-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin-top: 2px; }
.scorecard .sc-sub { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.scorecard.hl { border-color: var(--brand); background: linear-gradient(180deg, var(--brand-soft), #fff); }
.scorecard.hl .sc-value { color: var(--brand); }

/* ---------- Cards / layout ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head.wrap { flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-head h4 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.muted { color: var(--muted); font-size: 12px; }

/* ---------- Bars ---------- */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 42px; align-items: center; gap: 10px; }
.bar-label { font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--bg); border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 6px; }
.bar-fill.good { background: var(--good); }
.bar-count { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink); }

/* ---------- Category list ---------- */
.cat-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow: auto; }
.cat-row { display: flex; justify-content: space-between; padding: 6px 8px; border-radius: 6px; font-size: 13px; }
.cat-row:hover { background: var(--bg); }
.cat-row .c { color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ---------- Search / chips ---------- */
.search {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 13px; min-width: 260px;
}
.search.sm { min-width: 180px; padding: 6px 10px; }
.table-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-soft);
  border-radius: 20px; padding: 5px 12px; font-size: 12px; cursor: pointer; font-weight: 500;
}
.chip-btn:hover { background: var(--bg); }
.chip-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.links-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.links-table th, .links-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.links-table th { position: sticky; top: 0; background: var(--panel); font-size: 12px; color: var(--ink-soft); cursor: pointer; white-space: nowrap; }
.links-table th.num, .links-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.links-table th:hover { color: var(--brand); }
.links-table tr.link-row:hover { background: var(--bg); cursor: pointer; }
.links-table tr.auth td { background: var(--good-soft); }
.links-table tr.auth:hover td { background: #daf0e2; }

.score-pill { display: inline-flex; align-items: center; gap: 6px; }
.score-num { font-weight: 700; width: 26px; }
.score-track { width: 46px; height: 6px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.score-bar { height: 100%; background: var(--brand); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.yes { background: var(--good-soft); color: var(--good); }
.badge.no { background: var(--bg); color: var(--muted); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11px; background: var(--bg); color: var(--ink-soft); }
.tag.image { background: #fff3e0; color: var(--warn); }
.tag.spam { background: var(--bad-soft); color: var(--bad); }
.tag.sub { background: #fff3e0; color: var(--warn); }
.tag.file { background: var(--bad-soft); color: var(--bad); }

.ref-cell .t { font-weight: 600; color: var(--ink); display: block; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-cell a.u { color: var(--muted); font-size: 11px; text-decoration: none; }
.ref-cell a.u:hover { text-decoration: underline; }
.anchor-cell .a { color: var(--ink); }
.anchor-cell .tg { color: var(--muted); font-size: 11px; display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reasons-row td { background: #fbfcfe; }
.reasons { display: flex; gap: 6px; flex-wrap: wrap; }
.reason { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--bad-soft); color: var(--bad); }
.reason.ok { background: var(--good-soft); color: var(--good); }
.reason-meta { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }

/* ---------- Settings ---------- */
.settings-card .group-title { margin: 20px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 16px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.field input { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 14px; color: var(--ink); }
.toggles { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink); cursor: pointer; }
.switch input { width: 16px; height: 16px; }

/* ---------- Help ---------- */
.help h4 { margin: 18px 0 6px; }
.help ul { margin: 6px 0; padding-left: 20px; }
.help li { margin: 4px 0; }
.help code { background: var(--bg); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); z-index: 50;
}
.toast.err { background: var(--bad); }

/* ---------- Dashboard additions ---------- */
.dropzone.compact { padding: 20px 24px; text-align: left; margin-bottom: 14px; }
.dz-inline { display: flex; align-items: center; gap: 16px; }
.dz-inline .dz-icon { font-size: 26px; }
.dz-inline .dz-title { margin: 0; font-size: 15px; }

.inline-field { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.mini-input { width: 68px; border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; font-size: 13px; }
.mini-input.wide { width: 110px; }
.dash-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }

.dash-table td { vertical-align: middle; }
.dash-row { cursor: pointer; }
.dom-cell .dom { font-weight: 700; color: var(--brand); display: block; }
.dom-cell .src { font-size: 11px; color: var(--muted); }
.dash-table td.big { font-size: 18px; font-weight: 700; }
.types { max-width: 300px; }
.tchip { display: inline-block; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-size: 11px; margin: 1px 2px; color: var(--ink-soft); white-space: nowrap; }
.tchip.more { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-soft); }
.grade { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; color: #fff; font-weight: 800; font-size: 12px; vertical-align: middle; }
.pscore { font-weight: 700; font-size: 15px; margin-left: 6px; }
.sum-cell { max-width: 360px; font-size: 12px; color: var(--ink-soft); }
.sum-cell span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.del-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 8px; border-radius: 6px; }
.del-btn:hover { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Detail: profile score ---------- */
.grid-profile { display: grid; grid-template-columns: 320px 1fr; gap: 18px; margin-bottom: 18px; }
.profile-scorecards { margin-bottom: 0; }
.profile-main { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.profile-badge { width: 84px; height: 84px; border-radius: 16px; display: grid; place-items: center; color: #fff; font-size: 34px; font-weight: 800; background: var(--brand); }
.profile-grade { font-size: 18px; font-weight: 700; }
.profile-components { display: flex; flex-direction: column; gap: 8px; }
.pc-row { display: grid; grid-template-columns: 150px 1fr 32px; align-items: center; gap: 10px; }
.pc-label { font-size: 12px; color: var(--ink-soft); }
.pc-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.gates-card { padding: 12px 16px; }
.switch.sm { font-size: 12px; gap: 6px; }
.switch.sm input { width: 14px; height: 14px; }

@media (max-width: 900px) { .grid-profile { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
  .domain-actions { margin-left: 0; }
}

@media print {
  .topbar, .uploader, .domain-actions, .table-tools, #filterChips, .btn { display: none !important; }
  body { background: #fff; }
  .card, .scorecard, .domain-bar { box-shadow: none; }
}
