:root {
  --bg: #0e1116;
  --bg-2: #151a21;
  --bg-3: #1c232c;
  --line: #26303b;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4c8dff;
  --accent-2: #23c58a;
  --warn: #f0a020;
  --danger: #f0506e;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.xsmall { font-size: 11px; }
.mono { font-family: var(--mono); }

/* ---------- sidebar ---------- */
.sidebar {
  width: 260px; flex: 0 0 260px; min-height: 100vh;
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 16px; }
.brand .logo { font-size: 22px; }
.brand b { display: block; font-size: 15px; letter-spacing: .2px; }
.brand small { color: var(--muted); font-size: 11px; }

.add-target { display: flex; gap: 6px; margin-bottom: 14px; }
.add-target input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.add-target button {
  width: 34px; border: 1px solid var(--line); background: var(--bg-3);
  color: var(--text); border-radius: 8px; font-size: 18px; cursor: pointer;
}
.add-target button:hover { background: var(--accent); border-color: var(--accent); }

.target-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.target-item {
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.target-item:hover { background: var(--bg-3); }
.target-item.active { background: var(--bg-3); box-shadow: inset 2px 0 0 var(--accent); }
.target-item .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-item .sub { font-size: 11px; color: var(--muted); }
.target-item .del { opacity: 0; color: var(--muted); cursor: pointer; padding: 0 4px; }
.target-item:hover .del { opacity: 1; }
.target-item .del:hover { color: var(--danger); }
.sidebar-foot { padding-top: 12px; border-top: 1px solid var(--line); }
.account { display: flex; flex-direction: column; gap: 6px; padding: 0 6px; }
.account-actions { display: flex; gap: 12px; }
.linkish {
  background: none; border: 0; padding: 0; color: var(--accent);
  font-size: 12px; cursor: pointer; font-family: inherit;
}
.linkish:hover { text-decoration: underline; }

.notice {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-size: 12px; margin: 12px 0; line-height: 1.6;
}
.notice.warn { border-color: var(--warn); color: var(--warn); }
.notice.ok { border-color: var(--accent-2); color: var(--accent-2); }
.notice.bad { border-color: var(--danger); color: var(--danger); }

.section-head {
  font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  margin: 26px 0 4px; padding-top: 18px; border-top: 1px solid var(--line);
}
#settings-dialog input[type=text], #settings-dialog input[type=password] {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 13px;
}
dialog select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 13px;
}

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; padding: 20px 26px 60px; overflow-x: hidden; }
.empty { max-width: 560px; margin: 18vh auto; text-align: center; }
.empty h1 { font-size: 30px; margin-bottom: 8px; }

.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 24px; margin: 0; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  border: 1px solid var(--line); background: var(--bg-3); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.tiny { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge-authority {
  background: linear-gradient(135deg, #2b6cb0, #23c58a); color: #fff; font-weight: 700;
  padding: 6px 12px; border-radius: 8px; font-size: 15px; min-width: 46px; text-align: center;
}

/* ---------- crawl banner ---------- */
.crawl-banner {
  margin-top: 16px; padding: 12px 14px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.crawl-banner-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pulse {
  width: 9px; height: 9px; border-radius: 50%; background: var(--accent-2);
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }
.progress { height: 5px; background: var(--bg); border-radius: 3px; margin: 10px 0 6px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }

/* ---------- cards ---------- */
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin: 18px 0;
}
.stat {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .d { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  background: none; border: 0; color: var(--muted); padding: 10px 14px;
  cursor: pointer; font-size: 13px; font-weight: 500; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.panel { display: none; }
.panel.active { display: block; }

/* ---------- cards / charts ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; margin-bottom: 14px; }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

.chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 74px 1fr 52px; gap: 10px; align-items: center; font-size: 12px; }
/* These are spans, so they must be blockified for width/height to apply. */
.bar-track { display: block; background: var(--bg); border-radius: 4px; height: 16px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, #2b6cb0, #4c8dff); border-radius: 4px; min-width: 2px; }
.bar-row .n { text-align: right; color: var(--muted); font-family: var(--mono); }

.minilist { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.mini { border-left: 2px solid var(--line); padding-left: 10px; }
.mini .t { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .s { font-size: 11px; color: var(--muted); }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input, .filters select {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 10px; border-radius: 8px; font-size: 13px;
}
.filters .search { flex: 1; min-width: 200px; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); cursor: pointer; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); }
th {
  text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-3); }
.src-title { font-weight: 500; margin-bottom: 2px; }
.src-url { font-size: 11px; color: var(--muted); font-family: var(--mono); word-break: break-all; }
.ctx { font-size: 11px; color: var(--muted); margin-top: 4px; font-style: italic; }

.pill { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.pill.follow { background: rgba(35,197,138,.15); color: var(--accent-2); }
.pill.nofollow { background: rgba(240,160,32,.15); color: var(--warn); }
.pill.ugc, .pill.sponsored { background: rgba(76,141,255,.15); color: var(--accent); }
.pill.img { background: rgba(139,152,165,.15); color: var(--muted); }
.pill.lost { background: rgba(240,80,110,.15); color: var(--danger); }

.au { font-family: var(--mono); font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--bg-3); display: inline-block; min-width: 34px; text-align: center; }
.au.hi { color: var(--accent-2); } .au.mid { color: var(--warn); } .au.lo { color: var(--muted); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 14px; }
.empty-row { padding: 36px; text-align: center; color: var(--muted); }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  border-radius: 14px; padding: 22px 24px; width: min(640px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,.65); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 5px; }
dialog textarea, dialog input[type=number] {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 13px; font-family: var(--mono);
}
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.switches { display: flex; flex-direction: column; gap: 9px; margin-top: 16px; }
.switches .check { color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--line); padding: 11px 18px;
  border-radius: 10px; z-index: 99; box-shadow: 0 8px 26px rgba(0,0,0,.5); font-size: 13px;
}
.toast.err { border-color: var(--danger); color: var(--danger); }

@media (max-width: 780px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; flex: none; min-height: 0; }
  .main { padding: 16px; }
}

/* Report viewer needs more room than the settings dialogs. */
dialog.wide { width: min(1100px, 94vw); max-height: 88vh; overflow-y: auto; }
dialog.wide .cards { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
dialog.wide .search {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  padding: 9px 11px; border-radius: 8px; font-size: 13px;
}

/* Position/rank movement arrows in the keyword table. */
.mv { font-size: 12px; font-weight: 600; white-space: nowrap; }
.mv.up { color: var(--accent-2); }
.mv.down { color: var(--danger); }

/* DataForSEO balance, pinned above the account row in the sidebar. */
.balance {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 10px; font-size: 12px; line-height: 1.5;
}
.balance .amt { font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
.balance .lbl { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .5px; }
.balance .sub { color: var(--muted); font-size: 11px; }
.balance.low { border-color: var(--warn); }
.balance.low .amt { color: var(--warn); }
.balance.empty { border-color: var(--danger); }
.balance.empty .amt { color: var(--danger); }

/* Quick-filter chips above the backlink table. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--muted);
  padding: 5px 11px; border-radius: 999px; font-size: 12px; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip .n { opacity: .7; margin-left: 4px; }

/* DA / PA / spam pills in the table. */
.metric { display: inline-block; min-width: 30px; text-align: center;
          padding: 2px 6px; border-radius: 5px; font-size: 12px; font-weight: 700; }
.metric.hi  { background: rgba(35,197,138,.16); color: var(--accent-2); }
.metric.mid { background: rgba(76,141,255,.16); color: var(--accent); }
.metric.lo  { background: var(--bg-3); color: var(--muted); }
.metric.na  { background: transparent; color: var(--muted); font-weight: 400; }
.spam.clean { background: rgba(35,197,138,.16); color: var(--accent-2); }
.spam.risky { background: rgba(240,160,32,.16); color: var(--warn); }
.spam.toxic { background: rgba(240,80,110,.16); color: var(--danger); }
.kind-pill { display: inline-block; padding: 2px 7px; border-radius: 5px;
             font-size: 11px; background: var(--bg-3); color: var(--muted); }
