/* ── Supercharge Fabric Copilot Chat (Enhanced) ──────────────── */

/* ── Floating Action Button (FAB) ───────────────────────────── */
.copilot-fab,
#copilot-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #0078d4;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.copilot-fab:hover,
#copilot-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 120, 212, 0.4);
}
.copilot-fab:active,
#copilot-btn:active {
  transform: scale(0.96);
}

/* ── Panel ───────────────────────────────────────────────────── */
#copilot-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9998;
  width: 420px;
  max-height: 600px;
  display: flex;
  flex-direction: column;
  background: var(--md-default-bg-color, #fff);
  border: 3px solid #0078d4;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.22);
  overflow: hidden;
  transition: opacity 0.25s, transform 0.25s;
  min-width: 320px;
  min-height: 300px;
}
#copilot-panel.copilot-hidden {
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  pointer-events: none;
}
#copilot-panel.copilot-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ── Resize Handle ──────────────────────────────────────────── */
#copilot-resize-handle {
  position: absolute;
  top: -2px;
  left: -2px;
  width: 28px;
  height: 28px;
  cursor: nw-resize;
  z-index: 10;
  border-radius: 16px 0 8px 0;
  transition: background 0.15s;
}
#copilot-resize-handle:hover {
  background: rgba(0, 120, 212, 0.15);
}
#copilot-resize-handle::after {
  content: "";
  position: absolute;
  top: 7px;
  left: 7px;
  width: 10px;
  height: 10px;
  border-top: 2.5px solid rgba(255, 255, 255, 0.7);
  border-left: 2.5px solid rgba(255, 255, 255, 0.7);
  border-radius: 2px 0 0 0;
}
.copilot-fullpage-mode #copilot-resize-handle {
  display: none;
}

/* ── Header ──────────────────────────────────────────────────── */
#copilot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #0078d4;
  color: #fff;
}
#copilot-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
#copilot-logo { font-size: 1.3rem; }
#copilot-title {
  font-weight: 600;
  font-size: 0.95rem;
}
#copilot-header-right {
  display: flex;
  gap: 4px;
}
#copilot-header-right button {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
#copilot-header-right button:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* ── Messages ────────────────────────────────────────────────── */
#copilot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* Message row */
.copilot-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.copilot-msg-user {
  flex-direction: row-reverse;
}

/* Avatar */
.copilot-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: var(--md-default-fg-color--lightest, #f0f0f0);
}
.copilot-msg-user .copilot-avatar {
  background: #0078d4;
}

/* ── Message Bubbles ─────────────────────────────────────────── */
.copilot-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.copilot-msg-assistant .copilot-bubble {
  background: var(--md-code-bg-color, #f5f5f5);
  color: var(--md-default-fg-color, #333);
  border-bottom-left-radius: 4px;
}
.copilot-msg-user .copilot-bubble {
  background: #0078d4;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── Bubble Typography ───────────────────────────────────────── */
.copilot-bubble p { margin: 0 0 0.5em; }
.copilot-bubble p:last-child { margin-bottom: 0; }
.copilot-bubble code {
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.82em;
  background: rgba(0, 0, 0, 0.06);
}
.copilot-msg-user .copilot-bubble code {
  background: rgba(255, 255, 255, 0.2);
}
.copilot-bubble pre {
  margin: 0.5em 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.06);
  overflow-x: auto;
  font-size: 0.8em;
}
.copilot-bubble ul,
.copilot-bubble ol {
  margin: 0.3em 0;
  padding-left: 1.5em;
}
.copilot-bubble li {
  margin-bottom: 0.2em;
}
.copilot-bubble h2, .copilot-bubble h3, .copilot-bubble h4, .copilot-bubble h5 {
  margin: 0.6em 0 0.3em;
  font-size: 0.95em;
  font-weight: 600;
}
.copilot-bubble hr {
  border: none;
  border-top: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
  margin: 0.5em 0;
}
.copilot-bubble a {
  color: #0078d4;
  text-decoration: underline;
}
.copilot-msg-user .copilot-bubble a {
  color: #b3d9ff;
}

/* ── Blockquotes ─────────────────────────────────────────────── */
.copilot-bubble blockquote {
  margin: 0.5em 0;
  padding: 6px 12px;
  border-left: 3px solid #0078d4;
  background: rgba(0, 120, 212, 0.06);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--md-default-fg-color--light, #555);
}

/* ── Tables ──────────────────────────────────────────────────── */
.copilot-table-wrap {
  overflow-x: auto;
  margin: 0.5em 0;
  border-radius: 6px;
  border: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
}
.copilot-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82em;
}
.copilot-table-wrap th {
  background: rgba(0, 120, 212, 0.08);
  font-weight: 600;
  padding: 6px 10px;
  border-bottom: 2px solid var(--md-default-fg-color--lightest, #e0e0e0);
  white-space: nowrap;
}
.copilot-table-wrap td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
}
.copilot-table-wrap tr:last-child td {
  border-bottom: none;
}
.copilot-table-wrap tr:hover td {
  background: rgba(0, 120, 212, 0.04);
}

/* ── Task Lists ──────────────────────────────────────────────── */
.copilot-task-list {
  list-style: none;
  padding-left: 0.5em;
}
.copilot-task-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.copilot-task-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #0078d4;
  flex-shrink: 0;
  pointer-events: none;
}

/* ── Citation Superscripts ───────────────────────────────────── */
.copilot-cite-ref {
  font-size: 0.75em;
  color: #0078d4;
  cursor: pointer;
  vertical-align: super;
  font-weight: 600;
}

/* ── Citation Footer Cards ───────────────────────────────────── */
.copilot-citations-footer {
  margin-top: 0.75em;
  padding-top: 0.5em;
  border-top: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
}
.copilot-citations-title {
  font-size: 0.75em;
  font-weight: 600;
  color: var(--md-default-fg-color--light, #666);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.copilot-citation-card {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 8px;
  margin: 3px 0;
  background: rgba(0, 120, 212, 0.05);
  border-radius: 4px;
  border-left: 2px solid #0078d4;
  font-size: 0.78em;
  line-height: 1.4;
}
.copilot-citation-num {
  font-weight: 700;
  color: #0078d4;
  flex-shrink: 0;
}
.copilot-citation-text {
  color: var(--md-default-fg-color--light, #555);
}

/* ── Code Block with Copy Button ─────────────────────────────── */
.copilot-code-block {
  position: relative;
  margin: 0.5em 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
}
.copilot-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.04);
  border-bottom: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
  font-size: 0.72em;
}
.copilot-code-lang {
  color: var(--md-default-fg-color--light, #888);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.copilot-copy-btn {
  background: none;
  border: 1px solid var(--md-default-fg-color--lightest, #ccc);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 1em;
  color: var(--md-default-fg-color--light, #666);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.copilot-copy-btn:hover {
  background: rgba(0, 120, 212, 0.1);
  color: #0078d4;
  border-color: #0078d4;
}
.copilot-code-block pre {
  margin: 0;
  padding: 10px 12px;
  border-radius: 0;
  border: none;
  background: rgba(0, 0, 0, 0.03);
  overflow-x: auto;
  font-size: 0.82em;
}
.copilot-code-block code {
  padding: 0;
  background: none;
}

/* ── Input area ──────────────────────────────────────────────── */
#copilot-form {
  border-top: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
  padding: 10px 12px 8px;
  background: var(--md-default-bg-color, #fff);
}
#copilot-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--md-code-bg-color, #f5f5f5);
  border-radius: 12px;
  padding: 6px 8px 6px 14px;
  border: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
  transition: border-color 0.2s;
}
#copilot-input-wrap:focus-within {
  border-color: #0078d4;
}
#copilot-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--md-default-fg-color, #333);
  outline: none;
  font-family: inherit;
  max-height: 120px;
}
#copilot-input::placeholder {
  color: var(--md-default-fg-color--light, #999);
}
#copilot-send {
  background: #0078d4;
  border: none;
  border-radius: 8px;
  color: #fff;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
#copilot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#copilot-send:not(:disabled):hover {
  background: #106ebe;
}
#copilot-footer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--md-default-fg-color--light, #999);
  margin-top: 6px;
}

/* ── Streaming Caret Animation ───────────────────────────────── */
#copilot-streaming .copilot-bubble::after {
  content: "\25CA";
  display: inline-block;
  animation: copilot-caret 0.7s steps(2) infinite;
  margin-left: 2px;
  color: #0078d4;
  font-weight: bold;
}
@keyframes copilot-caret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Full-page mode (inline toggle) ──────────────────────────── */
#copilot-panel.copilot-fullpage-inline {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100% !important;
  max-height: 100% !important;
  border-radius: 0;
  border: none;
  z-index: 10000;
}

/* ── Full-page mode (dedicated page) ─────────────────────────── */
#copilot-fullpage {
  min-height: 420px;
}
.copilot-fullpage-mode {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  height: calc(100vh - 200px);
}
.copilot-fullpage-mode #copilot-btn {
  display: none !important;
}
.copilot-fullpage-mode #copilot-panel {
  position: relative;
  bottom: auto;
  right: auto;
  width: 100%;
  max-height: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}
.copilot-fullpage-mode #copilot-panel.copilot-hidden,
.copilot-fullpage-mode #copilot-panel.copilot-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.copilot-fullpage-mode #copilot-messages {
  max-height: none;
  flex: 1;
  min-height: 300px;
}
.copilot-fullpage-mode #copilot-fullscreen {
  display: none;
}
.copilot-fullpage-mode #copilot-fullpage-toggle {
  display: none;
}

/* ── Dark Mode: [data-md-color-scheme="slate"] ───────────────── */
[data-md-color-scheme="slate"] #copilot-panel {
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  border-color: #2a6bbd;
}
[data-md-color-scheme="slate"] .copilot-bubble pre,
[data-md-color-scheme="slate"] .copilot-bubble code {
  background: rgba(255, 255, 255, 0.08);
}
[data-md-color-scheme="slate"] .copilot-code-block {
  border-color: rgba(255, 255, 255, 0.12);
}
[data-md-color-scheme="slate"] .copilot-code-header {
  background: rgba(255, 255, 255, 0.06);
  border-bottom-color: rgba(255, 255, 255, 0.1);
}
[data-md-color-scheme="slate"] .copilot-code-block pre {
  background: rgba(255, 255, 255, 0.04);
}
[data-md-color-scheme="slate"] .copilot-copy-btn {
  color: rgba(255, 255, 255, 0.6);
  border-color: rgba(255, 255, 255, 0.2);
}
[data-md-color-scheme="slate"] .copilot-copy-btn:hover {
  background: rgba(59, 130, 246, 0.2);
  color: #93bbfc;
  border-color: #93bbfc;
}
[data-md-color-scheme="slate"] .copilot-bubble blockquote {
  background: rgba(59, 130, 246, 0.1);
  border-left-color: #4a9eff;
  color: rgba(255, 255, 255, 0.7);
}
[data-md-color-scheme="slate"] .copilot-table-wrap {
  border-color: rgba(255, 255, 255, 0.12);
}
[data-md-color-scheme="slate"] .copilot-table-wrap th {
  background: rgba(59, 130, 246, 0.15);
  border-bottom-color: rgba(255, 255, 255, 0.15);
}
[data-md-color-scheme="slate"] .copilot-table-wrap td {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}
[data-md-color-scheme="slate"] .copilot-table-wrap tr:hover td {
  background: rgba(59, 130, 246, 0.08);
}
[data-md-color-scheme="slate"] .copilot-cite-ref {
  color: #4a9eff;
}
[data-md-color-scheme="slate"] .copilot-citation-card {
  background: rgba(59, 130, 246, 0.08);
  border-left-color: #4a9eff;
}
[data-md-color-scheme="slate"] .copilot-citation-num {
  color: #4a9eff;
}
[data-md-color-scheme="slate"] .copilot-citation-text {
  color: rgba(255, 255, 255, 0.6);
}
[data-md-color-scheme="slate"] .copilot-bubble a {
  color: #4a9eff;
}
[data-md-color-scheme="slate"] .copilot-bubble hr {
  border-top-color: rgba(255, 255, 255, 0.12);
}

/* ── Dark Mode: prefers-color-scheme fallback ────────────────── */
@media (prefers-color-scheme: dark) {
  #copilot-panel {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  }
  .copilot-bubble pre,
  .copilot-bubble code {
    background: rgba(255, 255, 255, 0.08);
  }
  .copilot-code-block {
    border-color: rgba(255, 255, 255, 0.12);
  }
  .copilot-code-header {
    background: rgba(255, 255, 255, 0.06);
    border-bottom-color: rgba(255, 255, 255, 0.1);
  }
  .copilot-code-block pre {
    background: rgba(255, 255, 255, 0.04);
  }
  .copilot-copy-btn {
    color: rgba(255, 255, 255, 0.6);
    border-color: rgba(255, 255, 255, 0.2);
  }
  .copilot-bubble blockquote {
    background: rgba(59, 130, 246, 0.1);
    border-left-color: #4a9eff;
  }
  .copilot-table-wrap {
    border-color: rgba(255, 255, 255, 0.12);
  }
  .copilot-table-wrap th {
    background: rgba(59, 130, 246, 0.15);
  }
}

/* ── Search result links in chat ─────────────────────────────── */
.copilot-bubble a[href*="github.io"],
.copilot-bubble a[href*="github.com"] {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.82em;
  font-weight: 500;
  text-decoration: none !important;
  margin-right: 4px;
  transition: background 0.15s;
}
.copilot-bubble a[href*="github.io"] {
  background: rgba(0, 120, 212, 0.12);
  color: #0078d4;
}
.copilot-bubble a[href*="github.io"]:hover {
  background: rgba(0, 120, 212, 0.25);
}
.copilot-bubble a[href*="github.com"] {
  background: rgba(36, 41, 47, 0.08);
  color: #24292f;
}
.copilot-bubble a[href*="github.com"]:hover {
  background: rgba(36, 41, 47, 0.18);
}

[data-md-color-scheme="slate"] .copilot-bubble a[href*="github.io"] {
  background: rgba(59, 130, 246, 0.2);
  color: #93bbfc;
}
[data-md-color-scheme="slate"] .copilot-bubble a[href*="github.io"]:hover {
  background: rgba(59, 130, 246, 0.35);
}
[data-md-color-scheme="slate"] .copilot-bubble a[href*="github.com"] {
  background: rgba(255, 255, 255, 0.1);
  color: #c9d1d9;
}
[data-md-color-scheme="slate"] .copilot-bubble a[href*="github.com"]:hover {
  background: rgba(255, 255, 255, 0.18);
}

.copilot-bubble strong {
  color: inherit;
}

/* ── Responsive: Mobile Breakpoints ──────────────────────────── */
@media screen and (max-width: 600px) {
  #copilot-panel {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 80px;
    max-height: calc(100vh - 120px);
    border-radius: 12px;
  }
  .copilot-fab,
  #copilot-btn {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
  .copilot-bubble {
    max-width: 92%;
  }
  .copilot-table-wrap {
    font-size: 0.78em;
  }
  .copilot-code-block pre {
    font-size: 0.75em;
  }
}

@media screen and (max-width: 400px) {
  #copilot-panel {
    width: 100vw;
    right: 0;
    bottom: 72px;
    border-radius: 12px 12px 0 0;
  }
  .copilot-bubble {
    max-width: 95%;
    padding: 8px 10px;
    font-size: 0.84rem;
  }
}

/* ── Scrollbar Styling ───────────────────────────────────────── */
#copilot-messages::-webkit-scrollbar {
  width: 6px;
}
#copilot-messages::-webkit-scrollbar-track {
  background: transparent;
}
#copilot-messages::-webkit-scrollbar-thumb {
  background: var(--md-default-fg-color--lightest, #ccc);
  border-radius: 3px;
}
