/* ═══════════════════════════════════════════════════════════════
   copilot.css — AI Copilot chat widget
   All rules scoped to #chatToggle, #chatWidget, or .copilot-*
   Zero rules touch the global layout or topbar.
═══════════════════════════════════════════════════════════════ */

/* ── FAB toggle button ─────────────────────────────────────── */
#chatToggle {
  position: fixed !important;
  bottom: calc(env(safe-area-inset-bottom) + 95px) !important;
  right: 20px !important;
  z-index: 9999999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
  color: #0a0f0d;
  font-size: 1.45rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(0, 242, 254, 0.38), 0 2px 8px rgba(0, 0, 0, 0.45);
  opacity: 1 !important;
  visibility: visible !important;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

#chatToggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(0, 242, 254, 0.55), 0 2px 10px rgba(0, 0, 0, 0.5);
}

#chatToggle:active {
  transform: scale(0.96);
}

#chatToggle[aria-expanded="true"] {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

/* ── Chat window ───────────────────────────────────────────── */
#chatWidget {
  position: fixed !important;
  bottom: 158px;
  right: 22px;
  width: min(380px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 190px));
  z-index: 9999998;
  display: flex;
  flex-direction: column;
  background: rgba(11, 17, 14, 0.94);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid rgba(0, 242, 254, 0.18);
  border-radius: 18px;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.65), 0 0 0 0.5px rgba(0, 242, 254, 0.08);
  overflow: hidden;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.22s ease;
}

#chatWidget.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
}

/* ── Chat header ───────────────────────────────────────────── */
.copilot-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(0, 242, 254, 0.1);
  flex-shrink: 0;
}

.copilot-header-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #00f2fe;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(0, 242, 254, 0.7);
}

.copilot-header-title {
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: rgba(255, 255, 255, 0.92);
  flex: 1 1 auto;
}

.copilot-header-sub {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.38);
  flex-shrink: 0;
}

.copilot-header-greeting {
  font-size: 0.74rem;
  color: #00f2fe;
  opacity: 0.85;
  flex-shrink: 0;
}

.copilot-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.4);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s;
  flex-shrink: 0;
}

.copilot-close-btn:hover {
  color: rgba(255, 255, 255, 0.8);
}

/* ── Messages area ─────────────────────────────────────────── */
.copilot-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 242, 254, 0.18) transparent;
}

.copilot-messages::-webkit-scrollbar {
  width: 4px;
}

.copilot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.copilot-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 242, 254, 0.2);
  border-radius: 2px;
}

/* ── Message bubbles ───────────────────────────────────────── */
.copilot-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 0.84rem;
  line-height: 1.5;
  word-break: break-word;
}

.copilot-msg.is-user {
  align-self: flex-end;
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid rgba(0, 242, 254, 0.22);
  color: rgba(255, 255, 255, 0.92);
  border-bottom-right-radius: 4px;
}

.copilot-msg.is-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.86);
  border-bottom-left-radius: 4px;
}

.copilot-msg.is-error {
  align-self: flex-start;
  background: rgba(255, 80, 80, 0.1);
  border: 1px solid rgba(255, 80, 80, 0.22);
  color: rgba(255, 160, 160, 0.9);
  font-size: 0.8rem;
}

.copilot-msg.is-system {
  align-self: center;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.76rem;
  text-align: center;
  padding: 2px 0;
}

/* Streaming cursor */
.copilot-cursor::after {
  content: "▋";
  animation: copilot-blink 0.7s step-end infinite;
  color: #00f2fe;
  margin-left: 1px;
}

@keyframes copilot-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Config notice (shown when no API key) ─────────────────── */
.copilot-config-notice {
  margin: 8px 14px 0;
  padding: 10px 12px;
  background: rgba(255, 200, 0, 0.07);
  border: 1px solid rgba(255, 200, 0, 0.18);
  border-radius: 10px;
  font-size: 0.76rem;
  color: rgba(255, 220, 100, 0.8);
  line-height: 1.5;
  flex-shrink: 0;
}

.copilot-config-notice code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.74rem;
}

/* ── Input row ─────────────────────────────────────────────── */
.copilot-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.copilot-input {
  flex: 1 1 auto;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.84rem;
  padding: 8px 12px;
  outline: none;
  resize: none;
  font-family: inherit;
  line-height: 1.4;
  min-height: 38px;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s;
  scrollbar-width: none;
}

.copilot-input::-webkit-scrollbar {
  display: none;
}

.copilot-input:focus {
  border-color: rgba(0, 242, 254, 0.35);
}

.copilot-input::placeholder {
  color: rgba(255, 255, 255, 0.28);
}

.copilot-send-btn {
  background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: #0a0f0d;
  flex-shrink: 0;
  align-self: flex-end;
  transition: opacity 0.15s, transform 0.15s;
}

.copilot-send-btn:hover:not(:disabled) {
  opacity: 0.88;
  transform: scale(1.06);
}

.copilot-send-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
}

/* ── Provider badge ────────────────────────────────────────── */
.copilot-provider-badge {
  text-align: center;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.2);
  padding: 0 12px 8px;
  flex-shrink: 0;
}

/* ── Input notice (privacy reminder above badge) ─────────── */
.copilot-input-notice {
  text-align: center;
  font-size: 0.67rem;
  color: rgba(255, 255, 255, 0.28);
  padding: 0 12px 2px;
  flex-shrink: 0;
}

/* ── Chat consent notice ──────────────────────────────────── */
.copilot-consent-notice {
  align-self: stretch;
  max-width: 100%;
  background: rgba(0, 242, 254, 0.06);
  border: 1px solid rgba(0, 242, 254, 0.2);
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.80rem;
  line-height: 1.55;
  padding: 12px 14px;
}

.copilot-consent-btn {
  display: block;
  margin-top: 10px;
  width: 100%;
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid rgba(0, 242, 254, 0.3);
  border-radius: 7px;
  color: #00f2fe;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.copilot-consent-btn:hover {
  background: rgba(0, 242, 254, 0.22);
}

/* ── Mobile adjustments ────────────────────────────────────── */
@media (max-width: 768px) {
  #chatToggle {
    bottom: calc(env(safe-area-inset-bottom) + 95px) !important;
    right: 20px !important;
    width: 50px;
    height: 50px;
    font-size: 1.25rem;
  }

  #chatWidget {
    bottom: 140px;
    right: 14px;
    width: calc(100vw - 28px);
    max-height: calc(100vh - 160px);
    border-radius: 16px;
  }
}

@media (display-mode: standalone) and (max-width: 768px) {
  #chatToggle {
    bottom: calc(env(safe-area-inset-bottom) + 95px) !important;
    right: 20px !important;
  }
}

/* FINAL iOS STANDALONE TOP NAV TEXT FIT FIX */
.ios-pwa-standalone .app-shell {
  padding-top: 8px !important;
}

.ios-pwa-standalone .app-warning-banner {
  position: relative !important;
  z-index: 1000 !important;
  box-sizing: border-box !important;
  padding-top: calc(env(safe-area-inset-top, 0px) + 10px) !important;
  padding-bottom: 8px !important;
  height: auto !important;
  min-height: unset !important;
  overflow: visible !important;
}

.ios-pwa-standalone .app-header-card {
  position: relative !important;
  top: auto !important;
  z-index: 900 !important;
  min-height: unset !important;
  height: auto !important;
  box-sizing: border-box !important;
  margin-top: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  overflow: visible !important;
}

.ios-pwa-standalone .app-header-row {
  display: flex !important;
  align-items: center !important;
  box-sizing: border-box !important;
  min-height: 44px !important;
  height: auto !important;
  padding-top: 1px !important;
  padding-bottom: 1px !important;
  gap: 8px !important;
}

.ios-pwa-standalone .app-header-title,
body.ios-pwa-standalone .topbar-start .brand .app-header-title {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  margin: 0 !important;
  padding: 0 !important;
  vertical-align: middle !important;
  transform: translateY(-2px) !important;
  will-change: transform !important;
  white-space: nowrap !important;
}

.ios-pwa-standalone .app-header-action {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 7px !important;
  padding-bottom: 7px !important;
  box-sizing: border-box !important;
  vertical-align: middle !important;
  white-space: nowrap !important;
}

@supports (-webkit-touch-callout: none) {
  .ios-pwa-standalone .app-header-title,
  body.ios-pwa-standalone .topbar-start .brand .app-header-title {
    transform: translateY(-2px) !important;
  }
}

/* Reference-locked paint layer: placement and behavior remain unchanged. */
#chatToggle {
  border: 1px solid rgba(248, 246, 240, 0.2);
  background: linear-gradient(145deg, #1a1e20, #101315);
  color: #f7f4ed;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 253, 247, 0.12);
}

#chatToggle:hover {
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 253, 247, 0.15);
}

#chatToggle[aria-expanded="true"] {
  background: #f7f4ed;
  color: #111315;
}

#chatWidget {
  border-color: rgba(17, 19, 21, 0.12);
  border-radius: 26px;
  background: #f8f6f0;
  box-shadow: 0 28px 64px rgba(0, 0, 0, 0.28);
}

.copilot-header {
  border-bottom-color: rgba(17, 19, 21, 0.1);
  background: #f0ede5;
}

.copilot-header-dot {
  background: #087f82;
  box-shadow: none;
}

.copilot-header-title {
  color: #111315;
}

.copilot-header-sub,
.copilot-header-greeting,
.copilot-close-btn {
  color: #5b6161;
}

.copilot-close-btn:hover {
  background: rgba(17, 19, 21, 0.07);
  color: #111315;
}

.copilot-messages {
  scrollbar-color: rgba(8, 127, 130, 0.2) transparent;
}

.copilot-messages::-webkit-scrollbar-thumb {
  background: rgba(8, 127, 130, 0.2);
}

.copilot-msg.is-user {
  border-color: rgba(8, 127, 130, 0.16);
  background: rgba(8, 127, 130, 0.1);
  color: #111315;
}

.copilot-msg.is-assistant {
  border-color: rgba(17, 19, 21, 0.08);
  background: #f0ede5;
  color: #2b3030;
}

.copilot-msg.is-error {
  border-color: rgba(163, 68, 57, 0.2);
  background: #f7dfd8;
  color: #71342c;
}

.copilot-msg.is-system {
  color: #70736f;
}

.copilot-cursor::after {
  color: #087f82;
}

.copilot-config-notice {
  border-color: rgba(154, 106, 24, 0.18);
  background: #f2e5c8;
  color: #604718;
}

.copilot-input-row {
  border-top-color: rgba(17, 19, 21, 0.1);
  background: #f8f6f0;
}

.copilot-input {
  border-color: rgba(17, 19, 21, 0.14);
  border-radius: 999px;
  background: #fffdf9;
  color: #111315;
}

.copilot-input:focus {
  border-color: #087f82;
  box-shadow: 0 0 0 3px rgba(8, 127, 130, 0.2);
}

.copilot-input::placeholder {
  color: #717573;
}

.copilot-send-btn {
  border-radius: 999px;
  background: #111315;
  color: #f8f6f0;
}

.copilot-send-btn:hover {
  background: #252a2b;
}

.copilot-provider-badge,
.copilot-input-notice {
  color: #626865;
}

.copilot-consent-notice {
  border-color: rgba(154, 106, 24, 0.2);
  border-radius: 18px;
  background: #f2e5c8;
  color: #5f481c;
}

.copilot-consent-btn {
  border-radius: 999px;
  background: #111315;
  color: #f8f6f0;
}

.copilot-consent-btn:hover {
  background: #24292b;
}
