:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #d9dee7;
  --accent: #116466;
  --accent-dark: #0b4d4f;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
}

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

nav {
  display: flex;
  gap: 16px;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
  margin-bottom: 12px;
}

.head-actions,
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  cursor: pointer;
}

.button:hover {
  background: var(--accent-dark);
  text-decoration: none;
}

.button.secondary {
  background: #ffffff;
  color: var(--accent);
}

button.danger,
.button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #ffffff;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.compact {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 14px;
}

.table-wrap,
.panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #eef2f5;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.form {
  display: grid;
  gap: 16px;
}

.wide-form,
.panel {
  max-width: 820px;
}

.wide-form,
.panel {
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #c8d0dc;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-weight: 400;
}

textarea {
  resize: vertical;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.checks {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checks input {
  width: auto;
}

.alert,
.notice {
  max-width: 820px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 6px;
}

.alert {
  border: 1px solid #f0b5ae;
  background: #fff1f0;
  color: #8a1f17;
}

.notice {
  border: 1px solid #abefc6;
  background: #ecfdf3;
  color: #027a48;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  display: grid;
  gap: 8px;
  min-height: 160px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat-label,
.funnel-label {
  color: var(--muted);
  font-size: 14px;
}

.stat-value,
.funnel-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.15;
}

.stat-note,
.funnel-note {
  color: var(--muted);
  font-size: 13px;
}

.stats-section {
  margin-bottom: 24px;
}

.funnel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.funnel-step {
  position: relative;
  display: grid;
  gap: 8px;
  min-height: 130px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.funnel-step:not(:last-child)::after {
  content: "→";
  position: absolute;
  top: 50%;
  right: -13px;
  z-index: 1;
  width: 24px;
  height: 24px;
  transform: translateY(-50%);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--accent);
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}

.access-form-panel,
.access-table {
  margin-bottom: 20px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #eef2f5;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}

.status-pending {
  background: #fff8df;
  color: #654a06;
}

.status-active {
  background: #ecfdf3;
  color: #027a48;
}

.status-revoked {
  background: #fff1f0;
  color: #8a1f17;
}

.note-cell {
  min-width: 240px;
}

.note-form {
  display: grid;
  gap: 8px;
}

.note-form textarea {
  min-width: 220px;
  min-height: 64px;
  resize: vertical;
}

.scenario-shell {
  display: grid;
  gap: 16px;
}

.scenario-toolbar.panel {
  max-width: none;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.inline-check input {
  width: auto;
}

.hidden-input {
  display: none;
}

.status-line,
.warning-list,
.message-errors {
  padding: 10px 12px;
  border-radius: 6px;
}

.status-line {
  border: 1px solid #b8dfcc;
  background: #eefaf4;
  color: #11643b;
}

.status-line.bad,
.message-errors {
  border: 1px solid #f0b5ae;
  background: #fff1f0;
  color: #8a1f17;
}

.upload-progress {
  height: 10px;
  overflow: hidden;
  border: 1px solid #b8dfcc;
  border-radius: 999px;
  background: #e8f2ee;
}

.upload-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}

.upload-progress.indeterminate .upload-progress-bar {
  animation: upload-progress-pulse 1.1s ease-in-out infinite;
}

@keyframes upload-progress-pulse {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(260%);
  }
}

.warning-list {
  border: 1px solid #e7c469;
  background: #fff8df;
  color: #654a06;
}

.scenario-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.messages-list {
  display: grid;
  gap: 16px;
}

.messages-column {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.bottom-actions-panel.panel {
  display: grid;
  gap: 18px;
  max-width: none;
  padding: 16px;
}

.bottom-actions-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.message-card {
  display: grid;
  gap: 16px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.message-card-head,
.block-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.id-label {
  max-width: 220px;
  margin-top: 8px;
  font-size: 13px;
}

.delay-field {
  max-width: 180px;
}

.format-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.format-button {
  min-width: 38px;
  min-height: 36px;
  padding: 6px 9px;
  border-color: #c8d0dc;
  background: #ffffff;
  color: var(--text);
  line-height: 1;
}

.format-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.format-button.bold {
  font-weight: 700;
}

.format-button.italic {
  font-style: italic;
}

.format-button.underline {
  text-decoration: underline;
}

.format-button.strike {
  text-decoration: line-through;
}

.editor-block {
  display: grid;
  gap: 10px;
}

.editor-block h3 {
  margin: 0;
  font-size: 16px;
}

.media-list,
.button-list {
  display: grid;
  gap: 8px;
}

.media-row,
.media-item {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.7fr) auto;
  gap: 8px;
  align-items: center;
}

.media-item {
  grid-template-columns: 120px minmax(0, 1fr) auto;
  align-items: stretch;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.media-thumb {
  min-width: 0;
}

.media-thumb img,
.media-placeholder,
.media-audio-box {
  width: 100%;
  min-height: 92px;
  border: 1px solid #d5dce6;
  border-radius: 7px;
  background: #f8fafc;
}

.media-thumb img {
  display: block;
  height: 92px;
  object-fit: cover;
}

.media-placeholder,
.media-audio-box {
  display: grid;
  gap: 6px;
  align-content: center;
  padding: 10px;
}

.media-placeholder span,
.media-audio-box span,
.media-path {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.media-audio-box audio {
  width: 100%;
}

.media-fields {
  display: grid;
  gap: 8px;
}

.media-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.button-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 120px minmax(150px, 0.9fr) minmax(150px, 0.9fr) auto;
  gap: 8px;
  align-items: center;
}

.preview-panel.panel {
  position: sticky;
  top: 18px;
  max-width: none;
  padding: 16px;
}

.preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.preview-list {
  min-width: 0;
}

.phone-frame {
  overflow: hidden;
  border: 1px solid #ccd5e1;
  border-radius: 8px;
  background: #edf3f7;
}

.phone-bar {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 10px 14px;
  border-bottom: 1px solid #ccd5e1;
  background: #ffffff;
}

.phone-bar div {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.phone-bar strong,
.phone-bar span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phone-bar span {
  color: var(--muted);
  font-size: 13px;
}

.chat-window {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: min(68vh, 620px);
  min-height: 420px;
  overflow-y: auto;
  padding: 14px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.55)),
    #dbe8ec;
}

.chat-message {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.chat-bubble {
  display: grid;
  gap: 8px;
  width: min(100%, 280px);
  padding: 10px 12px;
  border-radius: 8px 8px 2px 8px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.preview-meta,
.preview-media,
.empty-left {
  color: var(--muted);
  font-size: 13px;
}

.preview-text {
  white-space: normal;
  overflow-wrap: anywhere;
}

.chat-buttons {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: min(100%, 280px);
}

.chat-buttons button {
  width: 100%;
  min-height: 34px;
  border-color: #c8d0dc;
  background: #ffffff;
  color: var(--accent);
}

.chat-photo {
  display: grid;
  gap: 5px;
  margin: 0;
}

.chat-photo img {
  display: block;
  width: 100%;
  max-height: 190px;
  object-fit: cover;
  border-radius: 6px;
  background: #eef2f5;
}

.chat-photo-album {
  display: grid;
  gap: 3px;
  overflow: hidden;
  border-radius: 7px;
  background: #d5dce6;
}

.chat-photo-album figure,
.chat-photo-album .chat-photo-placeholder {
  position: relative;
  min-height: 92px;
  margin: 0;
  border: 0;
  border-radius: 0;
}

.chat-photo-album img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 92px;
  object-fit: cover;
  background: #eef2f5;
}

.chat-photo-album.album-count-2,
.chat-photo-album.album-count-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chat-photo-album.album-count-3 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chat-photo-album.album-count-3 figure:first-child,
.chat-photo-album.album-count-3 .chat-photo-placeholder:first-child {
  grid-row: span 2;
}

.album-more {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.58);
  color: #ffffff;
  font-weight: 700;
  font-size: 22px;
}

.chat-photo figcaption,
.chat-photo-placeholder span,
.chat-voice span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.chat-photo-placeholder,
.chat-voice,
.preview-notice,
.preview-finish {
  border: 1px solid #d5dce6;
  border-radius: 7px;
  background: #f8fafc;
}

.chat-photo-placeholder {
  display: grid;
  gap: 3px;
  min-height: 92px;
  align-content: center;
  padding: 12px;
}

.chat-voice {
  display: grid;
  gap: 8px;
  padding: 9px;
}

.chat-voice audio {
  width: 100%;
}

.voice-wave {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
}

.voice-wave span {
  width: 5px;
  border-radius: 999px;
  background: var(--accent);
}

.voice-wave span:nth-child(1) {
  height: 12px;
}

.voice-wave span:nth-child(2) {
  height: 24px;
}

.voice-wave span:nth-child(3) {
  height: 18px;
}

.voice-wave span:nth-child(4) {
  height: 28px;
}

.preview-delay {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  color: #53606f;
  font-size: 13px;
}

.preview-delay span {
  height: 1px;
  background: #b9c5d1;
}

.preview-notice,
.preview-finish {
  justify-self: center;
  width: min(100%, 280px);
  padding: 9px 10px;
  color: #53606f;
  font-size: 13px;
  text-align: center;
}

.preview-finish {
  display: grid;
  gap: 3px;
  background: #eefaf4;
  border-color: #b8dfcc;
  color: #11643b;
}

.preview-finish span {
  color: #2d6b4b;
}

.preview-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.preview-buttons span {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 41, 51, 0.45);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  display: grid;
  gap: 14px;
  width: min(920px, 100%);
  max-height: min(760px, 92vh);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.xml-textarea {
  min-height: 420px;
  max-height: 58vh;
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  overflow: auto;
}

.mono {
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
}

.login-panel h1 {
  margin-bottom: 20px;
}

.media-form {
  grid-template-columns: 160px minmax(220px, 1fr) minmax(180px, 1fr) 120px auto;
  align-items: end;
}

@media (max-width: 820px) {
  .topbar,
  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .page {
    padding: 20px;
  }

  .grid-2,
  .stats-grid,
  .funnel,
  .media-form,
  .scenario-layout,
  .media-row,
  .media-item,
  .button-row {
    grid-template-columns: 1fr;
  }

  .funnel-step:not(:last-child)::after {
    top: auto;
    right: 50%;
    bottom: -13px;
    transform: translateX(50%) rotate(90deg);
  }

  .message-card-head,
  .block-head,
  .modal-head {
    flex-direction: column;
  }

  .preview-panel.panel {
    position: static;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .xml-textarea {
    min-height: 320px;
  }
}
