/* my-gui overlay: dropdown menu, modal, toast, tooltip (step 374).
   Values measured on the running My Atlas (docs/look.md 12, 13, 16, 18.3-18.5); behaviour in js/ui.js.
   Shadow strengths follow --m-sk (light .32, dark 1), so one rule serves every theme. */

/* ---------- dropdown menu ---------- */

.m-dd { position: relative; display: flex; }

.m-dd [data-m-dd] .m-chev {
  width: 11px;
  height: 11px;
  opacity: .6;
  transition: transform .22s var(--m-ease);
}
.m-dd.is-open [data-m-dd] .m-chev { transform: rotate(180deg); }

/* closed: stays in the DOM (display block), hidden by visibility and opacity, so it fades out */
.m-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 70;
  display: block;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--m-glass-edge);
  border-radius: 14px;
  background: var(--m-glass);
  box-shadow: var(--m-pop-sh);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  backdrop-filter: blur(22px) saturate(1.6);
  color: var(--m-text);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px) scale(.97);
  transform-origin: top left;
  transition: opacity .16s ease, transform .28s var(--m-spring), visibility 0s linear .16s;
}
.m-menu--right { right: 0; left: auto; transform-origin: top right; }
/* top / left are set by ui.js under the button; right stays free, or the menu would stretch to the window edge */
.m-menu--fixed, .m-menu--fixed.m-menu--right { position: fixed; right: auto; }

.m-dd.is-open > .m-menu {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity .16s ease, transform .28s var(--m-spring), visibility 0s;
}

.m-menu [hidden] { display: none !important; }
.m-menu > p { margin: 4px 10px 6px; }
.m-menu > .m-input { width: 100%; }

.m-mi {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 31px;
  margin: 0;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.m-mi:hover, .m-mi:focus-visible { background: rgba(var(--m-accent-rgb), .15); outline: none; }
.m-mi:disabled, .m-mi[aria-disabled="true"] { opacity: .5; cursor: default; background: transparent; }
.m-mi .m-i { width: 15px; height: 15px; opacity: .85; }
.m-mi .m-ck { color: var(--m-accent); opacity: 0; }
.m-mi[aria-checked="true"] .m-ck { opacity: 1; }

.m-msep { height: 1px; margin: 5px 8px; background: var(--m-line); }

/* ---------- modal ---------- */

/* closed: stays in the DOM, faded out; the scrim is the .m-modal itself */
.m-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--m-scrim);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--m-text);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility 0s linear .2s;
}
.m-modal.is-open { opacity: 1; visibility: visible; transition: opacity .2s ease, visibility 0s; }
.m-modal[hidden] { display: none; }

/* the app drags the box by an inline transform: no transform rule here beats it (inline wins) */
.m-modal-box {
  display: flex;
  flex-direction: column;
  width: min(480px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: hidden;
  border: 1px solid rgba(var(--m-ink), .14);
  border-radius: 20px;
  background: var(--m-modal);
  box-shadow:
    0 40px 100px -20px rgba(var(--m-shade), calc(.95 * var(--m-sk))),
    inset 0 1px 0 rgba(var(--m-ink), .06);
  transform: translateY(14px) scale(.965);
  transition: transform .42s var(--m-spring), opacity .32s var(--m-ease), box-shadow .32s var(--m-ease);
}
.m-modal.is-open .m-modal-box { transform: none; }

.m-modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(var(--m-ink), .06);
}
.m-modal-head > .m-h2 { flex: 1 1 0%; font-size: 17px; line-height: 1.25; font-weight: 800; }

.m-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px 18px;
  overflow: auto;
}

.m-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  padding: 12px 18px 16px;
}
.m-modal-foot[hidden] { display: none; }

/* page scroll is held while a modal is open (ui.js sets it only when the page itself scrolls) */
:root.m-modal-lock { overflow: hidden; }

/* ---------- toast ---------- */

.m-toasts {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 110;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  transform: translateX(-50%);
  pointer-events: none;
}
.m-toasts:empty { display: none; }

.m-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(460px, calc(100vw - 32px));
  padding: 9px 14px 9px 10px;
  border: 1px solid var(--m-glass-edge);
  border-radius: 14px;
  background: var(--m-glass-strong);
  box-shadow: 0 20px 50px -14px rgba(var(--m-shade), calc(.9 * var(--m-sk)));
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: var(--m-text);
  font-size: 12.5px;
  line-height: 1.45;
  font-weight: 600;
  pointer-events: auto;
  animation: m-toast-in .38s var(--m-spring) backwards;
  transition: opacity .22s ease, transform .26s var(--m-ease);
}
.m-toast.is-out { opacity: 0; transform: translateY(8px) scale(.97); }

@keyframes m-toast-in {
  from { opacity: 0; transform: translateY(14px) scale(.94); }
  to { opacity: 1; transform: none; }
}

.m-toast-ico {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(180deg, rgba(var(--m-accent-rgb), .55), rgba(40, 117, 232, .45));
  box-shadow: inset 0 0 0 1px rgba(120, 185, 255, .45);
}
.m-toast-ico .m-i { width: 13px; height: 13px; stroke-width: 2.2px; }

.m-toast--good .m-toast-ico {
  background: linear-gradient(180deg, #2FC05A, #0C8F0C);
  box-shadow: inset 0 0 0 1px rgba(140, 230, 160, .45);
}
.m-toast--err .m-toast-ico {
  background: linear-gradient(180deg, #FF5A72, #D6243E);
  box-shadow: inset 0 0 0 1px rgba(255, 140, 160, .5);
}
/* decided (374): warn has its own yellow variant; the dark mark keeps the icon readable on yellow */
.m-toast--warn .m-toast-ico {
  color: #3D2A00;
  background: linear-gradient(180deg, rgba(255, 255, 255, .25), rgba(255, 255, 255, 0)), var(--m-warn);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}

/* ---------- tooltip: data-tip="text" [data-tip-pos="below|below-end|end|right"] ---------- */

/* zero specificity: an app rule may still position the host */
:where([data-tip]) { position: relative; }

/* on ::after, so that the app can override the hidden state (max-width: 0) and the multi-line variant */
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 9px);
  left: 50%;
  z-index: 60;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--m-tip);
  color: var(--m-tip-text);
  box-shadow:
    0 8px 20px -6px rgba(var(--m-shade), calc(.85 * var(--m-sk))),
    inset 0 0 0 1px rgba(255, 255, 255, .08);
  font-family: var(--m-font);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
  text-align: left;
  text-transform: none;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 4px);
  transition: opacity .15s ease, transform .25s var(--m-spring);
}
[data-tip=""]::after { display: none; }

[data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
@media (hover: hover) {
  [data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); }
}

[data-tip-pos="below"]::after { top: calc(100% + 9px); bottom: auto; transform: translate(-50%, -4px); }

[data-tip-pos="below-end"]::after { top: calc(100% + 9px); bottom: auto; left: auto; right: 0; transform: translateY(-4px); }

[data-tip-pos="end"]::after { left: auto; right: 0; transform: translateY(4px); }

[data-tip-pos="right"]::after { top: 50%; bottom: auto; left: calc(100% + 9px); transform: translate(-4px, -50%); }

[data-tip-pos="below"]:focus-visible::after { transform: translate(-50%, 0); }
[data-tip-pos="below-end"]:focus-visible::after,
[data-tip-pos="end"]:focus-visible::after { transform: none; }
[data-tip-pos="right"]:focus-visible::after { transform: translate(0, -50%); }
@media (hover: hover) {
  [data-tip-pos="below"]:hover::after { transform: translate(-50%, 0); }
  [data-tip-pos="below-end"]:hover::after,
  [data-tip-pos="end"]:hover::after { transform: none; }
  [data-tip-pos="right"]:hover::after { transform: translate(0, -50%); }
}
