:root {
  --bg: #07090f;
  --bg-soft: rgba(15, 19, 31, 0.78);
  --panel: rgba(13, 17, 27, 0.76);
  --panel-strong: #101522;
  --line: rgba(255, 255, 255, 0.07);
  --text: #eef2ff;
  --muted: rgba(238, 242, 255, 0.66);
  --cyan: #45f0ff;
  --amber: #ffb84d;
  --green: #7effa0;
  --red: #ff6b7d;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(69, 240, 255, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 184, 77, 0.14), transparent 24%),
    radial-gradient(circle at bottom left, rgba(126, 255, 160, 0.08), transparent 22%),
    linear-gradient(160deg, #05070b 0%, #070b12 52%, #05070b 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.45), transparent 80%);
}

.backdrop {
  position: fixed;
  width: 36rem;
  height: 36rem;
  border-radius: 999px;
  filter: blur(36px);
  opacity: 0.35;
  pointer-events: none;
}

.backdrop-a {
  top: -10rem;
  right: -10rem;
  background: rgba(69, 240, 255, 0.18);
}

.backdrop-b {
  bottom: -12rem;
  left: -12rem;
  background: rgba(255, 184, 77, 0.16);
}

.shell {
  position: relative;
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.hidden {
  display: none !important;
}

.login-card,
.panel {
  background: linear-gradient(180deg, rgba(18, 24, 39, 0.84), rgba(11, 15, 24, 0.8));
  border: 1px solid var(--line);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(16px);
}

.login-card {
  width: min(520px, 100%);
  margin: 8vh auto 0;
  border-radius: 28px;
  padding: 32px;
}

.login-mark h1,
.topbar h1 {
  margin: 10px 0 8px;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

.login-mark p,
.topbar p,
.panel-head p,
.chip,
.hint,
.status-pill {
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.form-grid,
.stack {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 8px;
}

label span {
  font-size: 0.88rem;
  color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.025);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  outline: none;
  transition: border-color 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(69, 240, 255, 0.65);
  background: rgba(255, 255, 255, 0.06);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  color: #061017;
  background: linear-gradient(135deg, #67f3ff, #d8fbff);
  box-shadow: 0 10px 24px rgba(69, 240, 255, 0.14);
}

.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.error {
  color: #ff9aa7;
  min-height: 24px;
}

.app {
  display: grid;
  gap: 22px;
  animation: rise 0.4s ease both;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 8px 2px;
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat strong {
  display: block;
  font-size: 1.45rem;
  letter-spacing: -0.06em;
  margin-top: 6px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.panel {
  border-radius: 22px;
  padding: 18px;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.panel h2,
.panel h3 {
  margin: 0 0 8px;
  letter-spacing: -0.04em;
}

.rule-actions {
  display: flex;
  align-items: center;
}

.rule-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.rule-item {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.rule-item span {
  display: block;
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.rule-item strong {
  display: block;
  margin-top: 6px;
  font-size: 0.95rem;
  line-height: 1.35;
  word-break: break-word;
}

.rule-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.rule-table {
  display: grid;
  gap: 0;
  margin-top: 16px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
}

.rule-table-head,
.rule-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr 0.8fr 0.9fr 0.8fr 1fr 0.65fr auto;
  gap: 10px;
  align-items: center;
}

.rule-table-head {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.rule-row {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.rule-row strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.rule-row span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  word-break: break-word;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.table-empty {
  padding: 16px 14px;
  color: var(--muted);
}

.control-grid,
.simulate-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.button-row,
.pairing-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.button-row .btn,
.pairing-actions .btn {
  flex: 1 1 140px;
}

.pairing-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.025);
}

.pairing-card strong {
  font-size: clamp(1.25rem, 4vw, 1.9rem);
  letter-spacing: 0.14em;
  color: var(--cyan);
  word-break: break-word;
}

.simulate-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
}

.span-2 {
  grid-column: span 2;
}

.inline {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
}

.inline input {
  width: auto;
}

.status-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.records {
  display: grid;
  gap: 0;
  margin-top: 12px;
}

.records.compact {
  max-height: 360px;
  overflow: auto;
  padding-right: 6px;
}

.record {
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: transparent;
  padding: 12px 0;
}

.records .record:first-child {
  padding-top: 0;
}

.records .record:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.record header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.record h4 {
  margin: 0;
  font-size: 0.98rem;
}

.record .meta {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
}

.tag.green { color: var(--green); }
.tag.amber { color: var(--amber); }
.tag.red { color: var(--red); }
.tag.cyan { color: var(--cyan); }

.record-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(16, 21, 34, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  max-width: min(92vw, 720px);
  text-align: center;
  z-index: 40;
}

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

@media (max-width: 1180px) {
  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .grid,
  .control-grid,
  .split,
  .simulate-grid,
  .rule-preview,
  .rule-form-grid,
  .rule-table-head,
  .rule-row {
    grid-template-columns: 1fr;
  }

  .span-2,
  .panel.wide {
    grid-column: auto;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 18px, 100%);
  }

  .login-card,
  .panel {
    border-radius: 20px;
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
