/*
 * Totemia GIS — notices (gis-notify.js), in the portal's Alert anatomy
 * (PortalAlert / shadcn/ui Alert): icon, bold title, muted description,
 * optional action. Two uses:
 *   .gis-toast   a pop-up card over the map; enters from the edge it stacks
 *                against, leaves the same way, faster.
 *   .gis-alert   an inline callout inside a panel — card, or indicator (tinted
 *                strip with a thick left bar) for a short result.
 * Flat surfaces on the GIS tokens: a border separates, never a depth shadow.
 */

.gis-toasts,
.gis-alert {
  --notice-ink: var(--gis-ink);
}

.gis-toast[data-tone="success"],
.gis-alert[data-tone="success"] { --notice-tone: #15803d; }
.gis-toast[data-tone="warning"],
.gis-alert[data-tone="warning"] { --notice-tone: #8a6320; }
.gis-toast[data-tone="error"],
.gis-alert[data-tone="error"] { --notice-tone: #b42318; }
.gis-toast[data-tone="info"],
.gis-alert[data-tone="info"] { --notice-tone: #1f4f7a; }
.gis-toast[data-tone="progress"],
.gis-alert[data-tone="progress"] { --notice-tone: var(--gis-ink); }

/* ── Pop-up stack ──────────────────────────────────────────────────────── */

.gis-toasts {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(400px, calc(100vw - 24px));
  font-family: var(--gis-font);
  transform: translateX(-50%);
  pointer-events: none;
}

.gis-toast {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 4px 12px;
  overflow: hidden;
  padding: 10px 8px 10px 14px;
  border: 1px solid var(--gis-line);
  border-radius: 12px;
  background: var(--gis-paper);
  color: var(--gis-ink);
  pointer-events: auto;
  transition:
    opacity var(--duration) var(--ease-out),
    transform var(--duration) var(--ease-out);
}

/* A slim tone bar on the leading edge; grows in when the notice arrives. */
.gis-toast::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--notice-tone, var(--gis-ink));
  transform-origin: top center;
  transition:
    transform var(--duration-slow) var(--ease-out),
    background var(--duration) var(--ease-out);
}

@starting-style {
  .gis-toast {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }

  .gis-toast::before {
    transform: scaleY(0);
  }
}

.gis-toast.is-leaving {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition-duration: var(--duration-fast);
}

.gis-toast-media {
  position: relative;
  display: grid;
  place-items: center;
}

.gis-toast-thumb {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--gis-ivory);
}

.gis-toast-mark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: var(--notice-tone, var(--gis-ink));
}

/* With a thumbnail the tone rides on a small badge at its corner. */
.gis-toast-mark.is-badge {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 22px;
  height: 22px;
  border: 2px solid var(--gis-paper);
  border-radius: 50%;
  background: var(--gis-paper);
}

.gis-toast[data-tone="progress"] .gis-toast-mark svg {
  animation: gis-toast-spin 0.9s linear infinite;
}

@keyframes gis-toast-spin {
  to { transform: rotate(360deg); }
}

.gis-toast-mark svg {
  transition: transform var(--duration-slow) var(--ease-out);
}

/* The result icon settles in when a notice changes tone. */
@starting-style {
  .gis-toast-mark svg {
    transform: scale(0.6);
  }
}

.gis-toast-text {
  min-width: 0;
}

.gis-toast-title,
.gis-toast-detail {
  margin: 0;
}

.gis-toast-title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gis-toast[data-tone="error"] .gis-toast-title,
.gis-toast[data-tone="warning"] .gis-toast-title,
.gis-toast[data-tone="success"] .gis-toast-title {
  color: var(--notice-tone);
}

.gis-toast-detail {
  display: -webkit-box;
  margin-top: 2px;
  overflow: hidden;
  color: var(--gis-muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.gis-toast-detail[hidden],
.gis-toast-bar[hidden],
.gis-toast-action[hidden] {
  display: none;
}

.gis-toast-action button {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--gis-line);
  border-radius: 8px;
  background: var(--gis-paper);
  color: var(--gis-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}

.gis-toast-action button:active {
  transform: scale(0.97);
}

.gis-toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: start;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--gis-muted);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.gis-toast-close:focus-visible,
.gis-toast-action button:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(196, 152, 31, 0.32);
}

/* A determinate bar for one finite upload — never a live meter. */
.gis-toast-bar {
  grid-column: 1 / -1;
  height: 3px;
  margin: 6px 2px 0;
  overflow: hidden;
  border-radius: 999px;
  background: var(--gis-ivory);
}

.gis-toast-bar span {
  display: block;
  height: 100%;
  background: var(--gis-green);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--duration) var(--ease-out);
}

/* ── Inline callout ────────────────────────────────────────────────────── */

.gis-alert {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 2px 10px;
  overflow: hidden;
  padding: 10px 14px;
  border: 1px solid var(--gis-line);
  border-radius: 10px;
  background: var(--gis-paper);
  color: var(--gis-ink);
  font-family: var(--gis-font);
  font-size: 14px;
  transition:
    opacity var(--duration) var(--ease-out),
    transform var(--duration) var(--ease-out);
}

@starting-style {
  .gis-alert {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.gis-alert > svg {
  grid-row: span 2;
  margin-top: 1px;
  color: var(--notice-tone);
}

.gis-alert-title,
.gis-alert-detail {
  grid-column: 2;
  margin: 0;
}

.gis-alert-title {
  font-weight: 800;
}

.gis-alert-detail {
  color: var(--gis-muted);
  font-size: 13px;
}

.gis-alert[data-appearance="indicator"] {
  padding-left: 18px;
  border-color: color-mix(in srgb, var(--notice-tone) 32%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--notice-tone) 9%, var(--gis-paper));
  color: var(--notice-tone);
}

.gis-alert[data-appearance="indicator"]::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--notice-tone);
}

.gis-alert[data-appearance="indicator"] .gis-alert-detail {
  color: color-mix(in srgb, var(--notice-tone) 78%, var(--gis-ink));
}

@media (hover: hover) and (pointer: fine) {
  .gis-toast-close:hover {
    background: var(--gis-ivory);
    color: var(--gis-ink);
  }

  .gis-toast-action button:hover {
    background: var(--gis-ivory);
  }
}

@media (pointer: coarse) {
  .gis-toast-close {
    width: 44px;
    height: 44px;
  }

  .gis-toast-action button {
    min-height: 44px;
  }
}

/* Phones: the place panel is a bottom sheet, so notices drop from the top,
   under the search bar, and leave upward. */
@media (max-width: 720px) {
  .gis-toasts {
    top: calc(max(12px, env(safe-area-inset-top)) + 60px);
    bottom: auto;
  }

  @starting-style {
    .gis-toast {
      transform: translateY(-12px) scale(0.98);
    }
  }

  .gis-toast.is-leaving {
    transform: translateY(-12px) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  .gis-toast,
  .gis-toast.is-leaving,
  .gis-alert {
    transform: none;
    transition-property: opacity;
  }

  .gis-toast::before,
  .gis-toast-mark svg {
    transition: none;
  }

  @starting-style {
    .gis-toast,
    .gis-alert {
      transform: none;
    }

    .gis-toast::before {
      transform: none;
    }

    .gis-toast-mark svg {
      transform: none;
    }
  }

  .gis-toast[data-tone="progress"] .gis-toast-mark svg {
    animation-duration: 2.4s;
  }

  .gis-toast-bar span,
  .gis-toast-action button {
    transition: none;
  }
}
