:root {
  --bg: #0f141b;
  --bg-2: #161d27;
  --panel: #1b232f;
  --panel-2: #232d3b;
  --text: #e6edf6;
  --muted: #94a3b8;
  --border: #2a3646;
  --primary: #4f9eff;
  --primary-2: #2563eb;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2536 0%, var(--bg) 55%) fixed;
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 27, 0.7);
  backdrop-filter: blur(8px);
}

.brand { display: flex; gap: 14px; align-items: center; }
.brand .logo {
  font-size: 26px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 18px; letter-spacing: 0.2px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.status {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
}
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); }
.status.ok .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.status.bad .dot { background: var(--err); }

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 20px;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel.wide { min-width: 0; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:hover { background: #2c394d; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary-2); border-color: var(--primary-2); color: white; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { background: #7f1d1d; border-color: #b91c1c; color: #fee2e2; }
.btn.danger:hover { background: #991b1b; }
.btn.ghost { background: transparent; }

.target-list {
  list-style: none; padding: 0; margin: 0 0 16px;
  display: flex; flex-direction: column; gap: 8px;
  max-height: 360px; overflow: auto;
}
.target-item {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.target-item .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.target-item .name { font-weight: 600; }
.target-item .url { font-size: 12px; color: var(--muted); word-break: break-all; }
.target-item .meta { font-size: 11px; color: var(--muted); }
.target-item .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.target-item.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }

.advanced { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 12px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.hint { font-size: 11px; color: var(--muted); margin: 4px 0 8px; line-height: 1.4; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
@media (max-width: 900px) { .kpi-row { grid-template-columns: repeat(3, 1fr); } }

.kpi {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.kpi .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.kpi .val { font-size: 20px; font-weight: 700; }
.kpi.ok .val { color: var(--ok); }
.kpi.err .val { color: var(--err); }
.kpi.warn .val { color: var(--warn); }

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 8px;
}
@media (max-width: 900px) { .charts { grid-template-columns: 1fr; } }
.chart-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  height: 230px;
  position: relative;
}

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.runs-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.runs-table th, .runs-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap;
}
.runs-table th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 10px; }
.runs-table tr:hover td { background: rgba(255,255,255,0.02); }
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row input, .filter-row select { width: auto; min-width: 120px; }
.inline-label { display: flex; flex-direction: row; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.inline-label select { width: auto; min-width: 100px; padding: 4px 8px; font-size: 12px; }

.posts-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.posts-table th, .posts-table td {
  padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left;
  white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis;
}
.posts-table th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 10px; }
.posts-table tr:hover td { background: rgba(255,255,255,0.02); }
.posts-table td.url { font-family: ui-monospace, monospace; font-size: 11px; color: #93c5fd; }
.posts-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.posts-table td .ok-tag { color: var(--ok); font-weight: 600; }
.posts-table td .err-tag { color: var(--err); font-weight: 600; }

.toggle {
  position: relative; width: 40px; height: 22px; background: #334155;
  border-radius: 999px; cursor: pointer; transition: background 0.15s ease;
  display: inline-block; flex-shrink: 0;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; background: #e2e8f0; border-radius: 50%;
  transition: transform 0.15s ease;
}
.toggle.on { background: var(--ok); }
.toggle.on::after { transform: translateX(18px); }

.sync-info {
  margin-top: 8px; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-radius: 8px; background: var(--bg-2);
  border: 1px solid var(--border); display: none;
}
.sync-info.show { display: block; }
.sync-info.error { border-color: var(--err); color: #fecaca; }
.sync-info.ok { border-color: var(--ok); color: #bbf7d0; }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 600; text-transform: uppercase;
}
.badge.running { background: rgba(16,185,129,0.18); color: var(--ok); }
.badge.failed, .badge.error { background: rgba(239,68,68,0.18); color: var(--err); }
.badge.idle, .badge.pending { background: rgba(148,163,184,0.18); color: var(--muted); }
.badge.redirect { background: rgba(79,158,255,0.18); color: var(--primary); }
.badge.err { background: rgba(239,68,68,0.18); color: var(--err); }

.errors-panel {
  margin-top: 18px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
.errors-panel > summary {
  cursor: pointer; color: var(--muted); font-size: 13px;
  display: flex; align-items: center; gap: 10px;
}
.errors-panel h4 {
  margin: 14px 0 6px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); font-weight: 600;
}
.errors-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px;
}
@media (max-width: 900px) { .errors-grid { grid-template-columns: 1fr; } }

.inline-select { width: auto; min-width: 130px; padding: 4px 8px; font-size: 12px; }

.err-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.err-table th, .err-table td {
  padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: left;
  white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis;
}
.err-table th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 9px; }
.err-table td.num { text-align: right; }
.err-table td.err-msg {
  font-family: ui-monospace, monospace; white-space: normal; word-break: break-word;
  max-width: 400px;
}
.err-table td .sc {
  display: inline-block; padding: 1px 6px; border-radius: 4px; font-weight: 600;
}
.err-log-wrap { max-height: 280px; overflow: auto; }
.err-table tr:hover td { background: rgba(255,255,255,0.02); }


/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: grid; place-items: center;
  z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(640px, 92vw);
  max-height: 90vh; overflow: auto;
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13px; z-index: 100;
}
.toast[hidden] { display: none; }
.toast.error { border-color: var(--err); color: #fecaca; }
.toast.success { border-color: var(--ok); color: #bbf7d0; }
