/* PetShirube AI Concierge widget. All selectors are prefixed with .psc- to avoid host-page clashes. */
.psc-root {
  --psc-primary: #4f7565;
  --psc-primary-text: #ffffff;
  --psc-accent: #c7a45d;
  --psc-bg: #ffffff;
  --psc-text: #2f3437;
  --psc-bot: #f1f4f2;
  --psc-user: #e3ece7;
  position: fixed;
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 2147483000;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--psc-text);
}
.psc-root *, .psc-root *::before, .psc-root *::after { box-sizing: border-box; }

.psc-launcher {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 11px 18px 11px 14px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: linear-gradient(180deg, #dcc088 0%, var(--psc-accent) 100%);
  color: #1f1a0e;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(60, 44, 10, 0.32);
}
.psc-launcher-icon { flex: none; }
.psc-launcher:focus-visible, .psc-root button:focus-visible, .psc-input:focus-visible {
  outline: 3px solid var(--psc-accent);
  outline-offset: 2px;
}

.psc-panel {
  display: flex;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 540px;
  max-height: calc(100vh - 100px - env(safe-area-inset-top, 0px));
  margin-bottom: 12px;
  background: var(--psc-bg);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22);
}
.psc-panel[hidden] { display: none; }

.psc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--psc-primary);
  color: var(--psc-primary-text);
}
.psc-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.psc-reset, .psc-close {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.psc-reset { font-size: 12px; border: 1px solid rgba(255, 255, 255, 0.6); }
.psc-close { font-size: 20px; line-height: 1; }

.psc-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.psc-msg { display: flex; flex-direction: column; max-width: 88%; }
.psc-assistant { align-self: flex-start; }
.psc-user { align-self: flex-end; align-items: flex-end; }
.psc-bubble { padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.psc-assistant .psc-bubble { background: var(--psc-bot); border-top-left-radius: 4px; }
.psc-user .psc-bubble { background: var(--psc-user); border-top-right-radius: 4px; }
.psc-typing .psc-bubble { opacity: 0.7; font-style: italic; }
.psc-notice { margin-top: 4px; font-size: 12px; color: #6b5a2e; }

.psc-biz-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.psc-biz { display: flex; flex-direction: column; padding: 8px 10px; border: 1px dashed var(--psc-accent); border-radius: 8px; background: #fffdf7; }
.psc-badge { align-self: flex-start; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 4px; background: var(--psc-accent); color: #1f1a0e; }
.psc-biz-name { margin-top: 2px; }
.psc-biz-area, .psc-biz-labels { font-size: 12px; opacity: 0.85; }
.psc-biz-link { font-size: 12px; margin-top: 2px; color: var(--psc-primary); }

.psc-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.psc-chip {
  border: 1px solid var(--psc-primary);
  background: var(--psc-bg);
  color: var(--psc-primary);
  border-radius: 999px;
  padding: 3px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.psc-form { display: flex; gap: 8px; padding: 8px 12px 0; border-top: 1px solid #e5e8e6; }
.psc-input {
  flex: 1;
  resize: none;
  border: 1px solid #cfd6d2;
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  color: var(--psc-text);
}
.psc-send {
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--psc-primary);
  color: var(--psc-primary-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.psc-send:disabled { opacity: 0.5; cursor: default; }
.psc-counter { padding: 2px 12px 0; text-align: right; font-size: 11px; opacity: 0.7; }
.psc-counter.psc-over { color: #b3261e; opacity: 1; }
.psc-footer { margin: 0; padding: 4px 12px 10px; font-size: 11px; opacity: 0.75; }

/* Optional per-turn logging opt-in (shown only when the server can log text; unchecked by default). */
.psc-consent { padding: 6px 12px 0; }
.psc-consent[hidden] { display: none; }
.psc-consent-label { display: flex; align-items: flex-start; gap: 6px; font-size: 12px; cursor: pointer; }
.psc-consent-input { flex: none; width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--psc-primary); cursor: pointer; }
.psc-consent-input:focus-visible { outline: 3px solid var(--psc-accent); outline-offset: 2px; }
.psc-consent-input:disabled { cursor: default; }
.psc-consent-help { margin: 2px 0 0 22px; font-size: 11px; line-height: 1.5; opacity: 0.75; }

/* R21: the opt-in and its help take ~110px. The suggestion chips (4 stacked rows, ~135px) give up the space instead,
   as one scrollable row, so the greeting stays readable (PC 1280x800: log 114px -> fits) and nothing is clipped. */
.psc-has-consent .psc-chips, .psc-compact .psc-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
.psc-has-consent .psc-chip, .psc-compact .psc-chip { flex: none; white-space: nowrap; }

/* Short visible area (keyboard open, landscape phone, short desktop window), any width. Before R21 these rules
   applied only under 480px wide, so a 740x360 landscape phone clipped the input/send row even with the opt-in off. */
.psc-compact .psc-footer, .psc-compact .psc-counter { display: none; }
/* Keyboard open: keep the opt-in reachable, drop its long help (still the box's aria-describedby). */
.psc-compact .psc-consent { padding-top: 0; }
.psc-compact .psc-consent-help { display: none; }
.psc-compact .psc-header { padding: 6px 10px; }

.psc-retry {
  align-self: flex-start;
  margin-top: 6px;
  border: 1px solid var(--psc-primary);
  background: var(--psc-bg);
  color: var(--psc-primary);
  border-radius: 8px;
  padding: 4px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.psc-retry:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 480px) {
  .psc-root {
    right: calc(10px + env(safe-area-inset-right, 0px));
    bottom: calc(10px + env(safe-area-inset-bottom, 0px) + var(--psc-kb-inset, 0px));
    max-width: calc(100vw - 20px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }
  .psc-launcher { padding: 8px 14px 8px 11px; font-size: 13px; gap: 6px; min-height: 44px; } /* 44px tap target */
  .psc-launcher-icon { width: 18px; height: 18px; }
  /* While the panel is open the launcher would only cover the page / the chat input: hide it (close X is in the header). */
  .psc-open .psc-launcher { display: none; }
  .psc-panel {
    width: calc(100vw - 20px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    max-width: none;
    margin-bottom: 0;
    height: calc(100vh - 90px);
    height: calc(100dvh - 90px);
    /* Visible height (visual viewport) minus top/bottom gutters; falls back to the rules above without the JS variable. */
    max-height: calc(var(--psc-vvh, 100vh) - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  .psc-compact .psc-panel { height: calc(var(--psc-vvh) - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }
  .psc-consent-label { align-items: center; min-height: 44px; } /* whole row is the tap target */
  .psc-consent-input { width: 20px; height: 20px; margin: 0; }
  .psc-compact .psc-consent-label { min-height: 36px; }
  .psc-retry { min-height: 44px; } /* tap target */
  .psc-log { min-height: 0; }
  .psc-form { padding-bottom: 8px; }
  .psc-input { font-size: 16px; } /* >=16px prevents iOS focus-zoom */
}

/* R21: touch screens wider than 480px (landscape phone, tablet) keep the tap targets the SP layout has. */
@media (pointer: coarse) and (min-width: 481px) {
  .psc-consent-label { align-items: center; min-height: 44px; }
  .psc-compact .psc-consent-label { min-height: 36px; }
  .psc-retry { min-height: 44px; }
}

/* Touch screens (any width): enlarge the small controls. Header buttons grow their hit area with negative margins so
   the header height does not change; the business link is a standalone row, not inline prose. */
@media (pointer: coarse) {
  .psc-close, .psc-reset { min-height: 44px; margin: -8px 0; }
  .psc-close { min-width: 44px; }
  .psc-reset { padding: 2px 10px; }
  .psc-compact .psc-close, .psc-compact .psc-reset { min-height: 40px; margin: -8px 0; }
  .psc-chip { min-height: 36px; padding: 3px 12px; }
  .psc-compact .psc-chip { min-height: 32px; }
  .psc-biz-link { display: inline-flex; align-items: center; align-self: flex-start; min-height: 44px; margin-top: 0; }
}

/* R22: touch screens wider than 480px (landscape phone, tablet): the on-screen keyboard shrinks only the visual
   viewport, so follow it like the narrow layout does (psc-kb-inset / psc-vvh come from widget.js). */
@media (pointer: coarse) and (min-width: 481px) {
  .psc-root { bottom: calc(20px + env(safe-area-inset-bottom, 0px) + var(--psc-kb-inset, 0px)); }
  .psc-panel { max-height: calc(var(--psc-vvh, 100vh) - 100px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }
}

/* R22: landscape phone (short, wide, touch): the launcher under the open panel only costs ~60px of a ~390px screen.
   Hide it while open (the close button is in the header) and give the message log that room
   (20px gutters: the root keeps its 20px bottom offset here). */
@media (pointer: coarse) and (min-width: 481px) and (max-height: 520px) {
  .psc-open .psc-launcher { display: none; }
  .psc-panel {
    margin-bottom: 0;
    max-height: calc(var(--psc-vvh, 100vh) - 40px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  .psc-compact .psc-panel { height: calc(var(--psc-vvh) - 40px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }
}
