:root {
  --bg: #f3f0e9;
  --panel: #faf8f3;
  --paper: #ffffff;
  --ink: #1c1a17;
  --ink-2: #57524a;
  --ink-3: #8c867b;
  --line: #e6e0d4;
  --line-2: #d8d0bf;
  --accent: #e4572e;
  --accent-ink: #b8401d;
  --accent-soft: #fcebe4;
  --ok: #2f7d4f;
  --ok-soft: #e4f1e8;
  --warn: #9a6200;
  --warn-soft: #fbf1dc;
  --err: #b42318;
  --err-soft: #fde9e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(40 30 10 / 0.04), 0 6px 24px -8px rgb(40 30 10 / 0.12);
  --ui: 'Manrope Variable', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 500 14px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.i {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.i .fill {
  fill: currentColor;
  stroke: none;
}

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 650;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn-dark {
  background: var(--ink);
  color: #fff;
}

.btn-dark:hover:not(:disabled) {
  background: #36322c;
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-ink);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line-2);
  color: var(--ink);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--paper);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: 7px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.icon-btn:hover {
  background: rgb(0 0 0 / 0.05);
  color: var(--ink);
}

.icon-btn.sm {
  width: 28px;
  height: 28px;
}

.icon-btn.sm .i {
  width: 16px;
  height: 16px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Каркас ---------- */

.app {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 16px;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background:
    linear-gradient(var(--paper), var(--paper)) 8px 8px / 10px 2px no-repeat,
    linear-gradient(var(--paper), var(--paper)) 8px 13px / 7px 2px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 8px 18px / 10px 2px no-repeat,
    var(--ink);
}

.new-guide {
  justify-content: flex-start;
  margin-bottom: 12px;
}

.sidebar-label {
  padding: 0 10px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.guide-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -4px;
  padding: 0 4px;
}

.guide-item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.guide-item:hover {
  background: rgb(0 0 0 / 0.04);
}

.guide-item.active {
  background: var(--paper);
  box-shadow: inset 0 0 0 1px var(--line);
}

.guide-item-title {
  display: block;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guide-item-meta {
  display: block;
  font-size: 12px;
  color: var(--ink-3);
}

.sidebar-foot {
  padding: 10px 10px 0;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-3);
  line-height: 1.6;
}

.logout-btn {
  width: 100%;
  margin-top: 10px;
  color: var(--ink-2);
}

.logout-btn .i {
  width: 15px;
  height: 15px;
}

.main {
  min-width: 0;
  padding: 0 28px 48px;
}

.banner {
  margin: 16px 0 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 600;
  border: 1px solid rgb(154 98 0 / 0.2);
}

.banner code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
  background: rgb(255 255 255 / 0.6);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ---------- Верхня панель ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 0 14px;
}

.menu-btn {
  display: none;
}

.title-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  margin-left: -8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
}

.title-input:hover {
  border-color: var(--line);
}

.title-input:focus {
  outline: none;
  border-color: var(--line-2);
  background: var(--paper);
}

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-3);
  white-space: nowrap;
}

.save-state::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

.save-state[data-state='dirty']::before,
.save-state[data-state='saving']::before {
  background: var(--warn);
}

.save-state[data-state='error'] {
  color: var(--err);
}

.save-state[data-state='error']::before {
  background: var(--err);
}

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

/* ---------- Додавання відео ---------- */

.add-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.add-field {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink-3);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.add-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.add-field .i {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.add-field textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  line-height: 1.45;
  max-height: 140px;
  padding: 0;
}

.add-field textarea::placeholder {
  color: var(--ink-3);
}

/* ---------- Робоча область ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 24px;
  align-items: start;
}

.doc {
  min-width: 0;
}

.toolbar {
  position: sticky;
  top: 10px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 12px;
  padding: 5px;
  background: rgb(255 255 255 / 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.tb-group {
  display: flex;
  gap: 2px;
  padding-right: 4px;
  margin-right: 2px;
  border-right: 1px solid var(--line);
}

.tb-group:last-child {
  border-right: 0;
  padding-right: 0;
  margin-right: 0;
}

.toolbar button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.toolbar button:hover {
  background: rgb(0 0 0 / 0.05);
  color: var(--ink);
}

.toolbar button.ql-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.toolbar .tb-text {
  font-weight: 800;
  font-size: 12.5px;
}

.toolbar:has(~ .paper-wrap .lock:not([hidden])) {
  opacity: 0.5;
  pointer-events: none;
}

.paper-wrap {
  position: relative;
}

.paper {
  max-width: 820px;
  min-height: 70vh;
  margin: 0 auto;
  padding: 60px 72px 72px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.paper .ql-container {
  height: auto;
}

.paper .ql-editor {
  min-height: 55vh;
}

/* Редактор — це «аркуш», курсору достатньо; загальна рамка фокусу тут зайва */
.paper .ql-editor:focus,
.paper .ql-editor:focus-visible {
  outline: none;
}

.lock {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 120px;
  background: rgb(250 248 243 / 0.72);
  border-radius: 14px;
  backdrop-filter: blur(1.5px);
}

.lock-card {
  position: sticky;
  top: 120px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  max-width: 380px;
  padding: 18px 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.lock-card p {
  margin: 4px 0 0;
  color: var(--ink-2);
  font-size: 13px;
}

.spinner {
  width: 18px;
  height: 18px;
  flex: none;
  margin-top: 2px;
  border: 2px solid var(--line-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.sm {
  width: 12px;
  height: 12px;
  margin: 0;
  border-width: 1.5px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Права колонка ---------- */

.rail {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding-bottom: 8px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 14px 12px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  list-style: none;
  cursor: default;
}

summary.card-head {
  cursor: pointer;
}

summary.card-head::-webkit-details-marker {
  display: none;
}

.card-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

details[open] > .card-head {
  margin-bottom: 12px;
}

details .chev {
  color: var(--ink-3);
  transition: transform 0.15s;
}

details[open] .chev {
  transform: rotate(180deg);
}

.card > .card-head:not(summary) {
  margin-bottom: 10px;
}

.count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: var(--ink-2);
}

.sources {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.source {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.source-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.platform {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 8px;
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.platform-icon {
  display: block;
  width: 30px;
  height: 30px;
  flex: none;
}

/* У вихідному PNG кути білі, а не прозорі — ховаємо їх заокругленням */
.platform-icon.instagram {
  border-radius: 22%;
}

.platform.instagram {
  background: linear-gradient(135deg, #f9a13a, #e1306c 55%, #833ab4);
}

.platform.tiktok {
  background: #111;
  box-shadow: inset 2px 0 0 #25f4ee, inset -2px 0 0 #fe2c55;
}

.platform.youtube {
  background: #e62117;
}

.platform.other {
  background: var(--ink-2);
}

.source-info {
  flex: 1;
  min-width: 0;
}

.source-title {
  display: block;
  font-weight: 650;
  font-size: 13px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  text-decoration: none;
}

.source-title:hover {
  text-decoration: underline;
}

.source-meta {
  font-size: 12px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
}

.source-actions {
  display: flex;
  gap: 2px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--bg);
  color: var(--ink-2);
}

.chip.active {
  background: var(--warn-soft);
  color: var(--warn);
}

.chip.merged {
  background: var(--ok-soft);
  color: var(--ok);
}

.chip.error {
  background: var(--err-soft);
  color: var(--err);
}

.source-error {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--err-soft);
  color: var(--err);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.empty {
  padding: 18px 8px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}

.merge-error {
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 10px;
  background: var(--err-soft);
  color: var(--err);
  font-size: 12.5px;
}

.merge-error p {
  margin: 0 0 8px;
  word-break: break-word;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
}

.field > span {
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-2);
}

.field select,
.field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--paper);
  resize: vertical;
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
}

.versions {
  list-style: none;
  margin: 0;
  padding: 0;
}

.version {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.version:first-child {
  border-top: 0;
  padding-top: 0;
}

.version-info {
  min-width: 0;
}

.version-reason {
  font-size: 12.5px;
  font-weight: 650;
}

.version-date {
  font-size: 11.5px;
  color: var(--ink-3);
}

/* ---------- Діалог ---------- */

.dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(80vh, 900px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 64px -12px rgb(30 20 0 / 0.35);
}

.dialog[open] {
  display: flex;
  flex-direction: column;
}

.dialog::backdrop {
  background: rgb(28 26 23 / 0.4);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 12px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 800;
}

.dialog-kicker {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

.dialog-body {
  overflow-y: auto;
  padding: 8px 22px 16px;
}

.dialog-body h3 {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: 'Source Serif 4 Variable', Georgia, serif;
  font-size: 16px;
  line-height: 1.6;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 22px 18px;
  border-top: 1px solid var(--line);
}

.dialog-wide {
  width: min(820px, calc(100vw - 32px));
  max-height: min(90vh, 1000px);
}

.dialog-wide .dialog-body {
  padding-top: 16px;
}

.dialog-wide .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--paper);
  resize: vertical;
  line-height: 1.5;
}

.dialog-wide .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.prompt-text {
  font-size: 13.5px;
  background: var(--panel) !important;
}

/* ---------- Випадний список ---------- */

.dd {
  position: relative;
}

.dd-native {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.dd-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 40px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--paper);
  text-align: left;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.dd-button:hover {
  border-color: var(--ink-3);
}

.dd-button:focus-visible,
.dd.open .dd-button {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dd-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dd-chev {
  width: 16px;
  height: 16px;
  color: var(--ink-3);
  transition: transform 0.15s;
}

.dd.open .dd-chev {
  transform: rotate(180deg);
}

.dd-star {
  margin-left: 5px;
  color: var(--accent);
  font-size: 0.9em;
}

.dd-list {
  position: fixed;
  z-index: 60;
  overflow-y: auto;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px -12px rgb(30 20 0 / 0.28), 0 2px 6px rgb(30 20 0 / 0.06);
  font-size: 13.5px;
  animation: dd-in 0.12s ease-out;
}

.dd-list.up {
  animation-name: dd-in-up;
}

.dd-group + .dd-group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.dd-group-label {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.dd-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 6px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.dd-option.active {
  background: var(--bg);
}

.dd-option.selected {
  background: var(--accent-soft);
}

.dd-check {
  display: grid;
  place-items: center;
  width: 18px;
  flex: none;
  color: var(--accent-ink);
  visibility: hidden;
}

.dd-check .i {
  width: 15px;
  height: 15px;
  stroke-width: 2.4;
}

.dd-option.selected .dd-check {
  visibility: visible;
}

.dd-name {
  flex: 1;
  font-weight: 600;
}

.dd-option.selected .dd-name {
  color: var(--accent-ink);
}

.dd-meta {
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.dd-note {
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11px;
  font-weight: 700;
}

@keyframes dd-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@keyframes dd-in-up {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.summary-meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
}

details[open] .summary-meta {
  visibility: hidden;
}

.model-info {
  margin: -4px 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-2);
}

.model-info:empty {
  display: none;
}

.model-info p {
  margin: 0;
}

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

.model-tag {
  padding: 1px 8px;
  border-radius: 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-2);
}

.model-tag.rec {
  background: var(--ok-soft);
  border-color: transparent;
  color: var(--ok);
}

.model-warn {
  margin-top: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 600;
}

.model-warn code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11.5px;
}

.prompt-generate {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 0 18px;
}

.field-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.prompt-badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--bg);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 700;
}

.prompt-badge:empty {
  display: none;
}

.prompt-badge.custom {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.prompt-badge.unsaved {
  background: var(--warn-soft);
  color: var(--warn);
}

.spacer {
  flex: 1;
}

@media (max-width: 600px) {
  .prompt-generate {
    flex-direction: column;
    align-items: stretch;
  }

  .dialog-foot {
    flex-wrap: wrap;
  }
}

.dialog-confirm {
  width: min(440px, calc(100vw - 32px));
}

.dialog-confirm[open] {
  animation: ask-in 0.16s ease-out;
}

.dialog-confirm .ask-body {
  padding: 22px 22px 18px;
}

.dialog-confirm h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.dialog-confirm p {
  margin: 0;
  color: var(--ink-2);
  line-height: 1.55;
  white-space: pre-line;
}

.dialog-confirm p:empty {
  display: none;
}

.ask-input {
  width: 100%;
  margin-top: 12px;
  padding: 9px 12px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--paper);
}

.ask-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dialog-confirm .dialog-foot {
  padding: 12px 22px 16px;
  background: var(--panel);
  border-radius: 0 0 16px 16px;
}

.btn-danger {
  background: var(--err);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #8f1c13;
}

@keyframes ask-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}

/* ---------- Сповіщення ---------- */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
}

.toast {
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 12px 32px -8px rgb(0 0 0 / 0.35);
  font-size: 13.5px;
  animation: toast-in 0.2s ease-out;
}

.toast.error {
  background: var(--err);
}

.toast strong {
  display: block;
  margin-bottom: 2px;
}

.toast ul {
  margin: 6px 0 0;
  padding-left: 18px;
  color: rgb(255 255 255 / 0.82);
}

.toast-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.toast-actions button {
  height: 28px;
  padding: 0 10px;
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: 7px;
  background: transparent;
  color: #fff;
  font-weight: 650;
  font-size: 12.5px;
  cursor: pointer;
}

.toast-actions button:hover {
  background: rgb(255 255 255 / 0.1);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- Адаптивність ---------- */

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

  .rail {
    position: static;
    max-height: none;
    overflow: visible;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    align-items: start;
  }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: 0 0 40px rgb(0 0 0 / 0.2);
  }

  .sidebar.open {
    transform: none;
  }

  .menu-btn {
    display: inline-grid;
  }

  .main {
    padding: 0 16px 40px;
  }

  .title-input {
    font-size: 20px;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .topbar-actions .lbl,
  .save-state {
    display: none;
  }

  .paper {
    padding: 32px 22px 40px;
  }

  .guide {
    font-size: 17px;
  }
}
