/* === Repair/Enhance — Ship Self-Repair & Enhancement System === */

/* --- Trigger Button (beside Page Guide button) --- */
.repair-enhance-trigger {
  display: inline-flex;
  margin-left: 8px;
}

.repair-enhance-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0.5rem 1rem;
  background: rgba(245,158,11,0.06);
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: 8px;
  color: rgba(245,158,11,0.85);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  letter-spacing: 0.02em;
  box-shadow: 0 0 12px rgba(245,158,11,0.06);
}
.repair-enhance-btn:hover {
  background: rgba(245,158,11,0.12);
  border-color: rgba(245,158,11,0.5);
  color: #f59e0b;
  box-shadow: 0 0 18px rgba(245,158,11,0.12);
}
.repair-enhance-icon {
  flex-shrink: 0;
  opacity: 0.8;
}
.repair-enhance-btn:hover .repair-enhance-icon {
  opacity: 1;
}

/* --- Overlay --- */
.repair-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: reFadeIn 0.2s ease;
  padding: 20px;
}
@keyframes reFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Modal --- */
.repair-modal {
  background: #12121e;
  border: 1px solid rgba(245,158,11,0.15);
  border-radius: 14px;
  width: 100%;
  max-width: 1200px;
  height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 30px rgba(245,158,11,0.05);
  overflow: hidden;
}

/* --- Header --- */
.repair-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 18px 48px;
  border-bottom: 1px solid rgba(245,158,11,0.1);
  flex-shrink: 0;
  position: relative;
}
.repair-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #f59e0b;
  letter-spacing: 0.01em;
}
.repair-subtitle {
  margin: 0;
  font-size: 0.74rem;
  color: rgba(255,255,255,0.38);
  line-height: 1.5;
  max-width: 680px;
}
.repair-close {
  position: absolute;
  right: 16px;
  top: 14px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
  line-height: 1;
}
.repair-close:hover {
  color: #fff;
  background: rgba(255,255,255,0.08);
}

/* --- Body (two columns) --- */
.repair-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* --- Left: Categories Accordion --- */
.repair-categories {
  flex: 0 0 340px;
  overflow-y: auto;
  padding: 16px 20px;
  border-right: 1px solid rgba(255,255,255,0.06);
}

/* Accordion section */
.repair-accordion {
  margin-bottom: 6px;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.repair-accordion.open {
  border-color: rgba(245,158,11,0.2);
}
.repair-accordion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.repair-accordion-header:hover {
  background: rgba(255,255,255,0.04);
}
.repair-accordion-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
}
.repair-accordion-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  flex: 1;
}
.repair-accordion-arrow {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.3);
  transition: transform 0.2s;
}
.repair-accordion.open .repair-accordion-arrow {
  transform: rotate(90deg);
}
.repair-accordion-body {
  display: none;
  padding: 10px 14px 14px;
}
.repair-accordion.open .repair-accordion-body {
  display: block;
}
.repair-accordion-desc {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.5);
  margin-bottom: 10px;
  line-height: 1.5;
}

/* Example prompts (tappable pills) */
.repair-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.repair-prompt-pill {
  padding: 5px 10px;
  background: rgba(245,158,11,0.06);
  border: 1px solid rgba(245,158,11,0.15);
  border-radius: 14px;
  color: rgba(255,255,255,0.6);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  line-height: 1.35;
}
.repair-prompt-pill:hover {
  background: rgba(245,158,11,0.12);
  border-color: rgba(245,158,11,0.3);
  color: rgba(255,255,255,0.85);
}

/* --- Right: Engineering Chat --- */
.repair-chat {
  flex: 1 1 0%;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.repair-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.repair-commander-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #f59e0b;
}
.repair-commander-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #f59e0b;
}
.repair-chat-label {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.3);
  margin-left: auto;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Chat messages */
.repair-chat-messages {
  flex: 1 1 0%;
  overflow-y: auto;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
}
.re-msg {
  display: flex;
  gap: 8px;
  max-width: 95%;
  animation: reSlideIn 0.2s ease;
}
@keyframes reSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.re-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.re-msg-commander {
  align-self: flex-start;
}
.re-msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-top: 2px;
}
.re-msg-bubble {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.85);
}
.re-msg-user .re-msg-bubble {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-bottom-right-radius: 3px;
}
.re-msg-commander .re-msg-bubble {
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.12);
  border-bottom-left-radius: 3px;
}
.re-msg-bubble p { margin: 0 0 6px; }
.re-msg-bubble p:last-child { margin-bottom: 0; }
.re-msg-bubble strong { color: #fff; }

/* Progress indicator in chat */
.re-progress {
  padding: 10px 14px;
  background: rgba(245,158,11,0.06);
  border: 1px solid rgba(245,158,11,0.12);
  border-radius: 10px;
  animation: reSlideIn 0.2s ease;
}
.re-progress-label {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.7);
  margin-bottom: 8px;
}
.re-progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.re-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  border-radius: 2px;
  transition: width 0.4s ease;
}
.re-progress-step {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.4);
  margin-top: 4px;
}

/* Typing indicator */
.re-typing {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  align-items: center;
}
.re-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  opacity: 0.4;
  animation: reDotBounce 1.2s infinite;
}
.re-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.re-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes reDotBounce {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Status message (success/failure) */
.re-status {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.5;
  animation: reSlideIn 0.2s ease;
}
.re-status-success {
  background: rgba(34,197,94,0.08);
  border: 1px solid rgba(34,197,94,0.15);
  color: #22c55e;
}
.re-status-failure {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.15);
  color: #ef4444;
}

/* --- Chat Input --- */
.repair-chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.repair-chat-input textarea {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 12px 14px;
  color: #e0e0e0;
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: none;
  min-height: 56px;
  max-height: 160px;
  line-height: 1.5;
  overflow-y: auto;
}
.repair-chat-input textarea:focus {
  border-color: #f59e0b;
}
.repair-chat-input textarea::placeholder {
  color: rgba(255,255,255,0.25);
}
.repair-mic-btn,
.repair-send-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 8px 10px;
  transition: all 0.2s;
  font-family: inherit;
  line-height: 1;
}
.repair-send-btn {
  padding: 8px 14px;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}
.repair-mic-btn:hover, .repair-send-btn:hover {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.85);
  border-color: #f59e0b;
}
.repair-mic-btn.active {
  background: rgba(239,68,68,0.15);
  border-color: #ef4444;
  color: #ef4444;
  animation: reMicPulse 1.5s ease infinite;
}
@keyframes reMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
  50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}
.repair-mic-btn.re-hidden { display: none; }

/* --- Engineering Notice Banner --- */
.repair-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: rgba(245,158,11,0.05);
  border: 1px solid rgba(245,158,11,0.15);
  border-radius: 8px;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.55);
  line-height: 1.5;
}
.repair-notice svg {
  flex-shrink: 0;
  color: #f59e0b;
  margin-top: 1px;
}
.repair-notice strong {
  color: #f59e0b;
}

/* --- Change History Panel --- */
.repair-history-panel {
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.repair-history-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
.repair-history-toggle:hover {
  color: rgba(255,255,255,0.7);
}
.repair-history-toggle svg {
  opacity: 0.6;
}
.repair-history-arrow {
  font-size: 0.6rem;
  margin-left: auto;
  transition: transform 0.2s;
}
.repair-history-arrow.open {
  transform: rotate(90deg);
}
.repair-history-list {
  display: none;
  max-height: 200px;
  overflow-y: auto;
  padding: 0 18px 12px;
}
.repair-history-list.open {
  display: block;
}
.repair-history-loading,
.repair-history-empty {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.35);
  padding: 8px 0;
  text-align: center;
}
.repair-history-entry {
  padding: 10px 12px;
  margin-bottom: 6px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  transition: border-color 0.15s;
}
.repair-history-entry:hover {
  border-color: rgba(255,255,255,0.12);
}
.repair-history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.repair-history-date {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.35);
  font-variant-numeric: tabular-nums;
}
.repair-history-status {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.re-hist-success { background: rgba(34,197,94,0.1); color: #22c55e; }
.re-hist-failure { background: rgba(239,68,68,0.1); color: #ef4444; }
.re-hist-reverted { background: rgba(168,85,247,0.1); color: #a855f7; }
.re-hist-pending { background: rgba(245,158,11,0.1); color: #f59e0b; }
.repair-history-desc {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.7);
  line-height: 1.45;
  margin-bottom: 6px;
}
.repair-history-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.repair-history-cat {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.repair-revert-btn {
  font-size: 0.68rem;
  padding: 3px 10px;
  background: rgba(168,85,247,0.08);
  border: 1px solid rgba(168,85,247,0.2);
  border-radius: 5px;
  color: #a855f7;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.repair-revert-btn:hover {
  background: rgba(168,85,247,0.15);
  border-color: rgba(168,85,247,0.4);
}
.repair-revert-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.repair-revert-btn.reverted {
  background: rgba(168,85,247,0.05);
  border-color: rgba(168,85,247,0.1);
  color: rgba(168,85,247,0.5);
  cursor: default;
}

/* history list scrollbar */
.repair-history-list::-webkit-scrollbar { width: 4px; }
.repair-history-list::-webkit-scrollbar-track { background: transparent; }
.repair-history-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* --- Nav spinner (global indicator when job is running) --- */
.repair-nav-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: 12px;
  font-size: 0.68rem;
  color: #f59e0b;
  animation: reNavPulse 2s ease infinite;
  cursor: pointer;
}
@keyframes reNavPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
.repair-nav-spinner {
  width: 10px;
  height: 10px;
  border: 2px solid rgba(245,158,11,0.3);
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: reSpinnerSpin 0.8s linear infinite;
}
@keyframes reSpinnerSpin {
  to { transform: rotate(360deg); }
}

/* --- Scrollbar --- */
.repair-categories::-webkit-scrollbar,
.repair-chat-messages::-webkit-scrollbar {
  width: 5px;
}
.repair-categories::-webkit-scrollbar-track,
.repair-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.repair-categories::-webkit-scrollbar-thumb,
.repair-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

/* --- Desktop font bump --- */
@media (min-width: 769px) {
  .repair-header h2 { font-size: 1.2rem; }
  .repair-subtitle { font-size: 0.84rem; }
  .repair-accordion-title { font-size: 0.92rem; }
  .repair-accordion-desc { font-size: 0.88rem; }
  .repair-prompt-pill { font-size: 0.82rem; }
  .repair-notice { font-size: 0.82rem; }
  .repair-commander-name { font-size: 0.92rem; }
  .repair-chat-label { font-size: 0.78rem; }
  .re-msg-bubble { font-size: 0.95rem; }
  .repair-chat-input textarea { font-size: 0.95rem; }
  .repair-send-btn { font-size: 0.88rem; }
  .repair-mic-btn { font-size: 0.95rem; }
  .re-progress-label { font-size: 0.88rem; }
  .re-progress-step { font-size: 0.78rem; }
  .re-status { font-size: 0.9rem; }
  .repair-history-toggle { font-size: 0.82rem; }
  .repair-history-date { font-size: 0.76rem; }
  .repair-history-desc { font-size: 0.88rem; }
  .repair-history-cat { font-size: 0.72rem; }
  .repair-history-status { font-size: 0.72rem; }
  .repair-revert-btn { font-size: 0.76rem; }
  .repair-close { font-size: 1.6rem; }
}

/* --- Mobile --- */
@media (max-width: 768px) {
  .repair-overlay { padding: 10px; }
  .repair-modal {
    height: 95vh;
    border-radius: 10px;
  }
  .repair-body {
    flex-direction: column;
  }
  .repair-categories {
    flex: 0 0 auto;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    max-height: 30vh;
    padding: 10px 14px;
  }
  .repair-chat {
    min-height: 250px;
  }
  .repair-header {
    padding: 14px 16px;
    flex-wrap: wrap;
  }
  .repair-subtitle {
    width: 100%;
    flex: unset;
  }
  .repair-enhance-trigger {
    margin-left: 4px;
  }
}
