:root {
  --bg: #efeee9;
  --paper: #faf9f6;
  --ink: #111110;
  --soft: #6a675f;
  --line: #d8d4cb;
  --fill: #ffffff;
  --accent: #204e3b;
  --accent-hover: #16382b;
  --danger: #8b2e2e;
  --code-bg: #141413;
  --code-fg: #e7e3da;
  --shadow: 0 20px 60px rgba(17, 17, 16, .08);
  --r: 20px;
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
[hidden] { display: none !important; }
dialog:not([open]) { display: none !important; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  background:
    linear-gradient(180deg, #f4f3ee 0%, var(--bg) 45%, #e9e7e0 100%);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--mono); font-size: .92em; }

.wrap {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 36px 0 64px;
  display: grid;
  gap: 22px;
}

.hero {
  display: grid;
  gap: 10px;
  padding: 8px 2px 2px;
}
.hero .eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--soft);
}
.hero h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 550;
  font-size: clamp(40px, 7vw, 64px);
  letter-spacing: -.03em;
  line-height: .95;
}
.hero p {
  margin: 0;
  max-width: 46ch;
  color: var(--soft);
  font-size: 15px;
  line-height: 1.5;
}

.board {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: calc(var(--r) + 4px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.steps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--line);
}
.steps.steps-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.step {
  padding: 22px 22px 18px;
  display: grid;
  gap: 12px;
  align-content: start;
}
.step + .step { border-left: 1px solid var(--line); }
.locale-step {
  padding: 16px 22px 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 70%, #eef6f1);
  display: grid;
  gap: 10px;
}
.locale-step h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--soft);
  font-weight: 600;
}
.pill-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  font-size: 10px;
  font-weight: 700;
}
.pill.on .pill-count { background: rgba(255,255,255,.22); }
.system-locale-row {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}
.step h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--soft);
  font-weight: 600;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill {
  border: 1px solid var(--line);
  background: var(--fill);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  transition: .15s ease;
}
.pill:hover { border-color: #bdb7aa; }
.pill.on {
  background: var(--ink);
  border-color: var(--ink);
  color: #f6f4ee;
}

.fields {
  padding: 20px 22px;
  display: grid;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 80%, white);
}
.fields-top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.fields-top .about {
  margin: 0;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.45;
  max-width: 52ch;
}
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.field {
  display: grid;
  gap: 6px;
}
.field.full { grid-column: 1 / -1; }
.field label {
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--soft);
  font-weight: 600;
}
.field input, .field select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--fill);
  border-radius: 12px;
  padding: 12px 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 78, 59, .14);
}
.note {
  margin: 0;
  font-size: 12px;
  color: var(--soft);
  line-height: 1.4;
}
.err {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.btn {
  border: 1px solid var(--line);
  background: var(--fill);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 600;
  transition: .15s ease;
}
.btn:hover { border-color: #b7b0a3; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.main {
  background: var(--accent);
  border-color: var(--accent);
  color: #f3fff8;
}
.btn.main:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; }

.result {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 360px;
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: #1a1917;
  border-bottom: 1px solid #2c2b28;
}
.toolbar .file {
  font-family: var(--mono);
  font-size: 11px;
  color: #9e998e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toolbar .actions .btn {
  background: #262521;
  border-color: #3a3832;
  color: #f0ebe1;
  padding: 8px 12px;
}
.toolbar .actions .btn.main {
  background: var(--accent);
  border-color: var(--accent);
  color: #f3fff8;
}
.toolbar .actions .btn:hover { border-color: #58544c; }

pre#out {
  margin: 0;
  padding: 16px 18px 22px;
  background: var(--code-bg);
  color: var(--code-fg);
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  min-height: 320px;
}
pre#out:empty::before {
  content: 'Нажми «Сгенерировать», чтобы получить готовый скрипт.';
  color: #7d796f;
}

/* Preview layer */
.preview-layer {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  background: rgba(17, 17, 16, .55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 18px;
}
.preview-layer.open { display: grid !important; }
.preview-layer[hidden] { display: none !important; }
.preview-frame {
  width: min(1100px, 100%);
  height: min(860px, 100%);
  margin: auto;
  border: 0;
  border-radius: 16px;
  background: #e8eaed;
  box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.preview-close {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 2;
  border: 0;
  background: #111;
  color: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
}

.bulk-pad {
  border-top: 1px solid var(--line);
  background:
    radial-gradient(1200px 400px at 10% 0%, rgba(32,78,59,.08), transparent 60%),
    #f3f1ea;
}
.bulk-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}
.bulk-head .block-title { margin-bottom: 6px; }
.bulk-badge {
  flex: none;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.7);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}
.bulk-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(17,17,16,.04);
  display: grid;
  gap: 14px;
}
.dropzone-multi {
  min-height: 140px;
  display: grid;
  place-content: center;
  gap: 4px;
  background:
    linear-gradient(180deg, #fbfaf7, #f4f2ec);
}
.dropzone-icon {
  width: 42px;
  height: 42px;
  margin: 0 auto 8px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #f6f4ee;
  font-size: 18px;
  font-weight: 700;
}
.bulk-table .bulk-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(200px, 260px);
  gap: 12px;
  align-items: center;
  cursor: pointer;
}
.bulk-table .bulk-row.on {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(32, 78, 59, .12);
}
.bulk-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.bulk-main strong, .bulk-main .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bulk-check { display: flex !important; align-items: center; margin: 0; }
.bulk-locale {
  display: grid !important;
  gap: 4px;
  margin: 0;
}
.bulk-locale span {
  font-size: 10px !important;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--soft);
}
.bulk-locale select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--fill);
}
.bulk-toolbar { margin: 0; }

.library-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  min-height: 720px;
}
.library-side {
  border-right: 1px solid var(--line);
  background: #f4f2ec;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}
.library-filters {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}
.library-filters input,
.library-filters select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--fill);
}
.library-list {
  overflow: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lib-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 14px;
  padding: 12px 12px;
  display: grid;
  gap: 6px;
}
.lib-item:hover {
  background: rgba(255,255,255,.72);
  border-color: var(--line);
}
.lib-item.on {
  background: var(--fill);
  border-color: var(--line);
  box-shadow: 0 8px 20px rgba(17,17,16,.05);
}
.lib-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.lib-chip {
  flex: none;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8f0eb;
  color: var(--accent);
}
.library-editor {
  min-width: 0;
  background: var(--paper);
}
.library-empty {
  height: 100%;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 40px;
  text-align: center;
}
.library-empty h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 28px;
  font-weight: 550;
}
.library-empty p {
  margin: 0;
  color: var(--soft);
  max-width: 42ch;
}
.library-form {
  padding: 18px 20px 28px;
  gap: 14px;
}
.library-editor-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  flex-wrap: wrap;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.library-editor-head h3 {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: 28px;
  font-weight: 550;
}

@media (max-width: 820px) {
  .bulk-table .bulk-row {
    grid-template-columns: auto 1fr;
  }
  .bulk-locale { grid-column: 1 / -1; }
  .library-layout { grid-template-columns: 1fr; }
  .library-side {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 360px;
  }
}

@media (max-width: 820px) {
  .steps, .steps.steps-3 { grid-template-columns: 1fr; }
  .step + .step { border-left: 0; border-top: 1px solid var(--line); }
  .grid { grid-template-columns: 1fr; }
}

/* Auth */
body.is-login #app { display: none !important; }
body.is-authed #login-screen { display: none !important; }
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: calc(var(--r) + 4px);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  display: grid;
  gap: 10px;
}
.auth-card h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 42px;
  letter-spacing: -.03em;
  line-height: 1;
}
.auth-lead { margin: 0 0 8px; color: var(--soft); font-size: 14px; line-height: 1.5; }
.auth-form, .admin-form {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}
.auth-form label, .admin-form label { display: grid; gap: 6px; }
.auth-form label span, .admin-form label span {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--soft);
}
.auth-form input, .admin-form input, .admin-form select {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--fill);
}

.row-hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  flex-wrap: wrap;
}
.userbar, .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--soft); font-size: 13px; }
.pad { padding: 22px; }
.block-title {
  margin: 0 0 14px;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--soft);
  font-weight: 600;
}
.table { display: grid; gap: 8px; }
.table .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--fill);
}
.table .row .muted {
  margin-left: 10px;
  font-size: 12px;
}
.btn.danger { color: var(--danger); }
a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.audit {
  margin: 0;
  max-height: 280px;
  overflow: auto;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}
#pass-gate:not([hidden]) {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
}

/* Top navigation */
.top-tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.58);
}
.top-tab {
  border: 0;
  background: transparent;
  color: var(--soft);
  border-radius: 999px;
  padding: 10px 15px;
  font-size: 13px;
  font-weight: 700;
}
.top-tab.on { background: var(--ink); color: #f8f6ef; }
.view[hidden] { display: none !important; }
.view.on { display: block; }

/* System scripts */
.scripts-board { overflow: hidden; }
.scripts-intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}
.scripts-intro h2 { margin: 4px 0 6px; font-family: var(--display); font-size: 34px; font-weight: 550; }
.scripts-intro p:not(.eyebrow) { margin: 0; max-width: 66ch; color: var(--soft); font-size: 13px; line-height: 1.55; }
.safety-chip { white-space: nowrap; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--soft); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.script-layout { display: grid; grid-template-columns: minmax(250px, 330px) minmax(0, 1fr); min-height: 620px; }
.script-list { padding: 14px; border-right: 1px solid var(--line); background: #f4f2ec; display: flex; flex-direction: column; gap: 9px; }
.script-card { width: 100%; text-align: left; border: 1px solid transparent; background: transparent; border-radius: 16px; padding: 14px; display: grid; gap: 6px; transition: .15s ease; }
.script-card:hover { background: rgba(255,255,255,.72); border-color: var(--line); }
.script-card.on { background: var(--fill); border-color: var(--line); box-shadow: 0 8px 24px rgba(17,17,16,.05); }
.script-card-group, .script-group { color: var(--accent); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; font-weight: 800; }
.script-card strong { font-size: 14px; }
.script-card > span:last-child { color: var(--soft); font-size: 11px; line-height: 1.45; }
.script-reader { min-width: 0; display: grid; grid-template-rows: auto auto 1fr auto; background: var(--paper); }
.script-reader-head { padding: 20px 22px; display: flex; justify-content: space-between; align-items: start; gap: 18px; border-bottom: 1px solid var(--line); }
.script-reader-head h3 { margin: 4px 0 5px; font-size: 20px; }
.script-reader-head p { margin: 0; max-width: 65ch; color: var(--soft); font-size: 12px; line-height: 1.5; }
.warning-box { margin: 14px 18px 0; padding: 11px 13px; border: 1px solid #e4d7b9; border-radius: 12px; background: #fff9ec; color: #6e5520; font-size: 12px; line-height: 1.45; }
.system-code { margin: 14px 18px 18px; min-height: 430px; max-height: 580px; overflow: auto; padding: 16px 18px; border-radius: 16px; background: var(--code-bg); color: var(--code-fg); font-family: var(--mono); font-size: 11.5px; line-height: 1.55; white-space: pre; }
.copy-status { min-height: 20px; margin: -8px 20px 14px; color: var(--accent); font-size: 12px; }

@media (max-width: 820px) {
  .row-hero { align-items: start; }
  .top-tabs { width: 100%; }
  .top-tab { flex: 1; }
  .scripts-intro { align-items: start; flex-direction: column; }
  .script-layout { grid-template-columns: 1fr; }
  .script-list { border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr; }
  .script-reader-head { flex-direction: column; }
  .system-code { min-height: 360px; }
}

.hero-side {
  display: grid;
  gap: 12px;
  justify-items: end;
}
.meta-line {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--soft);
  letter-spacing: .04em;
}
.admin-board { overflow: hidden; }
.admin-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f4f2ec;
}
.admin-tab {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--soft);
}
.admin-tab.on {
  background: var(--fill);
  border-color: var(--line);
  color: var(--ink);
}
.admin-panel[hidden] { display: none !important; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.admin-form-actions { display: flex; align-items: end; }
.admin-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--fill);
  resize: vertical;
}
.admin-form textarea.code-area {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  min-height: 220px;
}
.publish-row {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f7f5ef;
}
.check {
  display: flex !important;
  align-items: center;
  gap: 10px;
  grid-template-columns: none !important;
}
.check span {
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 13px !important;
  color: var(--ink) !important;
}
dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
  width: min(420px, calc(100% - 32px));
}
dialog::backdrop { background: rgba(17,17,16,.45); }
dialog h3 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: 24px;
  font-weight: 550;
}
.dropzone {
  position: relative;
  border: 1.5px dashed var(--line);
  border-radius: 16px;
  background: #f7f5ef;
  padding: 22px 18px;
  text-align: center;
  cursor: pointer;
  transition: .15s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: #eef6f1;
}
.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dropzone p { margin: 0; font-size: 13px; }
.dropzone .muted { margin-top: 8px; }
.field-caption {
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--soft);
  font-weight: 600;
}

@media (max-width: 820px) {
  .hero-side { justify-items: stretch; width: 100%; }
  .userbar { justify-content: space-between; }
  .admin-grid { grid-template-columns: 1fr; }
  .table .row { flex-direction: column; align-items: stretch; }
}
