/* ==========================================================================
   AdLaunch UI v3 — two-level navy shell + light Meta-style ad builder
   Loaded after style.css; overrides the dark theme for the app chrome.
   ========================================================================== */
:root {
  --blue: #2f7df6;
  --blue-d: #1f6ae0;
  --blue-soft: #eaf2ff;
  --ink: #0f172a;
  --ink-2: #344054;
  --mut: #667085;
  --mut-2: #98a2b3;
  --line: #e5e8ee;
  --line-2: #dfe3ea;
  --bg: #f5f6f9;
  --card: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05);
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 13.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); }

/* shared controls -> light theme ---------------------------------------- */
input, select, textarea {
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  color: var(--ink);
  padding: 9px 11px;
}
input::placeholder, textarea::placeholder { color: #a2abb8; }
input:focus, select:focus, textarea:focus {
  border-color: #8fb3f0;
  box-shadow: 0 0 0 3px rgba(47, 125, 246, .12);
  outline: none;
}
textarea { min-height: 64px; resize: vertical; }
.btn {
  background: #fff; border: 1px solid var(--line-2); color: var(--ink);
  border-radius: 9px; padding: 8px 12px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: #f7f8fa; border-color: #cfd6e2; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-d); border-color: var(--blue-d); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.hint { color: var(--mut); font-size: 12px; }
.ok { color: var(--ok); }
.err { color: var(--bad); }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-1); color: var(--ink);
}
.card h2 { font-size: 15px; color: var(--ink); }
.pill { background: #f1f3f7; color: var(--ink-2); border-radius: 999px; padding: 2px 8px; font-size: 11.5px; font-weight: 600; }
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60; max-width: 420px;
  background: #101828; color: #fff; border: 1px solid #1f2937;
  padding: 12px 16px; border-radius: 11px; box-shadow: 0 16px 40px rgba(16, 24, 40, .28);
}
.toast.bad { background: #7f1d1d; border-color: #991b1b; }

/* ---------------------------------------------------------------- shell */
.shell {
  display: grid;
  grid-template-columns: 90px 300px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* icon rail ------------------------------------------------------------- */
.rail {
  background: linear-gradient(180deg, #14293f 0%, #0c1c2c 100%);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 6px 10px; gap: 6px; border-right: 1px solid rgba(255, 255, 255, .05);
  min-height: 0;
}
.rail-logo {
  width: 44px; height: 44px; border-radius: 14px; margin-bottom: 8px;
  background: linear-gradient(160deg, #3b82f6, #1d4ed8); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px rgba(29, 78, 216, .38);
}
.rail-nav {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 100%; flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin;
}
.rail-nav a, .rail-foot a {
  width: 74px; padding: 8px 4px 7px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: #9db2ca; font-size: 10.5px; font-weight: 600; text-decoration: none;
  text-align: center; line-height: 1.15; transition: background .12s, color .12s;
}
.rail-nav a svg, .rail-foot a svg { width: 21px; height: 21px; }
.rail-nav a:hover, .rail-foot a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.rail-nav a.active, .rail-nav a.on, .rail-foot a.active, .rail-foot a.on { background: #1e3a5c; color: #fff; }
.rail-foot { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 6px; }

/* side panel ------------------------------------------------------------ */
.panel {
  background: #12283f; color: #dbe6f3; min-height: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, .05);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 6px 18px;
}
.panel-head h2 { margin: 0; font-size: 19px; font-weight: 700; color: #fff; letter-spacing: .1px; }
.panel-tools { display: flex; gap: 4px; }
.pico {
  width: 30px; height: 30px; border: 0; background: transparent; border-radius: 8px;
  color: #a9bdd4; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.pico:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.pico svg { width: 18px; height: 18px; }

.pstats {
  margin: 10px 14px 12px; padding: 12px 10px 11px; border-radius: 14px;
  background: linear-gradient(165deg, #1c3854 0%, #152b42 100%);
  border: 1px solid rgba(140, 190, 255, .16);
}
.pstats-cap {
  display: flex; align-items: center; gap: 8px; margin-bottom: 9px;
  font-size: 10px; letter-spacing: .08em; color: #9fb6cf; font-weight: 700;
}
.pstats-cap span {
  background: #26445f; color: #d7e6f6; padding: 3px 8px; border-radius: 999px;
  letter-spacing: .01em; font-size: 10.5px;
}
.pstats-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; text-align: center; }
.pstats-nums > div { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.pstats-nums i { font-style: normal; font-size: 15px; line-height: 1.4; }
.pstats-nums b { color: #fff; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pstats-nums span { color: #93a9c2; font-size: 11px; }

.pnav { display: flex; flex-direction: column; gap: 2px; padding: 2px 10px; }
.pnav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #c3d3e4; font-weight: 600; font-size: 13px; text-decoration: none;
}
.pnav a svg { width: 18px; height: 18px; opacity: .9; }
.pnav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.pnav a.on, .pnav a.active { background: #1d3a59; color: #fff; }

.ppromo {
  margin: auto 14px 12px; padding: 12px; border-radius: 12px;
  background: rgba(255, 255, 255, .035); border: 1px solid rgba(255, 255, 255, .08);
}
.ppromo-t { display: flex; align-items: center; gap: 7px; font-size: 10px; letter-spacing: .07em; color: #9fb6cf; font-weight: 700; }
.ppromo-t b { color: #57a8ff; font-size: 11px; letter-spacing: 0; }
.ppromo-dot { width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .16); }
.ppromo p { margin: 8px 0 10px; font-size: 11.5px; color: #a8bdd3; line-height: 1.45; }
.ppromo-btn {
  width: 100%; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  background: #1d4ed8; border: 1px solid #2563eb; color: #fff; font-size: 11.5px; font-weight: 600;
}
.ppromo-btn:hover { background: #1a44bf; }
.pfoot { padding: 0 18px 14px; font-size: 11px; color: #8299b1; }
.pfoot-name { color: #cfe0f5; font-weight: 600; font-size: 12px; }
.pfoot-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10.5px; color: #7f96ae; }

/* work area ------------------------------------------------------------- */
.work { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 22px; margin: 0; background: #fff; border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 19px; font-weight: 700; margin: 0; }
.sub { color: var(--mut); font-size: 12px; }
#view { flex: 1; min-height: 0; overflow: auto; padding: 18px 22px 30px; }
body.studio-mode .topbar { display: none; }
body.studio-mode #view { padding: 0; overflow: hidden; display: flex; }
body.studio-mode .st3 { flex: 1; min-width: 0; }

/* ====================================================== builder  (v3) */
.st3 { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: #fff; }

.v3top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 16px; background: #fff; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.v3top-l, .v3top-r { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.acctsel {
  display: flex; align-items: center; gap: 6px; padding: 0 6px 0 8px;
  border: 1px solid var(--line-2); border-radius: 10px; background: #fff; height: 38px;
}
.acctsel select {
  border: 0; background: transparent; box-shadow: none; padding: 0 2px;
  font-weight: 600; max-width: 210px; height: 34px;
}
.acctsel select:focus { box-shadow: none; }
.pf {
  width: 20px; height: 20px; border-radius: 6px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: #fff;
  background: #1877f2; flex: 0 0 auto;
}
.pf.img { background: linear-gradient(160deg, #7c3aed, #4f46e5); }
.pf.ig { background: linear-gradient(160deg, #f58529, #dd2a7b 60%, #8134af); font-size: 12px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .16); flex: 0 0 auto; }
.live.sim { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.pick {
  display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 6px 0 8px;
  border: 1px solid var(--line-2); border-radius: 10px; background: #fff;
}
.pick select {
  border: 0; background: transparent; padding: 0; height: 34px; max-width: 170px;
  font-weight: 600; appearance: none; -webkit-appearance: none; padding-right: 2px;
}
.pick select:focus { box-shadow: none; }
.pick .chev { width: 14px; height: 14px; color: #98a2b3; flex: 0 0 auto; }
.mini {
  width: 28px; height: 28px; border: 0; background: transparent; border-radius: 7px;
  color: #667085; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.mini:hover { background: #f1f3f7; color: #101828; }
.mini .ic { width: 16px; height: 16px; }

.v3btn {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 10px; background: #fff; color: #1d2939;
  font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.v3btn:hover { background: #f7f8fa; border-color: #cfd6e2; }
.v3btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.v3btn.blue:hover { background: var(--blue-d); border-color: var(--blue-d); }
.v3btn.ghost { background: transparent; border-color: transparent; color: var(--mut); }
.v3btn.ghost:hover { background: #f1f3f7; color: var(--ink); }
.v3btn .ic { width: 16px; height: 16px; }
.syncstate {
  display: inline-flex; align-items: center; gap: 6px; color: var(--mut); font-size: 12px;
  font-weight: 600;
}
.syncstate .ic { width: 14px; height: 14px; color: var(--ok); }

/* two column body ------------------------------------------------------- */
.v3body {
  flex: 1; min-height: 0; display: grid; overflow: hidden;
  grid-template-columns: minmax(0, 1fr) clamp(430px, 33vw, 580px);
  gap: 14px; padding: 14px 16px; background: #f6f7f9;
}
.v3main { overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 14px; padding-right: 2px; }
.v3side {
  display: flex; flex-direction: column; min-height: 0; background: #fff;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow-1);
}

.v3card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px 16px; box-shadow: var(--shadow-1);
}
.cardhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.cardhead-l { display: flex; align-items: center; gap: 8px; }
.cardhead-l h3 { margin: 0; font-size: 15.5px; font-weight: 700; color: var(--ink); }
.cardhead-r { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.countpill {
  background: #f1f3f7; color: #475467; border-radius: 999px; min-width: 22px; text-align: center;
  padding: 1px 7px; font-size: 11.5px; font-weight: 700;
}

/* search + chips -------------------------------------------------------- */
.searchbox {
  display: flex; align-items: center; gap: 8px; height: 40px; margin-top: 12px;
  border: 1px solid var(--line-2); border-radius: 10px; padding: 0 10px; background: #fff;
}
.searchbox .ic { width: 16px; height: 16px; color: var(--mut-2); flex: 0 0 auto; }
.searchbox input {
  flex: 1; border: 0; padding: 0; height: 36px; background: transparent; font-size: 13px;
  min-width: 0;
}
.searchbox input:focus { box-shadow: none; }
.kbd {
  font-size: 10.5px; color: #98a2b3; border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 6px; padding: 1px 5px; background: #fafbfc; flex: 0 0 auto;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.setchip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--blue-soft); border: 1px solid #d3e2fb; color: #1e4b8f;
  border-radius: 999px; padding: 4px 4px 4px 9px; font-size: 12px; font-weight: 600;
}
.setchip .dotb { width: 6px; height: 6px; border-radius: 50%; background: #2f7df6; flex: 0 0 auto; }
.setchip .ct { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }
.xbtn {
  width: 18px; height: 18px; border: 0; border-radius: 50%; background: transparent;
  color: #5b7ba8; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.xbtn:hover { background: #dbe8fd; color: #17325c; }
.xbtn .ic { width: 11px; height: 11px; }
.mutedline { color: var(--mut-2); font-size: 12px; }

.setlist { margin-top: 10px; display: none; max-height: 236px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.setlist.show { display: block; }
.setlist .st-setlist { padding: 6px; }
.st-setitem {
  display: flex; align-items: flex-start; gap: 9px; width: 100%; text-align: left;
  background: #fff; border: 1px solid transparent; border-radius: 8px; padding: 7px 8px;
  cursor: pointer; color: var(--ink-2); font-size: 12.5px;
}
.st-setitem:hover { background: #f6f8fb; }
.st-setitem.on { background: #eff5ff; border-color: #cfe0fb; }
.st-tick {
  width: 16px; height: 16px; border: 1px solid var(--line-2); border-radius: 5px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; font-size: 10px; color: #fff;
  margin-top: 1px; background: #fff;
}
.st-setitem.on .st-tick { background: var(--blue); border-color: var(--blue); }
.st-setitem-body { display: flex; flex-direction: column; min-width: 0; }
.st-setitem-body b { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-setitem-body small { color: var(--mut-2); font-size: 11px; }
.st-empty { padding: 14px; color: var(--mut-2); font-size: 12px; text-align: center; }

.setfoot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 12px; flex-wrap: wrap;
}
.setfoot-r { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.blockpick { display: inline-flex; gap: 4px; }
.bchip {
  height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-2);
  background: #fff; color: var(--mut); font-size: 12px; font-weight: 600; cursor: pointer;
}
.bchip.on { background: #eef4ff; border-color: #bcd5fa; color: #1e4b8f; }
.v3btn.mode { background: #f4f6fa; border-color: #e2e7ef; color: #344054; }

/* fields --------------------------------------------------------------- */
.field { margin-top: 14px; }
.field.first { margin-top: 12px; }
.flabel {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: #344054; margin-bottom: 6px;
}
.flabel .counter { color: var(--mut-2); font-weight: 500; font-size: 11px; }
.field textarea, .field input, .field select { width: 100%; }
.st-ie-lg, .field textarea.st-ie-lg { min-height: 74px; }
.tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 7px; }
.toolbtn {
  display: inline-flex; align-items: center; gap: 5px; border: 0; background: transparent;
  color: #475467; font-size: 11.5px; font-weight: 600; cursor: pointer; padding: 0;
}
.toolbtn:hover { color: var(--blue); }
.toolbtn .ic { width: 14px; height: 14px; }
.toolbtn b { color: #98a2b3; font-weight: 600; }
.toolbtn.add { color: var(--blue); font-size: 12.5px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.row > input, .row > select { flex: 1; min-width: 0; }
.iconbtn {
  width: 36px; height: 36px; border: 1px solid var(--line-2); border-radius: 9px; background: #fff;
  color: #475467; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.iconbtn:hover { background: #f6f8fb; color: var(--blue); border-color: #cfe0fb; }
.iconbtn .ic { width: 16px; height: 16px; }
.helper { margin: 6px 0 0; color: var(--mut-2); font-size: 11px; line-height: 1.45; }
.helper a { color: var(--blue); }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: #344054; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--blue); flex: 0 0 auto; }
.check b { font-weight: 700; color: var(--ink); }
.switch {
  width: 40px; height: 22px; border-radius: 999px; border: 0; background: #d0d5dd; position: relative;
  cursor: pointer; padding: 0; flex: 0 0 auto; transition: background .15s;
}
.switch i { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(16, 24, 40, .25); transition: left .15s; }
.switch.on { background: var(--blue); }
.switch.on i { left: 20px; }
.state-b { font-size: 12.5px; font-weight: 700; color: var(--blue); }
.state-b.off { color: var(--mut); }
.utmchips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.st-chip {
  display: inline-flex; align-items: center; gap: 5px; background: #f4f6fa; border: 1px solid var(--line);
  border-radius: 7px; padding: 3px 7px; font-size: 11px; color: #475467;
}
.st-chip b { color: #1d2939; font-weight: 700; }
.namingbar {
  display: flex; align-items: center; gap: 10px; margin-top: 14px; padding-top: 12px;
  border-top: 1px dashed var(--line); flex-wrap: wrap;
}
.namingbar label { font-size: 11.5px; font-weight: 600; color: var(--mut); }
.namingbar input { flex: 1; min-width: 180px; height: 34px; font-size: 12px; font-family: ui-monospace, Menlo, monospace; }
.namingbar .npv { font-size: 11px; color: var(--mut-2); }

/* variant list (light) -------------------------------------------------- */
.st-varlist { margin-top: 8px; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.st-var {
  display: flex; align-items: flex-start; gap: 8px; padding: 7px 8px; border-radius: 8px;
  background: #fff; border: 1px solid var(--line); margin-bottom: 5px; cursor: pointer;
  color: var(--ink-2); font-size: 12px;
}
.st-var.on { border-color: #9dbcf5; background: #f0f6ff; }
.st-var-n {
  width: 18px; height: 18px; border-radius: 5px; background: #eef1f6; color: #475467;
  font-size: 10.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.st-var.on .st-var-n { background: var(--blue); color: #fff; }
.st-var-t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.st-var-t em { color: var(--mut-2); font-style: normal; }
.st-x { border: 0; background: transparent; color: #98a2b3; cursor: pointer; padding: 0 2px; font-size: 13px; }
.st-x:hover { color: var(--bad); }
.st-addvar {
  width: 100%; border: 1px dashed #bfd3f2; background: #fff; color: var(--blue);
  border-radius: 8px; padding: 7px; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.st-x-btn { border: 0; background: transparent; cursor: pointer; color: #98a2b3; }

/* ads rail -------------------------------------------------------------- */
.sidehead {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fff; flex-wrap: wrap;
}
.sidehead-l, .sidehead-r { display: flex; align-items: center; gap: 4px; }
.sidehead h3 { margin: 0; font-size: 14.5px; font-weight: 700; }
.sidehead-r { gap: 2px; }
.sideads { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; background: #fbfbfc; }
.adgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.adcard {
  background: #fff; border: 1px solid #e6e8ee; border-radius: 12px; padding: 6px;
  position: relative; transition: border-color .12s, box-shadow .12s;
}
.adcard:hover { border-color: #b9cdf0; box-shadow: 0 4px 14px rgba(16, 24, 40, .08); }
.adthumb {
  position: relative; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden;
  background-color: #eef1f5; background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
}
.adthumb.empty { border: 1px dashed #cdd5e1; background: #fafbfc; }
.adthumb .addmedia {
  border: 1px solid var(--line-2); background: #fff; color: #475467; border-radius: 8px;
  font-size: 11.5px; font-weight: 600; padding: 6px 9px; cursor: pointer;
}
.adthumb .addmedia:hover { border-color: #b9cdf0; color: var(--blue); }
.mbadge {
  position: absolute; right: 5px; top: 5px; background: #7aa9f2; color: #fff;
  border-radius: 5px; padding: 1px 6px; font-size: 10px; font-weight: 700; letter-spacing: .01em;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .18);
}
.mbadge.multi { background: #4f8ef7; }
.thumbtools {
  position: absolute; left: 5px; top: 5px; display: flex; gap: 4px; opacity: 0; transition: opacity .12s;
}
.adcard:hover .thumbtools { opacity: 1; }
.thumbtools button {
  width: 22px; height: 22px; border: 0; border-radius: 6px; cursor: pointer; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.thumbtools .rm { background: #ef4444; }
.thumbtools .eye { background: rgba(16, 24, 40, .62); }
.thumbtools .ic { width: 12px; height: 12px; }
.vbadge {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; text-shadow: 0 2px 10px rgba(0, 0, 0, .5); pointer-events: none;
}
.adname-l {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  margin: 7px 1px 2px; color: var(--mut-2); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
}
.adname-l .pencil { border: 0; background: transparent; color: #98a2b3; cursor: pointer; padding: 0; display: inline-flex; }
.adname-l .ic { width: 12px; height: 12px; }
.st-adname {
  width: 100%; border: 1px solid transparent; background: transparent; resize: none;
  font-size: 12.5px; font-weight: 600; color: #1d2939; padding: 2px 2px; min-height: 22px;
  line-height: 1.35; overflow: hidden; border-radius: 6px;
}
.st-adname:hover { border-color: var(--line); background: #fbfcfe; }
.st-adname:focus { border-color: #9dbcf5; background: #fff; box-shadow: 0 0 0 3px rgba(47, 125, 246, .1); }
.admeta { display: none; }
.addtile {
  border: 1px dashed #cdd5e1; border-radius: 12px; background: #fff; color: var(--mut);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; font-size: 11.5px; font-weight: 600; min-height: 120px; aspect-ratio: 3 / 4;
}
.addtile:hover { border-color: #b9cdf0; color: var(--blue); background: #fbfdff; }
.addtile .ic { width: 20px; height: 20px; }
.adblock { margin-bottom: 12px; }
.adblock:last-child { margin-bottom: 0; }
.adblock-head {
  display: flex; align-items: center; gap: 6px; margin: 0 2px 8px; color: var(--mut); font-size: 11.5px;
  font-weight: 600;
}
.adblock-head b { color: #1d2939; font-size: 12px; }
.adblock-head .sep { color: #d0d5dd; }

/* footer ---------------------------------------------------------------- */
.fbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--line); background: #fff; flex-wrap: wrap;
}
.fbtn {
  display: inline-flex; align-items: center; gap: 7px; height: 42px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: 10px; background: #fff; color: #1d2939;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.fbtn:hover { background: #f7f8fa; }
.fbtn .ic { width: 17px; height: 17px; }
.fbtn.split { padding-right: 8px; }
.fbtn.split .chev { padding-left: 6px; margin-left: 2px; border-left: 1px solid var(--line); display: inline-flex; align-items: center; }
.fbtn.split .chev .ic { width: 14px; height: 14px; color: #98a2b3; }
.fbar-sp { flex: 1; }
.fbtn-primary {
  display: inline-flex; align-items: center; gap: 10px; height: 44px; padding: 0 18px;
  border: 0; border-radius: 10px; background: linear-gradient(180deg, #4b8dfd, #2f7df6);
  color: #fff; font-size: 13.5px; font-weight: 700; cursor: pointer; max-width: 100%;
  box-shadow: 0 6px 16px rgba(47, 125, 246, .28);
}
.fbtn-primary:hover { filter: brightness(1.04); }
.fbtn-primary:disabled { opacity: .6; cursor: progress; }
.fbtn-primary #b-launch-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }
.fbtn-primary .ic { width: 17px; height: 17px; }
.fbar-run { padding: 0 12px; font-size: 11.5px; color: var(--mut); }
.fbar-run:empty { display: none; }
.fbar-run { padding-bottom: 8px; }
.fbar-prog { height: 3px; background: #eef1f5; }
.fbar-prog i { display: block; height: 100%; width: 0; background: var(--blue); transition: width .3s; }
.v3sum { font-size: 12px; color: var(--mut); padding: 2px 2px 0; }
.v3sum b { color: var(--ink); }

/* modals / popovers -> light */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .42); z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  backdrop-filter: blur(2px);
}
.modal {
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 26px 70px rgba(15, 23, 42, .26); padding: 18px 20px; width: min(760px, 100%);
  max-height: 88vh; overflow: auto;
}
.modal.wide { width: min(1180px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.modal-head strong { font-size: 15.5px; color: var(--ink); }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.st-pop {
  position: fixed; z-index: 50; background: #fff; color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 18px 44px rgba(15, 23, 42, .18); padding: 8px; width: 300px;
}
.st-pop-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; font-size: 12px; }
.st-popitem {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 8px 9px;
  border: 1px solid transparent; border-radius: 8px; background: #fff; cursor: pointer;
}
.st-popitem:hover { background: #f6f8fb; }
.st-popitem.on { background: #eff5ff; border-color: #cfe0fb; }
.st-popitem code { font-size: 12.5px; font-weight: 700; color: var(--ink); font-family: inherit; }
.st-popitem small { color: var(--mut); font-size: 11px; }

/* schedule / table helpers --------------------------------------------- */
.sched-note {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 10px;
  padding: 10px 12px; font-size: 12px; line-height: 1.5; margin-bottom: 14px;
}
.plan-pill {
  display: inline-flex; align-items: center; gap: 6px; background: #eef4ff; border: 1px solid #cfe0fb;
  color: #1e4b8f; border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 600;
}
.grid-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.grid-table th {
  text-align: left; font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--mut-2); font-weight: 700; padding: 8px 8px; border-bottom: 1px solid var(--line);
  background: #fafbfc; position: sticky; top: 0; z-index: 1;
}
.grid-table td { padding: 6px 8px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
.grid-table tr:hover td { background: #fbfcfe; }
.grid-table input {
  width: 100%; border: 1px solid transparent; background: transparent; padding: 5px 6px; font-size: 12.5px;
  border-radius: 6px;
}
.grid-table input:hover { border-color: var(--line); background: #fff; }
.grid-table input:focus { border-color: #9dbcf5; background: #fff; box-shadow: 0 0 0 3px rgba(47, 125, 246, .1); }
.grid-table .thumb-mini {
  width: 34px; height: 34px; border-radius: 6px; background-size: cover; background-position: center;
  background-color: #eef1f5; border: 1px solid var(--line);
}
.tbl-wrap { max-height: 56vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.style-card {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
  cursor: pointer; text-align: left;
}
.style-card:hover { border-color: #b9cdf0; background: #fbfdff; }
.style-card b { display: block; font-size: 12.5px; color: var(--ink); margin-bottom: 3px; }
.style-card span { color: var(--mut); font-size: 11px; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1500px) {
  .v3body { grid-template-columns: minmax(0, 1fr) clamp(400px, 30vw, 500px); }
}
@media (max-width: 1280px) {
  .shell { grid-template-columns: 84px 264px minmax(0, 1fr); }
  .adgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v3top .syncstate { display: none; }
}
@media (max-width: 1080px) {
  body.studio-mode #view { display: block; overflow: auto; }
  .v3body { display: block; overflow: visible; }
  .v3side { margin-top: 14px; }
  .sideads { max-height: none; overflow: visible; }
  .adgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fbar { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -6px 18px rgba(16, 24, 40, .06); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 68px minmax(0, 1fr); }
  .panel { display: none; }
  .rail-nav a, .rail-foot a { width: 54px; font-size: 9.5px; }
  .rail-logo { width: 38px; height: 38px; }
  .v3top { padding: 8px 10px; }
  .v3top-l .pick { display: none; }
  .v3body { padding: 10px; }
  .two { grid-template-columns: 1fr; }
  .adgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fbtn { height: 38px; padding: 0 10px; font-size: 12px; }
  .fbtn-primary { height: 40px; padding: 0 14px; }
}
@media (max-width: 560px) {
  .adgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fbar { gap: 6px; }
  .fbtn.split .chev { display: none; }
  .acctsel select { max-width: 130px; }
}

/* -------------------------------------------------------- v3 fixes (appended) */
.st3 textarea { min-height: 44px; }
.st3 textarea.st-ie-lg { min-height: 86px; }
body.panel-collapsed .shell { grid-template-columns: 90px 0 minmax(0, 1fr); }
body.panel-collapsed .panel { display: none; }
body.panel-collapsed .rail { border-right: 1px solid #1d2942; }
.cardhead select, .cardhead-r select { width: auto; min-width: 148px; flex: 0 0 auto; }
.utmchips .st-chip { height: auto; display: inline-flex; align-self: flex-start; }
.v3body { grid-template-columns: minmax(0, 1fr) clamp(440px, 36vw, 740px); }
.acctsel select {
  appearance: none; -webkit-appearance: none; max-width: 240px;
  padding: 0 4px 0 2px; text-overflow: ellipsis;
}
.acctsel { padding-right: 4px; }
.acctsel .mini { margin-left: 2px; }
.pstats-nums i { display: block; margin-bottom: 1px; }
.adname-l { text-transform: none; letter-spacing: 0; font-size: 10.5px; font-weight: 600; color: #98a2b3; }

/* rail: no stray horizontal scrollbar on narrow widths ---------------- */
.rail-nav { overflow-x: hidden; }
.rail-nav a, .rail-foot a { width: 100%; max-width: 74px; box-sizing: border-box; }
.rail-nav::-webkit-scrollbar, .panel::-webkit-scrollbar { width: 0; height: 0; }

/* ==========================================================================
   Ad Sets editor — Meta Ads Manager-style editable rows
   ========================================================================== */
:root { color-scheme: light; }
html { color-scheme: light; }

.cardhead-sub { color: var(--mut); font-size: 11.5px; font-weight: 600; padding-left: 2px; }

.aset-list { display: grid; gap: 8px; margin-top: 12px; }
.aset {
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04); transition: border-color .15s, box-shadow .15s;
}
.aset.open { border-color: #c9d6ea; box-shadow: 0 8px 22px rgba(16, 24, 40, .08); }
.aset-h { display: flex; align-items: center; gap: 8px; padding: 9px 11px; flex-wrap: nowrap; }
.aset-cv {
  flex: 0 0 auto; width: 24px; height: 24px; border: 1px solid transparent; border-radius: 7px;
  background: transparent; color: var(--mut); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.aset-cv .ic { width: 16px; height: 16px; transition: transform .16s; }
.aset.open .aset-cv .ic { transform: rotate(180deg); }
.aset-cv:hover { background: #f2f4f8; color: var(--ink-2); }
.aset-id { flex: 1 1 160px; min-width: 0; }
.aset-nm {
  width: 100%; border: 1px solid transparent; background: transparent; border-radius: 7px;
  padding: 2px 6px; margin-left: 0; font-family: inherit; font-size: 13.5px; font-weight: 650; line-height: 1.35; color: var(--ink);
}
.aset-nm:hover { border-color: var(--line-2); background: #fbfcfe; }
.aset-nm:focus { background: #fff; border-color: #8fb3f0; box-shadow: 0 0 0 3px rgba(47, 125, 246, .12); outline: none; }
.aset-meta { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--mut); padding-left: 0; min-width: 0; }
.aset-camp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.aset-meta .dotsep { color: var(--mut-2); }
.aset-meta code { font: 500 10.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--mut-2); }
.aset-pill {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; height: 25px; padding: 0 9px;
  border-radius: 999px; border: 1px solid var(--line-2); background: #f8fafc;
  font-size: 11px; font-weight: 700; color: var(--mut); cursor: pointer;
}
.aset-pill i { width: 6px; height: 6px; border-radius: 50%; background: var(--mut-2); }
.aset-pill.on { color: #067647; background: #ecfdf3; border-color: #b7e4c7; }
.aset-pill.on i { background: #16a34a; }
.aset-pill.off { color: #b42318; background: #fef3f2; border-color: #fecdca; }
.aset-pill.off i { background: #dc2626; }
.aset-sum { flex: 0 0 auto; text-align: right; min-width: 118px; line-height: 1.25; }
.aset-sum b { display: block; font-size: 13px; font-weight: 750; color: var(--ink); }
.aset-sum small { font-size: 10.5px; color: var(--mut); }
.aset-tools { flex: 0 0 auto; display: flex; gap: 2px; }
.rwbtn {
  width: 26px; height: 26px; border: 1px solid transparent; border-radius: 7px; background: transparent;
  color: var(--mut); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.rwbtn .ic { width: 15px; height: 15px; }
.rwbtn:hover { background: #f2f4f8; color: var(--ink); border-color: var(--line); }
.rwbtn.danger:hover { background: #fef3f2; color: #b42318; border-color: #fecdca; }

.aset-b { border-top: 1px solid var(--line); background: #fbfcfe; padding: 11px; border-radius: 0 0 12px 12px; }
.aset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; align-items: start; }
.aset-sec {
  display: flex; flex-direction: column; gap: 8px; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px;
}
.aset-sec h4 { margin: 0; font-size: 10.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--mut); }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld > span { font-size: 11px; font-weight: 650; color: var(--mut); }
.fld em { font-style: normal; font-weight: 500; color: var(--mut-2); }
.fld input, .fld select { width: 100%; height: 32px; padding: 4px 8px; font-size: 12.5px; border-radius: 8px; }
.fld select { padding-right: 22px; }
.aset-f2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mny {
  display: flex; align-items: stretch; height: 32px; border: 1px solid var(--line-2);
  border-radius: 8px; background: #fff; overflow: hidden;
}
.mny i {
  font-style: normal; display: flex; align-items: center; padding: 0 8px; font-size: 12px;
  color: var(--mut); background: #f9fafb; border-right: 1px solid var(--line);
}
.mny input { border: 0; border-radius: 0; height: 100%; padding: 0 8px; box-shadow: none; }
.mny input:focus { box-shadow: none; border: 0; }
.seg { display: inline-flex; gap: 2px; padding: 2px; background: #f1f3f7; border-radius: 8px; align-self: flex-start; max-width: 100%; flex-wrap: wrap; }
.seg-b {
  border: 0; background: transparent; border-radius: 6px; padding: 5px 10px;
  font-size: 11px; font-weight: 700; color: var(--mut); cursor: pointer; white-space: nowrap;
}
.seg-b:hover { color: var(--ink-2); }
.seg-b.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(16, 24, 40, .14); }
.ctry-wrap { display: flex; flex-wrap: wrap; gap: 5px; }
.ctry {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 4px 0 9px;
  border-radius: 999px; background: #eef4ff; color: #1d4ed8; font-size: 11px; font-weight: 700;
}
.ctry button {
  width: 16px; height: 16px; border: 0; border-radius: 50%; background: transparent;
  color: inherit; font-size: 13px; line-height: 1; cursor: pointer;
}
.ctry button:hover { background: rgba(29, 78, 216, .14); }
.ctry-add { display: flex; gap: 6px; margin-top: 2px; }
.ctry-add input { height: 30px; font-size: 12px; }
.agerow { display: flex; align-items: center; gap: 5px; }
.agerow span { color: var(--mut-2); font-size: 11px; }
.chk { display: flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.chk input { width: 15px; height: 15px; accent-color: var(--blue); margin: 0; }
.chk.sm { font-size: 11px; font-weight: 500; }
.plc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 8px; }
.aset-bidcap.off { display: none; }
.aset-bf {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line-2);
}
.aset-note { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--mut); }
.aset-note .ic { width: 14px; height: 14px; color: var(--ok); }
.aset-fbtns { display: flex; gap: 6px; }
.v3btn.sm { height: 30px; padding: 0 10px; font-size: 12px; }
.aset-empty {
  display: flex; flex-direction: column; align-items: center; gap: 5px; text-align: center;
  margin-top: 12px; padding: 24px 18px; border: 1px dashed var(--line-2); border-radius: 12px; color: var(--mut);
}
.aset-empty .ic { width: 22px; height: 22px; color: var(--mut-2); }
.aset-empty b { color: var(--ink); font-size: 13px; }
.aset-empty span { font-size: 12px; max-width: 380px; }
.st-setitem-side { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--mut); flex: 0 0 auto; }
.stat-dot { width: 6px; height: 6px; border-radius: 50%; background: #cbd5e1; display: inline-block; }
.stat-dot.on { background: #16a34a; }

@media (max-width: 1180px) {
  .aset-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .aset-h { flex-wrap: wrap; }
  .aset-id { flex: 1 1 100%; order: 1; }
  .aset-cv { order: 0; }
  .aset-pill { order: 2; }
  .aset-tools { order: 3; margin-left: auto; }
  .aset-sum { order: 4; flex: 1 1 100%; text-align: left; display: flex; gap: 8px; align-items: baseline; }
  .aset-sum small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .aset-f2, .plc-grid { grid-template-columns: 1fr; }
  .st-setitem-side { display: none; }
}

/* mobile refinements for the ad set editor */
@media (max-width: 900px) {
  .cardhead-sub { display: none; }
  #b-setcard .cardhead-l h3 { white-space: nowrap; }
}
@media (max-width: 820px) {
  .aset-h { row-gap: 7px; }
  .aset-id { flex: 1 1 calc(100% - 40px); }
  .aset-pill { margin-left: 32px; }
  .aset-tools { margin-left: auto; }
  .aset-sum { padding-left: 32px; }
  .aset-b { padding: 9px; }
  .aset-sec { padding: 9px 10px; }
}

/* ==========================================================================
   Layout breathing room + fluid field grid for the Ad Sets editor
   ========================================================================== */
.v3body { grid-template-columns: minmax(0, 1fr) clamp(360px, 27vw, 620px); }
@media (max-width: 1500px) {
  .v3body { grid-template-columns: minmax(0, 1fr) clamp(340px, 25vw, 470px); }
  .adgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.v3main { overflow-x: hidden; }
#b-setcard, .aset, .aset-list, .aset-grid, .aset-sec, .aset-f2, .plc-grid { min-width: 0; }
.aset { overflow-x: clip; }
.aset-grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.aset-grid > *, .aset-f2 > *, .plc-grid > *, .aset-sec > * { min-width: 0; }
.aset-sec select, .aset-sec input, .aset-sec .aset-in { max-width: 100%; }

/* sections stack in one column while the card is narrow, then split again */
.aset-grid { grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); align-items: start; }
.aset-sec { display: flex; flex-direction: column; gap: 8px; }
.ctry-add { align-items: center; }
.ctry-add input { flex: 1 1 90px; min-width: 0; }
.ctry-add .v3btn { flex: 0 0 auto; white-space: nowrap; padding: 0 10px; }
.agerow { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 4px; }
.agerow select { width: 100%; min-width: 0; padding-right: 16px; }
.aset-f2 .seg { width: 100%; }
.aset-f2 .seg .seg-b { flex: 1 1 0; justify-content: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aset-f2 .fld > span { white-space: nowrap; }
.aset-f2 .fld > span em { white-space: normal; }
@media (max-width: 820px) {
  .aset-grid { grid-template-columns: 1fr; }
}

/* segmented controls keep their natural width inside field columns */
.aset-f2 .seg { width: auto; max-width: 100%; flex-wrap: nowrap; }
.aset-f2 .seg .seg-b { flex: 0 0 auto; white-space: nowrap; padding: 0 10px; }

.ctry-add .v3btn { min-width: 54px; height: 32px; line-height: 1.5; }

.ctry { font-size: 12px; font-weight: 600; padding: 0 5px 0 10px; }

.ctry { font-weight: 500; letter-spacing: 0; }
