/* Alerts: the "Create alert" button, the popup to create or edit an alert, and toasts.
   Load it on every page that can create alerts (Listings for now) and on /alerts.
   Colors and sizes follow all_listings_styles.css and the gate/empty-state buttons. */

.am-vh {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}

/* ===== Button that opens the popup (Listings toolbar) ===== */
.alert_trigger {
  all: unset;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 13px 0 11px;
  border: 1px solid var(--border-color, #363636);
  border-radius: 8px;
  color: var(--text-1-color, #C2C2C2);
  font: 600 14px/1 'Inter', sans-serif;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.alert_trigger svg { color: #5b9bd0; }
.alert_trigger:hover {
  border-color: #4a4a4a;
  background-color: var(--background-color, #212121);
  color: #f2f2f2;
}
.alert_trigger:focus-visible { outline: 2px solid #8fb4e6; outline-offset: 2px; }

/* ===== Shared controls (also used on /alerts) ===== */
.am-btn {
  all: unset;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: 700 14px/1.2 'Inter', sans-serif;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.am-btn--primary { background: #4676b5; color: #fff; }
.am-btn--primary:hover { background: #3e6aa6; }
.am-btn--ghost { border-color: #424242; color: #c2c2c2; }
.am-btn--ghost:hover { border-color: #5e5e5e; color: #f2f2f2; }
.am-btn--small {
  min-height: 34px;
  padding: 0 12px;
  border-color: #424242;
  border-radius: 8px;
  color: #c2c2c2;
  font-size: 13px;
  font-weight: 600;
}
.am-btn--small:hover { border-color: #5e5e5e; color: #f2f2f2; }
.am-btn:disabled { opacity: 0.55; cursor: default; }
.am-btn:focus-visible { outline: 2px solid #8fb4e6; outline-offset: 2px; }

.am-link {
  all: unset;
  color: var(--text-2-color, #A3A3A3);
  text-decoration: underline;
  text-decoration-color: #5c5c5c;
  text-underline-offset: 3px;
  cursor: pointer;
}
.am-link:hover { color: #f2f2f2; text-decoration-color: #f2f2f2; }
.am-link:focus-visible { outline: 2px solid #8fb4e6; outline-offset: 2px; border-radius: 2px; }

.am-input {
  box-sizing: border-box;
  display: block;
  width: 100%;
  height: 36px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid var(--border-color, #363636);
  border-radius: 8px;
  background: none;
  color: var(--text-1-color, #C2C2C2);
  font: 14px/1 'Inter', sans-serif;
  transition: border-color 0.15s;
}
.am-input::placeholder { color: rgba(163, 163, 163, 0.5); opacity: 1; }
.am-input:hover { border-color: #4a4a4a; }
.am-input:focus { border-color: #5b9bd0; outline: none; }
.am-input.is-invalid { border-color: rgba(239, 83, 80, 0.85); }

.am-select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 32px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='5' viewBox='0 0 9 5'%3E%3Cpath d='M8.124 1.732 4.063 4.077 0 1.732 1 0l3.063 1.768L7.124 0z' fill='%23A3A3A3' fill-opacity='.6'/%3E%3C/svg%3E") no-repeat right 12px center / 9px 5px;
  cursor: pointer;
  text-overflow: ellipsis;
}
.am-select option { background: #1C1C1C; color: #C2C2C2; }

.am-hint {
  margin: 8px 0 0;
  color: #8a8a8a;
  font-size: 13px;
  line-height: 1.45;
}
.am-hint.is-error { color: #EF5350; }
.am-hint.is-ok { color: #26A69A; }

.am-seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border-color, #363636);
  border-radius: 10px;
}
.am-seg-opt { position: relative; display: block; }
.am-seg-opt span {
  display: flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 7px;
  color: var(--text-2-color, #A3A3A3);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, color 0.15s;
}
.am-seg-opt span:hover { color: #f2f2f2; }
.am-seg-opt input:checked + span { background: #2e2e2e; color: #f2f2f2; }
.am-seg-opt input:focus-visible + span { outline: 2px solid #8fb4e6; outline-offset: 1px; }

/* Narrow phones: three equal cells, long labels wrap inside their cell */
@media (max-width: 420px) {
  .am-seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .am-seg-opt span {
    justify-content: center;
    height: auto;
    min-height: 34px;
    padding: 4px 6px;
    line-height: 1.2;
    text-align: center;
    white-space: normal;
  }
}

/* ===== Popup ===== */
html.am-open { overflow: hidden; }

.am {
  box-sizing: border-box;
  width: min(560px, calc(100vw - 32px));
  max-width: none;
  max-height: min(820px, calc(100dvh - 48px));
  margin: auto;
  padding: 0;
  border: 1px solid #424242;
  border-radius: 16px;
  background: var(--body-color, #1C1C1C);
  color: var(--text-2-color, #A3A3A3);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 0 23px 8px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.am[open] { display: flex; flex-direction: column; }
.am::backdrop { background: rgba(0, 0, 0, 0.55); }
.am *, .am *::before, .am *::after { box-sizing: border-box; }
.am :where(h2, h3, p, ul, li) { margin: 0; padding: 0; }
.am :where(ul) { list-style: none; }
.am [hidden] { display: none !important; }

.am-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin: 0;
}

.am-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--background-color, #212121);
}
.am-head-text { flex: 1; min-width: 0; }
.am-title {
  color: #f2f2f2;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.am-title:focus { outline: none; }
.am-sub { margin-top: 4px; }

.am-x {
  all: unset;
  box-sizing: border-box;
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin: -6px -10px 0 0;
  border-radius: 8px;
  color: #8a8a8a;
  cursor: pointer;
}
.am-x:hover { background: var(--background-color, #212121); color: #f2f2f2; }
.am-x:focus-visible { outline: 2px solid #8fb4e6; }

.am-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 24px 8px;
  scrollbar-width: thin;
  scrollbar-color: #363636 transparent;
}

.am-sec {
  padding: 18px 0;
  border-bottom: 1px solid var(--background-color, #212121);
}
.am-sec:last-of-type { border-bottom: 0; }
.am-sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.am-label {
  display: block;
  margin: 0 0 10px;
  color: var(--text-1-color, #C2C2C2);
  font-size: 14px;
  font-weight: 600;
}
.am-sec-head .am-label { margin: 0; }
.am-opt { margin-left: 4px; color: #8a8a8a; font-size: 13px; font-weight: 400; }

/* Price (any "range" field) */
.am-range { display: flex; align-items: center; gap: 10px; }
.am-num { position: relative; flex: 1; max-width: 150px; }
.am-num .am-input { padding-right: 26px; font-variant-numeric: tabular-nums; }
.am-unit {
  position: absolute;
  top: 0;
  right: 10px;
  bottom: 0;
  display: flex;
  align-items: center;
  color: rgba(163, 163, 163, 0.5);
  font-size: 13px;
  pointer-events: none;
}
.am-sep { flex: none; width: 8px; height: 1.5px; background: rgba(163, 163, 163, 0.5); }

/* Filters taken from the page */
.am-rows {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  overflow: hidden;
  border-radius: 10px;
}
.am-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
  padding: 5px 6px 5px 12px;
  background: var(--background-color, #212121);
}
.am-row-k { flex: none; width: 112px; color: #8a8a8a; font-size: 13px; }
.am-row-v { flex: 1; min-width: 0; color: var(--text-1-color, #C2C2C2); overflow-wrap: anywhere; }
.am-row-x {
  all: unset;
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: #8a8a8a;
  cursor: pointer;
}
.am-row-x:hover { background: #2e2e2e; color: #f2f2f2; }
.am-row-x:focus-visible { outline: 2px solid #8fb4e6; }
.am-row-x--locked { cursor: default; }
.am-row-x--locked:hover { background: none; }

.am-note { margin-top: 10px; color: #8a8a8a; font-size: 13px; }
.am-warn {
  display: flex;
  gap: 9px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(228, 174, 57, 0.08);
  color: #d9b25a;
  font-size: 13px;
  line-height: 1.45;
}
.am-warn svg { flex: none; margin-top: 1px; }
.am-warn--error { background: rgba(239, 83, 80, 0.08); color: #EF5350; }

/* Channels */
.am-channels { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.am-ch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 8px 12px;
  border: 1px solid var(--border-color, #363636);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background-color 0.15s;
}
.am-ch:hover { border-color: #4a4a4a; }
.am-ch.is-on { border-color: rgba(38, 166, 154, 0.55); background: rgba(38, 166, 154, 0.05); }
.am-ch:has(.am-vh:focus-visible) { outline: 2px solid #8fb4e6; outline-offset: 2px; }
.am-check {
  flex: none;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-color, #363636);
  border-radius: 4px;
  color: transparent;
}
.am-ch.is-on .am-check { border-color: transparent; background: #26A69A99; color: #1C1C1C; }
.am-ch-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--background-color, #212121);
  color: #8a8a8a;
}
.am-ch.is-on .am-ch-icon { color: #f2f2f2; }
.am-ch-text { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; }
.am-ch-name { color: var(--text-1-color, #C2C2C2); font-weight: 600; }
.am-ch-sub {
  overflow: hidden;
  color: #8a8a8a;
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.am-ch-extra { margin: 8px 0 4px; }
.am-ch-extra > .am-hint:first-child { margin-top: 0; }

.am-discord {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 12px;
  border-radius: 10px;
  background: var(--background-color, #212121);
}
.am-discord-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.am-discord-foot .am-hint { margin: 0; flex: 1; min-width: 160px; }
.am-discord > .am-hint { margin: 0; }

/* Footer */
.am-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-top: 1px solid var(--background-color, #212121);
}
.am-foot-link { font-size: 13px; }
.am-foot-btns { display: flex; gap: 8px; margin-left: auto; }

.am-error {
  margin: 4px 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239, 83, 80, 0.08);
  color: #EF5350;
  font-size: 13px;
}
.am-preview { margin: 2px 0 16px; color: rgba(163, 163, 163, 0.55); font-size: 12px; }

/* Loading, login / Pro gate, errors */
.am-state {
  position: relative;
  padding: 44px 32px 34px;
  text-align: center;
}
.am-state .am-x { position: absolute; top: 14px; right: 14px; margin: 0; }
.am-state--loading { display: grid; place-items: center; min-height: 240px; }
.am-state-icon {
  display: inline-grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin-bottom: 16px;
  border-radius: 14px;
  background: var(--background-color, #212121);
  color: #5b9bd0;
}
.am-state-text { max-width: 27em; margin: 10px auto 0; font-size: 15px; line-height: 1.5; }
.am-state-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}
.am-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #333333;
  border-top-color: #0081B9;
  border-radius: 50%;
  animation: am-spin 0.8s linear infinite;
}
@keyframes am-spin { to { transform: rotate(360deg); } }

/* Phones: bottom sheet, like the filter sheet on Listings */
@media (max-width: 600px) {
  .am {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 16px);
    margin: auto 0 0;
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
  }
  .am-head { padding: 18px 18px 14px; }
  .am-body { padding: 0 18px 8px; }
  .am-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .am-foot-link { display: none; }
  .am-foot-btns { flex: 1; }
  .am-foot-btns .am-btn { flex: 1; }
  .am-row-k { width: 92px; }
  .am-num { max-width: none; }
  .am-input { font-size: 16px; } /* iOS zooms into smaller inputs */
  .am-state { padding: 40px 20px calc(28px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: no-preference) {
  .am[open] { animation: am-in 0.18s cubic-bezier(0.2, 0.7, 0.2, 1); }
  .am[open]::backdrop { animation: am-fade 0.18s ease-out; }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 600px) {
  .am[open] { animation: am-up 0.22s cubic-bezier(0.2, 0.7, 0.2, 1); }
}
@keyframes am-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes am-up { from { transform: translateY(100%); } }
@keyframes am-fade { from { opacity: 0; } }

/* ===== Toast ===== */
.am-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border: 1px solid #424242;
  border-radius: 10px;
  background: #2a2a2a;
  color: #f2f2f2;
  font: 500 14px/1.4 'Inter', sans-serif;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.am-toast.is-on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.am-toast--error { border-color: rgba(239, 83, 80, 0.55); }
.am-toast a { color: #8fb4e6; font-weight: 600; text-decoration: none; white-space: nowrap; }
.am-toast a:hover { text-decoration: underline; }
