:root {
  --font-th: "DB Heavent", "DB Heavent Cond", "Noto Sans Thai", sans-serif;
  --font-en: "Poppins", sans-serif;
  --ink: #13233b;
  --muted: #6f819a;
  --blue: #2d66d5;
  --blue-dark: #17449f;
  --blue-soft: #eaf4ff;
  --line: rgba(106, 145, 199, 0.2);
  --glass: rgba(255,255,255,0.68);
  --shadow: 0 22px 70px rgba(67, 104, 159, 0.14);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-th);
  background:
    radial-gradient(circle at 10% 10%, rgba(120, 186, 255, .22), transparent 30%),
    radial-gradient(circle at 90% 16%, rgba(195, 225, 255, .5), transparent 25%),
    linear-gradient(135deg, #f7fbff 0%, #edf6ff 48%, #ffffff 100%);
  overflow-x: hidden;
}
button, input { font: inherit; }
.en { font-family: var(--font-en); }

.ambient {
  position: fixed;
  border-radius: 999px;
  filter: blur(3px);
  pointer-events: none;
  opacity: .7;
  animation: float 12s ease-in-out infinite;
}
.ambient-one { width: 280px; height: 280px; background: rgba(90, 160, 255, .12); top: 8%; left: -110px; }
.ambient-two { width: 340px; height: 340px; background: rgba(120, 205, 255, .12); bottom: -130px; right: -80px; animation-delay: -5s; }
@keyframes float { 0%,100%{ transform: translateY(0) translateX(0);} 50%{transform: translateY(-18px) translateX(12px);} }

.app-shell { display: grid; grid-template-columns: 290px 1fr; gap: 22px; max-width: 1660px; margin: 0 auto; padding: 22px; position: relative; z-index: 1; }
.glass-panel {
  background: var(--glass);
  border: 1px solid rgba(255,255,255,.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}
.sidebar { min-height: calc(100vh - 44px); border-radius: 30px; padding: 24px 18px; position: sticky; top: 22px; align-self: start; }
.brand-block { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; border-bottom: 1px solid var(--line); }
.brand-logo { width: 54px; height: 54px; object-fit: contain; border-radius: 16px; background: rgba(255,255,255,.85); padding: 5px; box-shadow: 0 10px 25px rgba(40, 98, 180, .12); }
.brand-block h1 { margin: 0; font-size: 22px; line-height: 1.1; }
.brand-block p { margin: 5px 0 0; color: var(--muted); font-size: 15px; }
.sidebar-label { font-family: var(--font-en); text-transform: uppercase; letter-spacing: .13em; color: #88a0bd; font-size: 11px; font-weight: 600; margin: 22px 12px 10px; }
.template-list { display: flex; flex-direction: column; gap: 7px; }
.template-item { width: 100%; border: 0; background: transparent; padding: 12px; border-radius: 16px; display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center; text-align: left; color: var(--ink); cursor: pointer; transition: .22s ease; }
.template-item:hover:not(:disabled) { background: rgba(255,255,255,.72); transform: translateX(3px); }
.template-item.active { color: white; background: linear-gradient(135deg, #2358c1, #5a9cff); box-shadow: 0 12px 28px rgba(45,102,213,.28); }
.template-item:disabled { opacity: .48; cursor: default; }
.template-code { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: rgba(45,102,213,.09); font-family: var(--font-en); font-size: 11px; font-weight: 700; color: var(--blue); }
.template-item.active .template-code { background: rgba(255,255,255,.18); color: white; }
.template-copy strong { display: block; font-size: 15px; line-height: 1.15; }
.template-copy span { display: block; font-family: var(--font-en); color: var(--muted); font-size: 10px; margin-top: 3px; text-transform: uppercase; letter-spacing: .06em; }
.template-item.active .template-copy span { color: rgba(255,255,255,.75); }

.workspace { min-width: 0; }
.topbar { border-radius: 24px; min-height: 96px; padding: 20px 24px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.eyebrow { font-family: var(--font-en); color: var(--blue); font-size: 11px; font-weight: 700; letter-spacing: .12em; }
.topbar h2 { margin: 5px 0 0; font-size: 29px; line-height: 1.1; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.72); cursor: pointer; color: var(--blue); display: grid; place-items: center; transition: .2s ease; }
.icon-button:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(45,102,213,.15); }
svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.editor-grid { display: grid; grid-template-columns: minmax(350px, .76fr) minmax(540px, 1.24fr); gap: 22px; align-items: start; }
.control-panel, .preview-panel { border-radius: 28px; padding: 24px; }
.section-heading, .preview-toolbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 22px; }
.section-heading > div, .preview-toolbar > div:first-child { display: flex; align-items: center; gap: 10px; }
.step-index { font-family: var(--font-en); width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; color: var(--blue); background: var(--blue-soft); font-size: 10px; font-weight: 700; }
h3 { margin: 0; font-size: 21px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 14px; text-align: right; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label, .subject-box label { font-weight: 600; font-size: 14px; }
.field input, .subject-box input { width: 100%; border: 1px solid rgba(105,146,202,.24); background: rgba(255,255,255,.78); border-radius: 14px; padding: 12px 14px; color: var(--ink); outline: none; transition: .2s ease; }
.field input:focus, .subject-box input:focus { border-color: rgba(45,102,213,.55); box-shadow: 0 0 0 4px rgba(45,102,213,.09); }
.subject-box { margin-top: 18px; }
.copy-row { display: flex; gap: 9px; margin-top: 7px; }
.small-button { border: 0; border-radius: 14px; padding: 0 14px; background: rgba(45,102,213,.1); color: var(--blue-dark); font-family: var(--font-en); font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 7px; }
.attachment-note { margin-top: 16px; display: flex; align-items: center; gap: 12px; background: rgba(232,244,255,.8); border: 1px solid rgba(74,133,212,.13); border-radius: 16px; padding: 13px 15px; color: var(--blue-dark); }
.attachment-note div { display: flex; flex-direction: column; line-height: 1.25; }
.attachment-note span { color: var(--muted); font-size: 14px; }
.action-stack { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.primary-action, .secondary-action { min-height: 48px; border-radius: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 9px; font-family: var(--font-en); font-weight: 600; transition: .22s ease; }
.primary-action { border: 0; color: white; background: linear-gradient(135deg, #194cae, #5597ff); box-shadow: 0 13px 28px rgba(45,102,213,.26); }
.secondary-action { border: 1px solid rgba(45,102,213,.22); color: var(--blue-dark); background: rgba(255,255,255,.72); }
.primary-action:hover, .secondary-action:hover { transform: translateY(-2px); }

.preview-panel { min-height: 760px; }
.device-toggle { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(224,237,252,.78); }
.device-button { border: 0; border-radius: 9px; padding: 7px 11px; background: transparent; color: var(--muted); font-family: var(--font-en); font-size: 11px; cursor: pointer; }
.device-button.active { background: white; color: var(--blue-dark); box-shadow: 0 5px 14px rgba(50,92,150,.12); }
.preview-stage { border-radius: 22px; min-height: 670px; padding: 24px; background: linear-gradient(135deg, rgba(223,239,255,.72), rgba(255,255,255,.68)); border: 1px solid rgba(255,255,255,.88); display: flex; justify-content: center; align-items: flex-start; overflow: auto; }
.email-viewport { background: white; border-radius: 15px; box-shadow: 0 18px 50px rgba(54,82,120,.16); overflow: hidden; transition: width .3s ease; }
.email-viewport.desktop { width: min(100%, 720px); }
.email-viewport.mobile { width: 390px; }
.email-viewport iframe { display: block; width: 100%; min-height: 1130px; border: 0; background: white; }
.toast { position: fixed; right: 25px; bottom: 25px; transform: translateY(15px); opacity: 0; pointer-events: none; background: #142b4d; color: white; border-radius: 14px; padding: 12px 17px; z-index: 20; box-shadow: 0 14px 35px rgba(20,43,77,.25); transition: .25s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 240px 1fr; }
  .editor-grid { grid-template-columns: 1fr; }
  .preview-panel { min-height: auto; }
}
@media (max-width: 780px) {
  .app-shell { display: block; padding: 12px; }
  .sidebar { position: relative; top: 0; min-height: auto; margin-bottom: 14px; }
  .template-list { display: grid; grid-template-columns: repeat(2, 1fr); }
  .topbar { margin-bottom: 14px; }
  .topbar h2 { font-size: 24px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .action-stack { grid-template-columns: 1fr; }
  .section-heading { display: block; }
  .section-heading p { text-align: left; margin-top: 8px; }
  .preview-stage { padding: 10px; }
  .email-viewport.mobile, .email-viewport.desktop { width: 100%; }
}

/* Subject field layout fix */
.copy-row input { flex: 1; min-width: 0; }


/* Smart field controls */
.field select {
  width: 100%;
  border: 1px solid rgba(105,146,202,.24);
  background: rgba(255,255,255,.78);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--ink);
  outline: none;
  transition: .2s ease;
}

.field select:focus {
  border-color: rgba(45,102,213,.55);
  box-shadow: 0 0 0 4px rgba(45,102,213,.09);
}

.checkbox-field {
  background: rgba(255,255,255,.54);
  border: 1px solid rgba(105,146,202,.18);
  border-radius: 14px;
  padding: 11px 13px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 500 !important;
}

.checkbox-label input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.checkbox-visual {
  width: 21px;
  height: 21px;
  flex: 0 0 21px;
  border: 1.5px solid rgba(45,102,213,.4);
  border-radius: 7px;
  background: white;
  display: grid;
  place-items: center;
  transition: .2s ease;
}

.checkbox-label input:checked + .checkbox-visual {
  border-color: #2d66d5;
  background: linear-gradient(135deg,#2358c1,#5a9cff);
  box-shadow: 0 6px 14px rgba(45,102,213,.22);
}

.checkbox-label input:checked + .checkbox-visual::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg) translateY(-1px);
}

.checkbox-copy {
  color: var(--ink);
  line-height: 1.35;
}
