:root {
  --qp-primary: #4B75AD;
  --qp-primary-dark: #2f557f;
  --qp-primary-soft: rgba(75, 117, 173, 0.11);
  --qp-ai-accent: #f9a826;
  --qp-ink: #172033;
  --qp-text: #263447;
  --qp-muted: #64748b;
  --qp-bg: #fff;
  --qp-surface: #ffffff;
  --qp-surface-2: #f9fbff;
  --qp-line: #dbe3ef;
  --qp-line-soft: rgba(219, 227, 239, 0.74);
  --qp-success: #16a34a;
  --qp-radius: 8px;
  --qp-radius-sm: 6px;
  --qp-shadow-sm: 0 8px 22px rgba(15, 23, 42, 0.08);
  --qp-shadow-md: 0 18px 42px rgba(15, 23, 42, 0.16);
  --qp-transition: 180ms ease;
  --qp-launcher-offset: 18px;
}

.qp-drawer[hidden],
.qp-bottom-drawer[hidden],
.qp-launcher[hidden],
.qp-helper-launcher[hidden] {
  display: none !important;
}

.qp-drawer,
.qp-bottom-drawer {
  position: fixed;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--qp-line);
  border-radius: var(--qp-radius);
  background: var(--qp-surface);
  box-shadow: var(--qp-shadow-md);
  transition: transform 220ms ease, opacity 160ms ease, visibility 160ms ease;
}

.qp-drawer {
  top: 100px;
  right: calc(var(--qp-launcher-offset) + 48px);
  bottom: 18px;
  width: 460px;
  z-index: 1100;
}

.qp-drawer.collapsed {
  transform: translateX(calc(100% + 28px));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.qp-bottom-drawer {
  left: 20px;
  right: calc(var(--qp-launcher-offset) + 48px);
  bottom: 18px;
  height: 220px;
  max-height: calc(100vh - 88px);
  z-index: 1050;
}

.qp-bottom-drawer.collapsed {
  transform: translateY(calc(100% + 28px));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.qp-drawer-header,
.qp-bottom-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--qp-line);
  background:
    linear-gradient(135deg, rgba(75, 117, 173, 0.09), rgba(75, 117, 173, 0)),
    var(--qp-surface);
}

.qp-drawer-title {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.qp-drawer-title strong {
  display: block;
  color: var(--qp-ink);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0;
}

.qp-drawer-title small {
  display: block;
  overflow: hidden;
  color: var(--qp-muted);
  font-size: 0.73rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qp-drawer-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: var(--qp-radius-sm);
  color: var(--qp-primary);
  background: var(--qp-primary-soft);
}

.qp-drawer-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 42px;
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--qp-line-soft);
  background: var(--qp-surface-2);
}

.qp-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  max-width: 100%;
  padding: 0.26rem 0.55rem;
  border: 1px solid rgba(22, 163, 74, 0.22);
  border-radius: 999px;
  color: #166534;
  background: rgba(22, 163, 74, 0.08);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.qp-status-chip i {
  color: var(--qp-success);
  font-size: 0.42rem;
}

.qp-drawer-body,
.qp-bottom-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.9rem;
  overflow: auto;
  background: var(--qp-bg);
}

.qp-bottom-body {
  padding: 0.8rem;
}

.qp-panel-progress-host {
  position: relative;
}

.qp-panel-progress {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(244, 247, 251, 0.82);
  backdrop-filter: blur(1px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.qp-panel-progress-card {
  display: grid;
  grid-template-columns: auto minmax(260px, 430px);
  align-items: center;
  gap: 0.8rem 0.9rem;
  width: min(520px, calc(100% - 2rem));
  padding: 1rem 1.1rem;
  border: 1px solid rgba(75, 117, 173, 0.24);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 14px 38px rgba(30, 64, 110, 0.18);
}

.qp-panel-progress-card > .qp-spinner {
  grid-row: 1 / span 2;
  width: 30px;
  height: 30px;
}

.qp-panel-progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--qp-muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.qp-panel-progress-label strong {
  color: var(--qp-primary);
  font-variant-numeric: tabular-nums;
}

.qp-panel-progress-track {
  grid-column: 2;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(75, 117, 173, 0.14);
}

.qp-panel-progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--qp-primary), #62a9e8);
  box-shadow: 0 0 10px rgba(75, 117, 173, 0.28);
  transition: width 300ms ease;
}

.qp-panel-progress.is-complete {
  opacity: 0;
  transform: translateY(-4px);
}

.qp-panel-progress.is-error .qp-panel-progress-track span {
  background: #dc3545;
}

.qp-empty-state,
.qp-loading-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.45rem;
  min-height: 180px;
  padding: 1rem;
  border: 1px dashed var(--qp-line);
  border-radius: var(--qp-radius);
  color: var(--qp-muted);
  background: var(--qp-surface);
  text-align: center;
}

.qp-empty-state-compact,
.qp-loading-state {
  min-height: 118px;
}

.qp-empty-state i {
  color: var(--qp-primary);
  font-size: 1.15rem;
}

.qp-empty-state strong,
.qp-loading-state strong {
  color: var(--qp-ink);
  font-size: 0.9rem;
  font-weight: 800;
}

.qp-empty-state span {
  max-width: 320px;
  font-size: 0.82rem;
}

.qp-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(75, 117, 173, 0.18);
  border-top-color: var(--qp-primary);
  border-radius: 50%;
  animation: qpSpin 800ms linear infinite;
}

@keyframes qpSpin {
  to { transform: rotate(360deg); }
}

.qp-close-btn {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 1px solid var(--qp-line);
  border-radius: var(--qp-radius-sm);
  color: var(--qp-muted);
  background: #ffffff;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: color var(--qp-transition), background var(--qp-transition), border-color var(--qp-transition);
}

.qp-close-btn:hover {
  border-color: rgba(75, 117, 173, 0.38);
  color: var(--qp-primary-dark);
  background: var(--qp-primary-soft);
}

.qp-resize-handle {
  position: absolute;
  top: 0;
  left: -8px;
  z-index: 1115;
  width: 16px;
  height: 100%;
  cursor: col-resize;
}

.qp-resize-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 7px;
  width: 2px;
  height: 52px;
  border-radius: 99px;
  background: transparent;
  transform: translateY(-50%);
  transition: background var(--qp-transition);
}

.qp-resize-handle:hover::after {
  background: var(--qp-primary);
}

.qp-bottom-resize-handle {
  position: absolute;
  top: -8px;
  left: 0;
  right: 0;
  z-index: 1060;
  height: 16px;
  cursor: row-resize;
}

.qp-bottom-resize-handle::after {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  width: 58px;
  height: 2px;
  border-radius: 99px;
  background: transparent;
  transform: translateX(-50%);
  transition: background var(--qp-transition);
}

.qp-bottom-resize-handle:hover::after {
  background: var(--qp-primary);
}

.qp-launcher,
.qp-helper-launcher {
  position: fixed;
  right: var(--qp-launcher-offset);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  border: 0;
  border-radius: var(--qp-radius-sm);
  color: #ffffff;
  background: linear-gradient(135deg, var(--qp-primary), var(--qp-primary-dark));
  box-shadow: var(--qp-shadow-sm);
  cursor: pointer;
  transition: transform var(--qp-transition), box-shadow var(--qp-transition), background var(--qp-transition);
  z-index: 9999;
}

.qp-launcher span,
.qp-helper-launcher span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.qp-launcher:hover,
.qp-helper-launcher:hover {
  transform: translateX(-4px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
}

.qp-launcher {
  top: 52%;
  height: 138px;
}

.qp-helper-launcher {
  top: calc(52% + 148px);
  height: 110px;
  background: linear-gradient(135deg, #5f6f82, #3f4d5d);
}

/* ===== AI Copilot skin ===== */
.qp-ai-launcher {
  position: fixed;
  top: calc(52% + 268px);
  right: var(--qp-launcher-offset);
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 82px;
  padding: 0;
  border: 1px solid rgba(249, 168, 38, 0.88);
  border-radius: var(--qp-radius-sm);
  color: var(--qp-ai-accent);
  background: linear-gradient(135deg, var(--qp-primary), var(--qp-primary-dark));
  box-shadow: var(--qp-shadow-sm), inset 3px 0 0 var(--qp-ai-accent);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  transition: transform var(--qp-transition), box-shadow var(--qp-transition);
  z-index: 9999;
}

.qp-ai-launcher:hover {
  background: linear-gradient(135deg, var(--qp-primary), var(--qp-primary-dark));
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18), inset 3px 0 0 var(--qp-ai-accent);
  color: #ffffff;
  transform: rotate(180deg) translateX(-4px);
}

.qp-ai-chat {
  top: 70px;
  right: 18px;
  width: 620px;
  height: min(80vh, calc(100vh - 88px));
  max-height: calc(100vh - 88px);
  border: 1px solid var(--qp-line);
  border-radius: var(--qp-radius);
  background: var(--qp-surface);
  box-shadow: var(--qp-shadow-md);
  transition: transform 220ms ease, opacity 160ms ease, visibility 160ms ease;
}

.qp-ai-chat.collapsed {
  transform: translateX(calc(100% + 28px));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.qp-ai-header {
  min-height: 58px;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--qp-line);
  border-radius: var(--qp-radius) var(--qp-radius) 0 0;
  color: var(--qp-ink);
  background:
    linear-gradient(135deg, rgba(75, 117, 173, 0.11), rgba(75, 117, 173, 0)),
    var(--qp-surface);
}

.qp-ai-header strong {
  color: var(--qp-ink);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0;
}

.qp-ai-nav {
  gap: 0.42rem;
  padding: 0.58rem 0.75rem;
  border-bottom: 1px solid var(--qp-line-soft);
  background: var(--qp-surface-2);
  flex-wrap: nowrap;
  overflow-x: auto;
}

.qp-ai-nav button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0.34rem 0.62rem;
  border: 1px solid var(--qp-line);
  border-radius: 999px;
  color: var(--qp-muted);
  background: #ffffff;
  font-size: 0.74rem;
  font-weight: 800;
  transition: color var(--qp-transition), background var(--qp-transition), border-color var(--qp-transition);
}

.qp-ai-nav button:hover,
.qp-ai-nav button.active {
  border-color: var(--qp-primary);
  color: #ffffff;
  background: var(--qp-primary);
}

.qp-ai-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.95rem;
  background: var(--qp-bg);
}

.qp-ai-input {
  padding: 0.75rem;
  border-top: 1px solid var(--qp-line);
  background: var(--qp-surface);
}

.qp-ai-input input {
  width: 100%;
  min-height: 42px;
  padding: 0.62rem 0.78rem;
  border: 1px solid var(--qp-line);
  border-radius: var(--qp-radius-sm);
  color: var(--qp-text);
  background: #ffffff;
  outline: none;
  transition: border-color var(--qp-transition), box-shadow var(--qp-transition);
}

.qp-ai-input input:focus {
  border-color: rgba(75, 117, 173, 0.55);
  box-shadow: 0 0 0 0.2rem rgba(75, 117, 173, 0.12);
}

.qp-ai-message {
  margin: 0.65rem 0;
}

.qp-ai-message-user {
  text-align: right;
}

.qp-ai-message-user .qp-ai-bubble,
.qp-ai-message-ai .qp-ai-bubble {
  display: inline-block;
  max-width: 82%;
  padding: 0.68rem 0.78rem;
  border-radius: var(--qp-radius);
  box-shadow: var(--qp-shadow-sm);
  text-align: left;
  font-size: 0.86rem;
}

.qp-ai-message-user .qp-ai-bubble {
  color: #ffffff;
  background: var(--qp-primary);
}

.qp-ai-message-user .qp-ai-time {
  color: rgba(255, 255, 255, 0.76);
}

.qp-ai-message-ai .qp-ai-bubble {
  border: 1px solid var(--qp-line);
  color: var(--qp-text);
  background: var(--qp-surface);
}

.qp-ai-time {
  margin-bottom: 0.25rem;
  color: var(--qp-muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.qp-ai-loading {
  padding: 1rem;
  text-align: center;
}

.qp-ai-loading-dots span {
  background: var(--qp-primary);
}

#qpAIOutput > div[style*="text-align:center"],
#qpAIOutput > div[style*="text-align:center"] h3,
#qpAIOutput > div[style*="text-align:center"] p {
  color: var(--qp-ink) !important;
}

#qpAIOutput > div[style*="text-align:center"] {
  margin: 0 auto;
  border: 1px solid var(--qp-line);
  border-radius: var(--qp-radius);
  background: var(--qp-surface) !important;
}

#qpAIOutput div[onclick^="qpAILoad"] {
  border: 1px solid var(--qp-line) !important;
  border-radius: var(--qp-radius) !important;
  background: var(--qp-surface) !important;
  box-shadow: var(--qp-shadow-sm);
  transition: border-color var(--qp-transition), transform var(--qp-transition);
}

#qpAIOutput div[onclick^="qpAILoad"]:hover {
  border-color: rgba(75, 117, 173, 0.48) !important;
  transform: translateY(-1px);
}

#qpAIOutput div[onclick^="qpAISendSuggestion"] {
  color: var(--qp-primary-dark) !important;
  border-radius: var(--qp-radius-sm);
}

#qpAIOutput div[onclick^="qpAISendSuggestion"]:hover {
  background: var(--qp-primary-soft);
}

.qp-ai-resize-left,
.qp-ai-resize-top,
.qp-ai-resize-corner {
  background: transparent;
}

.qp-ai-resize-left:hover,
.qp-ai-resize-top:hover,
.qp-ai-resize-corner:hover {
  background: rgba(75, 117, 173, 0.16);
}

/* AI module compatibility skin.
   These selectors are intentionally broad but scoped to common qPanel AI wrappers. */
#qpAiPanel,
#qpAIPanel,
.qp-ai-panel,
.qp-ai-drawer,
.ai-panel.qpanel-ai,
.qpanel-ai {
  color: var(--qp-text);
  border: 1px solid var(--qp-line);
  border-radius: var(--qp-radius);
  background: var(--qp-surface);
  box-shadow: var(--qp-shadow-sm);
}

#qpAiPanel .card,
#qpAIPanel .card,
.qp-ai-panel .card,
.qp-ai-drawer .card,
.qpanel-ai .card {
  border: 1px solid var(--qp-line);
  border-radius: var(--qp-radius);
  box-shadow: none;
}

#qpAiPanel .card-header,
#qpAIPanel .card-header,
.qp-ai-panel .card-header,
.qp-ai-drawer .card-header,
.qpanel-ai .card-header {
  border-bottom: 1px solid var(--qp-line);
  color: var(--qp-ink);
  background: linear-gradient(135deg, rgba(75, 117, 173, 0.09), rgba(75, 117, 173, 0));
  font-weight: 800;
}

#qpAiPanel textarea,
#qpAIPanel textarea,
.qp-ai-panel textarea,
.qp-ai-drawer textarea,
.qpanel-ai textarea,
#qpAiPanel input,
#qpAIPanel input,
.qp-ai-panel input,
.qp-ai-drawer input,
.qpanel-ai input {
  border: 1px solid var(--qp-line);
  border-radius: var(--qp-radius-sm);
  color: var(--qp-text);
}

#qpAiPanel textarea:focus,
#qpAIPanel textarea:focus,
.qp-ai-panel textarea:focus,
.qp-ai-drawer textarea:focus,
.qpanel-ai textarea:focus,
#qpAiPanel input:focus,
#qpAIPanel input:focus,
.qp-ai-panel input:focus,
.qp-ai-drawer input:focus,
.qpanel-ai input:focus {
  border-color: rgba(75, 117, 173, 0.55);
  box-shadow: 0 0 0 0.2rem rgba(75, 117, 173, 0.12);
}

#qpAiPanel .btn-primary,
#qpAIPanel .btn-primary,
.qp-ai-panel .btn-primary,
.qp-ai-drawer .btn-primary,
.qpanel-ai .btn-primary {
  border-color: var(--qp-primary);
  background: var(--qp-primary);
}

#qpAiPanel .btn-primary:hover,
#qpAIPanel .btn-primary:hover,
.qp-ai-panel .btn-primary:hover,
.qp-ai-drawer .btn-primary:hover,
.qpanel-ai .btn-primary:hover {
  border-color: var(--qp-primary-dark);
  background: var(--qp-primary-dark);
}

.qp-drawer-body-frame,
.qp-bottom-body-frame {
  padding: 0;
  overflow: hidden;
}

.qp-frame-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #ffffff;
}

.qp-frame-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.65rem;
  color: var(--qp-muted);
  background: rgba(255, 255, 255, 0.96);
  transition: opacity 160ms ease, visibility 160ms ease;
}

.qp-frame-loading strong {
  color: var(--qp-ink);
  font-size: 0.9rem;
  font-weight: 800;
}

.qp-frame-loading.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.qp-drawer-frame {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100%;
  border: 0;
  background: #ffffff;
  opacity: 0;
  transition: opacity 160ms ease;
}

.qp-drawer-frame.is-ready {
  opacity: 1;
}

@media (max-width: 991.98px) {
  .qp-bottom-drawer {
    left: 20px;
    right: 20px;
  }
}

@media (max-width: 767.98px) {
  :root {
    --qp-launcher-offset: 10px;
  }

  .qp-drawer {
    top: 100px;
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
  }

  .qp-bottom-drawer {
    left: 20px;
    right: 20px;
    bottom: 10px;
    height: 42vh;
  }

  .qp-launcher,
  .qp-helper-launcher,
  .qp-ai-launcher {
    width: 30px;
  }

  .qp-launcher span,
  .qp-helper-launcher span {
    font-size: 0.64rem;
  }

  .qp-ai-launcher {
    font-size: 0.64rem;
  }
}
