:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --green: #3fb950;
  --red: #f85149;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); margin-top: 8px; min-height: 18px; }
h1, h2 { margin: 0 0 6px; }
h2 { font-size: 17px; }
a { color: var(--accent); }

input, select, button { font: inherit; }
input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 8px;
  outline: none;
  width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  white-space: nowrap;
}
button:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent-2); border-color: var(--accent-2); }
.btn-primary:hover { background: var(--accent); }
.btn-secondary { background: var(--bg-3); }
.btn-ghost { background: transparent; }
.btn-danger-ghost { background: transparent; color: var(--red); border-color: var(--red); margin-top: 14px; }

.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 340px; text-align: center; }
.login-card input { margin: 8px 0; }
.login-card button { width: 100%; background: var(--accent-2); border-color: var(--accent-2); margin-top: 6px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 22px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; }
.tabs { display: flex; gap: 4px; }
.tab { background: transparent; border: none; color: var(--muted); padding: 8px 14px; border-radius: 8px; }
.tab.active { background: var(--bg-3); color: var(--text); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.container { max-width: 1100px; margin: 0 auto; padding: 22px; }

/* Stats */
.grid { display: grid; gap: 14px; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { text-align: center; padding: 18px; }
.stat-num { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* Fields */
.field { margin: 12px 0; }
.field label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.output-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.copy { display: flex; gap: 6px; }
.copy input { flex: 1; font-family: monospace; font-size: 12px; }

/* Provider form */
.provider-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.provider-form .row { grid-column: 1 / -1; justify-content: flex-end; }
.test-result { margin-top: 12px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; }
.badge.ok { background: rgba(63,185,80,.15); color: var(--green); }
.badge.err { background: rgba(248,81,73,.15); color: var(--red); }

/* Provider cards */
.prov {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.prov-main { flex: 1; min-width: 220px; }
.prov-name { font-weight: 600; font-size: 15px; }
.prov-host { color: var(--muted); font-size: 12px; font-family: monospace; }
.prov-counts { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 6px; }
.prov-status { font-size: 12px; margin-top: 4px; }
.prov-actions { display: flex; gap: 8px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { display: none; }
.slider { position: absolute; inset: 0; background: var(--bg-3); border: 1px solid var(--border); border-radius: 24px; transition: .2s; }
.slider::before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: var(--muted); border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--accent-2); border-color: var(--accent-2); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }

/* Categories */
.cat-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: var(--bg); color: var(--muted); }
.seg button.active { background: var(--accent-2); color: #fff; }
.cat-search { flex: 1; }
#cat-search { flex: 1; min-width: 160px; }
#cat-provider { width: auto; min-width: 180px; }
.cat-bulk { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cat-list { display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; }
.cat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 8px;
}
.cat-item:hover { background: var(--bg); }
.cat-name { flex: 1; }
.cat-meta { color: var(--muted); font-size: 12px; }

/* Sync banner */
.sync-banner {
  background: rgba(47,129,247,.12); border-bottom: 1px solid var(--accent-2);
  padding: 8px 22px; font-size: 13px; color: var(--accent);
}
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.prov.is-syncing { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }
.prov-status.syncing { color: var(--accent); font-weight: 600; margin-top: 4px; }
.prov-status.err-text { color: var(--red); margin-top: 4px; }
button:disabled { opacity: .6; cursor: default; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 10px; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

@media (max-width: 640px) {
  .output-grid, .provider-form { grid-template-columns: 1fr; }
  .topbar { gap: 10px; }
}
