/* notifications.css — the bell's panel, toast and header button
   (notifications.js, NMNotify). Loaded by the map page and, through
   nav-auth.js, by every other page — so it carries its own colours for
   both themes and assumes nothing from style.css, theme.css or pages.css.

   Wide screens: a panel beside the bell. Phones (≤ 640 px): a sheet from
   the bottom with a handle, over a dimmed page. Dimmed text uses explicit
   colours per theme (5.98:1 light, 5.71:1 dark), never opacity — opacity
   measured under AA on white (style.css's note on the old panel). */

.nmn-panel,
.nmn-toast,
.nmn-bell {
  --nmn-bg: #ffffff;
  --nmn-fg: #1f2937;
  --nmn-dim: #5b6472;
  --nmn-line: rgba(15, 23, 42, 0.09);
  --nmn-hover: rgba(34, 139, 34, 0.07);
  --nmn-unread: rgba(34, 197, 94, 0.08);
  --nmn-brand: #1a7a1a;
  --nmn-accent: #228b22;
  --nmn-chip: #f1f5f9;
  --nmn-shadow: 0 18px 48px rgba(15, 23, 42, 0.22), 0 2px 6px rgba(15, 23, 42, 0.08);
}
[data-theme='dark'] .nmn-panel,
[data-theme='dark'] .nmn-toast,
[data-theme='dark'] .nmn-bell {
  --nmn-bg: #1e293b;
  --nmn-fg: #e2e8f0;
  --nmn-dim: #94a3b8;
  --nmn-line: rgba(255, 255, 255, 0.08);
  --nmn-hover: rgba(74, 222, 128, 0.09);
  --nmn-unread: rgba(34, 197, 94, 0.13);
  --nmn-brand: #6ee7b7;
  --nmn-accent: #4ade80;
  --nmn-chip: #334155;
  --nmn-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

/* ── The header bell (pages other than the map) ─────────────────────── */
.nmn-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid currentColor;
  border-color: color-mix(in srgb, currentColor 25%, transparent);
  background: transparent;
  color: inherit;
  cursor: pointer;
  vertical-align: middle;
  flex: none;
}
.nmn-bell:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
.nmn-bell:focus-visible { outline: 2px solid #22c55e; outline-offset: 2px; }
.nmn-bell svg { width: 18px; height: 18px; }
.nmn-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font: 700 0.66rem/18px system-ui, sans-serif;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
  font-variant-numeric: tabular-nums;
}
[data-theme='dark'] .nmn-badge { box-shadow: 0 0 0 2px #1e293b; }
.nmn-badge[hidden] { display: none; }

/* A new arrival rings the bell once. */
.nmn-ring svg { animation: nmnRing 0.9s ease-in-out; transform-origin: 50% 8%; }
@keyframes nmnRing {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(16deg); }
  30% { transform: rotate(-14deg); }
  45% { transform: rotate(10deg); }
  60% { transform: rotate(-6deg); }
  75% { transform: rotate(3deg); }
}

/* ── Panel ──────────────────────────────────────────────────────────── */
.nmn-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1340;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  transition: opacity 0.2s;
}
.nmn-backdrop.is-open { opacity: 1; }
.nmn-backdrop[hidden] { display: none; }

.nmn-panel {
  position: fixed;
  z-index: 1350;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--nmn-bg);
  color: var(--nmn-fg);
  border: 1px solid var(--nmn-line);
  border-radius: 14px;
  box-shadow: var(--nmn-shadow);
  font: 400 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  text-align: left;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.nmn-panel.is-open { opacity: 1; transform: none; }
.nmn-panel[hidden] { display: none; }
.nmn-panel *,
.nmn-panel *::before,
.nmn-panel *::after { box-sizing: border-box; }
.nmn-panel button { font: inherit; color: inherit; }

.nmn-grab { display: none; }
.nmn-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 8px 16px;
}
.nmn-title {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--nmn-fg);
  outline: none;
}
.nmn-markall {
  border: 0;
  background: none;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.8rem !important;
  font-weight: 700;
  color: var(--nmn-brand) !important;
  cursor: pointer;
}
.nmn-markall:hover:not(:disabled) { background: var(--nmn-hover); }
.nmn-markall:disabled { opacity: 0.45; cursor: default; }
.nmn-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--nmn-dim) !important;
  cursor: pointer;
}
.nmn-close:hover { background: var(--nmn-hover); color: var(--nmn-fg) !important; }

.nmn-tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--nmn-line);
}
.nmn-tab {
  border: 0;
  background: none;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem !important;
  font-weight: 700;
  color: var(--nmn-dim) !important;
  cursor: pointer;
}
.nmn-tab[aria-selected='true'] { background: var(--nmn-chip); color: var(--nmn-fg) !important; }
.nmn-tab:focus-visible,
.nmn-markall:focus-visible,
.nmn-close:focus-visible,
.nmn-open:focus-visible,
.nmn-x:focus-visible,
.nmn-go:focus-visible,
.nmn-older:focus-visible,
.nmn-admin-row:focus-visible,
.nmn-all:focus-visible { outline: 2px solid var(--nmn-accent); outline-offset: 2px; }

.nmn-admin {
  margin: 8px 12px 0;
  padding: 8px;
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.nmn-admin[hidden] { display: none; }
.nmn-admin-h {
  padding: 0 4px 4px;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--nmn-dim);
}
.nmn-admin-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px;
  border-radius: 7px;
  color: var(--nmn-fg) !important;
  text-decoration: none !important;
  font-size: 0.82rem;
}
.nmn-admin-row b { font-variant-numeric: tabular-nums; }
.nmn-admin-row span { margin-left: auto; color: var(--nmn-dim); }
.nmn-admin-row:hover { background: rgba(245, 158, 11, 0.14); }

.nmn-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.nmn-list { list-style: none; margin: 0; padding: 4px 0; }
.nmn-day {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 16px 4px;
  background: var(--nmn-bg);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--nmn-dim);
}

.nmn-item {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: start;
  padding: 10px 10px 10px 14px;
  border-left: 3px solid transparent;
}
.nmn-item:hover { background: var(--nmn-hover); }
.nmn-item.is-unread { background: var(--nmn-unread); border-left-color: var(--nmn-accent); }
.nmn-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: #fff;
  background: #64748b;
  flex: none;
}
.kind-account .nmn-ico, .nmn-ico.kind-account { background: #2563eb; }
.kind-reminder .nmn-ico, .nmn-ico.kind-reminder { background: #d97706; }
.kind-payment .nmn-ico, .nmn-ico.kind-payment { background: #16a34a; }
.kind-document .nmn-ico, .nmn-ico.kind-document { background: #7c3aed; }
.kind-news .nmn-ico, .nmn-ico.kind-news { background: #db2777; }
.kind-admin .nmn-ico, .nmn-ico.kind-admin { background: #0f766e; }

.nmn-main { min-width: 0; }
.nmn-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.nmn-t {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--nmn-fg);
  overflow-wrap: anywhere;
}
.is-unread .nmn-t { font-weight: 800; }
.nmn-m {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin-top: 2px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--nmn-dim);
  overflow-wrap: anywhere;
}
.is-expanded .nmn-m { display: block; -webkit-line-clamp: unset; overflow: visible; white-space: pre-line; }
.nmn-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 4px;
  font-size: 0.74rem;
  color: var(--nmn-dim);
  font-variant-numeric: tabular-nums;
}
.nmn-go {
  font-weight: 700;
  color: #2563eb !important;
  text-decoration: none !important;
}
[data-theme='dark'] .nmn-go { color: #93c5fd !important; }
.nmn-go:hover { text-decoration: underline !important; }
.nmn-dot {
  position: absolute;
  top: 16px;
  right: 14px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--nmn-accent);
}
.nmn-x {
  width: 30px;
  height: 30px;
  margin-top: 14px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--nmn-dim) !important;
  font-size: 1.15rem !important;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
}
.nmn-item:hover .nmn-x,
.nmn-x:focus-visible { opacity: 1; }
.nmn-x:hover { background: var(--nmn-chip); color: var(--nmn-fg) !important; }

.nmn-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 32px 24px 28px;
  text-align: center;
  color: var(--nmn-dim);
  font-size: 0.82rem;
}
.nmn-empty svg { width: 34px; height: 34px; opacity: 0.5; margin-bottom: 4px; }
.nmn-empty b { color: var(--nmn-fg); font-size: 0.92rem; }

.nmn-more { padding: 0 12px; }
.nmn-more:empty { display: none; }
.nmn-older,
.nmn-error button {
  display: block;
  width: 100%;
  margin: 6px 0 10px;
  padding: 9px;
  border: 1px solid var(--nmn-line);
  border-radius: 9px;
  background: none;
  font-size: 0.8rem !important;
  font-weight: 700;
  color: var(--nmn-brand) !important;
  cursor: pointer;
}
.nmn-older:hover, .nmn-error button:hover { background: var(--nmn-hover); }
.nmn-loading, .nmn-error { padding: 14px 4px; text-align: center; font-size: 0.8rem; color: var(--nmn-dim); }
.nmn-spin {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  vertical-align: -2px;
  border: 2px solid var(--nmn-line);
  border-top-color: var(--nmn-accent);
  border-radius: 50%;
  animation: nmnSpin 0.8s linear infinite;
}
@keyframes nmnSpin { to { transform: rotate(360deg); } }

.nmn-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--nmn-line);
  text-align: center;
}
.nmn-all {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--nmn-brand) !important;
  text-decoration: none !important;
}
.nmn-all:hover { text-decoration: underline !important; }

.nmn-sr,
.nmn-live {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── New-arrival toast ──────────────────────────────────────────────── */
.nmn-toast {
  position: fixed;
  z-index: 1360;
  top: 70px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(380px, calc(100vw - 24px));
  padding: 10px 8px 10px 10px;
  border-radius: 12px;
  background: var(--nmn-bg);
  color: var(--nmn-fg);
  border: 1px solid var(--nmn-line);
  box-shadow: var(--nmn-shadow);
  font: 600 0.85rem/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
}
.nmn-toast.is-open { opacity: 1; transform: none; }
.nmn-toast[hidden] { display: none; }
.nmn-toast .nmn-ico { width: 30px; height: 30px; border-radius: 9px; }
.nmn-toast-t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.nmn-toast-v {
  border: 0;
  border-radius: 8px;
  padding: 7px 12px;
  background: #228b22;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.nmn-toast-x {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--nmn-dim);
  font-size: 1.15rem;
  cursor: pointer;
}

/* ── Phones: a sheet from the bottom ────────────────────────────────── */
@media (max-width: 640px) {
  .nmn-panel.is-sheet {
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0;
    width: auto !important;
    max-height: 85vh;
    max-height: 85dvh;
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    transform: translateY(100%);
    opacity: 1;
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .nmn-panel.is-sheet.is-open { transform: none; }
  .nmn-panel.is-sheet .nmn-grab {
    display: flex;
    justify-content: center;
    padding: 8px 0 0;
    touch-action: none;
  }
  .nmn-panel.is-sheet .nmn-grab span {
    width: 40px;
    height: 5px;
    border-radius: 999px;
    background: var(--nmn-line);
    background: color-mix(in srgb, var(--nmn-fg) 25%, transparent);
  }
  .nmn-panel.is-sheet .nmn-head { touch-action: none; }
  .nmn-toast {
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    max-width: none;
    transform: translateY(8px);
  }
}

/* Touch: the dismiss is always there (no hover to reveal it), and every
   control is a finger's width. */
@media (pointer: coarse) {
  .nmn-x { opacity: 1; width: 40px; height: 40px; margin-top: 8px; }
  .nmn-tab, .nmn-markall { min-height: 40px; }
  .nmn-close { width: 42px; height: 42px; }
  .nmn-admin-row { min-height: 40px; }
  .nmn-bell { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .nmn-panel, .nmn-panel.is-sheet, .nmn-toast, .nmn-backdrop { transition: none; }
  .nmn-ring svg, .nmn-spin { animation: none; }
}
