:root {
  --teal: #196774;
  --teal-dark: #0f4a54;
  --teal-darker: #0b3940;
  --teal-50: #eaf4f5;
  --teal-100: #d7e9eb;
  --teal-200: #bcdadd;
  --ink: #15262a;
  --ink-soft: #5c757c;
  --ink-soft-2: #98afb6;
  --line: #dbe9ea;
  --surface: #ffffff;
  --bg: #f2f8f8;
  --wa: #25d366;
  --wa-dark: #1ea952;
  --bubble: #e3f8db;
  --danger: #d8553f;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm:
    0 1px 2px rgba(15, 53, 60, 0.07), 0 1px 1px rgba(15, 53, 60, 0.05);
  --shadow-md: 0 10px 28px -10px rgba(15, 53, 60, 0.22);
  --font-ui: "Manrope", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --header-h: 56px;
  --footer-h: 68px;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;

  background: #f5f5f5;
  background-image: url("images/whatsapp-back_25.png");
}

button {
  font-family: inherit;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- App shell ---------- */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1180px;
  margin: 0 auto;
  background: var(--bg);
}

.appbar {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.appbar svg {
    display: inline-block;
    transform: translateY(-1px);
    width: 24px;
    height: 24px;
    fill: var(--ink-soft-2);
}


.appbar-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.appbar-back:hover {
  color: var(--teal);
}
.appbar h1 {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  color: var(--teal);
  margin: 0;
  flex: 1;
  text-align: center;
}
.help-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--teal-200);
  background: var(--teal-100);
  color: var(--teal);
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
}
.help-btn:active {
  transform: scale(0.93);
}

.install-btn {
  height: 32px;
  flex: 0 0 auto;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 16px;
  border: 1px solid var(--teal-200);
  background: var(--teal-50);
  color: var(--teal-darker);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.install-btn[hidden] {
  display: none;
}
.install-btn:active {
  transform: scale(0.94);
}
.install-btn .tb-label {
  display: none;
}
@media (min-width: 560px) {
  .install-btn .tb-label {
    display: inline;
  }
}

/* ---------- Toolbar ---------- */
.toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: var(--header-h);
  z-index: 19;
}
.tb-btn {
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--teal-50);
  color: var(--teal-darker);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.12s ease,
    transform 0.08s ease;
}
.tb-btn:hover {
  background: var(--teal-100);
}
.tb-btn:active {
  transform: scale(0.93);
}
.tb-btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}
.tb-btn b {
  font-weight: 800;
}
.tb-btn i {
  font-style: italic;
}
.tb-btn s {
  text-decoration: line-through;
}
.tb-btn .mono {
  font-family: "Courier New", monospace;
  font-weight: 700;
}
.tb-btn.emoji-trigger,
.tb-btn.tpl-trigger {
  background: var(--teal-50);
  font-size: 16px;
}
.tb-divider {
  width: 1px;
  height: 24px;
  background: var(--line);
  margin: 0 4px;
}
.tb-label {
  display: none;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 12.5px;
}

/* ---------- Layout: editor + preview ---------- */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 14px 0;
  gap: 12px;
}

.editor-col {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.editor-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--teal-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
#editor {
  width: 100%;
  min-height: 30vh;
  max-height: 38vh;
  resize: vertical;
  border: none;
  outline: none;
  background: transparent;
  padding: 14px;
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.5;
  color: var(--ink);
  border-radius: var(--radius-md);
}
#editor::placeholder {
  color: #9bb0b4;
  font-style: italic;
}
.editor-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px 9px;
  font-size: 12px;
  color: var(--ink-soft);
}
.text-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 6px;
}
.text-btn:hover {
  color: var(--danger);
  background: #fdecea;
}

.ad-slot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 62px;
  padding: 6px 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.ad-mobile-only {
  display: flex;
}

/* ---------- Preview (central focus) ---------- */
.preview-col {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px 6px;
}
.preview-header span:first-child {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--teal);
}
.preview-header .muted {
  font-size: 11.5px;
  color: var(--ink-soft);
}

.chat-mock {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  background:
    radial-gradient(
      circle at 20% 10%,
      rgba(25, 103, 116, 0.05),
      transparent 40%
    ),
    linear-gradient(180deg, #eef4f2, #e7efec);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.chat-bubble {
  margin-left: auto;
  max-width: 92%;
  background: var(--bubble);
  border-radius: 14px 14px 4px 14px;
  padding: 10px 12px 18px;
  box-shadow: var(--shadow-sm);
  font-size: 15px;
  line-height: 1.45;
  color: #1d2e23;
  position: relative;
  word-wrap: break-word;
}
.chat-bubble p {
  margin: 0 0 4px;
}
.chat-bubble p:last-child {
  margin-bottom: 0;
}
.chat-bubble ul,
.chat-bubble ol {
  margin: 4px 0;
  padding-left: 20px;
}
.chat-bubble li {
  margin: 2px 0;
}
.chat-bubble blockquote {
  margin: 6px 0;
  padding: 4px 10px;
  border-left: 3px solid var(--wa-dark);
  background: rgba(37, 211, 102, 0.08);
  border-radius: 4px;
  color: #2b3a32;
}
.chat-bubble code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 0.92em;
}
.chat-bubble .placeholder {
  color: #7c958d;
  font-style: italic;
}
.chat-time {
  position: absolute;
  right: 10px;
  bottom: 6px;
  font-size: 10.5px;
  color: #5c8a6c;
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ---------- Bottom action bar ---------- */
.actionbar {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.btn {
  flex: 1;
  height: 46px;
  border-radius: var(--radius-md);
  border: none;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    transform 0.08s ease,
    filter 0.12s ease;
}
.btn:active {
  transform: scale(0.97);
}
.btn-outline {
  background: var(--teal-50);
  color: var(--teal-darker);
  border: 1px solid var(--teal-200);
  flex: 0.85;
}
.btn-outline:hover {
  background: var(--teal-100);
}
.btn-primary {
  background: var(--wa);
  color: #fff;
  flex: 1.3;
  box-shadow: 0 6px 16px -4px rgba(37, 211, 102, 0.55);
}
.btn-primary:hover {
  background: var(--wa-dark);
}

/* ---------- Sheets (emoji / templates) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 42, 48, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 40;
}
.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow-md);
  transform: translateY(100%);
  transition: transform 0.22s ease;
  z-index: 41;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}
.sheet.open {
  transform: translateY(0);
}
.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 10px auto 4px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  font-family: var(--font-ui);
  font-size: 15px;
  margin: 0;
  color: var(--teal-darker);
}
.sheet-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--teal-50);
  color: var(--teal-darker);
  font-size: 16px;
  cursor: pointer;
}
.sheet-body {
  overflow-y: auto;
  padding: 12px 16px 20px;
}

.emoji-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.emoji-tab {
  border: 1px solid var(--line);
  background: var(--teal-50);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.emoji-tab.active {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.emoji-grid button {
  border: none;
  background: none;
  font-size: 22px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
}
.emoji-grid button:hover {
  background: var(--teal-50);
}

.tpl-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--teal-50);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 10px;
  cursor: pointer;
}
.tpl-card:hover {
  background: var(--teal-100);
}
.tpl-icon {
  font-size: 24px;
  line-height: 1;
}
.tpl-title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  color: var(--teal-darker);
  margin: 0 0 2px;
}
.tpl-desc {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 0;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-h) + 14px);
  transform: translate(-50%, 10px);
  background: var(--teal-darker);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 24px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  z-index: 60;
  box-shadow: var(--shadow-md);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Help popover ---------- */
.help-pop {
  position: fixed;
  top: 60px;
  right: 14px;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);  
  box-shadow: 0px 0px 30px 0px #00000047;
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--ink-soft);
  display: none;
  z-index: 50;
  line-height: 1.6;
}
.help-pop.open {
  display: block;
}
.help-pop b {
  color: var(--ink);
}

/* ================= DESKTOP ================= */
@media (min-width: 900px) {
  .app {
    padding: 0 8px;
  }
  .appbar {
    padding: 0 6px;
  }
  .appbar h1 {
    font-size: 17px;
    text-align: left;
  }
  .appbar-back span {
    display: inline;
  }

  .tb-label {
    display: inline;
  }
  .tb-btn {
    padding: 0 12px;
  }

  .layout {
    flex-direction: row;
    padding: 18px 6px 0;
    gap: 20px;
  }
  .editor-col {
    flex: 1 1 0;
    min-width: 0;
  }
  .preview-col {
    flex: 1 1 0;
    min-width: 0;
  }
  #editor {
    min-height: 46vh;
    max-height: 62vh;
  }
  .chat-mock {
    min-height: 46vh; 
    background-color: #fdf0c8;
    border: 1px solid var(--teal-200);
    background-image: url("images/whatsapp-back_25.png");
  }

  .actionbar {
    max-width: 100%;
    padding: 14px 6px calc(14px + env(safe-area-inset-bottom));
  }
  .btn {
    height: 50px;
    font-size: 15px;
  }

  .ad-mobile-only {
    display: none;
  }
}

@media (min-width: 1180px) {
  .app {
    max-width: 1180px;
    margin: 0 auto;
    box-shadow: 0px 0px 40px 0px #0000002d; 
    background: #f5f5f5;
  }
}