:root {
  --bg: #fff;
  --text: #111;
  --muted: #666;
  --border: #e5e5e5;
  --accent: #111;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 15px;
}

a {
  color: var(--accent);
}

header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  background: #fafafa;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

input[type='text'],
input[type='password'],
textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  background: #fff;
}

textarea {
  min-height: 120px;
  font-family: inherit;
  font-size: 15px;
}

.menu-json-textarea {
  min-height: 320px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

button,
.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}

button.primary,
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.danger,
.btn.danger {
  color: #b42318;
  border-color: rgba(180, 35, 24, 0.45);
  background: #fff5f5;
}

button.danger:hover,
.btn.danger:hover {
  background: #ffe8e8;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}

.row > div {
  flex: 1;
  min-width: 140px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 500;
}

.msg {
  padding: 0.5rem 0;
  font-size: 14px;
}

.msg.err {
  color: #b00020;
}

.hidden {
  display: none !important;
}

.tags {
  font-size: 13px;
  color: var(--muted);
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* ——— Меню бота: форма ——— */
.menu-intro {
  margin-top: 0;
  margin-bottom: 1rem;
  max-width: 52rem;
}

#menu-panel-form {
  position: relative;
}

.menu-panel-body {
  animation: menuFade 0.15s ease;
}

@keyframes menuFade {
  from {
    opacity: 0.6;
  }
  to {
    opacity: 1;
  }
}

.menu-section {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.menu-section:last-of-type {
  border-bottom: none;
}

.menu-section h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}

.menu-section .hint,
.menu-panel .hint {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
  max-width: 48rem;
  line-height: 1.4;
}

.menu-section .field {
  margin-bottom: 0.75rem;
}

.menu-actions {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.tg-kb-row-block {
  margin-bottom: 6px;
}

.tg-kb-row-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.tg-kb-add-row {
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0 0.35rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: #f8f8f8;
  font-size: 1.1rem;
  line-height: 1;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

.tg-kb-add-row:hover {
  background: #f0f0f0;
  border-style: solid;
}

.tg-kb-row-append {
  display: flex;
  justify-content: center;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed rgba(0, 0, 0, 0.08);
}

.tg-kb-add-row--end {
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  height: auto;
  min-width: auto;
}

/* ——— Общая панель HTML над каруселью ——— */
.menu-fmt-global {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  max-width: 460px;
  margin: 0 auto 0.65rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}

.menu-fmt-global-hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin-right: 2px;
}

.menu-fmt-toolbar-hint {
  max-width: 460px;
  margin: 0 auto 0.75rem;
  padding: 0 4px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--muted);
}

/* ——— Карусель экранов меню ——— */
.menu-carousel-ui {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) 2rem;
  align-items: stretch;
  gap: 0.25rem;
  max-width: 460px;
  margin: 0 auto;
}

.menu-car-arrow {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  padding: 0 0.15rem;
}

.menu-car-arrow:hover {
  background: #eee;
}

.menu-car-arrow:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.menu-carousel-viewport {
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}

.menu-carousel-track {
  display: flex;
  flex-direction: row;
}

.menu-slide {
  flex-shrink: 0;
  scroll-snap-align: start;
  box-sizing: border-box;
  padding: 0 2px 8px;
}

.menu-slide-heading {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
}

.menu-carousel-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.menu-carousel-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.menu-dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #ccc;
  cursor: pointer;
}

.menu-dot.active {
  background: var(--accent);
}

.menu-modes-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.menu-json-details {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.menu-json-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.9rem;
}

.tg-slide-caption {
  margin: 0 0 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.tg-bubble--wide {
  width: 100%;
}

.tg-bubble-text--solo {
  min-height: 7rem;
}

.tg-keyboard--single {
  margin-top: 8px;
}

.tg-dna-unified {
  margin: 10px 0 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 8px;
}

.tg-dna-unified label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.8rem;
  color: rgba(0, 0, 0, 0.65);
  font-weight: 600;
}

.tg-dna-unified input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  padding: 10px 8px;
  font-size: 15px;
  text-align: center;
  background: rgba(255, 255, 255, 0.95);
}

.tg-dna-hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: rgba(0, 0, 0, 0.55);
}

.tg-preview-shell {
  max-width: 420px;
  margin: 0 auto 1rem;
}

.tg-preview {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

.tg-chat-bg {
  background: linear-gradient(180deg, #6c9fc4 0%, #7aaccc 40%, #8eb8d4 100%);
  padding: 12px 10px 14px;
  min-height: 200px;
}

.tg-bubble-outer {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 10px;
}

.tg-bubble {
  max-width: 100%;
  width: 100%;
  background: #fff;
  border-radius: 12px 12px 12px 4px;
  padding: 8px 10px 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.tg-bubble-title {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.35;
  color: #000;
  padding: 2px 0;
  margin-bottom: 4px;
  font-family: inherit;
}

.tg-bubble-title:focus {
  outline: 1px dashed var(--accent);
  outline-offset: 2px;
}

.tg-bubble-text {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  resize: vertical;
  min-height: 3.2em;
  font-size: 15px;
  line-height: 1.4;
  color: #000;
  padding: 0;
  font-family: inherit;
}

.tg-bubble-text:focus {
  outline: 1px dashed var(--accent);
  outline-offset: 2px;
}

.menu-fmt-editor {
  width: 100%;
}

.menu-fmt-view {
  display: block;
  width: 100%;
  cursor: text;
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  min-height: 3.2em;
}

.menu-fmt-editor .tg-bubble-text--solo.menu-fmt-view {
  min-height: 7rem;
}

.menu-fmt-view:focus {
  outline: 1px dashed var(--accent);
  outline-offset: 2px;
}

.menu-fmt-view[data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: #8e8e93;
  pointer-events: none;
}

.menu-fmt-view tg-spoiler {
  background: linear-gradient(180deg, rgba(220, 38, 38, 0.14), rgba(220, 38, 38, 0.08));
  border: 1px solid rgba(220, 38, 38, 0.28);
  border-radius: 4px;
  padding: 1px 4px;
  color: inherit;
}

.menu-fmt-view code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  color: #1565c0;
  background: rgba(21, 101, 192, 0.09);
  border: 1px solid rgba(21, 101, 192, 0.2);
  padding: 0 4px;
  border-radius: 4px;
}

.tg-bubble-meta,
.tg-bubble-time {
  text-align: right;
  font-size: 12px;
  color: #8e8e93;
  margin-top: 2px;
  user-select: none;
}

.tg-keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  margin: 0;
}

.tg-kb-row {
  display: flex;
  flex-direction: row;
  gap: 6px;
  width: 100%;
  min-height: 0;
}

.tg-kb-row:empty {
  min-height: 40px;
  border: 1px dashed rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.35);
}

.tg-kb-cell {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
}

.tg-kb-cell-inner {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}

.tg-kb-drag-handle {
  flex-shrink: 0;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.06);
  cursor: grab;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--muted);
}

.tg-kb-drag-handle:active {
  cursor: grabbing;
}

.fmt-btn {
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--text);
}

.fmt-btn:hover {
  background: #f5f5f5;
}

.menu-fmt-global .fmt-btn {
  min-width: 1.6rem;
  font-weight: 600;
}

.tg-kb-cell-inner .tg-kb-inp {
  flex: 1 1 0;
  min-width: 0;
}

.tg-kb-inp {
  width: 100%;
  box-sizing: border-box;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px 8px;
  font-size: 15px;
  line-height: 1.25;
  text-align: center;
  color: #000;
  font-family: inherit;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
}

.tg-kb-inp:focus {
  outline: 2px solid rgba(255, 255, 255, 0.9);
  outline-offset: 1px;
  background: #fff;
}

.menu-mode-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.menu-mode-name {
  min-width: 8rem;
  font-size: 0.9rem;
}

.menu-mode-select {
  flex: 1;
  min-width: 12rem;
  max-width: 20rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
}
