:root {
  --bg: #f7f8ff;
  --panel: rgba(255, 255, 255, 0.92);
  --text: #0f172a;
  --muted: #64748b;
  --accent: #10b981;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --ok: #16a34a;
  --border: rgba(15, 23, 42, 0.12);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(900px 500px at 15% 0%, rgba(16,185,129,.20), transparent 60%),
              radial-gradient(900px 500px at 85% 0%, rgba(250,204,21,.18), transparent 60%),
              linear-gradient(180deg, #f8fafc, var(--bg));
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a.btn, a.btn:hover { text-decoration: none; }
a.btn:visited { color: var(--text); }
a.btn.primary:visited,
a.btn.danger:visited { color: #ffffff; }
a.btn.link:visited { color: var(--accent); }

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 26px 16px 56px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand {
  font-weight: 700;
  letter-spacing: .2px;
}
.brand small { color: var(--muted); font-weight: 500; }

.nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,0.55);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.45);
}

.card-header h1 {
  margin: 0;
  font-size: 16px;
}

.card-body {
  padding: 16px;
}

.alert {
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.alert.ok { border-color: rgba(22,163,74,.30); background: rgba(22,163,74,.08); }
.alert.err { border-color: rgba(239,68,68,.30); background: rgba(239,68,68,.08); }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.05;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 1px 0 rgba(15,23,42,0.04);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border-color 120ms ease, filter 120ms ease;
}
.btn:hover {
  background: #f8fafc;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(15,23,42,0.12);
}
.btn:active {
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(15,23,42,0.10);
}
.btn.primary { border-color: rgba(16,185,129,.35); background: linear-gradient(180deg, rgba(16,185,129,.92), rgba(34,197,94,.92)); color: #ffffff; }
.btn.primary:hover { filter: brightness(0.98); }
.btn.danger { border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.92); color: #ffffff; }
.btn.danger:hover { filter: brightness(0.98); }
.btn.link { background: transparent; border: none; padding: 0; font-weight: 600; color: var(--accent); }
.btn.link:hover { text-decoration: none; filter: brightness(0.92); }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 780px) {
  .grid { grid-template-columns: 1fr; }
}

label {
  display: block;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: 0.1px;
}
input, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.95);
  color: var(--text);
}
input::placeholder { color: rgba(15,23,42,0.35); }
select option { color: var(--text); background: #ffffff; }
input:focus, select:focus {
  outline: none;
  border-color: rgba(16,185,129,.45);
  box-shadow: 0 0 0 3px rgba(16,185,129,.18);
}

.help { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 700; text-align: left; }
td code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  word-break: break-all;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; overflow-y: hidden; border-radius: 12px; }
.table-wrap .actions { flex-wrap: nowrap; }
.actions .btn { white-space: nowrap; flex: 0 0 auto; }
.rules-table td:last-child .actions { justify-content: flex-end; }
tbody tr:hover { background: rgba(2,6,23,0.025); }

.rules-table { table-layout: fixed; }

/* Responsive-ish widths: adapt to parent width, with sane clamps */
.rules-table th:nth-child(1),
.rules-table td:nth-child(1) { width: clamp(180px, 22%, 30%); }

.rules-table th:nth-child(2),
.rules-table td:nth-child(2) { width: clamp(62px, 6%, 86px); }

.rules-table th:nth-child(4),
.rules-table td:nth-child(4) { width: clamp(260px, 32%, 42%); }

.rules-table th:last-child,
.rules-table td:last-child { width: clamp(220px, 20%, 300px); }

/* Keep action buttons visible even if table scrolls horizontally */
.rules-table th:last-child,
.rules-table td:last-child {
  position: sticky;
  right: 0;
  background: var(--panel);
  z-index: 1;
}
.rules-table th:last-child { background: rgba(255,255,255,0.85); z-index: 2; }
.rules-table td:last-child { box-shadow: -14px 0 18px rgba(15,23,42,0.08); }
tbody tr:hover td:last-child { background: rgba(255,255,255,0.95); }

/* Use ellipsis for long domain/upstream to avoid forcing horizontal scroll */
.rules-table td:nth-child(1) code,
.rules-table td:nth-child(4) code {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}

code {
  background: rgba(2,6,23,0.04);
  border: 1px solid rgba(2,6,23,0.06);
  padding: 1px 6px;
  border-radius: 8px;
}

.field { margin-bottom: 12px; }
.form-section {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(15,23,42,0.10);
  background: rgba(255,255,255,0.70);
  box-shadow: 0 1px 0 rgba(15,23,42,0.03);
  margin-bottom: 12px;
}
.form-section .field { margin-bottom: 0; }
.form-section .grid { gap: 16px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

/* Toasts */
.toast-container {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 28px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.96);
  box-shadow: 0 14px 30px rgba(15,23,42,0.14);
  animation: toast-in 160ms ease-out both;
}
.toast.ok { border-left: 5px solid rgba(16,185,129,0.95); }
.toast.err { border-left: 5px solid rgba(239,68,68,0.95); }

.toast .toast-title { font-weight: 800; font-size: 13px; margin-bottom: 2px; }
.toast .toast-msg { color: var(--text); font-size: 13px; line-height: 1.4; }
.toast .toast-close {
  appearance: none;
  border: 1px solid rgba(15,23,42,0.10);
  background: rgba(255,255,255,0.8);
  color: var(--muted);
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
  flex: 0 0 auto;
  transition: transform 120ms ease, box-shadow 120ms ease, color 120ms ease, background 120ms ease;
}
.toast .toast-close:hover {
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(15,23,42,0.10);
}
.toast.hide {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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