:root {
  --bg: #f2f4f5;
  --panel: #ffffff;
  --text: #111b21;
  --muted: #667781;
  --border: #e4e6eb;
  --accent: #008069;
  --accent-strong: #067a5b;
  --header-green: #008069;
  --chat-bg: #efeae2;
  --chat-pattern: radial-gradient(circle at 20% 20%, rgba(17, 27, 33, 0.03) 1px, transparent 0),
    radial-gradient(circle at 80% 0%, rgba(17, 27, 33, 0.03) 1px, transparent 0);
  --bubble-me: #d9fdd3;
  --bubble-other: #ffffff;
  --bubble-text: #111b21;
  --meta: #667781;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  --keyboard-bg: #d1d7db;
}

.theme-dark {
  --bg: #0b141a;
  --panel: #111b21;
  --text: #e9edef;
  --muted: #8696a0;
  --border: #1f2c34;
  --accent: #008069;
  --accent-strong: #128c7e;
  --header-green: #008069;
  --chat-bg: #111b21;
  --chat-pattern: none;
  --bubble-me: #005c4b;
  --bubble-other: #202c33;
  --bubble-text: #e9edef;
  --meta: #8696a0;
  --shadow: 0 14px 46px rgba(0, 0, 0, 0.5);
  --keyboard-bg: #202c33;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand .dot {
  width: 12px; height: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(0,128,105,0.18);
}
.title { font-weight: 700; }
.subtitle { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-left, 320px) 8px 1fr 8px var(--sidebar-right, 360px);
  gap: 12px;
  padding: 16px;
  height: calc(100vh - 60px);
  overflow: hidden;
  position: relative;
}
.resizer {
  width: 100%;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  position: relative;
}
.resizer::before {
  content: '';
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: rgba(102, 119, 129, 0.25);
  border-radius: 4px;
}
.resizer:hover::before,
.resizer.active::before { background: rgba(0, 128, 105, 0.6); }

.panel, .chat-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel { overflow-y: auto; }
.panel-header h2, .panel-header h3 { margin: 0; }
.panel-subtext { color: var(--muted); font-size: 13px; }
.panel-divider { margin: 14px 0; border-bottom: 1px dashed var(--border); }
.small-btn { padding: 6px 10px; }
.field { width: 100%; margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.background-controls { flex-wrap: wrap; align-items: flex-start; flex-direction: column; gap: 12px; }
.background-controls label { min-width: 140px; }
.background-controls input:disabled,
.background-controls button:disabled { opacity: 0.5; cursor: not-allowed; }
.theme-row { gap: 12px; }
.sound-row { display: flex; flex-direction: column; gap: 8px; padding: 6px 0; }
.sound-row label { gap: 10px; }

.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.space-between { justify-content: space-between; }
.align-center { align-items: center; }
.grow { flex: 1; }
.background-controls { width: 100%; }
.background-controls > * { width: 100%; }
.background-controls button { width: auto; }

label span.label { font-size: 12px; color: var(--muted); }
.label-inline { color: var(--text); font-size: 14px; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  width: 100%;
}
input[type="checkbox"], input[type="radio"] {
  width: auto;
  padding: 0;
  margin-right: 8px;
}
select { margin-bottom: 8px; padding: 6px 8px; border-radius: 6px; }
textarea { min-height: 140px; resize: vertical; }

button {
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  box-shadow: 0 10px 20px rgba(34,197,94,0.3);
}
button.ghost { background: transparent; border: 1px solid var(--border); }
button.danger { color: #ef4444; border-color: #ef4444; }
button:hover { transform: translateY(-1px); }

.participants-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.participant-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  position: relative;
}
.participant-card .event-actions { gap: 6px; }
.participant-card .event-actions button { padding: 6px 10px; }
.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--border);
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 600;
  position: relative;
}
.avatar.small { width: 28px; height: 28px; font-size: 12px; }
.avatar-edit {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}
.participant-name-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  width: 100%;
}
.participant-meta { display: flex; flex-direction: column; gap: 2px; }
.participants-panel button.primary { width: 100%; font-weight: 600; border-radius: 8px; }
.pill {
  background: var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  align-items: center;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  height: 100%;
}
.preview-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  flex-direction: column;
}
.phone-wrapper { display: flex; justify-content: center; }
.phone-frame {
  width: 390px;
  height: 760px;
  border-radius: 32px;
  overflow: hidden;
  background: #000;
  position: relative;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  border: 8px solid #000;
}
.exit-icon {
  position: fixed;
  top: 16px;
  right: 20px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  z-index: 200;
}

.wa-header {
  height: 56px;
  background: var(--header-green);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  flex-shrink: 0;
  box-sizing: border-box;
}
.wa-icon {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 0;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px 18px;
}
.wa-icon.back { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' stroke='%23fff' fill='none' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 18l-6-6 6-6'/%3E%3C/svg%3E"); }
.wa-icon.video { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' stroke='%23fff' fill='none' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='13' height='14' rx='2'/%3E%3Cpath d='M16 9l5-3v12l-5-3z'/%3E%3C/svg%3E"); }
.wa-icon.call { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' stroke='%23fff' fill='none' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 4h3l2 4-2 2c2.5 3.5 5.5 6.5 9 9l2-2 4 2v3c0 1-1 2-2 2C14 22 2 10 2 6c0-1 1-2 2-2z'/%3E%3C/svg%3E"); }
.wa-icon.more { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='5' r='1.5'/%3E%3Ccircle cx='12' cy='12' r='1.5'/%3E%3Ccircle cx='12' cy='19' r='1.5'/%3E%3C/svg%3E"); }
.wa-title { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.wa-title .group-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-title .participants-summary {
  color: rgba(255,255,255,0.8);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}
.wa-spacer { flex: 0 0 6px; }
.group-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #128c7e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
}

.chat-background {
  position: relative;
  border-radius: 0;
  background-color: var(--chat-bg);
  background-image: var(--chat-pattern);
  background-size: 360px 360px;
  overflow: hidden;
  flex: 1;
  display: flex;
}
.chat-canvas {
  flex: 1;
  padding: 12px;
  padding-bottom: 140px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.message-row { 
  display: flex; 
  gap: 6px; 
  align-items: flex-end; 
  max-width: 100%; 
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.message-row.me { justify-content: flex-end; }
.message-row.other { justify-content: flex-start; }
.message-row.followup { margin-top: -4px; }
.bubble-wrap {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}
.message-row.other .bubble-wrap { justify-content: flex-start; }
.message-row.me .bubble-wrap { justify-content: flex-end; }
.message-row.me .bubble { margin-left: 0; margin-right: 0; }
.message-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--border);
  overflow: hidden;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
  margin-bottom: 2px;
  align-self: flex-end;
}
.message-avatar.spacer { visibility: hidden; }
.bubble {
  max-width: 78%;
  width: auto;
  min-width: 72px;
  padding: 8px 10px;
  border-radius: 12px 12px 12px 2px;
  position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,0.15);
  overflow: hidden;
  margin: 6px 0;
  animation: pop 0.25s ease-out;
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  box-sizing: border-box;
  align-items: flex-start;
}
.message-row.me .bubble {
  align-items: flex-end;
}
.message-row.me .bubble-wrap .bubble {
  margin-left: auto;
  margin-right: 0;
}
.message-row.other .bubble-wrap .bubble {
  margin-left: 0;
  margin-right: auto;
}
.bubble-left { background: var(--bubble-other); color: var(--bubble-text); border-radius: 12px 12px 12px 2px; }
.bubble-right { background: var(--bubble-me); border-radius: 12px 12px 2px 12px; }
.message-row.followup .bubble { margin-top: 2px; margin-bottom: 2px; }
.sender-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
  color: #9fd6ff;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: 100%;
}
.bubble-left .sender-name { color: #3b82f6; }
.message-text {
  line-height: 1.3;
  font-size: 14px;
  color: inherit;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: none;
  overflow: visible;
  flex-shrink: 1;
  min-width: 0;
  word-spacing: normal;
  max-width: 100%;
}
.info-row {
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0;
}
.info-row::before, .info-row::after {
  content: '';
  display: inline-block;
  width: 20px;
  border-top: 1px solid var(--border);
  margin: 0 8px;
  vertical-align: middle;
}
.media-preview {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 6px;
  border: 1px solid rgba(0,0,0,0.05);
  background: rgba(0,0,0,0.02);
}
.media-preview img {
  display: block;
  width: 100%;
  height: auto;
}
.file-preview {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: rgba(0,0,0,0.04);
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.06);
}
.file-icon { font-size: 18px; }
.file-details { display: flex; flex-direction: column; }
.file-name { font-weight: 600; color: var(--text); }
.file-size { color: var(--muted); font-size: 12px; }
.media-thumb {
  width: 100%;
  max-width: 140px;
  min-height: 60px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
}
.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-size: 10px;
  color: var(--meta);
  white-space: nowrap;
  align-self: flex-end;
  flex-shrink: 0;
  overflow: visible;
  width: 100%;
}
.meta .time { font-size: 10px; }
.bubble-left .meta { color: var(--meta); }
.theme-dark .bubble-left { color: var(--bubble-text); }
.theme-dark .bubble-right { background: #0b6b57; color: #e9edef; }
.theme-dark .bubble-left .sender-name { color: #9fd6ff; }
.ticks { font-size: 11px; letter-spacing: -2px; font-family: "Segoe UI", sans-serif; transform: scaleX(1.05); }
.ticks.read { color: #53bdeb; }
.reaction-bar { display: inline-flex; gap: 6px; margin-top: 6px; align-items: center; font-size: 13px; }
@keyframes pop { 0% { transform: scale(0.95); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.typing-indicator {
  position: absolute;
  bottom: 18px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2;
}
.typing-indicator.hidden { display: none; }
.typing-bubble {
  background: var(--bubble-other);
  padding: 6px 10px;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
.typing-indicator .typing-name { color: var(--muted); font-size: 14px; }
.typing-indicator .dots span {
  display: inline-block;
  width: 6px; height: 6px;
  background: #aebac1;
  border-radius: 50%;
  animation: blink 1s infinite ease-in-out;
}
.typing-indicator .dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { transform: scale(0.6); opacity: 0.6; } 40% { transform: scale(1); opacity: 1; } }

.keyboard {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--keyboard-bg);
  color: var(--text);
  padding: 10px 10px 16px;
  transform: translateY(110%);
  transition: transform 0.3s ease;
  box-shadow: 0 -10px 24px rgba(0,0,0,0.2);
  min-height: 260px;
  z-index: 3;
}
.keyboard:not(.hidden) { transform: translateY(0); }
.keyboard.hidden { transform: translateY(110%); }
.keyboard-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border-radius: 18px;
  padding: 8px 10px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
}
.kbd-icon { font-size: 16px; }
.kbd-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.kbd-input { flex: 1; color: var(--muted); }
.kbd-icon {
  font-size: 16px;
  color: transparent;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 16px;
}
.kbd-icon.plus { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111b21' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
.kbd-icon.camera { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111b21' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h3l2-2h6l2 2h3a1 1 0 011 1v10a1 1 0 01-1 1H4a1 1 0 01-1-1V8a1 1 0 011-1z'/%3E%3Ccircle cx='12' cy='13' r='4'/%3E%3C/svg%3E"); }
.kbd-icon.mic { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111b21' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4a3 3 0 013 3v6a3 3 0 11-6 0V7a3 3 0 013-3z'/%3E%3Cpath d='M19 10v2a7 7 0 01-14 0v-2'/%3E%3Cpath d='M12 19v3'/%3E%3C/svg%3E"); }
.kbd-icon.send {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23008069' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 4l16 8-16 8 3-8-3-8z'/%3E%3Cpath d='M9 12h5'/%3E%3C/svg%3E");
}
.theme-dark .composer-icon,
.theme-dark .kbd-icon { filter: invert(1) brightness(1.4); }
.keys { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.alt-keys { display: none; flex-direction: column; gap: 6px; margin-top: 10px; }
.key-row { display: flex; gap: 6px; justify-content: center; }
.key-row span {
  background: rgba(0,0,0,0.08);
  color: var(--text);
  padding: 10px 10px;
  border-radius: 8px;
  min-width: 0;
  border: 1px solid rgba(0,0,0,0.05);
  transition: background 0.1s ease, transform 0.05s ease;
  flex: 1 1 0;
  text-align: center;
}
.key-row.condensed span { flex: 1; min-width: 0; }
.key-row span.wide { flex: 2 1 0; text-align: center; }
.key-row span.pressed {
  background: rgba(0,0,0,0.18);
  transform: translateY(1px);
}
.keyboard.lowercase .key-row span:not(.wide) {
  text-transform: lowercase;
}
.kbd-icon.send.pressed,
.composer-send.pressed {
  transform: translateY(1px);
  filter: brightness(0.9);
}
.keyboard.show-numbers .keys { display: none; }
.keyboard.show-numbers .alt-keys.numbers { display: flex; }
.keyboard.show-emojis .keys { display: none; }
.keyboard.show-emojis .alt-keys.emojis { display: flex; }

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 4;
}
.composer-input {
  flex: 1;
  min-height: 38px;
  max-height: 80px;
  padding: 10px 12px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  overflow-y: auto;
}
.composer-input:empty:before {
  content: 'Type a message';
  color: var(--muted);
  pointer-events: none;
}
.composer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.composer-icon {
  font-size: 16px;
  color: transparent;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px 18px;
}
.composer-icon.plus { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111b21' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
.composer-actions .composer-icon.camera { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111b21' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h3l2-2h6l2 2h3a1 1 0 011 1v10a1 1 0 01-1 1H4a1 1 0 01-1-1V8a1 1 0 011-1z'/%3E%3Ccircle cx='12' cy='13' r='4'/%3E%3C/svg%3E"); }
.composer-actions .composer-icon.mic { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111b21' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4a3 3 0 013 3v6a3 3 0 11-6 0V7a3 3 0 013-3z'/%3E%3Cpath d='M19 10v2a7 7 0 01-14 0v-2'/%3E%3Cpath d='M12 19v3'/%3E%3C/svg%3E"); }
.composer-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 4l16 8-16 8 3-8-3-8z'/%3E%3Cpath d='M9 12h5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 16px;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 390px;
  margin: 8px auto 0;
}
.controls button { width: auto; }
.preview-container .controls { justify-content: center; }
.status { color: var(--muted); font-size: 13px; }

.script-panel { display: flex; flex-direction: column; gap: 10px; }
.script-input { min-height: 200px; font-family: 'SFMono-Regular', Menlo, monospace; }
.warnings { color: #d97706; font-size: 12px; }
.events-list { display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 320px); overflow-y: auto; }
.help-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.92);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  padding: 20px 22px 16px;
  max-width: 540px;
  width: 92%;
  max-height: 80vh;
  z-index: 300;
  display: none;
  backdrop-filter: blur(10px);
}
.help-modal.visible { display: block; }
.help-modal h3 { margin: 0 0 6px; font-size: 18px; }
.help-modal p { margin: 0 0 10px; color: var(--muted); }
.help-modal ul { padding-left: 18px; margin: 8px 0 12px; display: grid; gap: 6px; }
.help-modal li { line-height: 1.4; }
.help-modal code { background: rgba(0,0,0,0.05); padding: 2px 6px; border-radius: 6px; }
.help-modal .help-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.help-modal button { margin: 0; }
.theme-dark .help-modal { background: rgba(17,27,33,0.95); border-color: #1f2c34; }
.theme-dark .help-modal code { background: rgba(255,255,255,0.08); }
.event-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  background: #f8f8f8;
  margin-bottom: 4px;
}
.event-card.dragging { opacity: 0.7; border-style: dashed; }
.event-body { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.event-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.event-actions .danger { padding: 8px 10px; }
.event-type { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.theme-dark .event-card { background: rgba(255,255,255,0.04); border-color: #1f2c34; }

.hidden { display: none !important; }

body.preview-only { font-size: 18px; }
body.preview-only .panel { display: none; }
body.preview-only .topbar { display: none; }
body.preview-only .layout { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh; width: 100vw; padding: 0; }
body.preview-only .chat-panel { width: 100vw; height: 100vh; background: transparent; border: none; box-shadow: none; padding: 0; gap: 0; align-items: center; position: relative; }
body.preview-only .controls { justify-content: center; position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); width: auto; max-width: none; margin: 0; z-index: 5; }
body.preview-only .resizer { display: none; }
body.preview-only .exit-icon { display: inline-flex; }
body.preview-only .preview-container { height: 100%; width: 100%; }
body.preview-only .phone-wrapper { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; }
body.preview-only .wa-title .group-name { font-size: 20px; }
body.preview-only .wa-title .participants-summary { font-size: 14px; }
body.preview-only .message-text { font-size: 22px; line-height: 1.45; }
body.preview-only .sender-name { font-size: 16px; }
body.preview-only .meta, body.preview-only .meta .time { font-size: 13px; }
body.preview-only .composer, body.preview-only .keyboard-bar { font-size: 18px; }
body.preview-only.preview-landscape .chat-panel { align-items: center; justify-content: center; }
body.preview-only.preview-landscape .phone-frame { width: 60vw; height: 60vh; flex-direction: column; border-radius: 24px; border: 6px solid #000; box-shadow: 0 12px 36px rgba(0,0,0,0.25); }
body.preview-only.preview-portrait .chat-panel { align-items: center; justify-content: center; height: auto; min-height: 100vh; }
body.preview-only.preview-portrait .phone-frame { width: min(480px, 100vw); height: 100vh; max-height: 920px; flex-direction: column; border-radius: 32px; border: 8px solid #000; box-shadow: 0 10px 40px rgba(0,0,0,0.25); }
body.preview-only.preview-portrait .controls { position: static; transform: none; margin: 8px auto 0; }
#orientationToggle { display: none; }
body.preview-only #orientationToggle { display: inline-flex; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .chat-panel { order: -1; }
}
