:root {
  --bg-0: #f4f8ff;
  --bg-1: #edf6ff;
  --bg-2: #f7fff7;
  --card: rgba(255, 255, 255, 0.88);
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(61, 95, 201, 0.18);
  --primary: #1d4ed8;
  --primary-2: #0891b2;
  --accent: #22c55e;
  --mono: "JetBrains Mono", "Consolas", monospace;
  --sans: "Space Grotesk", "Avenir", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1100px 500px at 8% -10%, rgba(59, 130, 246, 0.24), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(16, 185, 129, 0.2), transparent 60%),
    linear-gradient(155deg, var(--bg-0), var(--bg-1) 45%, var(--bg-2));
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.14);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 34;
}

body.help-focus-active::after {
  opacity: 1;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(29, 78, 216, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(29, 78, 216, 0.08) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at center, black 40%, transparent 100%);
  pointer-events: none;
  z-index: -1;
}

.container {
  width: min(980px, 94vw);
  margin: 22px auto 28px;
  display: grid;
  gap: 16px;
}

.card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  background: var(--card);
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 48px rgba(12, 41, 97, 0.08);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-toggle {
  border-radius: 10px;
  border: 1px solid rgba(29, 78, 216, 0.25);
  background: #fff;
  color: #1e3a8a;
  font-weight: 700;
  padding: 8px 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #1e3a8a;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.16), rgba(34, 211, 238, 0.18));
}

.lang-switch {
  display: inline-flex;
  gap: 6px;
}

.lang-btn {
  border: 1px solid rgba(29, 78, 216, 0.25);
  border-radius: 10px;
  background: white;
  color: #1e3a8a;
  font-weight: 700;
  padding: 8px 10px;
  min-width: 44px;
}

.lang-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  color: #fff;
  border-color: transparent;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 4.2vw, 2.4rem);
  line-height: 1.1;
  color: #0b2e75;
}

.hero p {
  margin: 0;
  max-width: 64ch;
  color: var(--muted);
}

.hero-meta {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-meta span {
  font-family: var(--mono);
  font-size: 0.77rem;
  border-radius: 999px;
  padding: 5px 10px;
  border: 1px solid rgba(14, 116, 144, 0.25);
  color: #0f766e;
  background: rgba(236, 253, 245, 0.9);
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.auth-grid h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

form {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  color: #1f3a76;
}

.help-inline {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1;
  padding: 0;
  margin-left: 6px;
  background: linear-gradient(135deg, #1d4ed8, #0891b2);
  display: inline-grid;
  place-items: center;
}

input,
textarea,
select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(30, 64, 175, 0.2);
  background: rgba(255, 255, 255, 0.9);
  font: inherit;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #1d4ed8;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.17);
}

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

button {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 120ms ease, box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(29, 78, 216, 0.24);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.lang-btn:focus-visible {
  outline: 3px solid rgba(14, 165, 233, 0.5);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

button.secondary {
  background: linear-gradient(135deg, #0f766e, var(--accent));
}

.action-grid {
  margin-top: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

pre {
  margin: 0;
  background: rgba(248, 250, 252, 0.95);
  border: 1px solid rgba(30, 64, 175, 0.14);
  color: #0f172a;
  padding: 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.45;
}

#templates {
  display: grid;
  gap: 9px;
}

.template-item {
  border: 1px solid rgba(20, 83, 45, 0.2);
  border-radius: 12px;
  padding: 11px;
  background: rgba(255, 255, 255, 0.95);
}

.template-item p {
  margin: 8px 0;
  color: #334155;
}

.template-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

#crm-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #334155;
}

.help-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100dvh;
  background: rgba(255, 255, 255, 0.96);
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 32px rgba(15, 23, 42, 0.15);
  padding: 16px;
  transform: translateX(100%);
  transition: transform 180ms ease;
  z-index: 30;
  overflow-y: auto;
}

.help-panel.is-open {
  transform: translateX(0);
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.help-header h2 {
  margin: 0;
}

.help-subtitle,
.help-panel p {
  color: var(--muted);
}

.help-actions {
  margin: 10px 0;
}

.help-search-label {
  display: grid;
  gap: 8px;
  color: #0f2f6a;
}

.help-results {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.help-item {
  border: 1px solid rgba(30, 64, 175, 0.15);
  border-radius: 12px;
  padding: 10px;
  background: rgba(247, 250, 252, 0.9);
}

.help-item h4 {
  margin: 0 0 6px;
  color: #0f2f6a;
}

.help-item p {
  margin: 0;
  color: #334155;
  font-size: 0.9rem;
}

.inline-help-popover {
  position: absolute;
  z-index: 45;
  --arrow-left: 20px;
  width: min(280px, calc(100vw - 20px));
  border-radius: 12px;
  border: 1px solid rgba(30, 64, 175, 0.22);
  background: #fff;
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.2);
  padding: 10px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px) scale(0.98);
  transform-origin: top left;
  transition: opacity 160ms ease, transform 180ms ease, visibility 0ms linear 180ms;
}

.inline-help-popover.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 160ms ease, transform 180ms ease, visibility 0ms linear 0ms;
}

.inline-help-popover.is-open.is-below {
  transform: translateY(0) scale(1);
}

.inline-help-popover.is-open.is-above {
  transform: translateY(0) scale(1);
}

.inline-help-popover.is-below {
  transform-origin: top left;
  transform: translateY(6px) scale(0.98);
}

.inline-help-popover.is-above {
  transform-origin: bottom left;
  transform: translateY(-6px) scale(0.98);
}

.inline-help-popover::before,
.inline-help-popover::after {
  content: "";
  position: absolute;
  left: var(--arrow-left);
  transform: translateX(-50%);
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
}

.inline-help-popover.is-below::before {
  top: -9px;
  border-bottom: 9px solid rgba(30, 64, 175, 0.22);
}

.inline-help-popover.is-below::after {
  top: -8px;
  border-bottom: 8px solid #fff;
}

.inline-help-popover.is-above::before {
  bottom: -9px;
  border-top: 9px solid rgba(30, 64, 175, 0.22);
}

.inline-help-popover.is-above::after {
  bottom: -8px;
  border-top: 8px solid #fff;
}

.inline-help-text {
  margin: 0;
  color: #1e293b;
  font-size: 0.87rem;
  line-height: 1.4;
}

.inline-help-close {
  margin-top: 8px;
  width: auto;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  background: linear-gradient(135deg, #0f766e, var(--accent));
}

.tour-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}

.tour-overlay.is-open {
  display: flex;
}

.tour-card {
  width: min(560px, 94vw);
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: #fff;
  padding: 16px;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.2);
}

.tour-card h3 {
  margin: 0 0 8px;
}

.tour-card p {
  margin: 0;
  color: #334155;
}

.tour-controls {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tour-highlight {
  position: relative;
  z-index: 35;
  outline: 3px solid rgba(14, 165, 233, 0.7);
  outline-offset: 3px;
  border-radius: 12px;
}

.reveal {
  animation: reveal-up 420ms ease both;
}

@keyframes reveal-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 768px) {
  .container {
    width: min(680px, 95vw);
    margin-top: 14px;
    gap: 12px;
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

  .topbar {
    position: sticky;
    top: 8px;
    z-index: 3;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .hero-meta span {
    font-size: 0.72rem;
  }

  button {
    width: 100%;
  }

  .template-row {
    flex-direction: column;
    align-items: stretch;
  }

  .help-panel {
    width: 100vw;
  }

  .tour-controls {
    display: grid;
    grid-template-columns: 1fr;
  }
}
