/*
 * iPresso Inbox — self-scoped styles (issues 05–10).
 *
 * Everything is namespaced under `.ipresso-inbox-*` and self-contained so the plugin
 * blends with the theme (Orgarium in production; verified against Twenty Twenty-One)
 * without depending on or overriding it. Only the font is inherited (`font: inherit`);
 * surfaces are neutral and defined here. A single inline SVG bell is used (no icon
 * font). The bell activates in place — the active and anonymous states share the same
 * box so there is no layout shift.
 *
 * Issue 10 (theme blend) added the control reset just below: because the plugin injects
 * its own `<button>`s and `<a>`s into a live theme, aggressive global element rules can
 * repaint them. The reset shields the plugin's controls; see its comment for the why.
 */

/* --- Control reset: shield the plugin's buttons/anchors from the theme ----
 *
 * The plugin injects `<button>`s and `<a>`s into a live theme. Classic/block themes
 * ship aggressive *global* element rules — e.g. Twenty Twenty-One styles every
 * `button:not(:hover):not(:active):not(.has-background)` with a dark primary
 * background and light text, at (0,3,1) specificity (three `:not()`s). That outranks
 * a plain plugin class ((0,1,0)) and repaints our list rows, the delete "×", the
 * "load more" control, the CTA, and the modal close as dark theme buttons — the theme
 * *breaking* the plugin (spec → "no visible collision", "the theme must not break it").
 *
 * Rather than an escalating specificity war against an arbitrary theme, we reset the
 * theme-inherited surface/typography properties on exactly our own controls back to a
 * neutral, self-contained baseline. `!important` is used deliberately — it's the only
 * reliable way to beat a theme's `:not()`-inflated global element rules without
 * guessing at their selectors — and mirrors the already-documented `display: flex
 * !important` decision on `.ipresso-inbox-row`. Each control's real look is set by its
 * own rule below; this only neutralizes what the theme would otherwise impose. */
.ipresso-inbox-bell-button,
.ipresso-inbox-row-open,
.ipresso-inbox-row-delete,
.ipresso-inbox-row-confirm-yes,
.ipresso-inbox-row-confirm-no,
.ipresso-inbox-load-more,
.ipresso-inbox-modal-close,
.ipresso-inbox-modal-cta {
  box-sizing: border-box !important;
  width: auto !important;
  min-width: 0 !important;
  background: transparent !important;
  color: inherit !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  text-decoration: none !important;
  font: inherit !important;
  -webkit-appearance: none !important;
  appearance: none !important;
}

.ipresso-inbox-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  font: inherit;
}

.ipresso-inbox-bell-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px !important;
  height: 40px;
  padding: 0;
  cursor: pointer;
  line-height: 0;
}

.ipresso-inbox-bell-button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
  border-radius: 4px;
}

.ipresso-inbox-bell-icon {
  width: 22px;
  height: 22px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

/* Unread badge (issue 07): a small count pill on the bell button, hidden at zero.
 * Absolutely positioned so it overlays the icon without affecting the bell's box —
 * activation and count changes cause no layout shift. */
.ipresso-inbox-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #b3261e;
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
}

.ipresso-inbox-badge[hidden] {
  display: none;
}

/* Anonymous/disabled and error states: greyed, non-interactive-looking. Same box as
 * active, so activation causes no layout shift. */
.ipresso-inbox-bell[data-state="anonymous"] .ipresso-inbox-bell-button,
.ipresso-inbox-bell[data-state="error"] .ipresso-inbox-bell-button {
  opacity: 0.45;
}

.ipresso-inbox-bell[data-state="error"] .ipresso-inbox-bell-icon {
  stroke: #b3261e;
}

.ipresso-inbox-bell[data-state="active"] .ipresso-inbox-bell-button {
  opacity: 1;
}

/* Info/error panel shown on click in the non-active states. */
.ipresso-inbox-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 1000;
  width: 260px;
  padding: 12px 14px;
  background: #ffffff;
  color: #1f1f1f;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 0.85rem;
  line-height: 1.4;
}

.ipresso-inbox-bell[data-open="true"] .ipresso-inbox-panel {
  display: block;
}

/* --- Dropdown: the Inbox itself (issue 06) -------------------------------- */

/* When the panel is the dropdown, drop the info-panel text padding — rows and
 * notices carry their own — and widen it a touch for the list. The dropdown view
 * (inbox-dropdown.mjs) adds `.ipresso-inbox-dropdown` to the panel element itself,
 * so this styles the same element that carries `.ipresso-inbox-panel`. */
.ipresso-inbox-panel.ipresso-inbox-dropdown {
  width: 320px;
  padding: 0;
}

/* The dropdown is height-capped as a whole (spec: "the dropdown never grows past
 * this"): the list scrolls inside the cap while "load more" / notices stay pinned
 * below it. Gated on `data-open` so the flex layout only applies while the panel is
 * open — otherwise this `display: flex` would override the panel's `display: none`
 * default (the panel carries both classes) and the dropdown could never be closed. */
.ipresso-inbox-bell[data-open="true"] .ipresso-inbox-dropdown {
  display: flex;
  flex-direction: column;
  max-height: 380px;
}

.ipresso-inbox-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  /* Allow the flex child to shrink below its content height so it — not the whole
   * dropdown — is what scrolls. */
  min-height: 0;
}

/* The row lays its open-button and its trailing delete control side by side; the
 * open-button flexes to fill and the actions sit at the trailing edge (issue 09).
 *
 * `display: flex` is forced with `!important` because these rows are `<li>`s injected
 * into the theme's real nav menu, and a theme's menu rules can outrank a plain
 * plugin class (Twenty Twenty-One's `.primary-navigation > div > .menu-wrapper li`
 * sets `display: block` at a higher specificity). Rather than an escalating
 * specificity war against an arbitrary theme, we pin the one layout-critical property
 * — this keeps the plugin self-contained and theme-agnostic (spec → "blend … without
 * depending on or breaking the theme's styling"). */
.ipresso-inbox-row {
  display: flex !important;
  align-items: stretch;
  border-bottom: 1px solid #f0f0f0;
}

.ipresso-inbox-row:last-child {
  border-bottom: 0;
}

/* Hovering anywhere on the row tints the whole row (open-button + actions). */
.ipresso-inbox-row:hover {
  background: #f6f6f6;
}

/* The message body is a button (keyboard-openable) that opens the full-message modal
 * (issue 08). The native button chrome is stripped by the control reset above; here it
 * just lays out as a list row and flexes to fill the row beside the delete control. */
.ipresso-inbox-row-open {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  text-align: left;
  cursor: pointer;
}

.ipresso-inbox-row-title {
  font-weight: 400;
  /* Truncate rather than widen the row. The row-open button is a flex column; its
   * children default to `min-width: auto`, so the title's min-content width (text +
   * emoji) would force the button past its flex basis and overflow the dropdown.
   * `min-width: 0` lets it shrink, and the ellipsis truncates the excess. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Unread rows read heavier and carry a small leading dot; a read row (opened) drops
 * both. Driven by the row's data-read hook the list controller flips in place. */
.ipresso-inbox-row[data-read="false"] .ipresso-inbox-row-title {
  font-weight: 600;
}

.ipresso-inbox-row[data-read="false"] .ipresso-inbox-row-title::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #1a73e8;
  vertical-align: middle;
}

.ipresso-inbox-row-lead {
  color: #5f5f5f;
  font-size: 0.8rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Per-row delete (issue 09): the trailing control that swaps between an idle "×"
 * trigger and an in-row "Delete? / Cancel" confirm. It sits at the row's trailing edge
 * and is centred against the (multi-line) message body. */
.ipresso-inbox-row-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding-right: 8px;
}

/* The idle "×" trigger — a quiet, greyed control that darkens on hover, so it does not
 * compete with the message content. */
.ipresso-inbox-row-delete {
  width: 28px !important;
  height: 28px;
  padding: 0;
  color: #9e9e9e !important;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50% !important;
}

.ipresso-inbox-row-delete:hover {
  background: #ececec !important;
  color: #b3261e !important;
}

/* The in-row confirm prompt + Delete / Cancel buttons. */
.ipresso-inbox-row-confirm-prompt {
  color: #5f5f5f;
  font-size: 0.78rem;
}

.ipresso-inbox-row-confirm-yes,
.ipresso-inbox-row-confirm-no {
  padding: 3px 8px;
  border: 1px solid #e0e0e0 !important;
  background: #ffffff !important;
  color: inherit;
  font-size: 0.78rem;
  line-height: 1.2;
  cursor: pointer;
  border-radius: 6px !important;
}

/* The confirming "Delete" reads as the destructive action. */
.ipresso-inbox-row-confirm-yes {
  border-color: #b3261e !important;
  background: #b3261e !important;
  color: #ffffff !important;
  font-weight: 600;
}

.ipresso-inbox-row-confirm-yes:hover {
  background: #9c211a !important;
}

.ipresso-inbox-row-confirm-no:hover {
  background: #f0f0f0 !important;
}

.ipresso-inbox-row-confirm-yes:disabled,
.ipresso-inbox-row-confirm-no:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Empty / loading / error lines. */
.ipresso-inbox-notice {
  padding: 16px 14px;
  color: #5f5f5f;
  text-align: center;
}

.ipresso-inbox-notice--error {
  color: #b3261e;
}

/* "Load more" sits under the list, full width, pinned below the scroll region. */
.ipresso-inbox-load-more {
  display: block;
  width: 100% !important;
  padding: 10px 14px;
  border-top: 1px solid #e0e0e0 !important;
  cursor: pointer;
}

.ipresso-inbox-load-more:hover {
  background: #f6f6f6 !important;
}

.ipresso-inbox-load-more:disabled {
  opacity: 0.6;
  cursor: default;
}

/* --- Full-message modal (issue 08) --------------------------------------- */

/* The overlay is portaled to `<body>` (out of the header's stacking context) so it
 * floats above the whole page while the dropdown stays open behind it. A very high
 * z-index and its own fixed backdrop keep it self-contained — no dependency on, and
 * no collision with, the theme. */
.ipresso-inbox-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 16px 16px;
  background: rgba(0, 0, 0, 0.45);
  font: inherit;
}

.ipresso-inbox-modal-overlay[hidden] {
  display: none;
}

.ipresso-inbox-modal {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  background: #ffffff;
  color: #1f1f1f;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

/* The message content wrapper inside the padded modal (title, lead, content, CTA, or a
 * loading/error notice). A plain block; the modal's padding and the children's own
 * rules carry the layout. */
.ipresso-inbox-modal-body {
  min-width: 0;
}

.ipresso-inbox-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px !important;
  height: 32px;
  padding: 0;
  color: #5f5f5f !important;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50% !important;
}

.ipresso-inbox-modal-close:hover {
  background: #f0f0f0 !important;
  color: #1f1f1f !important;
}

.ipresso-inbox-modal-title {
  margin: 0 32px 8px 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.ipresso-inbox-modal-lead {
  margin: 0 0 12px;
  color: #5f5f5f;
}

.ipresso-inbox-modal-content {
  line-height: 1.5;
}

.ipresso-inbox-modal-content img {
  max-width: 100%;
  height: auto;
}

/* The CTA: a plain new-tab anchor (the URL self-tracks the click). */
.ipresso-inbox-modal-cta {
  display: inline-block;
  margin-top: 16px !important;
  padding: 9px 16px;
  background: #1a73e8 !important;
  color: #ffffff !important;
  border-radius: 8px !important;
  font-weight: 600;
}

.ipresso-inbox-modal-cta:hover {
  background: #1666cf !important;
}

.ipresso-inbox-modal-notice {
  padding: 8px 0;
  color: #5f5f5f;
}

.ipresso-inbox-modal-notice--error {
  color: #b3261e;
}
