:root {
  --bg: #f3f6fb;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-2: #2563eb;
  --accent: #5b6cf7;
  --accent-soft: #e0e7ff;
  --line: #dbe4f2;
  --danger: #be123c;
  --success: #0f766e;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 10%, #dbeafe, transparent 36%),
    radial-gradient(circle at 86% 0%, #e0e7ff, transparent 32%),
    radial-gradient(circle at 95% 95%, #dbeafe, transparent 34%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
  color: var(--text);
  min-height: 100vh;
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(54px);
  z-index: 0;
  opacity: 0.28;
}

.bg-a { width: 420px; height: 420px; background: #93c5fd; top: -140px; left: -170px; }
.bg-b { width: 360px; height: 360px; background: #c4b5fd; bottom: -120px; right: -100px; }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 2rem));
  margin: 1.2rem auto 2rem;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.05rem;
  align-items: start;
}

.layout {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.05rem;
}

.workspace {
  min-width: 0;
}

.panel {
  backdrop-filter: blur(8px);
  background: var(--panel);
  border: 1px solid #eef3fb;
  box-shadow: var(--shadow);
  border-radius: 16px;
  padding: 1rem 1.15rem;
  animation: rise .4s ease-out;
}

.sidebar {
  position: sticky;
  top: 1rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(241, 245, 255, 0.92));
}

.side-nav {
  margin-top: 1rem;
  display: grid;
  gap: .45rem;
}

.side-nav .tab-btn {
  text-align: left;
  width: 100%;
}

.sidebar-foot {
  margin-top: 1rem;
  font-size: .8rem;
  color: #64748b;
  border-top: 1px solid #dbe4f2;
  padding-top: .7rem;
}

@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

h1, h2 { margin: 0 0 .5rem; letter-spacing: -0.02em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.12rem; }
p { margin: 0; color: var(--muted); }

a {
  color: #1d4ed8;
  text-decoration-color: #93c5fd;
}

a:hover {
  color: #4338ca;
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  margin-bottom: .45rem;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  padding: .28rem .62rem;
  background: #eef2ff;
  color: #4338ca;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.hero {
  background:
    linear-gradient(120deg, rgba(29, 78, 216, 0.08), rgba(91, 108, 247, 0.1) 55%, rgba(255, 255, 255, 0.75));
}

.chips {
  margin-top: .8rem;
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}

.chips span {
  border: 1px solid #d4dff1;
  border-radius: 999px;
  padding: .35rem .66rem;
  font-size: .8rem;
  color: #1e3a8a;
  background: #eff6ff;
}

.tabs {
  margin-top: .9rem;
  display: flex;
  gap: .5rem;
}

.tab-btn {
  background: #f7f9ff;
  border: 1px solid #d9e2f3;
  color: #334155;
  font-weight: 700;
}

.tab-btn.active {
  background: linear-gradient(110deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.hidden { display: none; }

.repeater-wrap {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .62rem .68rem;
  background: #f8fbff;
}

.repeater-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
  font-size: .86rem;
  color: #475569;
}

.small-inline {
  padding: .35rem .5rem;
  font-size: .82rem;
}

.repeater-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .45rem;
  margin-bottom: .4rem;
}

.repeater-row:last-child { margin-bottom: 0; }

.remove-url-btn {
  background: #fff;
  color: var(--danger);
  border: 1px solid #fda4af;
  border-radius: 8px;
  padding: .45rem .55rem;
  font-size: .8rem;
}

form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .8rem;
}

label {
  display: flex;
  flex-direction: column;
  font-size: .9rem;
  color: #475569;
  gap: .35rem;
}

label.check {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
}

input, select, button {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .65rem .7rem;
  font-size: .95rem;
}

input,
select,
textarea {
  background: #ffffff;
  color: #0f172a;
}

input:focus, select:focus {
  outline: 2px solid #bfdbfe;
  border-color: #3b82f6;
}

button {
  cursor: pointer;
  background: linear-gradient(110deg, var(--primary), var(--accent));
  color: white;
  border: none;
  font-weight: 600;
  transition: transform .15s ease, box-shadow .22s ease, filter .22s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
  filter: brightness(1.03);
}

button.ghost {
  background: white;
  color: #1e3a8a;
  border: 1px solid #c7d2fe;
}

button.ghost:hover {
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.18);
}

form button { grid-column: 1 / -1; }

.progress-wrap {
  grid-column: 1 / -1;
  display: none;
  background: #f8fbff;
  border: 1px solid #d8e4f6;
  border-radius: 12px;
  padding: .55rem .65rem;
}

.progress-wrap.visible { display: block; }
.progress-wrap.error { border-color: #fecdd3; background: #fff1f2; }

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .35rem;
  font-size: .84rem;
  color: #1e3a8a;
}

.progress-wrap.error .progress-head { color: #9f1239; }

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #dbeafe;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #5b6cf7);
  transition: width .35s ease;
}

.progress-wrap.error .progress-bar {
  background: linear-gradient(90deg, #e11d48, #fb7185);
}

.log-tail {
  grid-column: 1 / -1;
  display: none;
  margin: 0;
  padding: .6rem .7rem;
  border-radius: 12px;
  background: #0f172a;
  color: #c7d2fe;
  font-size: .78rem;
  max-height: 130px;
  overflow: auto;
  white-space: pre-wrap;
}

.log-tail.visible { display: block; }

.note { margin-top: .55rem; font-size: .84rem; }

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  margin-bottom: .7rem;
}

.actions { display: flex; gap: .45rem; }

#status {
  min-height: 1.2rem;
  color: var(--success);
  margin-bottom: .45rem;
  font-size: .9rem;
  padding: .5rem .65rem;
  border-radius: 10px;
  background: #ecfdf5;
  border: 1px solid #99f6e4;
}

#status.error {
  color: var(--danger);
  background: #fff1f2;
  border-color: #fecdd3;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

th, td {
  padding: .6rem .65rem;
  border-bottom: 1px solid #edf2fa;
  text-align: left;
  font-size: .9rem;
}

th {
  background: #f8faff;
  color: #334155;
  font-weight: 700;
}

tbody tr:nth-child(even) {
  background: #fbfdff;
}

tbody tr:hover {
  background: #f1f5ff;
}

tr:last-child td { border-bottom: none; }

.small-btn {
  background: #fff;
  color: var(--danger);
  border: 1px solid #fda4af;
  padding: .35rem .6rem;
  border-radius: 8px;
  font-size: .82rem;
}

.visual-pending {
  font-size: .8rem;
  color: #1d4ed8;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
  margin-bottom: .65rem;
}

.metric-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .75rem .85rem;
  background: linear-gradient(140deg, #ffffff, #f8faff);
}

.metric-title {
  font-size: .82rem;
  color: #64748b;
  margin-bottom: .2rem;
}

.metric-value {
  font-size: 1.02rem;
  font-weight: 700;
  color: #1e3a8a;
}

.subhead {
  margin: .55rem 0 .4rem;
  font-size: .86rem;
  font-weight: 700;
  color: #334155;
}

.mini-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.mini-table th,
.mini-table td {
  padding: .45rem .55rem;
  border-bottom: 1px solid #edf2fa;
  text-align: left;
  font-size: .84rem;
}

.mini-table th {
  background: #f8faff;
  color: #334155;
  font-weight: 700;
}

.mini-table tr:last-child td {
  border-bottom: none;
}

.rules-editor {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .7rem;
  font-family: "JetBrains Mono", "Consolas", monospace;
  font-size: .86rem;
  background: #f8faff;
  color: #1e293b;
}

.rules-panel button {
  margin-top: .6rem;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .side-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .side-nav .tab-btn {
    text-align: center;
  }

  form { grid-template-columns: 1fr; }
  .table-head { flex-direction: column; align-items: flex-start; }
  table { font-size: .82rem; display: block; overflow-x: auto; }
  .metrics-grid { grid-template-columns: 1fr; }
}
