@custom-variant dark (&:where(.dark, .dark *));

@theme {
  --font-sans: 'Onest', ui-sans-serif, system-ui;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

:root {
  --background: 60 14% 95%;
  --foreground: 240 6% 10%;
  --card: 0 0% 100%;
  --field: 60 20% 98%;
  --muted: 60 13% 93%;
  --muted-foreground: 240 4% 41%;
  --border: 60 9% 88%;
  --input: 60 9% 86%;
  --ring: 224 71% 49%;
  --accent-color: 224 71% 49%;
  --accent-foreground: 0 0% 100%;
  --destructive: 0 62% 48%;
  --success: 148 64% 29%;
  --shadow-card: 0 1px 2px rgb(24 24 27 / .04), 0 6px 20px -8px rgb(24 24 27 / .08);
}

.dark {
  --background: 240 10% 6%;
  --foreground: 240 9% 96%;
  --card: 240 10% 10%;
  --field: 240 10% 12%;
  --muted: 240 9% 15%;
  --muted-foreground: 240 6% 64%;
  --border: 240 9% 18%;
  --input: 240 9% 22%;
  --ring: 224 100% 75%;
  --accent-color: 224 100% 75%;
  --accent-foreground: 224 65% 12%;
  --destructive: 0 83% 70%;
  --success: 145 50% 58%;
  --shadow-card: 0 1px 2px rgb(0 0 0 / .5);
}

button { cursor: pointer; }

html, body {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: 'Onest', ui-sans-serif, system-ui;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── color utilities ── */
.bg-bg        { background: hsl(var(--background)); }
.bg-card      { background: hsl(var(--card)); }
.bg-muted     { background: hsl(var(--muted)); }
.bg-accent    { background: hsl(var(--accent-color)); }
.bg-success   { background: hsl(var(--success)); }
.bg-destructive { background: hsl(var(--destructive)); }
.text-fg                { color: hsl(var(--foreground)); }
.text-muted-foreground  { color: hsl(var(--muted-foreground)); }
.text-accent            { color: hsl(var(--accent-color)); }
.text-accent-foreground { color: hsl(var(--accent-foreground)); }
.text-destructive       { color: hsl(var(--destructive)); }
.text-success           { color: hsl(var(--success)); }
.border-border      { border-color: hsl(var(--border)); }
.border-accent      { border-color: hsl(var(--accent-color)); }
.border-destructive { border-color: hsl(var(--destructive)); }

/* ── density (applied on body) ── */
body[data-density="compact"]     .step-gap  { gap: 1.25rem; }
body[data-density="compact"]     .field-gap { gap: 0.75rem; }
body[data-density="compact"]     .card-pad  { padding: 1rem; }
body[data-density="comfortable"] .step-gap  { gap: 2.25rem; }
body[data-density="comfortable"] .field-gap { gap: 1.25rem; }
body[data-density="comfortable"] .card-pad  { padding: 1.75rem; }

/* ── animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.anim-in { animation: fadeIn .35s ease-out both; }

@keyframes tickPop {
  0%   { transform: scale(0);    opacity: 0; }
  60%  { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}
.tick-pop { animation: tickPop .3s ease-out; }

@keyframes shimmer {
  0%   { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}
.skeleton {
  display: inline-block;
  background: linear-gradient(90deg, hsl(var(--muted)) 0, hsl(var(--border)) 40%, hsl(var(--muted)) 80%);
  background-size: 200px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 4px;
}
.skeleton-block { display: block; }

/* ── input ── */
.input {
  height: 2.75rem;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid hsl(var(--input));
  background: hsl(var(--field));
  padding: 0 0.875rem;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  transition: box-shadow .15s, border-color .15s, background-color .15s;
  outline: none;
  font-family: inherit;
}
.input:hover            { border-color: hsl(var(--muted-foreground) / 0.35); }
.input::placeholder     { color: hsl(var(--muted-foreground)); }
.input:focus            { border-color: hsl(var(--ring)); background: hsl(var(--card)); box-shadow: 0 0 0 4px hsl(var(--ring) / 0.14); }
.input.err              { border-color: hsl(var(--destructive)); }
.input.err:focus        { box-shadow: 0 0 0 4px hsl(var(--destructive) / 0.14); }
textarea.input          { min-height: 9rem; height: auto; padding: 0.75rem 0.875rem; line-height: 1.6; resize: vertical; }
textarea.input.textarea-lg { min-height: 14rem; }
select.input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  padding-right: 2rem;
  cursor: pointer;
}
.dark select.input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'><polyline points='6 9 12 15 18 9'/></svg>");
}

/* ── input with leading icon ── */
.input-icon-wrap { position: relative; }
.input-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}
.input.has-icon { padding-left: 2.5rem; }
.select-icon { display: inline-flex; flex: none; color: hsl(var(--muted-foreground)); }

/* ── markdown editor ── */
.md-editor {
  border: 1px solid hsl(var(--input));
  border-radius: 0.625rem;
  background: hsl(var(--field));
  overflow: hidden;
  transition: box-shadow .15s, border-color .15s;
}
.md-editor:focus-within { border-color: hsl(var(--ring)); box-shadow: 0 0 0 4px hsl(var(--ring) / 0.14); }
.md-editor.err { border-color: hsl(var(--destructive)); }
.md-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0.3125rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
}
.md-btn {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 0.4375rem;
  background: transparent;
  color: hsl(var(--foreground) / 0.8);
  transition: background .15s, color .15s;
}
.md-btn:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }
.input.md-textarea,
.input.md-textarea:focus,
.input.md-textarea:hover {
  display: block;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

/* ── button ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.5rem;
  padding: 0 1rem;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all .15s;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled                    { opacity: 0.5; cursor: not-allowed; }
.btn-primary                     { background: hsl(var(--accent-color)); color: hsl(var(--accent-foreground)); font-weight: 600; box-shadow: inset 0 1px 0 rgb(255 255 255 / .18), 0 6px 16px -6px hsl(var(--accent-color) / 0.6); }
.btn-primary:hover:not(:disabled){ filter: brightness(1.08); }
.btn-primary:active:not(:disabled){ transform: translateY(1px); }
.btn-primary:focus-visible       { outline: none; box-shadow: 0 0 0 4px hsl(var(--accent-color) / 0.3); }
.btn-outline                     { background: hsl(var(--card)); color: hsl(var(--foreground)); border-color: hsl(var(--border)); }
.btn-outline:hover:not(:disabled){ background: hsl(var(--muted)); }
.btn-ghost                       { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover:not(:disabled)  { background: hsl(var(--muted)); }
.btn-lg  { height: 3rem;    padding: 0 1.25rem;  font-size: 0.9375rem; border-radius: 0.75rem; }
.btn-sm  { height: 2rem;    padding: 0 0.75rem;  font-size: 0.8125rem; }
.btn-xs  { height: 1.75rem; padding: 0 0.625rem; font-size: 0.75rem; }

/* ── chip ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  height: 2.25rem;
  padding: 0 0.875rem;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--foreground) / 0.8);
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.chip:hover  { background: hsl(var(--muted)); color: hsl(var(--foreground)); }
.chip.active { background: hsl(var(--accent-color) / 0.08); color: hsl(var(--accent-color)); border-color: hsl(var(--accent-color) / 0.3); font-weight: 600; }

/* ── segmented (brand / geo) ── */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 0.75rem;
  background: hsl(var(--muted));
}
.segmented .chip {
  height: 2.25rem;
  min-width: 3rem;
  justify-content: center;
  border: none;
  border-radius: 0.5625rem;
  background: transparent;
  color: hsl(var(--muted-foreground));
}
.segmented .chip:hover  { color: hsl(var(--foreground)); background: hsl(var(--card) / 0.5); }
.segmented .chip.active { background: hsl(var(--card)); color: hsl(var(--foreground)); box-shadow: 0 1px 2px rgb(0 0 0 / .08), 0 0 0 1px hsl(var(--border)); }

/* ── geo flag ── */
.geo-flag {
  display: inline-block;
  flex: none;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 0 0 1px hsl(var(--foreground) / 0.12);
}
.geo-flag svg { display: block; }
.segmented .chip { gap: 0.4375rem; }

/* ── brand logo ── */
.brand-plate {
  display: inline-flex;
  align-items: center;
  flex: none;
  padding: 0 5px;
  border-radius: 4px;
  background: #0B2140;
}

/* ── kpi icon ── */
.kpi-icon {
  width: 2rem;
  height: 2rem;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 0.5625rem;
  background: hsl(var(--accent-color) / 0.1);
  color: hsl(var(--accent-color));
}

/* ── card ── */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 1rem;
  box-shadow: var(--shadow-card);
}

/* ── step header ── */
.step-num {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.5rem;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  display: inline-grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  font-weight: 600;
  flex: none;
}
.step-ok {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: 1.625rem;
  padding: 0 0.625rem;
  border-radius: 999px;
  background: hsl(var(--success) / 0.12);
  color: hsl(var(--success));
  font-size: 0.75rem;
  font-weight: 600;
}

/* ── rail ── */
.rail-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem;
  border-radius: 0.75rem;
  cursor: pointer;
  color: hsl(var(--foreground));
  transition: all .2s;
  border: none;
  text-align: left;
  width: 100%;
  font-size: 0.875rem;
  background: transparent;
  font-family: inherit;
}
.rail-item:hover                    { background: hsl(var(--muted)); }
.rail-item.active                   { background: hsl(var(--accent-color) / 0.08); }
.rail-item.active .rail-title       { font-weight: 600; }
.rail-item.active .rail-dot         { border-color: hsl(var(--accent-color)); color: hsl(var(--accent-color)); background: hsl(var(--card)); }
.rail-item.done .rail-dot           { background: hsl(var(--success) / 0.12); color: hsl(var(--success)); border-color: transparent; }
.rail-item.active.done .rail-dot    { background: hsl(var(--accent-color)); color: hsl(var(--accent-foreground)); border-color: transparent; }
.rail-dot {
  flex: none;
  width: 1.75rem;
  height: 1.75rem;
  border: 1.5px dashed hsl(var(--input));
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.6875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: hsl(var(--card));
  transition: all .25s;
}
.rail-title { font-weight: 500; line-height: 1.25; }
.rail-sub   { font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-top: 2px; }

/* ── scroll ── */
html { scroll-behavior: smooth; }
.scroll-mt-24 { scroll-margin-top: 6rem; }

/* ── template preview popup ── */
.tpl-eye { position: relative; }
.tpl-select-wrap { width: 260px; }

/* ── image preview ── */
.img-preview-wrap {
  width: 600px;
  max-width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  overflow: hidden;
}
.tpl-popup {
  position: fixed;
  width: 360px;
  max-height: 90vh;
  overflow-y: auto;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  box-shadow: 0 20px 40px rgb(0 0 0 / 0.25);
  z-index: 9999;
}
.tpl-popup-inner {
  padding: 1rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}
@media (max-width: 900px) {
  .tpl-popup { width: calc(100vw - 2rem); }
}

/* ── mini email bars ── */
.mini-email         { font-size: 0.6875rem; line-height: 1.4; color: hsl(var(--muted-foreground)); }
.mini-email .bar    { height: 6px; border-radius: 3px; background: hsl(var(--muted)); margin: 3px 0; }
.mini-email .bar.w60 { width: 60%; }
.mini-email .bar.w80 { width: 80%; }
.mini-email .bar.w40 { width: 40%; }
.stripes { background-image: repeating-linear-gradient(45deg, hsl(var(--muted)) 0 8px, hsl(var(--card)) 8px 16px); }

/* ── code block ── */
.code {
  background: #0f172a;
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.55;
  padding: 1rem 1.25rem;
  border-radius: 0.75rem;
  overflow: auto;
  max-height: 420px;
  margin: 0;
}

/* ── toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  padding: 0.625rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  opacity: 0;
  transition: all .2s;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.2);
  white-space: nowrap;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── tweaks fab ── */
.tweaks-fab {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 40;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
  cursor: pointer;
  border: none;
  transition: opacity .15s;
}
.tweaks-fab:hover { opacity: 0.85; }

/* ── tweaks panel ── */
.tweaks-panel {
  position: fixed;
  bottom: 5rem;
  right: 1.25rem;
  z-index: 40;
  width: 280px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  box-shadow: 0 20px 40px rgb(0 0 0 / 0.15);
  padding: 1rem;
}

/* ── color swatches ── */
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all .15s;
  display: inline-grid;
  place-items: center;
  background: none;
  padding: 0;
}
.swatch[data-on="true"] { border-color: hsl(var(--foreground)); }
.swatch::after { content: ""; width: 16px; height: 16px; border-radius: 999px; background: var(--c); }

/* ── focus-visible ── */
.btn:focus-visible       { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
button:focus-visible,
a:focus-visible          { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; border-radius: 4px; }

/* ── easter: night owl ── */
.night-owl {
  position: fixed;
  left: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  animation: owlIn .6s cubic-bezier(.2, .8, .3, 1.2) both;
}
.night-owl-body { background: none; border: none; padding: 0; cursor: pointer; }
.night-owl-bubble {
  margin-bottom: 2.25rem;
  max-width: 15rem;
  padding: 0.625rem 0.875rem;
  border-radius: 0.875rem 0.875rem 0.875rem 0.25rem;
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  font-size: 0.8125rem;
  line-height: 1.4;
  box-shadow: 0 10px 30px -10px rgb(0 0 0 / .35);
}
.owl-eyes { transform-box: fill-box; transform-origin: center; animation: owlBlink 4s infinite; }
@keyframes owlIn {
  from { transform: translateY(120%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes owlBlink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

@media (prefers-reduced-motion: reduce) {
  .night-owl, .owl-eyes { animation: none; }
}
/* ── custom scrollbar ── */
* {
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--muted-foreground) / 0.3) transparent;
}

/* Chrome / Edge / Safari */
*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb {
    background: hsl(var(--muted-foreground) / 0.25);
    border-radius: 4px;
    transition: background 0.15s;
    border: 2px solid transparent;
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.5);
    background-clip: padding-box;
    border: 2px solid transparent;
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* Для тёмной темы — чуть светлее */
.dark *::-webkit-scrollbar-thumb {
    background: hsl(var(--muted-foreground) / 0.3);
    background-clip: padding-box;
}

.dark *::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.55);
    background-clip: padding-box;
}

/* Для textarea и контейнера колонок — скролл внутри, а не снаружи */
textarea.input,
#columnsContainer {
    scrollbar-width: thin;
}

textarea.input::-webkit-scrollbar,
#columnsContainer::-webkit-scrollbar {
    width: 6px;
}

textarea.input::-webkit-scrollbar-thumb,
#columnsContainer::-webkit-scrollbar-thumb {
    background: hsl(var(--border));
    border-radius: 3px;
}

textarea.input::-webkit-scrollbar-thumb:hover,
#columnsContainer::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.5);
}