:root {
  --bg: #f6f2ec;
  --bg-accent: #efe7dc;
  --surface: #ffffff;
  --surface-muted: #faf8f5;
  --border: #e5ddd1;
  --border-strong: #d3c7b6;

  --text: #1f2421;
  --text-muted: #665f56;
  --text-soft: #8c8378;

  --primary: #1b7f56;
  --primary-hover: #156645;
  --primary-soft: #e6f5ee;

  --gold: #9a6d38;
  --gold-soft: #f7efe4;

  --danger: #b9382c;
  --danger-soft: #fdecea;
  --danger-hover: #fadbd7;

  --wa-bg: #ebe5dc;
  --wa-bubble: #e7ffdb;
  --wa-border: #d5eec9;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 8px 24px -12px rgba(42, 33, 21, 0.12), 0 1px 3px rgba(42, 33, 21, 0.05);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  position: relative;
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 12% 10%, rgba(154, 109, 56, 0.10), transparent 38%),
    radial-gradient(circle at 88% 15%, rgba(27, 127, 86, 0.09), transparent 40%),
    linear-gradient(180deg, var(--bg) 0%, #f3ede4 100%);
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 18px 48px;
}

/* Header */
.app-header {
  text-align: center;
  margin-bottom: 28px;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.header-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
}

.app-header h1 {
  margin: 0 0 6px;
  font-size: clamp(1.55rem, 3vw, 2.15rem);
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--text);
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.96rem;
}

/* Grid */
.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.95fr);
  gap: 22px;
  align-items: start;
}

.preview-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 700;
  color: var(--text);
}

.base-url-chip {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid #ead8be;
  padding: 4px 10px;
  border-radius: 999px;
}

/* Form Elements */
.field-group {
  margin-bottom: 18px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  flex-wrap: wrap;
}

label {
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--text);
}

.required-mark {
  color: var(--danger);
}

.optional-tag {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-accent);
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 4px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84em;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 5px;
}

input[type="text"],
input[type="tel"],
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input[type="text"]:focus,
input[type="tel"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(27, 127, 86, 0.14);
}

input.is-invalid,
textarea.is-invalid {
  border-color: var(--danger);
}

input.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(185, 56, 44, 0.15);
}

.select-wrapper {
  position: relative;
}

.select-wrapper select {
  appearance: none;
  padding-right: 38px;
  cursor: pointer;
}

.select-chevron {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.input-with-action {
  position: relative;
}

.input-with-action input {
  padding-right: 36px;
}

.input-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: var(--bg-accent);
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, color 0.15s;
}

.input-clear-btn:hover {
  background: var(--border-strong);
  color: var(--text);
}

.input-clear-btn[hidden] {
  display: none;
}

.wa-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.flex-1 {
  flex: 1 1 auto;
  min-width: 0;
}

.wa-preview-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.field-hint {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.field-error {
  margin: 6px 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--danger);
}

/* Textarea & Emoji Toolbar */
.textarea-toolbar {
  border: 1.5px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--surface-muted);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.emoji-bar,
.placeholder-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.emoji-btn {
  border: 1px solid transparent;
  background: var(--surface);
  border-radius: 8px;
  width: 32px;
  height: 30px;
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, border-color 0.12s, background-color 0.12s;
}

.emoji-btn:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--gold-soft);
}

.var-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}

.var-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

textarea#pesanTextarea {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  resize: vertical;
  min-height: 175px;
  line-height: 1.55;
  font-family: inherit;
}

.text-action-btn {
  border: none;
  background: transparent;
  color: var(--gold);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.text-action-btn:hover {
  text-decoration: underline;
}

/* Buttons */
.action-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: 0.94rem;
  font-weight: 650;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  border: 1.5px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s, color 0.15s;
}

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

.btn-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger-soft {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f4ccc7;
}

.btn-danger-soft:hover {
  background: var(--danger-hover);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-contact {
  padding: 0 13px;
  white-space: nowrap;
}

.btn-contact svg {
  width: 16px;
  height: 16px;
}

.inline-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Link Preview Box */
.url-box {
  background: var(--surface-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  word-break: break-all;
}

.url-box code {
  border: none;
  background: transparent;
  padding: 0;
  font-size: 0.86rem;
  color: var(--primary-hover);
}

/* WhatsApp Bubble Preview */
.wa-wallpaper {
  background-color: var(--wa-bg);
  background-image: radial-gradient(rgba(154, 109, 56, 0.08) 1px, transparent 1px);
  background-size: 16px 16px;
  border-radius: var(--radius-md);
  padding: 14px;
  border: 1px solid var(--border);
}

.wa-bubble {
  background: var(--wa-bubble);
  border: 1px solid var(--wa-border);
  border-radius: 12px 12px 2px 12px;
  padding: 12px 14px 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.wa-message-text {
  font-size: 0.89rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #1b241d;
}

.wa-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(27, 127, 86, 0.12);
  font-size: 0.72rem;
  color: #546e5a;
}

.wa-ticks {
  color: #34b7f1;
  font-weight: 700;
  letter-spacing: -2px;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.history-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

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

.history-name {
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-copy-btn {
  flex-shrink: 0;
  padding: 4px 9px;
  font-size: 0.75rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2421;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.2);
  z-index: 50;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast[hidden] {
  display: none;
}

/* Responsive */
@media (max-width: 880px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .container {
    padding: 18px 12px 36px;
  }

  .card {
    padding: 16px;
    border-radius: 15px;
  }

  .action-bar {
    grid-template-columns: 1fr;
  }
}
