/**
 * PCC Library Chat Widget — Styles
 *
 * All selectors are scoped to .pcc-chat-* to prevent conflicts with host pages.
 * A mini reset inside .pcc-chat-widget neutralizes common host-page globals
 * (box-sizing, margins, font inheritance) that would otherwise bleed in.
 *
 * @version 0.1.0-scaffold
 */

/* ---------------------------------------------------------------------------
   Mini reset — scoped to widget root
   Prevents host-page globals on button, a, ul, li, iframe from leaking in.
--------------------------------------------------------------------------- */

.pcc-chat-widget,
.pcc-chat-widget *,
.pcc-chat-widget *::before,
.pcc-chat-widget *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.pcc-chat-widget {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #1a1a1a;
}

.pcc-chat-widget a {
  color: inherit;
  text-decoration: underline;
}

.pcc-chat-widget ul,
.pcc-chat-widget ol {
  list-style: none;
}

/* ---------------------------------------------------------------------------
   Positioning — fixed bottom-right container
   min-height reserved before init completes to prevent CLS.
--------------------------------------------------------------------------- */

.pcc-chat-widget {
  position: fixed;
  bottom: 0;
  right: 1rem;
  z-index: 200; /* overridden at runtime from config.zIndex */
  min-height: 48px; /* CLS prevention: reserve trigger tab height before JS runs */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* ---------------------------------------------------------------------------
   Trigger tab (the always-visible "Chat with a librarian" button)
--------------------------------------------------------------------------- */

.pcc-chat-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  background-color: #005362; /* PCC dark cyan */
  color: #ffffff;
  border: none;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.pcc-chat-trigger:hover,
.pcc-chat-trigger:focus-visible {
  background-color: #0d234c;
  outline: 3px solid #ffffff;
  outline-offset: -3px;
}

.pcc-chat-trigger__icon {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Drawer panel
--------------------------------------------------------------------------- */

.pcc-chat-panel {
  width: 400px;
  height: 420px;
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pcc-chat-panel[aria-hidden="true"] {
  display: none;
}

.pcc-chat-panel:not([aria-hidden="true"]) ~ .pcc-chat-trigger {
  display: none;
}

/* Panel header bar */
.pcc-chat-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background-color: #005362;
  color: #ffffff;
  flex-shrink: 0;
}

.pcc-chat-panel__title {
  font-size: 0.9375rem;
  font-weight: 600;
}

.pcc-chat-panel__close {
  background: none;
  border: none;
  color: #ffffff;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem;
  border-radius: 3px;
}

.pcc-chat-panel__close:hover,
.pcc-chat-panel__close:focus-visible {
  background-color: rgba(255, 255, 255, 0.2);
  outline: 2px solid #ffffff;
  outline-offset: 1px;
}

/* Panel body — fills remaining height */
.pcc-chat-panel__body {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

/* ---------------------------------------------------------------------------
   Loading state
--------------------------------------------------------------------------- */

.pcc-chat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #555555;
  font-size: 0.875rem;
}

/* ---------------------------------------------------------------------------
   Available state — LibraryH3lp iframe
--------------------------------------------------------------------------- */

.pcc-chat-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ---------------------------------------------------------------------------
   Unavailable state — offline message + LibAnswers fallback
--------------------------------------------------------------------------- */

.pcc-chat-offline {
  padding: 1.25rem 1rem;
}

.pcc-chat-offline__message {
  font-size: 0.9375rem;
  margin-bottom: 1rem;
}

.pcc-chat-offline__email-link {
  display: inline-block;
  margin-bottom: 1.25rem;
  font-weight: 600;
  color: #005362;
}

.pcc-chat-offline__fallback-btn {
  display: block;
  width: 100%;
  padding: 0.625rem 1rem;
  background-color: #005362;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
}

.pcc-chat-offline__fallback-btn:hover,
.pcc-chat-offline__fallback-btn:focus-visible {
  background-color: #0d234c;
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

.pcc-chat-offline__email-link:focus-visible,
.pcc-chat-error__links a:focus-visible {
  outline: 3px solid #005362;
  outline-offset: 2px;
  border-radius: 2px;
}

/* LibAnswers widget container — injected on demand */
.pcc-chat-libanswers {
  padding: 0.5rem;
}

/* ---------------------------------------------------------------------------
   Error state
--------------------------------------------------------------------------- */

.pcc-chat-error {
  padding: 1.25rem 1rem;
}

.pcc-chat-error__heading {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.pcc-chat-error__links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pcc-chat-error__links a {
  color: #005362;
  font-size: 0.875rem;
}

/* ---------------------------------------------------------------------------
   Aria-live region (visually hidden, read by screen readers)
--------------------------------------------------------------------------- */

.pcc-chat-live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------------------
   Mobile
--------------------------------------------------------------------------- */

@media (max-width: 400px) {
  .pcc-chat-widget {
    right: 0;
  }

  .pcc-chat-panel {
    width: 100vw;
    border-radius: 6px 6px 0 0;
  }
}
