:root {
  --bg: #07111f;
  --bg-deep: #050b14;
  --panel: rgba(10, 22, 38, 0.72);
  --panel-solid: #0c1a2c;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(52, 211, 153, 0.28);
  --text: #f1f5f9;
  --muted: #93a4bb;
  --accent: #22c55e;
  --accent-2: #34d399;
  --accent-dim: rgba(34, 197, 94, 0.14);
  --cyan: #22d3ee;
  --danger: #f43f5e;
  --danger-dim: rgba(244, 63, 94, 0.14);
  --ok-dim: rgba(52, 211, 153, 0.16);
  --shadow: 0 18px 50px rgba(2, 6, 23, 0.45);
  --radius: 18px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --space: 12px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Vazirmatn, Tahoma, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  isolation: isolate;
}
body.app { padding: 20px clamp(14px, 3vw, 40px) 72px; }
a { color: inherit; }
button, input { font: inherit; }
button { cursor: pointer; }
img, svg { display: block; }

.fx {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(900px 420px at 88% -8%, rgba(34, 197, 94, 0.16), transparent 55%),
    radial-gradient(720px 380px at -10% 108%, rgba(34, 211, 238, 0.1), transparent 50%),
    linear-gradient(180deg, #07111f 0%, #050b14 100%);
}
.fx-grid {
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.08) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 78%);
}
.fx-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(42px);
  opacity: 0.55;
  animation: drift 18s var(--ease) infinite alternate;
}
.fx-orb-a {
  width: 280px;
  height: 280px;
  top: -80px;
  left: 12%;
  background: rgba(34, 197, 94, 0.22);
}
.fx-orb-b {
  width: 340px;
  height: 340px;
  right: -80px;
  bottom: 8%;
  background: rgba(14, 165, 233, 0.16);
  animation-duration: 22s;
}
.fx-orb-c {
  width: 180px;
  height: 180px;
  left: 42%;
  bottom: -40px;
  background: rgba(52, 211, 153, 0.12);
  animation-duration: 16s;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.03em; }
h1 { font-size: 1.35rem; font-weight: 800; }
h2 { font-size: 1.02rem; font-weight: 700; }
.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-2);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-family: "Fira Code", Vazirmatn, monospace;
}
.muted { color: var(--muted); }
.mono { font-family: "Fira Code", Vazirmatn, monospace; font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; text-align: left; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.shell { width: min(1180px, 100%); margin: 0 auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.mark {
  width: 42px;
  height: 42px;
  color: var(--accent-2);
  background: linear-gradient(180deg, rgba(34, 197, 94, 0.16), rgba(34, 197, 94, 0.05));
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.mark svg { width: 22px; height: 22px; }

.topbar,
.panel,
.gate-card,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 20px;
  margin-bottom: 16px;
}
.topbar-meta { display: flex; gap: 10px; align-items: center; }

.led {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid var(--line);
}
.led i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.led.is-on i { box-shadow: 0 0 0 4px rgba(134, 239, 172, 0.18); }
.led.is-off i { box-shadow: 0 0 0 4px rgba(253, 164, 175, 0.18); }
.app-card form {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
}
.led.is-on { color: #86efac; background: var(--ok-dim); }
.led.is-off { color: #fda4af; background: var(--danger-dim); }

.subnav {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
  overflow: auto;
}
.subnav a {
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  background: rgba(8, 18, 32, 0.5);
  white-space: nowrap;
  transition: color 180ms var(--ease), border-color 180ms var(--ease), background 180ms var(--ease);
}
.subnav a:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space);
  margin-bottom: 16px;
}
.metric {
  padding: 16px;
  border-radius: var(--radius);
}
.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 8px;
}
.metric-value {
  display: block;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.04em;
}
.metric-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.bento {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--space);
  margin-bottom: 16px;
}
.panel {
  padding: 18px;
  margin-bottom: 16px;
  border-radius: 22px;
}
.panel-kicker {
  color: var(--cyan);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-family: "Fira Code", Vazirmatn, monospace;
  margin-bottom: 6px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 14px;
}
.pulse { box-shadow: 0 0 0 1px var(--line-strong), var(--shadow); }
.ip-hero {
  margin: 10px 0 16px;
  font-size: clamp(1.15rem, 2.4vw, 1.7rem);
  font-weight: 600;
  color: #ecfdf5;
}

.inline-actions,
.master-form,
.add-ip,
.stack {
  display: flex;
  gap: 10px;
}
.stack { flex-direction: column; }
.inline-actions, .master-form, .add-ip { flex-wrap: wrap; align-items: center; }
.add-ip { margin-bottom: 14px; }
.add-ip input { flex: 1; min-width: 180px; }

label { display: grid; gap: 6px; font-size: 0.88rem; color: var(--muted); }
input, input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(5, 11, 20, 0.72);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 13px;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
input::placeholder { color: #64748b; }
input:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.16);
}
.search { min-width: min(240px, 100%); }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  min-height: 44px;
  transition: transform 160ms var(--ease), background 180ms var(--ease), box-shadow 180ms var(--ease), opacity 180ms var(--ease);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.65; cursor: wait; transform: none; }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(180deg, #4ade80, var(--accent));
  color: #052e16;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.22);
}
.btn-danger { background: var(--danger); color: white; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn-tiny {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 9px;
}
.btn.is-copied { color: #86efac; border-color: var(--line-strong); }

.switch {
  width: 52px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #1e293b;
  position: relative;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px var(--line);
}
.switch-sm { width: 44px; height: 26px; min-height: 26px; }
.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e2e8f0;
  transition: transform 180ms var(--ease), background 180ms var(--ease);
}
.switch-sm .switch-knob { width: 20px; height: 20px; }
.switch.is-on { background: var(--accent); box-shadow: none; }
.switch.is-on .switch-knob {
  transform: translateX(22px);
  background: #052e16;
}
.switch-sm.is-on .switch-knob { transform: translateX(18px); }
.master-panel.is-off { border-color: rgba(244, 63, 94, 0.28); }

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 700;
}
.chip-live { background: var(--ok-dim); color: #86efac; }
.chip-off { background: var(--danger-dim); color: #fda4af; }

.banner {
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.banner-bad { background: var(--danger-dim); color: #fecdd3; border-color: rgba(244, 63, 94, 0.28); }
.banner-ok { background: var(--ok-dim); color: #bbf7d0; border-color: var(--line-strong); }
.flash { animation: rise 280ms var(--ease); }
.flash.is-leaving { opacity: 0; transform: translateY(-6px); transition: 280ms var(--ease); }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
}
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { text-align: right; padding: 11px 12px; font-size: 0.9rem; }
th {
  color: var(--muted);
  font-weight: 600;
  background: rgba(8, 18, 32, 0.7);
  position: sticky;
  top: 0;
}
td { border-top: 1px solid var(--line); }
tbody tr:hover td { background: rgba(34, 197, 94, 0.04); }
.row-actions { width: 1%; }

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}
.app-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.55);
}
.app-card.is-off { opacity: 0.7; }
.app-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--accent-dim);
  color: var(--accent-2);
  font-weight: 800;
  flex: 0 0 auto;
}
.app-card.is-off .app-mark {
  background: rgba(148, 163, 184, 0.1);
  color: var(--muted);
}
.app-copy { flex: 1; min-width: 0; }
.app-card h3 { font-size: 0.95rem; }
.app-copy p { margin: 3px 0 0; font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty {
  margin: 4px 0 0;
  padding: 18px;
  border-radius: 14px;
  border: 1px dashed var(--line);
  color: var(--muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }
.empty p { margin: 0; }
.empty-warn {
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
  color: #fde68a;
}
.empty-warn strong { color: #fef3c7; }

body.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
  align-items: stretch;
}
.gate-side {
  padding: 28px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.gate-side h1 { font-size: clamp(1.7rem, 3vw, 2.3rem); margin: 18px 0 12px; }
.lede { color: var(--muted); line-height: 1.95; margin: 0 0 18px; }
.gate-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.gate-points li {
  display: flex;
  gap: 10px;
  align-items: center;
  color: #dbe7f3;
  font-weight: 500;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 5px var(--accent-dim);
  flex: 0 0 auto;
}
.gate-card {
  border-radius: 26px;
  padding: 28px 24px;
}
.gate-card h2 { margin-bottom: 6px; }

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(24px, -18px, 0) scale(1.08); }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 960px) {
  .metrics, .bento, .gate { grid-template-columns: 1fr; }
  .gate-side { padding: 8px 4px 0; }
}
@media (max-width: 720px) {
  .topbar, .panel-head, .master-form { flex-direction: column; align-items: stretch; }
  .add-ip { flex-direction: column; }
  .metrics { grid-template-columns: 1fr 1fr; }
  body.app { padding-top: 12px; }
}
@media (max-width: 520px) {
  .metrics { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .fx-orb, .flash, .btn, .switch-knob, .subnav a { animation: none; transition: none; }
}
