/* =============================================
   Popup Container & Layout
   ============================================= */
.popup-container {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--ac-font-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
  background: var(--ac-bg, #fdfcf8);
  color: var(--ac-text, #1a1a1a);
  height: 100%;
}

.home-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* =============================================
   Header
   ============================================= */
.header {
  flex-shrink: 0;
  padding: 16px 20px 12px;
  background: var(--ac-surface, #ffffff);
  border-bottom: var(--ac-border-width, 1px) solid var(--ac-border, #e7e5e4);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--ac-accent, #d97757);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ac-accent-contrast, #ffffff);
  flex-shrink: 0;
}

.header-logo svg {
  width: 16px;
  height: 16px;
}

.header-title {
  font-family: var(--ac-font-heading, var(--ac-font-body));
  font-size: 16px;
  font-weight: 700;
  color: var(--ac-text, #1a1a1a);
  margin: 0;
  letter-spacing: -0.01em;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: all var(--ac-motion-fast, 120ms) ease;
}

.header-status .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.header-status.status-running {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}

.header-status.status-running .status-dot {
  background: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.header-status.status-recording {
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

.header-status.status-recording .status-dot {
  background: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.18);
  animation: rr-record-pulse 1.2s ease-in-out infinite;
}

.header-status.status-warning {
  background: rgba(234, 179, 8, 0.1);
  color: #a16207;
}

.header-status.status-warning .status-dot {
  background: #eab308;
}

.header-status.status-error {
  background: rgba(239, 68, 68, 0.08);
  color: #dc2626;
}

.header-status.status-error .status-dot {
  background: #ef4444;
}

.header-status.status-unknown {
  background: var(--ac-surface-muted, #f2f0eb);
  color: var(--ac-text-muted, #6e6e6e);
}

.header-status.status-unknown .status-dot {
  background: #9ca3af;
}

/* =============================================
   Content Area
   ============================================= */
.content {
  flex: 1;
  padding: 12px 16px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.content::-webkit-scrollbar {
  display: none;
}

/* =============================================
   Sections
   ============================================= */
.section {
  margin-bottom: 16px;
}

.section:last-child {
  margin-bottom: 8px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 0 2px;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ac-text-muted, #6e6e6e);
  margin: 0;
}

.refresh-status-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--ac-text-subtle, #a8a29e);
  transition: all var(--ac-motion-fast, 120ms) ease;
  display: flex;
  align-items: center;
}

.refresh-status-button:hover {
  background: var(--ac-hover-bg, #f5f5f4);
  color: var(--ac-text-muted, #6e6e6e);
}

.refresh-status-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.refresh-status-button.is-refreshing .icon-small {
  animation: popup-refresh-spin 0.9s linear infinite;
}

/* =============================================
   Config Card
   ============================================= */
.config-card {
  background: var(--ac-surface, #ffffff);
  border-radius: var(--ac-radius-card, 12px);
  border: var(--ac-border-width, 1px) solid var(--ac-border, #e7e5e4);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ac-text-muted, #6e6e6e);
  margin: 0;
}

.status-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  height: 8px;
  width: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.bg-emerald-500 {
  background-color: #10b981;
}

.status-dot.bg-red-500 {
  background-color: #ef4444;
}

.status-dot.bg-yellow-500 {
  background-color: #eab308;
}

.status-dot.bg-gray-500 {
  background-color: #9ca3af;
}

.status-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--ac-text, #1a1a1a);
}

.status-timestamp {
  font-size: 11px;
  color: var(--ac-text-subtle, #a8a29e);
}

/* =============================================
   MCP Config Section
   ============================================= */
.mcp-config-section {
  border-top: 1px solid var(--ac-border, #e7e5e4);
  padding-top: 12px;
}

.mcp-config-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.mcp-config-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ac-text-muted, #6e6e6e);
  margin: 0;
}

.mcp-background-mode-section {
  border-top: 1px solid var(--ac-border, #e7e5e4);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mcp-background-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mcp-background-mode-info {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.mcp-background-mode-notice {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(16, 185, 129, 0.26);
  background: rgba(16, 185, 129, 0.08);
  color: #047857;
  font-size: 11px;
  line-height: 1.45;
}

.mcp-background-mode-state {
  flex-shrink: 0;
  border: 1px solid var(--ac-border, #e7e5e4);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ac-text-subtle, #a8a29e);
  background: var(--ac-surface-inset, #f2f0eb);
}

.mcp-background-mode-state.is-on {
  border-color: rgba(16, 185, 129, 0.26);
  color: #047857;
  background: rgba(16, 185, 129, 0.1);
}

.mcp-background-mode-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}

.mcp-background-mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mcp-background-mode-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--ac-surface-inset, #f2f0eb);
  border: 1px solid var(--ac-border, #e7e5e4);
  transition:
    background var(--ac-motion-fast, 120ms) ease,
    border-color var(--ac-motion-fast, 120ms) ease;
}

.mcp-background-mode-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--ac-surface, #ffffff);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transition: transform var(--ac-motion-fast, 120ms) ease;
}

.mcp-background-mode-toggle input:checked + .mcp-background-mode-slider {
  border-color: var(--ac-accent, #d97757);
  background: var(--ac-accent, #d97757);
}

.mcp-background-mode-toggle input:checked + .mcp-background-mode-slider::before {
  transform: translateX(18px);
}

.mcp-background-mode-toggle input:focus-visible + .mcp-background-mode-slider {
  outline: 2px solid var(--ac-accent, #d97757);
  outline-offset: 2px;
}

.copy-config-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ac-accent, #d97757);
  transition: all var(--ac-motion-fast, 120ms) ease;
}

.copy-config-button:hover {
  background: var(--ac-accent-subtle, rgba(217, 119, 87, 0.12));
}

.mcp-config-content {
  background: var(--ac-surface-inset, #f2f0eb);
  border: 1px solid var(--ac-border, #e7e5e4);
  border-radius: var(--ac-radius-inner, 8px);
  padding: 10px 12px;
  overflow-x: auto;
}

.mcp-config-json {
  font-family: var(--ac-font-code, 'JetBrains Mono', monospace);
  font-size: 11px;
  line-height: 1.5;
  color: var(--ac-text, #1a1a1a);
  margin: 0;
  white-space: pre;
  overflow-x: auto;
}

.register-command-error {
  margin: 6px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: #dc2626;
  padding: 6px 8px;
  background: rgba(239, 68, 68, 0.06);
  border-radius: var(--ac-radius-inner, 8px);
}

/* =============================================
   Register Fallback (collapsible)
   ============================================= */
.register-fallback-section {
  border-top: 1px solid var(--ac-border, #e7e5e4);
  padding-top: 12px;
}

.register-fallback-summary {
  font-size: 12px;
  font-weight: 500;
  color: var(--ac-text-muted, #6e6e6e);
  cursor: pointer;
  padding: 2px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.register-fallback-summary::-webkit-details-marker {
  display: none;
}

.register-fallback-summary::before {
  content: '▸';
  font-size: 10px;
  transition: transform var(--ac-motion-fast, 120ms) ease;
}

details.register-fallback-section[open] > .register-fallback-summary::before {
  transform: rotate(90deg);
}

.register-fallback-content {
  padding-top: 10px;
}

.register-fallback-hint {
  font-size: 11px;
  color: var(--ac-text-subtle, #a8a29e);
  margin: 0 0 8px;
  line-height: 1.4;
}

/* =============================================
   Quick Tools
   ============================================= */
.quick-tools-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.quick-tool-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px 10px;
  background: var(--ac-surface, #ffffff);
  border: var(--ac-border-width, 1px) solid var(--ac-border, #e7e5e4);
  border-radius: var(--ac-radius-card, 12px);
  cursor: pointer;
  transition: all var(--ac-motion-fast, 120ms) ease;
}

.quick-tool-item:hover:not(.quick-tool-disabled) {
  border-color: var(--ac-border-strong, #d6d3d1);
  background: var(--ac-hover-bg, #f5f5f4);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.quick-tool-item:active:not(.quick-tool-disabled) {
  transform: translateY(0);
}

.quick-tool-disabled {
  opacity: 0.45;
  cursor: default;
}

.quick-tool-disabled:hover {
  opacity: 0.55;
}

.quick-tool-item:disabled {
  cursor: default;
}

.quick-tool-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ac-radius-inner, 8px);
}

.quick-tool-icon svg {
  width: 20px;
  height: 20px;
}

.quick-tool-icon.icon-record {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.quick-tool-icon.icon-stop {
  background: rgba(185, 28, 28, 0.1);
  color: #b91c1c;
}

.quick-tool-icon.icon-edit {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

.quick-tool-icon.icon-marker {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.quick-tool-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--ac-text-muted, #6e6e6e);
  text-align: center;
  line-height: 1.2;
}

.recorded-flow-card {
  margin-top: 10px;
  padding: 10px;
  border: var(--ac-border-width, 1px) solid var(--ac-border, #e7e5e4);
  border-radius: var(--ac-radius-card, 12px);
  background: var(--ac-surface, #ffffff);
}

.recorded-flow-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.recorded-flow-title {
  font-size: 12px;
  font-weight: 600;
  margin: 0;
  color: var(--ac-text, #1a1a1a);
}

.recorded-flow-id {
  font-size: 10px;
  color: var(--ac-text-subtle, #a8a29e);
  font-family: var(--ac-font-code, 'JetBrains Mono', monospace);
}

.recorded-flow-fields {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recorded-flow-label {
  font-size: 11px;
  color: var(--ac-text-muted, #6e6e6e);
}

.recorded-flow-input {
  width: 100%;
  border: var(--ac-border-width, 1px) solid var(--ac-border, #e7e5e4);
  border-radius: var(--ac-radius-inner, 8px);
  background: var(--ac-surface-inset, #f2f0eb);
  color: var(--ac-text, #1a1a1a);
  font-size: 12px;
  padding: 8px 10px;
}

.recorded-flow-textarea {
  min-height: 68px;
  resize: vertical;
}

.recorded-flow-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.recorded-flow-btn {
  border: var(--ac-border-width, 1px) solid var(--ac-border, #e7e5e4);
  background: var(--ac-surface, #ffffff);
  color: var(--ac-text-muted, #6e6e6e);
  border-radius: var(--ac-radius-button, 8px);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.recorded-flow-btn-primary {
  border-color: transparent;
  background: var(--ac-accent, #d97757);
  color: var(--ac-accent-contrast, #ffffff);
}

.recorded-flow-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* CSS Tooltip */
.has-tooltip {
  position: relative;
}

.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  color: var(--ac-text-inverse, #ffffff);
  background-color: var(--ac-text, #1a1a1a);
  border-radius: 6px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 80ms ease, visibility 80ms ease;
  pointer-events: none;
  z-index: 100;
}

.has-tooltip::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--ac-text, #1a1a1a);
  opacity: 0;
  visibility: hidden;
  transition: opacity 80ms ease, visibility 80ms ease;
  pointer-events: none;
  z-index: 100;
}

.has-tooltip:hover::after,
.has-tooltip:hover::before {
  opacity: 1;
  visibility: visible;
}

@keyframes rr-record-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(0.8);
    opacity: 0.6;
  }
}

@keyframes popup-refresh-spin {
  to {
    transform: rotate(360deg);
  }
}

/* =============================================
   Entry Cards (Management Portal)
   ============================================= */
.entry-card {
  background: var(--ac-surface, #ffffff);
  border-radius: var(--ac-radius-card, 12px);
  border: var(--ac-border-width, 1px) solid var(--ac-border, #e7e5e4);
  overflow: hidden;
}

.entry-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ac-border, #e7e5e4);
  cursor: pointer;
  transition: all var(--ac-motion-fast, 120ms) ease;
  text-align: left;
}

.entry-item:last-child {
  border-bottom: none;
}

.entry-item:hover {
  background: var(--ac-hover-bg, #f5f5f4);
}

.entry-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ac-radius-inner, 8px);
  flex-shrink: 0;
}

.entry-icon svg {
  width: 18px;
  height: 18px;
}

.entry-icon.workflow {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

.entry-icon.marker {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.entry-content {
  flex: 1;
  min-width: 0;
}

.entry-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ac-text, #1a1a1a);
  line-height: 1.3;
}

.entry-desc {
  display: block;
  font-size: 11px;
  color: var(--ac-text-subtle, #a8a29e);
  line-height: 1.3;
  margin-top: 1px;
}

.entry-arrow {
  color: var(--ac-text-subtle, #a8a29e);
  flex-shrink: 0;
  transition: transform var(--ac-motion-fast, 120ms) ease;
}

.entry-item:hover .entry-arrow {
  transform: translateX(2px);
  color: var(--ac-text-muted, #6e6e6e);
}

/* =============================================
   Footer
   ============================================= */
.footer {
  flex-shrink: 0;
  padding: 10px 16px 12px;
  border-top: var(--ac-border-width, 1px) solid var(--ac-border, #e7e5e4);
  background: var(--ac-surface, #ffffff);
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 6px;
}

.footer-link {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--ac-text-muted, #6e6e6e);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  transition: all var(--ac-motion-fast, 120ms) ease;
}

.footer-link:hover {
  color: var(--ac-accent, #d97757);
  background: var(--ac-accent-subtle, rgba(217, 119, 87, 0.12));
}

.footer-link svg {
  width: 13px;
  height: 13px;
}

.footer-text {
  text-align: center;
  font-size: 10px;
  color: var(--ac-text-subtle, #a8a29e);
  margin: 0;
  letter-spacing: 0.03em;
}

.footer-version {
  text-align: center;
  font-size: 10px;
  color: var(--ac-text-subtle, #a8a29e);
  margin: 4px 0 0;
  font-family: var(--ac-font-code, 'JetBrains Mono', monospace);
  letter-spacing: 0.04em;
}

/* =============================================
   Icon Utilities
   ============================================= */
.icon-small {
  width: 14px;
  height: 14px;
}

.icon-default {
  width: 20px;
  height: 20px;
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 320px) {
  .popup-container {
    width: 100%;
    height: 100vh;
    border-radius: 0;
  }

  .header {
    padding: 14px 16px 10px;
  }

  .content {
    padding: 10px 14px;
  }

  .quick-tools-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .config-card {
    padding: 12px;
  }

  .footer-links {
    gap: 4px;
  }
}
