/* =====================================================================
   WA Chat Suite - form controls
   Themed replacements for the three native widgets that ignore CSS and
   render in the operating system's own colours: <select>, the date input
   and a phone field with a country picker.

   Every control keeps its real <input>/<select> in the DOM (hidden), so
   forms submit exactly as before and the page still works without JS.
   ===================================================================== */

/* ------------------------------------------------------- shared popup */
.pop{
  position:fixed;z-index:300;min-width:180px;max-width:min(420px,calc(100vw - 24px));
  background:var(--surface);border:1px solid var(--border);border-radius:12px;
  box-shadow:var(--shadow);padding:6px;display:flex;flex-direction:column;
  animation:popIn .13s cubic-bezier(.2,.8,.3,1);overflow:hidden;
}
@keyframes popIn{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:none}}
.pop-search{position:relative;padding:2px 2px 6px;flex:none}
.pop-search input{
  width:100%;min-height:36px;padding:8px 12px 8px 34px;font-size:13.5px;
  background:var(--bg);border:1px solid var(--border);border-radius:8px;color:var(--text);outline:none;
}
html[data-theme="light"] .pop-search input{background:var(--surface2)}
.pop-search input:focus{border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ring)}
.pop-search .i{position:absolute;left:12px;top:50%;transform:translateY(-50%);margin-top:-3px;width:16px;height:16px;color:var(--muted);pointer-events:none}
.pop-list{overflow-y:auto;overscroll-behavior:contain;max-height:288px;margin:0 -2px;padding:0 2px}
.pop-opt{
  display:flex;align-items:center;gap:10px;width:100%;text-align:left;border:0;background:none;
  padding:9px 11px;border-radius:8px;color:var(--text);font:inherit;font-size:13.5px;line-height:1.35;
  cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.pop-opt:hover,.pop-opt.hot{background:var(--hover)}
.pop-opt[aria-selected="true"]{background:var(--primary-soft);color:var(--primary);font-weight:600}
.pop-opt .tick{margin-left:auto;width:16px;height:16px;flex:none;opacity:0;color:var(--primary)}
.pop-opt[aria-selected="true"] .tick{opacity:1}
.pop-opt .lbl{overflow:hidden;text-overflow:ellipsis}
.pop-empty{padding:18px 12px;text-align:center;color:var(--muted);font-size:13px}
.pop-foot{flex:none;display:flex;gap:6px;padding:6px 2px 2px;margin-top:4px;border-top:1px solid var(--border)}
.pop-foot button{
  flex:1;padding:7px 10px;border-radius:8px;border:1px solid var(--border);background:transparent;
  color:var(--muted);font:inherit;font-size:12.5px;font-weight:600;cursor:pointer;
}
.pop-foot button:hover{border-color:var(--primary);color:var(--primary)}

/* ------------------------------------------------------ custom select */
.sel{position:relative;display:block;width:100%}
.sel > select{
  position:absolute;left:0;top:0;width:100%;height:100%;opacity:0;pointer-events:none;margin:0;
}
.sel-btn{
  display:flex;align-items:center;gap:9px;width:100%;min-height:40px;
  padding:calc(9px * var(--density)) 12px;background:var(--bg);border:1px solid var(--border);
  border-radius:var(--radius-sm);color:var(--text);font:inherit;font-size:14px;text-align:left;
  cursor:pointer;transition:border-color .15s,box-shadow .15s;
}
html[data-theme="light"] .sel-btn{background:var(--surface)}
.sel-btn:hover{border-color:var(--muted)}
.sel-btn .sel-val{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.sel-btn .sel-val.ph{color:var(--muted)}
.sel-btn .sel-chev{width:16px;height:16px;flex:none;color:var(--muted);transition:transform .18s}
.sel.open .sel-btn{border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ring)}
.sel.open .sel-chev{transform:rotate(180deg)}
.sel-btn:focus-visible{border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ring);outline:none}
.sel.disabled{opacity:.55;pointer-events:none}

/* the workspace switcher in the top bar wears the same chrome as the buttons */
.ws-pick .sel-btn{
  height:38px;min-height:38px;padding:0 12px 0 38px;background:var(--surface);
  border-radius:10px;font-size:13.5px;font-weight:600;max-width:230px;
}
.ws-pick .sel{width:auto}
.ws-pick .sel-btn .sel-val{max-width:150px}
/* the static chevron is the native select's; ours is inside the button */
.ws-pick:has(.sel) .i.r{display:none}

/* places where the native select carried its own sizing */
.btn-line .sel-btn{min-height:38px;padding:8px 10px;font-size:13px;background:var(--surface)}
.scope-bar .sel{width:auto;min-width:220px}
.inline .sel{width:auto}

/* ------------------------------------------------------- date picker */
.dp{position:relative;display:block;width:100%}
.dp > input[type=date],.dp > input.dp-real{
  position:absolute;left:0;top:0;width:100%;height:100%;opacity:0;pointer-events:none;margin:0;
}
.dp-field{
  display:flex;align-items:center;gap:9px;width:100%;min-height:40px;
  padding:calc(9px * var(--density)) 12px;background:var(--bg);border:1px solid var(--border);
  border-radius:var(--radius-sm);transition:border-color .15s,box-shadow .15s;cursor:text;
}
html[data-theme="light"] .dp-field{background:var(--surface)}
.dp-field input{
  flex:1;min-width:0;border:0;background:none;outline:none;box-shadow:none;padding:0;min-height:0;
  color:var(--text);font:inherit;font-size:14px;
}
.dp-field input::placeholder{color:var(--muted);opacity:.7}
.dp-field .dp-open{
  background:none;border:0;padding:0;width:24px;height:24px;flex:none;display:grid;place-items:center;
  color:var(--muted);cursor:pointer;border-radius:6px;
}
.dp-field .dp-open:hover{color:var(--primary);background:var(--hover)}
.dp-field .dp-open .i{width:18px;height:18px}
.dp.open .dp-field,.dp-field:focus-within{border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ring)}

.dp-pop{min-width:288px;padding:10px}
.dp-head{display:flex;align-items:center;gap:6px;margin-bottom:8px}
.dp-head .dp-nav{
  width:32px;height:32px;flex:none;border:0;background:none;border-radius:8px;color:var(--muted);
  display:grid;place-items:center;cursor:pointer;
}
.dp-head .dp-nav:hover{background:var(--hover);color:var(--text)}
.dp-head .dp-nav .i{width:17px;height:17px}
.dp-head .dp-title{
  flex:1;border:0;background:none;color:var(--text);font:inherit;font-size:14px;font-weight:700;
  padding:6px 8px;border-radius:8px;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:6px;
}
.dp-head .dp-title:hover{background:var(--hover)}
.dp-head .dp-title .i{width:14px;height:14px;color:var(--muted)}
.dp-dow{display:grid;grid-template-columns:repeat(7,1fr);gap:2px;margin-bottom:4px}
.dp-dow span{
  text-align:center;font-size:10.5px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;
  color:var(--muted);padding:4px 0;
}
.dp-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:2px}
.dp-day{
  height:36px;border:0;background:none;border-radius:9px;color:var(--text);font:inherit;font-size:13.5px;
  cursor:pointer;display:grid;place-items:center;position:relative;
}
.dp-day:hover{background:var(--hover)}
.dp-day.out{color:var(--muted);opacity:.45}
.dp-day.today{font-weight:700;color:var(--primary)}
.dp-day.today::after{
  content:"";position:absolute;bottom:5px;left:50%;transform:translateX(-50%);
  width:4px;height:4px;border-radius:50%;background:var(--primary);
}
.dp-day.on{background:var(--primary);color:var(--on-primary);font-weight:700}
.dp-day.on::after{background:var(--on-primary)}
.dp-months{display:grid;grid-template-columns:repeat(3,1fr);gap:4px}
.dp-months button{
  padding:11px 4px;border:0;background:none;border-radius:9px;color:var(--text);font:inherit;font-size:13px;cursor:pointer;
}
.dp-months button:hover{background:var(--hover)}
.dp-months button.on{background:var(--primary);color:var(--on-primary);font-weight:700}
.dp-years{max-height:232px;overflow-y:auto;display:grid;grid-template-columns:repeat(4,1fr);gap:4px}
.dp-years button{padding:9px 4px;border:0;background:none;border-radius:8px;color:var(--text);font:inherit;font-size:13px;cursor:pointer}
.dp-years button:hover{background:var(--hover)}
.dp-years button.on{background:var(--primary);color:var(--on-primary);font-weight:700}

/* ------------------------------------------------------ phone + flag */
.phone{display:flex;align-items:stretch;gap:0;width:100%;position:relative}
.phone > input[type=hidden]{display:none}
.phone-cc{
  display:flex;align-items:center;gap:7px;flex:none;padding:0 10px 0 12px;min-height:40px;
  background:var(--bg);border:1px solid var(--border);border-right:0;
  border-radius:var(--radius-sm) 0 0 var(--radius-sm);color:var(--text);font:inherit;font-size:14px;
  cursor:pointer;transition:border-color .15s,background .15s;
}
html[data-theme="light"] .phone-cc{background:var(--surface2)}
.phone-cc:hover{background:var(--hover)}
.phone-cc .flag{font-size:17px;line-height:1;font-family:"Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif}
/* the fallback badge on platforms without flag glyphs */
.flag .iso{
  display:inline-block;font-family:var(--font);font-size:10px;font-weight:800;letter-spacing:.04em;
  line-height:1;padding:4px 5px;border-radius:5px;background:var(--primary-soft);color:var(--primary);
}
.phone-cc .dial{font-variant-numeric:tabular-nums;color:var(--muted);font-size:13.5px}
.phone-cc .i{width:14px;height:14px;color:var(--muted);flex:none}
.phone-num{
  flex:1;min-width:0;border-radius:0 var(--radius-sm) var(--radius-sm) 0!important;
  letter-spacing:.01em;
}
.phone.focus .phone-cc,.phone:focus-within .phone-cc{border-color:var(--primary)}
.phone.focus .phone-num,.phone:focus-within .phone-num{border-color:var(--primary)}
.phone-cc:focus-visible{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ring)}
.phone-hint{font-size:12px;color:var(--muted);margin-top:6px}
.phone-hint b{color:var(--text);font-variant-numeric:tabular-nums}

.cc-pop{min-width:320px}
.cc-pop .pop-opt{gap:11px}
.cc-pop .flag{font-size:18px;line-height:1;flex:none;width:26px;text-align:center;
  font-family:"Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif}
.cc-pop .dial{margin-left:auto;color:var(--muted);font-size:12.5px;font-variant-numeric:tabular-nums;flex:none}
.cc-pop .pop-opt[aria-selected="true"] .dial{color:var(--primary)}

/* the visitor chat is a smaller canvas */
.modal .phone-cc{min-height:44px}
.modal .phone-num{min-height:44px}

@media(max-width:560px){
  .pop{max-width:calc(100vw - 20px)}
  .cc-pop,.dp-pop{min-width:min(320px,calc(100vw - 20px))}

  /* ui-controls.js docks every popover to the bottom below this width and
     hands the geometry over here. Bigger rows too - these are the targets a
     thumb actually has to hit. */
  .pop.sheet{
    left:0;right:0;bottom:0;top:auto;width:100%;max-width:none;min-width:0!important;
    border-radius:18px 18px 0 0;border-bottom:0;
    padding:14px 10px calc(10px + env(safe-area-inset-bottom));
    box-shadow:0 -6px 20px rgba(0,0,0,.28),0 -24px 60px rgba(0,0,0,.4);
    animation:sheetUp .22s cubic-bezier(.2,.8,.3,1);
  }
  /* the grab handle that says "this pulls up from the bottom" */
  .pop.sheet::before{
    content:"";position:absolute;top:6px;left:50%;transform:translateX(-50%);
    width:38px;height:4px;border-radius:2px;background:var(--border-strong);
  }
  .pop.sheet .pop-list{max-height:min(54vh,430px)}
  .pop.sheet .pop-opt{padding:13px 12px;font-size:15px;border-radius:10px}
  .pop.sheet .pop-search input{min-height:46px;font-size:16px}
  .pop.sheet .pop-foot button{padding:11px 10px;font-size:13.5px}
  .pop.sheet .dp-day{height:42px;font-size:15px}
  .pop.sheet .dp-months button,.pop.sheet .dp-years button{padding:13px 4px;font-size:14px}
}
@keyframes sheetUp{from{transform:translateY(100%)}to{transform:none}}
@media(prefers-reduced-motion:reduce){.pop{animation:none}}
